Skip to content

Commit f9e895a

Browse files
committed
improve to find program
1 parent d8a33ac commit f9e895a

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

xmake/core/sandbox/modules/import/lib/detect/find_program.lua

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,6 @@ end
178178
-- find program
179179
function sandbox_lib_detect_find_program._find(name, paths, opt)
180180

181-
-- valid program file?
182-
if path.is_absolute(name) and os.isfile(name) then
183-
return name
184-
end
185-
186181
-- attempt to find it from the given directories
187182
local program_path = sandbox_lib_detect_find_program._find_from_paths(name, paths, opt)
188183
if program_path and opt.system ~= false then
@@ -205,7 +200,11 @@ function sandbox_lib_detect_find_program._find(name, paths, opt)
205200
if not program_name:endswith(".exe") then
206201
program_name = program_name .. ".exe"
207202
end
208-
program_path = winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" .. program_name)
203+
if path.is_absolute(program_name) and os.isfile(program_name) then
204+
program_path = program_name
205+
else
206+
program_path = winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" .. program_name)
207+
end
209208
if program_path then
210209
program_path = program_path:trim()
211210
if os.isexec(program_path) then
@@ -216,10 +215,19 @@ function sandbox_lib_detect_find_program._find(name, paths, opt)
216215
end
217216
end
218217
else
219-
-- attempt to find it use `which program` command
220-
local ok, program_path = os.iorunv("which", {name})
221-
if ok and program_path then
222-
program_path = program_path:trim()
218+
if path.is_absolute(name) and os.isfile(name) then
219+
program_path = name
220+
else
221+
-- attempt to find it use `which program` command
222+
local ok, result = os.iorunv("which", {name})
223+
if ok and result then
224+
program_path = result:trim()
225+
else
226+
program_path = nil
227+
end
228+
end
229+
230+
if program_path then
223231
local program_path_real = sandbox_lib_detect_find_program._check(program_path, opt)
224232
if program_path_real then
225233
return program_path_real

0 commit comments

Comments
 (0)