diff options
| author | ruki <[email protected]> | 2025-09-17 11:45:56 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-17 11:45:56 +0800 |
| commit | 37e64cd80c7793a12b76f20b62fc98687843d9ca (patch) | |
| tree | 89216ac99f40e30973a7bd62df1b739b7abbaf2c | |
| parent | a133d583ac95a4ecbdf646d54797886cc0389802 (diff) | |
| parent | 1833ec0da4395ba3a25bd93d357eaee8083b8428 (diff) | |
Merge pull request #6817 from xmake-io/opti
Improve build targets
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_program.lua | 26 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_ar.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_cl.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_clang.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_clang_cl.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_clangxx.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_gcc.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_gxx.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_link.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_llvm_ar.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_ml.lua | 14 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_ml64.lua | 16 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/xmake.lua | 4 |
14 files changed, 51 insertions, 46 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 68fbc59ae..858b413e8 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua @@ -43,6 +43,8 @@ function sandbox_lib_detect_find_program._do_check(program, opt) -- do not attempt to run program? check it fastly if opt.norun then return os.isfile(program) + elseif opt.norunfile and path.is_absolute(program) and os.isfile(program) then + return true end -- no check script? attempt to run it directly @@ -200,7 +202,11 @@ function sandbox_lib_detect_find_program._find(name, paths, opt) if not program_name:endswith(".exe") then program_name = program_name .. ".exe" end - program_path = winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" .. program_name) + if path.is_absolute(program_name) and os.isfile(program_name) then + program_path = program_name + else + program_path = winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" .. program_name) + end if program_path then program_path = program_path:trim() if os.isexec(program_path) then @@ -211,10 +217,19 @@ function sandbox_lib_detect_find_program._find(name, paths, opt) end end else - -- attempt to find it use `which program` command - local ok, program_path = os.iorunv("which", {name}) - if ok and program_path then - program_path = program_path:trim() + if path.is_absolute(name) and os.isfile(name) then + program_path = name + else + -- attempt to find it use `which program` command + local ok, result = os.iorunv("which", {name}) + if ok and result then + program_path = result:trim() + else + program_path = nil + end + end + + if program_path then local program_path_real = sandbox_lib_detect_find_program._check(program_path, opt) if program_path_real then return program_path_real @@ -282,6 +297,7 @@ end -- - opt.paths the program paths (e.g. dirs, paths, winreg paths, script paths) -- - opt.check the check script or command -- - opt.norun do not attempt to run program to check program fastly +-- - opt.norunfile do not attempt to run program to check program if it's valid file path. -- - opt.system true: only find it from system, false: only find it from xmake/packages -- -- @return the program name or path diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 5824ae40d..f4cd684e0 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -867,7 +867,7 @@ function nf_pmheader(self, pcheaderfile, opt) if self:kind() == "mm" then local target = opt.target local pcoutputfile = target:pcoutputfile("m") - if self:name() == "clang" then + if self:name():startswith("clang") then return {"-include", pcheaderfile, "-include-pch", pcoutputfile} else return {"-I", path.directory(pcoutputfile), "-include", path.filename(pcheaderfile)} @@ -880,7 +880,7 @@ function nf_pmxxheader(self, pcheaderfile, opt) if self:kind() == "mxx" then local target = opt.target local pcoutputfile = target:pcoutputfile("mxx") - if self:name() == "clang" then + if self:name():startswith("clang") then return {"-include", pcheaderfile, "-include-pch", pcoutputfile} else return {"-I", path.directory(pcoutputfile), "-include", path.filename(pcheaderfile)} diff --git a/xmake/modules/detect/tools/find_ar.lua b/xmake/modules/detect/tools/find_ar.lua index 47dc11276..caac33278 100644 --- a/xmake/modules/detect/tools/find_ar.lua +++ b/xmake/modules/detect/tools/find_ar.lua @@ -51,7 +51,8 @@ end -- @endcode -- function main(opt) - opt = opt or {} + opt = opt or {} opt.check = opt.check or _check + opt.norunfile = true return find_program(opt.program or "ar", opt) end diff --git a/xmake/modules/detect/tools/find_cl.lua b/xmake/modules/detect/tools/find_cl.lua index f7c970987..2e38cd71f 100644 --- a/xmake/modules/detect/tools/find_cl.lua +++ b/xmake/modules/detect/tools/find_cl.lua @@ -35,10 +35,9 @@ import("lib.detect.find_programver") -- @endcode -- function main(opt) - - -- init options - opt = opt or {} - opt.check = opt.check or function (program) + opt = opt or {} + opt.norunfile = true + opt.check = opt.check or function (program) local ok = try { function () os.runv(program, {}, {envs = opt.envs}); return true end } if not ok then -- @see https://github.com/xmake-io/xmake/issues/3057 diff --git a/xmake/modules/detect/tools/find_clang.lua b/xmake/modules/detect/tools/find_clang.lua index 764a7beb5..6f742b774 100644 --- a/xmake/modules/detect/tools/find_clang.lua +++ b/xmake/modules/detect/tools/find_clang.lua @@ -37,6 +37,7 @@ import("lib.detect.find_programver") -- function main(opt) opt = opt or {} + opt.norunfile = true local program = find_program(opt.program or "clang", opt) local version = nil if program and opt and opt.version then diff --git a/xmake/modules/detect/tools/find_clang_cl.lua b/xmake/modules/detect/tools/find_clang_cl.lua index f222f2989..e297fa250 100644 --- a/xmake/modules/detect/tools/find_clang_cl.lua +++ b/xmake/modules/detect/tools/find_clang_cl.lua @@ -35,15 +35,10 @@ import("lib.detect.find_programver") -- @endcode -- function main(opt) - - -- init options opt = opt or {} - - -- find program - local program = find_program(opt.program or "clang-cl.exe", opt) - - -- find program version + opt.norunfile = true local version = nil + local program = find_program(opt.program or "clang-cl.exe", opt) if program and opt and opt.version then version = find_programver(program, opt) end diff --git a/xmake/modules/detect/tools/find_clangxx.lua b/xmake/modules/detect/tools/find_clangxx.lua index c6dba4d6a..a48fa99cc 100644 --- a/xmake/modules/detect/tools/find_clangxx.lua +++ b/xmake/modules/detect/tools/find_clangxx.lua @@ -37,6 +37,7 @@ import("lib.detect.find_programver") -- function main(opt) opt = opt or {} + opt.norunfile = true local program = find_program(opt.program or "clang++", opt) local version = nil if program and opt and opt.version then diff --git a/xmake/modules/detect/tools/find_gcc.lua b/xmake/modules/detect/tools/find_gcc.lua index d63c5d1b6..b8c7b71a5 100644 --- a/xmake/modules/detect/tools/find_gcc.lua +++ b/xmake/modules/detect/tools/find_gcc.lua @@ -53,6 +53,7 @@ end -- function main(opt) opt = opt or {} + opt.norunfile = true local program = find_program(opt.program or "gcc", opt) local version = nil if program and opt.version then diff --git a/xmake/modules/detect/tools/find_gxx.lua b/xmake/modules/detect/tools/find_gxx.lua index f218dc415..c25248541 100644 --- a/xmake/modules/detect/tools/find_gxx.lua +++ b/xmake/modules/detect/tools/find_gxx.lua @@ -37,8 +37,8 @@ import("detect.tools.find_gcc") -- @endcode -- function main(opt) - opt = opt or {} + opt.norunfile = true local program = find_program(opt.program or "g++", opt) local version = nil if program and opt and opt.version then diff --git a/xmake/modules/detect/tools/find_link.lua b/xmake/modules/detect/tools/find_link.lua index 16a0e478b..7966e2ede 100644 --- a/xmake/modules/detect/tools/find_link.lua +++ b/xmake/modules/detect/tools/find_link.lua @@ -43,6 +43,7 @@ function main(opt) -- init options opt = opt or {} + opt.norunfile = true opt.check = opt.check or function (program) local toolchain = opt.toolchain if toolchain and toolchain:name() == "masm32" then diff --git a/xmake/modules/detect/tools/find_llvm_ar.lua b/xmake/modules/detect/tools/find_llvm_ar.lua index 44fe88628..ba3c29dc9 100644 --- a/xmake/modules/detect/tools/find_llvm_ar.lua +++ b/xmake/modules/detect/tools/find_llvm_ar.lua @@ -37,17 +37,13 @@ import("lib.detect.find_programver") -- @endcode -- function main(opt) - - -- init options opt = opt or {} + opt.norunfile = true opt.check = opt.check or "-h" opt.command = opt.command or "--version" - -- find program - local program = find_program(opt.program or "llvm-ar", opt) - - -- find program version local version = nil + local program = find_program(opt.program or "llvm-ar", opt) if program and opt.version then version = find_programver(program, opt) end diff --git a/xmake/modules/detect/tools/find_ml.lua b/xmake/modules/detect/tools/find_ml.lua index 513fe31ab..3163130c2 100644 --- a/xmake/modules/detect/tools/find_ml.lua +++ b/xmake/modules/detect/tools/find_ml.lua @@ -35,16 +35,14 @@ import("lib.detect.find_programver") -- @endcode -- function main(opt) + opt = opt or {} + opt.norunfile = true + opt.check = opt.check or function (program) + os.runv(program, {}, {envs = opt.envs}) + end - -- init options - opt = opt or {} - opt.check = opt.check or function (program) os.runv(program, {}, {envs = opt.envs}) end - - -- find program - local program = find_program(opt.program or "ml.exe", opt) - - -- find program version local version = nil + local program = find_program(opt.program or "ml.exe", opt) if program and opt and opt.version then opt.command = opt.command or function () local _, info = os.iorunv(program, {}, {envs = opt.envs}); return info end opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end diff --git a/xmake/modules/detect/tools/find_ml64.lua b/xmake/modules/detect/tools/find_ml64.lua index 1535fc6e8..8551fc414 100644 --- a/xmake/modules/detect/tools/find_ml64.lua +++ b/xmake/modules/detect/tools/find_ml64.lua @@ -35,23 +35,19 @@ import("lib.detect.find_programver") -- @endcode -- function main(opt) + opt = opt or {} + opt.norunfile = true + opt.check = opt.check or function (program) + os.runv(program, {}, {envs = opt.envs}) + end - -- init options - opt = opt or {} - opt.check = opt.check or function (program) os.runv(program, {}, {envs = opt.envs}) end - - -- find program - local program = find_program(opt.program or "ml64.exe", opt) - - -- find program version local version = nil + local program = find_program(opt.program or "ml64.exe", opt) if program and opt and opt.version then opt.command = opt.command or function () local _, info = os.iorunv(program, {}, {envs = opt.envs}); return info end opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end version = find_programver(program, opt) end - - -- ok? return program, version end diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 87df96fa6..dfe224d29 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -40,14 +40,14 @@ toolchain("xcode") local xc_dsymutil = bindir and path.join(bindir, "dsymutil") or "dsymutil" toolchain:set("toolset", "cc", xc_clang) - toolchain:set("toolset", "cxx", xc_clang, xc_clangxx) + toolchain:set("toolset", "cxx", xc_clangxx, xc_clang) toolchain:set("toolset", "ld", xc_clangxx, xc_clang) toolchain:set("toolset", "sh", xc_clangxx, xc_clang) toolchain:set("toolset", "ar", xc_ar) toolchain:set("toolset", "strip", xc_strip) toolchain:set("toolset", "dsymutil", xc_dsymutil, "dsymutil") toolchain:set("toolset", "mm", xc_clang) - toolchain:set("toolset", "mxx", xc_clang, xc_clangxx) + toolchain:set("toolset", "mxx", xc_clangxx, xc_clang) toolchain:set("toolset", "sc", xc_swift_frontend, "swift_frontend", xc_swiftc, "swiftc") toolchain:set("toolset", "scld", xc_swiftc, "swiftc") toolchain:set("toolset", "scsh", xc_swiftc, "swiftc") |
