Skip to content

Call where in find_program #5104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions xmake/core/sandbox/modules/import/lib/detect/find_program.lua
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,28 @@ function sandbox_lib_detect_find_program._find(name, paths, opt)
if program_path_real then
return program_path_real
end

-- attempt to find it use `where.exe program.exe` command
--
-- and we need to add `.exe` suffix to avoid find some incorrect programs. e.g. pkg-config.bat
if os.host() == "windows" then
local program_name = name:lower()
if not program_name:endswith(".exe") then
program_name = program_name .. ".exe"
end
local ok, wherepaths = os.iorunv("where.exe", {program_name})
if ok and wherepaths then
for _, program_path in ipairs(wherepaths:split("\n")) do
program_path = program_path:trim()
if #program_path > 0 then
local program_path_real = sandbox_lib_detect_find_program._check(program_path, opt)
if program_path_real then
return program_path_real
end
end
end
end
end
end

-- find program
Expand Down
38 changes: 38 additions & 0 deletions xmake/modules/detect/tools/find_where.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--!A cross-platform build utility based on Lua
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file find_where.lua
--

-- imports
import("lib.detect.find_program")

-- find where
--
-- @code
-- local where = find_where()
-- @endcode
--
function main(opt)
opt = opt or {}
opt.check = "/?"
local program
if is_host("windows") then
program = find_program(opt.program or "where.exe", opt)
end
return program
end
18 changes: 4 additions & 14 deletions xmake/toolchains/llvm/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
-- imports
import("core.project.config")
import("lib.detect.find_path")
import("lib.detect.find_tool")
import("detect.sdks.find_xcode")
import("detect.sdks.find_cross_toolchain")

Expand Down Expand Up @@ -64,7 +65,6 @@ function main(toolchain)
elseif is_host("linux") and os.isfile("/usr/bin/llvm-ar") then
sdkdir = "/usr"
elseif is_host("macosx") then
local bindir
if os.arch() == "arm64" then
bindir = find_path("llvm-ar", "/opt/homebrew/opt/llvm/bin")
else
Expand All @@ -74,19 +74,9 @@ function main(toolchain)
sdkdir = path.directory(bindir)
end
elseif is_host("windows") then
bindir = try {function () return path.directory(os.iorunv("where", {"llvm-ar.exe"})) end}
if not bindir then
local pathenv = os.getenv("PATH")
if pathenv then
for _, v in ipairs(path.splitenv(pathenv)) do
if os.isfile(path.join(v, "llvm-ar.exe")) then
bindir = v
break
end
end
end
end
if bindir then
local llvm_ar = find_tool("llvm-ar", {force = true, envs = {PATH = os.getenvs("PATH")}})
if llvm_ar and llvm_ar.program and os.isfile(llvm_ar.program) then
bindir = path.directory(llvm_ar.program)
sdkdir = path.directory(bindir)
end
end
Expand Down
Loading