From 54bc2d2a3f07b875bafa4437c8b7138eed8641a7 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 17 Sep 2025 00:42:39 +0800 Subject: improve find_program --- xmake/core/sandbox/modules/import/lib/detect/find_program.lua | 5 +++++ 1 file changed, 5 insertions(+) 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..e1379bf44 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua @@ -178,6 +178,11 @@ end -- find program function sandbox_lib_detect_find_program._find(name, paths, opt) + -- valid program file? + if path.is_absolute(name) and os.isfile(name) then + return name + end + -- attempt to find it from the given directories local program_path = sandbox_lib_detect_find_program._find_from_paths(name, paths, opt) if program_path and opt.system ~= false then -- cgit v1.3.1 From d8a33ac4341a747119b151efdfa50d9d50660926 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 17 Sep 2025 00:46:58 +0800 Subject: improve xcode --- xmake/toolchains/xcode/xmake.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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") -- cgit v1.3.1 From f9e895a3d33d021d4ddda6be9dfc4bacf358e6ea Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 17 Sep 2025 00:50:16 +0800 Subject: improve to find program --- .../modules/import/lib/detect/find_program.lua | 28 ++++++++++++++-------- 1 file changed, 18 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 e1379bf44..7c53d0a03 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua @@ -178,11 +178,6 @@ end -- find program function sandbox_lib_detect_find_program._find(name, paths, opt) - -- valid program file? - if path.is_absolute(name) and os.isfile(name) then - return name - end - -- attempt to find it from the given directories local program_path = sandbox_lib_detect_find_program._find_from_paths(name, paths, opt) if program_path and opt.system ~= false then @@ -205,7 +200,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 @@ -216,10 +215,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 -- cgit v1.3.1 From 63c49fb4d349a51899a04a6de77e79623cfa43f1 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 17 Sep 2025 00:52:40 +0800 Subject: improve to find gcc/clang --- xmake/core/sandbox/modules/import/lib/detect/find_program.lua | 3 +++ xmake/modules/detect/tools/find_clang.lua | 1 + xmake/modules/detect/tools/find_clangxx.lua | 1 + xmake/modules/detect/tools/find_gcc.lua | 1 + xmake/modules/detect/tools/find_gxx.lua | 2 +- 5 files changed, 7 insertions(+), 1 deletion(-) 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 7c53d0a03..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 @@ -295,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/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_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 -- cgit v1.3.1 From 8f2b49d09f78829ebca18c910647421e3509c9b5 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 17 Sep 2025 00:53:34 +0800 Subject: improve to find cl --- xmake/modules/detect/tools/find_ar.lua | 3 ++- xmake/modules/detect/tools/find_cl.lua | 7 +++---- xmake/modules/detect/tools/find_clang_cl.lua | 9 ++------- xmake/modules/detect/tools/find_link.lua | 1 + xmake/modules/detect/tools/find_llvm_ar.lua | 8 ++------ xmake/modules/detect/tools/find_ml.lua | 14 ++++++-------- xmake/modules/detect/tools/find_ml64.lua | 16 ++++++---------- 7 files changed, 22 insertions(+), 36 deletions(-) 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_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_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 -- cgit v1.3.1 From 1833ec0da4395ba3a25bd93d357eaee8083b8428 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 16 Sep 2025 23:34:01 +0800 Subject: Refactor clang check to use startswith method --- xmake/modules/core/tools/gcc.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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)} -- cgit v1.3.1