summaryrefslogtreecommitdiff
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
parent42f44fa0a7a7c44a2e4eab067ebf56364bfabc2f (diff)
parent49f14868b5fa9bca4aa2f51ea2b70f9edae89cb6 (diff)
Merge pull request #506 from OpportunityLiu/dev
improve check flags with file
-rw-r--r--xmake/core/tool/tool.lua20
-rw-r--r--xmake/modules/core/tools/cl.lua2
-rw-r--r--xmake/modules/core/tools/gcc.lua2
-rw-r--r--xmake/modules/core/tools/nvcc.lua4
-rw-r--r--xmake/modules/lib/detect/has_flags.lua63
-rw-r--r--xmake/rules/cuda/gencodes/xmake.lua6
6 files changed, 55 insertions, 42 deletions
diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua
index f0b185960..43284c58c 100644
--- a/xmake/core/tool/tool.lua
+++ b/xmake/core/tool/tool.lua
@@ -106,19 +106,25 @@ function _instance:get(name)
end
-- has the given flag?
-function _instance:has_flags(flags, flagkind)
+function _instance:has_flags(flags, flagkind, opt)
- -- import has_flags()
- self._has_flags = self._has_flags or import("lib.detect.has_flags")
+ -- init options
+ opt = opt or {}
+ opt.program = opt.program or self:program()
+ opt.toolkind = opt.toolkind or self:kind()
+ opt.flagkind = opt.flagkind or flagkind
-- get system flags
- local sysflags = self:get(self:kind() .. 'flags')
- if not sysflags and flagkind then
- sysflags = self:get(flagkind)
+ opt.sysflags = opt.sysflags or self:get(self:kind() .. 'flags')
+ if not opt.sysflags and flagkind then
+ opt.sysflags = self:get(flagkind)
end
+ -- import has_flags()
+ self._has_flags = self._has_flags or import("lib.detect.has_flags", {anonymous = true})
+
-- has flags?
- return self._has_flags(self:name(), flags, {program = self:program(), toolkind = self:kind(), flagkind = flagkind, sysflags = sysflags})
+ return self._has_flags(self:name(), flags, opt)
end
-- load the given tool from the given kind
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index 8e3c0bd1b..0c139fc63 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -104,7 +104,7 @@ function nf_symbol(self, level, target)
-- check and add symbol output file
flags = "-Zi -Fd" .. path.join(symboldir, "compile." .. path.filename(symbolfile))
- if self:has_flags({"-Zi", "-FS", "-Fd" .. os.tmpfile() .. ".pdb"}, "cxflags") then
+ if self:has_flags({"-Zi", "-FS", "-Fd" .. os.nuldev() .. ".pdb"}, "cxflags", { flagskey = "-Zi -FS -Fd" }) then
flags = "-FS " .. flags
end
else
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 1e4267be1..e029f8566 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -405,7 +405,7 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags)
-- support `-MMD -MF depfile.d`? some old gcc does not support it at same time
if depfile and _g._HAS_MMD_MF == nil then
- _g._HAS_MMD_MF = self:has_flags({"-MMD", "-MF", os.nuldev()}, "cxflags") or false
+ _g._HAS_MMD_MF = self:has_flags({"-MMD", "-MF", os.nuldev()}, "cxflags", { flagskey = "-MMD -MF" }) or false
end
-- generate includes file
diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua
index 9f92e0425..b863058e6 100644
--- a/xmake/modules/core/tools/nvcc.lua
+++ b/xmake/modules/core/tools/nvcc.lua
@@ -80,7 +80,7 @@ function nf_symbol(self, level, target)
-- check and add symbol output file
host_flags = "-Zi -Fd" .. path.join(symboldir, "compile." .. path.filename(symbolfile))
- if self:has_flags({'-Xcompiler "-Zi -FS -Fd' .. os.tmpfile() .. '.pdb"'}, "cuflags") then
+ if self:has_flags({'-Xcompiler "-Zi -FS -Fd' .. os.nuldev() .. '.pdb"'}, "cuflags", { flagskey = '-Xcompiler "-Zi -FS -Fd"' }) then
host_flags = "-FS " .. host_flags
end
else
@@ -316,7 +316,7 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags)
function ()
-- support `-M -MF depfile.d`?
if depfile and _g._HAS_M_MF == nil then
- _g._HAS_M_MF = self:has_flags({"-M", "-MF", os.nuldev()}, "cuflags") or false
+ _g._HAS_M_MF = self:has_flags({"-M", "-MF", os.nuldev()}, "cuflags", { flagskey = "-M -MF" }) or false
end
-- generate includes file
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?
diff --git a/xmake/rules/cuda/gencodes/xmake.lua b/xmake/rules/cuda/gencodes/xmake.lua
index d1a1dc277..09e45ed72 100644
--- a/xmake/rules/cuda/gencodes/xmake.lua
+++ b/xmake/rules/cuda/gencodes/xmake.lua
@@ -98,7 +98,6 @@ rule("cuda.gencodes")
end
end
- local result = { clang = {}, nvcc = {} }
if v_arch == nil and #r_archs == 0 then
return nil
end
@@ -111,15 +110,16 @@ rule("cuda.gencodes")
if v_arch then
table.insert(r_archs, v_arch)
+ else
+ v_arch = math.min(unpack(r_archs))
end
r_archs = table.unique(r_archs)
+
local clang_flags = {}
for _, r_arch in ipairs(r_archs) do
table.insert(clang_flags, '--cuda-gpu-arch=sm_' .. r_arch)
end
- r_archs = table.unique(r_archs)
- v_arch = v_arch or math.min(unpack(r_archs))
local nvcc_flags = nil
if #r_archs == 1 then
nvcc_flags = '-gencode arch=compute_' .. v_arch .. ',code=sm_' .. r_archs[1]