summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-19 08:59:27 +0800
committerGitHub <[email protected]>2025-09-19 08:59:27 +0800
commit7186aec3786cd31f4dea25716ddf57954bef5bf6 (patch)
tree21d35f7099aeb6587b29c651ad6397b821768c1b /xmake/modules
parent44812793dd6e8c9cae32bf8517d516709e91b3db (diff)
parente8a0b0b9d8ad08e0ab3efe5962c10017d84aaf9f (diff)
Merge pull request #6824 from xmake-io/opti
Improve has_flags
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/core/tools/cl/has_flags.lua13
-rw-r--r--xmake/modules/core/tools/gcc/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/find_cmake.lua1
-rw-r--r--xmake/modules/detect/tools/find_ninja.lua1
-rw-r--r--xmake/modules/lib/detect/find_tool.lua11
-rw-r--r--xmake/modules/lib/detect/has_flags.lua6
6 files changed, 36 insertions, 9 deletions
diff --git a/xmake/modules/core/tools/cl/has_flags.lua b/xmake/modules/core/tools/cl/has_flags.lua
index 487338a0b..48884b340 100644
--- a/xmake/modules/core/tools/cl/has_flags.lua
+++ b/xmake/modules/core/tools/cl/has_flags.lua
@@ -21,10 +21,19 @@
-- imports
import("core.language.language")
import("core.cache.global_detectcache")
+import("core.base.hashset")
-- attempt to check it from known flags
function _check_from_knownargs(flags, opt)
local flag = flags[1]:gsub("/", "-")
+ local known_flags = _g.known_flags
+ if known_flags == nil then
+ known_flags = hashset.from({"-Ox", "-O1", "-O2", "-Od", "-MT", "-MD", "-MTd", "-MDd", "-EHsc"})
+ _g.known_flags = known_flags
+ end
+ if known_flags:has(flag) then
+ return true
+ end
if flag:startswith("-D") or
flag:startswith("-U") or
flag:startswith("-I") then
@@ -105,10 +114,10 @@ function main(flags, opt)
-- attempt to check it from the argument list
opt = opt or {}
if not opt.tryrun then
- if _check_from_arglist(flags, opt) then
+ if _check_from_knownargs(flags, opt) then
return true
end
- if _check_from_knownargs(flags, opt) then
+ if _check_from_arglist(flags, opt) then
return true
end
end
diff --git a/xmake/modules/core/tools/gcc/has_flags.lua b/xmake/modules/core/tools/gcc/has_flags.lua
index 731e5da2f..4d001ef6e 100644
--- a/xmake/modules/core/tools/gcc/has_flags.lua
+++ b/xmake/modules/core/tools/gcc/has_flags.lua
@@ -21,6 +21,7 @@
-- imports
import("core.cache.detectcache")
import("core.language.language")
+import("core.base.hashset")
-- is linker?
function _islinker(flags, opt)
@@ -45,6 +46,14 @@ end
-- attempt to check it from known flags
function _check_from_knownargs(flags, opt, islinker)
local flag = flags[1]
+ local known_flags = _g.known_flags
+ if known_flags == nil then
+ known_flags = hashset.from({"-O", "-O0", "-O1", "-O2", "-O3", "-Os", "-g"})
+ _g.known_flags = known_flags
+ end
+ if known_flags:has(flag) then
+ return true
+ end
if not islinker then
if flag:startswith("-D") or
flag:startswith("-U") or
@@ -119,10 +128,10 @@ function main(flags, opt)
-- attempt to check it from the argument list
if not opt.tryrun then
- if _check_from_arglist(flags, opt, islinker) then
+ if _check_from_knownargs(flags, opt, islinker) then
return true
end
- if _check_from_knownargs(flags, opt, islinker) then
+ if _check_from_arglist(flags, opt, islinker) then
return true
end
end
diff --git a/xmake/modules/detect/tools/find_cmake.lua b/xmake/modules/detect/tools/find_cmake.lua
index cebb5487d..a9267543d 100644
--- a/xmake/modules/detect/tools/find_cmake.lua
+++ b/xmake/modules/detect/tools/find_cmake.lua
@@ -40,6 +40,7 @@ function main(opt)
-- init options
opt = opt or {}
+ opt.norunfile = true
if is_host("windows") then
opt.paths = "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware\\CMake;InstallDir)\\bin"
end
diff --git a/xmake/modules/detect/tools/find_ninja.lua b/xmake/modules/detect/tools/find_ninja.lua
index 4a03d9e41..06b95f24c 100644
--- a/xmake/modules/detect/tools/find_ninja.lua
+++ b/xmake/modules/detect/tools/find_ninja.lua
@@ -40,6 +40,7 @@ function main(opt)
-- find program
opt = opt or {}
+ opt.norunfile = true
local program = find_program(opt.program or "ninja", opt)
if not program and is_host("windows") then
local msvc = toolchain.load("msvc", {plat = os.host(), arch = os.arch()})
diff --git a/xmake/modules/lib/detect/find_tool.lua b/xmake/modules/lib/detect/find_tool.lua
index ddf96753e..dc30b314a 100644
--- a/xmake/modules/lib/detect/find_tool.lua
+++ b/xmake/modules/lib/detect/find_tool.lua
@@ -33,16 +33,21 @@ function _find_from_modules(name, opt)
if program then
return {name = toolname or name, program = program, version = version}
end
+ return false
end
+ return nil
end
-- find tool
function _find_tool(name, opt)
local toolname = find_toolname(name or opt.program)
if toolname then
- local tool = _find_from_modules(toolname, opt)
- if tool then
- return tool
+ local result = _find_from_modules(toolname, opt)
+ if result then
+ return result
+ elseif result == false then
+ -- find_xxx.lua exists, but program not found
+ return
end
end
diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua
index b122bcebb..36409ef84 100644
--- a/xmake/modules/lib/detect/has_flags.lua
+++ b/xmake/modules/lib/detect/has_flags.lua
@@ -53,8 +53,10 @@ function main(name, flags, opt)
opt.flagskey = opt.flagskey or table.concat(flags, " ")
opt.sysflags = table.wrap(opt.sysflags)
+ -- @note avoid running additional `program --version` processes
+ --opt.version = true
+
-- find tool program and version first
- opt.version = true
local tool = find_tool(name, opt)
if not tool then
return false
@@ -63,7 +65,7 @@ function main(name, flags, opt)
-- init tool
opt.toolname = tool.name
opt.program = tool.program
- opt.programver = tool.version
+ --opt.programver = tool.version
-- get tool platform
local plat = opt.plat or config.get("plat") or os.host()