summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-02-26 00:43:13 +0800
committerruki <[email protected]>2022-02-26 00:43:13 +0800
commit9d77af7a00a833e0d42c0815877c6dc0ad5c4498 (patch)
treeba287ab375d7e9805812b94bbe6bcf8bf92748da
parentdf4777bc2a897d054e4a5706fa2a34393b37c815 (diff)
improve cl/has_flags
-rw-r--r--xmake/modules/detect/tools/cl/has_flags.lua29
-rw-r--r--xmake/modules/detect/tools/link/has_flags.lua32
-rw-r--r--xmake/modules/lib/detect/has_flags.lua4
3 files changed, 20 insertions, 45 deletions
diff --git a/xmake/modules/detect/tools/cl/has_flags.lua b/xmake/modules/detect/tools/cl/has_flags.lua
index 1c7f65325..ceb3561d4 100644
--- a/xmake/modules/detect/tools/cl/has_flags.lua
+++ b/xmake/modules/detect/tools/cl/has_flags.lua
@@ -19,28 +19,15 @@
--
-- imports
-import("core.cache.detectcache")
import("core.language.language")
+import("core.cache.global_detectcache")
-- attempt to check it from the argument list
function _check_from_arglist(flags, opt)
-
- -- only one flag?
- if #flags > 1 then
- return
- end
-
- -- make cache key
local key = "detect.tools.cl.has_flags"
-
- -- make allflags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
-
- -- get all allflags from argument list
- local allflags = detectcache:get2(key, flagskey)
+ local allflags = global_detectcache:get2(key, flagskey)
if not allflags then
-
- -- get argument list
allflags = {}
local arglist = os.iorunv(opt.program, {"-?"}, {envs = opt.envs})
if arglist then
@@ -48,12 +35,14 @@ function _check_from_arglist(flags, opt)
allflags[arg:gsub("/", "-")] = true
end
end
-
- -- save cache
- detectcache:set2(key, flagskey, allflags)
- detectcache:save()
+ global_detectcache:set2(key, flagskey, allflags)
+ global_detectcache:save()
+ end
+ local flag = flags[1]:gsub("/", "-")
+ if flag:startswith("-D") or flag:startswith("-I") then
+ return true
end
- return allflags[flags[1]:gsub("/", "-")]
+ return allflags[flag]
end
-- get extension
diff --git a/xmake/modules/detect/tools/link/has_flags.lua b/xmake/modules/detect/tools/link/has_flags.lua
index e0e2d8292..b7d93fe34 100644
--- a/xmake/modules/detect/tools/link/has_flags.lua
+++ b/xmake/modules/detect/tools/link/has_flags.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("core.cache.detectcache")
+import("core.cache.global_detectcache")
import("lib.detect.find_tool")
-- try running
@@ -30,30 +30,15 @@ end
-- attempt to check it from the argument list
function _check_from_arglist(flags, opt)
-
- -- only one flag?
- if #flags > 1 then
- return
- end
-
- -- make cache key
local key = "detect.tools.link.has_flags"
-
- -- make allflags key
local flagskey = opt.program .. "_" .. (opt.programver or "")
-
- -- get all allflags from argument list
- local allflags = detectcache:get2(key, flagskey)
+ local allflags = global_detectcache:get2(key, flagskey)
if not allflags then
-
- -- get argument list
allflags = {}
local arglist = nil
- try
- {
+ try {
function () os.runv(opt.program, {"-?"}, {envs = opt.envs}) end,
- catch
- {
+ catch {
function (errors) arglist = errors end
}
}
@@ -62,12 +47,11 @@ function _check_from_arglist(flags, opt)
allflags[arg:gsub("/", "-"):lower()] = true
end
end
-
- -- save cache
- detectcache:set2(key, flagskey, allflags)
- detectcache:save()
+ global_detectcache:set2(key, flagskey, allflags)
+ global_detectcache:save()
end
- return allflags[flags[1]:gsub("/", "-"):lower()]
+ local flag = flags[1]:gsub("/", "-"):lower()
+ return allflags[flag]
end
-- try running to check flags
diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua
index 4559f7959..88bb958b5 100644
--- a/xmake/modules/lib/detect/has_flags.lua
+++ b/xmake/modules/lib/detect/has_flags.lua
@@ -73,7 +73,9 @@ function main(name, flags, opt)
local arch = opt.arch or config.get("arch") or os.arch()
-- init cache key
- local key = plat .. "_" .. arch .. "_" .. tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. (opt.flagkind or "") .. "_" .. table.concat(opt.sysflags, " ") .. "_" .. opt.flagskey
+ local key = plat .. "_" .. arch .. "_" .. tool.program .. "_"
+ .. (tool.version or "") .. "_" .. (opt.toolkind or "")
+ .. "_" .. (opt.flagkind or "") .. "_" .. table.concat(opt.sysflags, " ") .. "_" .. opt.flagskey
-- @note avoid detect the same program in the same time if running in the coroutine (e.g. ccache)
local coroutine_running = scheduler.co_running()