summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-05-16 23:14:25 +0800
committerruki <[email protected]>2024-05-16 23:14:25 +0800
commitf13e6a5bf8965ee36fc940333010504eba357d6d (patch)
tree84ec8e5224695c505d801382ad497a36c428110d
parentea920486c914a69b159832065816ebd17273b094 (diff)
fix find where
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_program.lua32
1 files changed, 22 insertions, 10 deletions
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
index 160cae2d6..3923916d9 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
@@ -205,16 +205,6 @@ function sandbox_lib_detect_find_program._find(name, paths, opt)
end
end
end
-
- -- attempt to find it use `where.exe program` command
- local ok, program_path = os.iorunv("where.exe", {name})
- if ok and program_path then
- program_path = program_path:trim()
- local program_path_real = sandbox_lib_detect_find_program._check(program_path, opt)
- if program_path_real then
- return program_path_real
- end
- end
else
-- attempt to find it use `which program` command
local ok, program_path = os.iorunv("which", {name})
@@ -253,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