summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-12-21 00:04:36 +0800
committerruki <[email protected]>2018-12-20 18:27:39 +0800
commitf1065f8b97b0521a57782eca4e9758929aebcd70 (patch)
tree75ebf78326fccf5dea0a06558603243fce8fed9a
parentd95758dc85e1e34e6ce507ffee78f7634a0661c5 (diff)
improve has_flags tips
-rw-r--r--xmake/core/tool/tool.lua10
-rw-r--r--xmake/modules/detect/tools/gcc/has_flags.lua3
-rw-r--r--xmake/modules/lib/detect/has_flags.lua21
3 files changed, 19 insertions, 15 deletions
diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua
index 7556860ab..e082ed592 100644
--- a/xmake/core/tool/tool.lua
+++ b/xmake/core/tool/tool.lua
@@ -114,14 +114,14 @@ function _instance:has_flags(flags, flagkind)
-- import has_flags()
self._has_flags = self._has_flags or import("lib.detect.has_flags")
- -- get base flags
- local baseflags = self:get(self:kind() .. 'flags')
- if not baseflags and flagkind then
- baseflags = self:get(flagkind)
+ -- get system flags
+ local sysflags = self:get(self:kind() .. 'flags')
+ if not sysflags and flagkind then
+ sysflags = self:get(flagkind)
end
-- has flags?
- return self._has_flags(self:name(), table.join(flags, baseflags), {program = self:program(), toolkind = self:kind(), flagkind = flagkind})
+ return self._has_flags(self:name(), flags, {program = self:program(), toolkind = self:kind(), flagkind = flagkind, sysflags = sysflags})
end
-- load the given tool from the given kind
diff --git a/xmake/modules/detect/tools/gcc/has_flags.lua b/xmake/modules/detect/tools/gcc/has_flags.lua
index e229e023a..a0cceda72 100644
--- a/xmake/modules/detect/tools/gcc/has_flags.lua
+++ b/xmake/modules/detect/tools/gcc/has_flags.lua
@@ -94,7 +94,8 @@ function _check_try_running(flags, opt, islinker)
if islinker then
-- get extension
- local extension = table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c"
+ -- @note we need detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
+ local extension = opt.program:endswith("++") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c")
-- make an stub source file
local sourcefile = path.join(os.tmpdir(), "detect", "gcc_has_flags" .. extension)
diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua
index 9245b3f30..0dd3b341f 100644
--- a/xmake/modules/lib/detect/has_flags.lua
+++ b/xmake/modules/lib/detect/has_flags.lua
@@ -32,7 +32,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 = "", 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]"}
--
-- @return true or false
--
@@ -54,12 +54,12 @@ function main(name, flags, opt)
return false
end
- -- wrap flags
- flags = table.wrap(flags)
+ -- 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(flags) do
+ for _, flag in ipairs(checkflags) do
flag = flag:trim()
if #flag > 0 then
if flag:find(" ", 1, true) then
@@ -69,7 +69,7 @@ function main(name, flags, opt)
end
end
end
- flags = results
+ checkflags = results
-- init tool
opt.toolname = tool.name
@@ -87,7 +87,7 @@ 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(flags, " ")
+ local key = plat .. "_" .. arch .. "_" .. tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. (opt.flagkind or "") .. "_" .. table.concat(checkflags, " ")
-- @note avoid detect the same program in the same time if running in the coroutine (.e.g ccache)
local coroutine_running = coroutine.running()
@@ -111,15 +111,18 @@ function main(name, flags, opt)
local hasflags = import("detect.tools." .. tool.name .. ".has_flags", {try = true})
local errors = nil
if hasflags then
- result, errors = hasflags(flags, opt)
+ result, errors = hasflags(checkflags, opt)
else
- result = try { function () os.runv(tool.program, flags); return true end, catch { function (errs) errors = errs end }}
+ result = try { function () os.runv(tool.program, checkflags); return true end, catch { function (errs) errors = errs end }}
end
_g._checking = nil
-- trace
if option.get("verbose") or option.get("diagnosis") or opt.verbose then
- cprint("checking for the flags(%s) %s ... %s", path.filename(tool.program), table.concat(flags, " "), ifelse(result, "${green}ok", "${red}no"))
+ cprint("${dim}checking for the flags (%s) ... %s", table.concat(table.wrap(flags), " "), ifelse(result, "${green}ok", "${red}no"))
+ if option.get("diagnosis") then
+ cprint("${dim}> %s %s", path.filename(tool.program), table.concat(checkflags, " "))
+ end
end
if errors and #errors > 0 and option.get("diagnosis") then
cprint("${yellow}checkinfo:${clear dim} %s", errors:trim())