summaryrefslogtreecommitdiff
path: root/xmake/modules/lib/detect/has_flags.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2019-07-23 13:57:34 +0800
committerGitHub <[email protected]>2019-07-23 13:57:34 +0800
commit536bfe31ce652068d331a561a4f615df5c141218 (patch)
treee6a9f293b32156bf6eb76042e4b99a3de8e3e895 /xmake/modules/lib/detect/has_flags.lua
parent42f44fa0a7a7c44a2e4eab067ebf56364bfabc2f (diff)
parent49f14868b5fa9bca4aa2f51ea2b70f9edae89cb6 (diff)
Merge pull request #506 from OpportunityLiu/dev
improve check flags with file
Diffstat (limited to 'xmake/modules/lib/detect/has_flags.lua')
-rw-r--r--xmake/modules/lib/detect/has_flags.lua63
1 files changed, 35 insertions, 28 deletions
diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua
index d409e4217..bebe836d2 100644
--- a/xmake/modules/lib/detect/has_flags.lua
+++ b/xmake/modules/lib/detect/has_flags.lua
@@ -28,7 +28,7 @@ import("lib.detect.find_tool")
--
-- @param name the tool name
-- @param flags the flags
--- @param opt the argument options, .e.g {verbose = false, program = "", sysflags = {}, flagkind = "cxflag", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"}
+-- @param opt the argument options, .e.g { verbose = false, program = "", sysflags = {}, flagkind = "cxflag", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]", flagskey = "custom key" }
--
-- @return true or false
--
@@ -40,8 +40,12 @@ import("lib.detect.find_tool")
--
function main(name, flags, opt)
+ flags = table.wrap(flags)
+
-- init options
opt = opt or {}
+ opt.flagskey = opt.flagskey or table.concat(flags, " ")
+ opt.sysflags = table.wrap(opt.sysflags)
-- find tool program and version first
opt.version = true
@@ -50,23 +54,6 @@ function main(name, flags, opt)
return false
end
- -- generate all checked flags
- local checkflags = table.join(flags, opt.sysflags)
-
- -- split flag group, .e.g "-I /xxx" => {"-I", "/xxx"}
- local results = {}
- for _, flag in ipairs(checkflags) do
- flag = flag:trim()
- if #flag > 0 then
- if flag:find(" ", 1, true) then
- table.join2(results, os.argv(flag))
- else
- table.insert(results, flag)
- end
- end
- end
- checkflags = results
-
-- init tool
opt.toolname = tool.name
opt.program = tool.program
@@ -83,8 +70,8 @@ function main(name, flags, opt)
local arch = 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(checkflags, " ")
-
+ 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 = coroutine.running()
if coroutine_running then
@@ -96,14 +83,31 @@ function main(name, flags, opt)
end
-- attempt to get result from cache first
- local cacheinfo = cache.load("lib.detect.has_flags")
+ local cacheinfo = cache.load("lib.detect.has_flags")
local result = cacheinfo[key]
if result ~= nil then
return result
end
+ -- generate all checked flags
+ local checkflags = table.join(flags, opt.sysflags)
+
+ -- split flag group, .e.g "-I /xxx" => {"-I", "/xxx"}
+ local results = {}
+ for _, flag in ipairs(checkflags) do
+ flag = flag:trim()
+ if #flag > 0 then
+ if flag:find(" ", 1, true) then
+ table.join2(results, os.argv(flag))
+ else
+ table.insert(results, flag)
+ end
+ end
+ end
+ checkflags = results
+
-- detect.tools.xxx.has_flags(flags, opt)?
- _g._checking = ifelse(coroutine_running, key, nil)
+ _g._checking = coroutine_running and key or nil
local hasflags = import("detect.tools." .. tool.name .. ".has_flags", {try = true})
local errors = nil
if hasflags then
@@ -112,20 +116,23 @@ function main(name, flags, opt)
result = try { function () os.runv(tool.program, checkflags); return true end, catch { function (errs) errors = errs end }}
end
_g._checking = nil
+ result = result or false
-- trace
if option.get("verbose") or option.get("diagnosis") or opt.verbose then
- cprint("${dim}checking for the flags (%s) ... %s", table.concat(table.wrap(flags), " "), result and "${color.success}${text.success}" or "${color.nothing}${text.nothing}")
+ cprintf("${dim}checking for the flags (")
+ io.write(opt.flagskey)
+ cprint("${dim}) ... %s", result and "${color.success}${text.success}" or "${color.nothing}${text.nothing}")
if option.get("diagnosis") then
- cprint("${dim}> %s %s", path.filename(tool.program), table.concat(checkflags, " "))
+ cprint("${dim}> %s \"%s\"", path.filename(tool.program), table.concat(checkflags, "\" \""))
+ if errors and #tostring(errors) > 0 then
+ cprint("${color.warning}checkinfo:${clear dim} %s", tostring(errors):trim())
+ end
end
end
- if errors and option.get("diagnosis") and #tostring(errors) > 0 then
- cprint("${color.warning}checkinfo:${clear dim} %s", tostring(errors):trim())
- end
-- save result to cache
- cacheinfo[key] = ifelse(result, result, false)
+ cacheinfo[key] = result
cache.save("lib.detect.has_flags", cacheinfo)
-- ok?