summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-06-20 16:18:51 +0800
committerruki <[email protected]>2020-06-20 16:18:51 +0800
commit966b8dd7a01b09a93ba21ee4d2df0d471ab2282c (patch)
tree144af8b8bebb12e441402dcc90325cbb9949b494
parentda2e3b83c53752c43b651effeb273cb72090d7b0 (diff)
bind runenvs to has_flags
-rw-r--r--xmake/core/tool/tool.lua3
-rw-r--r--xmake/modules/detect/tools/cl/has_flags.lua4
-rw-r--r--xmake/modules/detect/tools/link/has_flags.lua22
-rw-r--r--xmake/modules/detect/tools/ml/has_flags.lua4
-rw-r--r--xmake/modules/lib/detect/has_flags.lua6
5 files changed, 19 insertions, 20 deletions
diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua
index b33727114..44df48bb0 100644
--- a/xmake/core/tool/tool.lua
+++ b/xmake/core/tool/tool.lua
@@ -165,6 +165,9 @@ function _instance:has_flags(flags, flagkind, opt)
-- import has_flags()
self._has_flags = self._has_flags or import("lib.detect.has_flags", {anonymous = true})
+ -- bind the run environments
+ opt.envs = self:runenvs()
+
-- has flags?
return self._has_flags(self:name(), flags, opt)
end
diff --git a/xmake/modules/detect/tools/cl/has_flags.lua b/xmake/modules/detect/tools/cl/has_flags.lua
index 1d9deff3f..b5dabc737 100644
--- a/xmake/modules/detect/tools/cl/has_flags.lua
+++ b/xmake/modules/detect/tools/cl/has_flags.lua
@@ -44,7 +44,7 @@ function _check_from_arglist(flags, opt)
-- get argument list
allflags = {}
- local arglist = os.iorunv(opt.program, {"-?"})
+ local arglist = os.iorunv(opt.program, {"-?"}, {envs = opt.envs})
if arglist then
for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do
allflags[arg:gsub("/", "-")] = true
@@ -72,7 +72,7 @@ function _check_try_running(flags, opt)
-- check it
local errors = nil
return try { function ()
- local _, errs = os.iorunv(opt.program, table.join("-c", "-nologo", flags, "-Fo" .. os.nuldev(), sourcefile))
+ local _, errs = os.iorunv(opt.program, table.join("-c", "-nologo", flags, "-Fo" .. os.nuldev(), sourcefile), {envs = opt.envs})
if errs and #errs:trim() > 0 then
return false, errs
end
diff --git a/xmake/modules/detect/tools/link/has_flags.lua b/xmake/modules/detect/tools/link/has_flags.lua
index db93ba195..188d22976 100644
--- a/xmake/modules/detect/tools/link/has_flags.lua
+++ b/xmake/modules/detect/tools/link/has_flags.lua
@@ -20,13 +20,12 @@
-- imports
import("lib.detect.cache")
+import("lib.detect.find_tool")
-- try running
-function _try_running(...)
-
- local argv = {...}
+function _try_running(program, argv, opt)
local errors = nil
- return try { function () os.runv(unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors
+ return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors
end
-- attempt to check it from the argument list
@@ -55,7 +54,7 @@ function _check_from_arglist(flags, opt)
local arglist = nil
try
{
- function () os.runv(opt.program, {"-?"}) end,
+ function () os.runv(opt.program, {"-?"}, {envs = opt.envs}) end,
catch
{
function (errors) arglist = errors end
@@ -71,8 +70,6 @@ function _check_from_arglist(flags, opt)
cacheinfo[flagskey] = allflags
cache.save(key, cacheinfo)
end
-
- -- ok?
return allflags[flags[1]:gsub("/", "-"):lower()]
end
@@ -94,16 +91,15 @@ function _check_try_running(flags, opt)
-- compile the source file
local objectfile = os.tmpfile() .. ".obj"
local binaryfile = os.tmpfile() .. ".exe"
- os.runv("cl", {"-c", "-nologo", "-Fo" .. objectfile, sourcefile})
+ local cl = find_tool("cl")
+ if cl then
+ os.runv(cl.program, {"-c", "-nologo", "-Fo" .. objectfile, sourcefile}, {envs = envs})
+ end
-- try link it
- local ok, errors = _try_running(opt.program, table.join(flags, "-nologo", "-out:" .. binaryfile, objectfile))
-
- -- remove files
+ local ok, errors = _try_running(opt.program, table.join(flags, "-nologo", "-out:" .. binaryfile, objectfile), {envs = opt.envs})
os.tryrm(objectfile)
os.tryrm(binaryfile)
-
- -- ok?
return ok, errors
end
diff --git a/xmake/modules/detect/tools/ml/has_flags.lua b/xmake/modules/detect/tools/ml/has_flags.lua
index 98bbb2775..21641d91d 100644
--- a/xmake/modules/detect/tools/ml/has_flags.lua
+++ b/xmake/modules/detect/tools/ml/has_flags.lua
@@ -44,7 +44,7 @@ function _check_from_arglist(flags, opt)
-- get argument list
allflags = {}
- local arglist = os.iorunv(opt.program, {"-?"})
+ local arglist = os.iorunv(opt.program, {"-?"}, {envs = opt.envs})
if arglist then
for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do
allflags[arg:gsub("/", "-")] = true
@@ -72,7 +72,7 @@ function _check_try_running(flags, opt)
-- check it
local errors = nil
return try { function ()
- local _, errs = os.iorunv(opt.program, table.join("-c", "-nologo", flags, "-Fo" .. os.nuldev(), sourcefile))
+ local _, errs = os.iorunv(opt.program, table.join("-c", "-nologo", flags, "-Fo" .. os.nuldev(), sourcefile), {envs = opt.envs})
if errs and #errs:trim() > 0 then
return false, errs
end
diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua
index 833bbcf65..4e4f3535a 100644
--- a/xmake/modules/lib/detect/has_flags.lua
+++ b/xmake/modules/lib/detect/has_flags.lua
@@ -62,14 +62,14 @@ function main(name, flags, opt)
opt.programver = tool.version
-- get tool platform
- local plat = config.get("plat") or os.host()
+ local plat = opt.plat or config.get("plat") or os.host()
-- get tool architecture
--
-- some tools select arch by path environment, not be flags, e.g. cl.exe of msvc)
-- so, it will affect the cache result
--
- local arch = config.get("arch") or os.arch()
+ 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
@@ -113,7 +113,7 @@ function main(name, flags, opt)
if hasflags then
result, errors = hasflags(checkflags, opt)
else
- result = try { function () os.runv(tool.program, checkflags); return true end, catch { function (errs) errors = errs end }}
+ result = try { function () os.runv(tool.program, checkflags, {envs = opt.envs}); return true end, catch { function (errs) errors = errs end }}
end
_g._checking = nil
result = result or false