Skip to content

Commit 37e64cd

Browse files
authored
Merge pull request #6817 from xmake-io/opti
Improve build targets
2 parents a133d58 + 1833ec0 commit 37e64cd

File tree

14 files changed

+51
-46
lines changed

14 files changed

+51
-46
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function sandbox_lib_detect_find_program._do_check(program, opt)
4343
-- do not attempt to run program? check it fastly
4444
if opt.norun then
4545
return os.isfile(program)
46+
elseif opt.norunfile and path.is_absolute(program) and os.isfile(program) then
47+
return true
4648
end
4749

4850
-- no check script? attempt to run it directly
@@ -200,7 +202,11 @@ function sandbox_lib_detect_find_program._find(name, paths, opt)
200202
if not program_name:endswith(".exe") then
201203
program_name = program_name .. ".exe"
202204
end
203-
program_path = winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" .. program_name)
205+
if path.is_absolute(program_name) and os.isfile(program_name) then
206+
program_path = program_name
207+
else
208+
program_path = winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" .. program_name)
209+
end
204210
if program_path then
205211
program_path = program_path:trim()
206212
if os.isexec(program_path) then
@@ -211,10 +217,19 @@ function sandbox_lib_detect_find_program._find(name, paths, opt)
211217
end
212218
end
213219
else
214-
-- attempt to find it use `which program` command
215-
local ok, program_path = os.iorunv("which", {name})
216-
if ok and program_path then
217-
program_path = program_path:trim()
220+
if path.is_absolute(name) and os.isfile(name) then
221+
program_path = name
222+
else
223+
-- attempt to find it use `which program` command
224+
local ok, result = os.iorunv("which", {name})
225+
if ok and result then
226+
program_path = result:trim()
227+
else
228+
program_path = nil
229+
end
230+
end
231+
232+
if program_path then
218233
local program_path_real = sandbox_lib_detect_find_program._check(program_path, opt)
219234
if program_path_real then
220235
return program_path_real
@@ -282,6 +297,7 @@ end
282297
-- - opt.paths the program paths (e.g. dirs, paths, winreg paths, script paths)
283298
-- - opt.check the check script or command
284299
-- - opt.norun do not attempt to run program to check program fastly
300+
-- - opt.norunfile do not attempt to run program to check program if it's valid file path.
285301
-- - opt.system true: only find it from system, false: only find it from xmake/packages
286302
--
287303
-- @return the program name or path

xmake/modules/core/tools/gcc.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ function nf_pmheader(self, pcheaderfile, opt)
867867
if self:kind() == "mm" then
868868
local target = opt.target
869869
local pcoutputfile = target:pcoutputfile("m")
870-
if self:name() == "clang" then
870+
if self:name():startswith("clang") then
871871
return {"-include", pcheaderfile, "-include-pch", pcoutputfile}
872872
else
873873
return {"-I", path.directory(pcoutputfile), "-include", path.filename(pcheaderfile)}
@@ -880,7 +880,7 @@ function nf_pmxxheader(self, pcheaderfile, opt)
880880
if self:kind() == "mxx" then
881881
local target = opt.target
882882
local pcoutputfile = target:pcoutputfile("mxx")
883-
if self:name() == "clang" then
883+
if self:name():startswith("clang") then
884884
return {"-include", pcheaderfile, "-include-pch", pcoutputfile}
885885
else
886886
return {"-I", path.directory(pcoutputfile), "-include", path.filename(pcheaderfile)}

xmake/modules/detect/tools/find_ar.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ end
5151
-- @endcode
5252
--
5353
function main(opt)
54-
opt = opt or {}
54+
opt = opt or {}
5555
opt.check = opt.check or _check
56+
opt.norunfile = true
5657
return find_program(opt.program or "ar", opt)
5758
end

xmake/modules/detect/tools/find_cl.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ import("lib.detect.find_programver")
3535
-- @endcode
3636
--
3737
function main(opt)
38-
39-
-- init options
40-
opt = opt or {}
41-
opt.check = opt.check or function (program)
38+
opt = opt or {}
39+
opt.norunfile = true
40+
opt.check = opt.check or function (program)
4241
local ok = try { function () os.runv(program, {}, {envs = opt.envs}); return true end }
4342
if not ok then
4443
-- @see https://github.com/xmake-io/xmake/issues/3057

xmake/modules/detect/tools/find_clang.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import("lib.detect.find_programver")
3737
--
3838
function main(opt)
3939
opt = opt or {}
40+
opt.norunfile = true
4041
local program = find_program(opt.program or "clang", opt)
4142
local version = nil
4243
if program and opt and opt.version then

xmake/modules/detect/tools/find_clang_cl.lua

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ import("lib.detect.find_programver")
3535
-- @endcode
3636
--
3737
function main(opt)
38-
39-
-- init options
4038
opt = opt or {}
41-
42-
-- find program
43-
local program = find_program(opt.program or "clang-cl.exe", opt)
44-
45-
-- find program version
39+
opt.norunfile = true
4640
local version = nil
41+
local program = find_program(opt.program or "clang-cl.exe", opt)
4742
if program and opt and opt.version then
4843
version = find_programver(program, opt)
4944
end

xmake/modules/detect/tools/find_clangxx.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import("lib.detect.find_programver")
3737
--
3838
function main(opt)
3939
opt = opt or {}
40+
opt.norunfile = true
4041
local program = find_program(opt.program or "clang++", opt)
4142
local version = nil
4243
if program and opt and opt.version then

xmake/modules/detect/tools/find_gcc.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ end
5353
--
5454
function main(opt)
5555
opt = opt or {}
56+
opt.norunfile = true
5657
local program = find_program(opt.program or "gcc", opt)
5758
local version = nil
5859
if program and opt.version then

xmake/modules/detect/tools/find_gxx.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import("detect.tools.find_gcc")
3737
-- @endcode
3838
--
3939
function main(opt)
40-
4140
opt = opt or {}
41+
opt.norunfile = true
4242
local program = find_program(opt.program or "g++", opt)
4343
local version = nil
4444
if program and opt and opt.version then

xmake/modules/detect/tools/find_link.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function main(opt)
4343

4444
-- init options
4545
opt = opt or {}
46+
opt.norunfile = true
4647
opt.check = opt.check or function (program)
4748
local toolchain = opt.toolchain
4849
if toolchain and toolchain:name() == "masm32" then

0 commit comments

Comments
 (0)