summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-06-20 12:38:44 +0800
committerruki <[email protected]>2020-06-20 12:38:44 +0800
commit281e06a020f7704fe998be52a6ecc2711cfd4fb7 (patch)
tree7296f3837d062dcdf6031b821dc6ea0ff1c8986d
parent01dd21d4f3bccda1ff18ad1213b959feeaae37eb (diff)
improve to find cl/link
-rw-r--r--xmake/core/base/os.lua4
-rw-r--r--xmake/core/platform/environment.lua4
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_program.lua30
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_programver.lua2
-rw-r--r--xmake/core/tool/toolchain.lua36
-rw-r--r--xmake/modules/detect/tools/find_cl.lua2
-rw-r--r--xmake/modules/detect/tools/find_lib.lua6
-rw-r--r--xmake/modules/detect/tools/find_link.lua12
-rw-r--r--xmake/modules/detect/tools/find_ml.lua4
-rw-r--r--xmake/modules/detect/tools/find_ml64.lua4
-rw-r--r--xmake/modules/lib/detect/find_tool.lua2
-rw-r--r--xmake/toolchains/msvc/check.lua12
-rw-r--r--xmake/toolchains/msvc/load.lua4
13 files changed, 65 insertions, 57 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 269ed22eb..ed4dbe1a6 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -690,6 +690,10 @@ function os.execv(program, argv, opt)
if opt.envs then
local envars = os.getenvs()
for k, v in pairs(opt.envs) do
+ -- TODO
+ if type(v) == "table" then
+ v = path.joinenv(v)
+ end
envars[k] = v
end
envs = {}
diff --git a/xmake/core/platform/environment.lua b/xmake/core/platform/environment.lua
index d3ff0a0fd..8fc67bfac 100644
--- a/xmake/core/platform/environment.lua
+++ b/xmake/core/platform/environment.lua
@@ -46,13 +46,15 @@ function environment._enter_toolchains()
os.addenv("PATH", path.join(os.programdir(), "winenv", "bin"))
end
+ --[[
-- add the runenvs of toolchains
for name, values in pairs(platform:runenvs()) do
if not oldenvs[name] then
oldenvs[name] = os.getenv(name)
end
os.addenv(name, table.unpack(table.wrap(values)))
- end
+ end]]
+
environment._OLDENVS_TOOLCHAINS = oldenvs
return true
end
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
index 120125687..85d4d733b 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
@@ -55,14 +55,14 @@ function sandbox_lib_detect_find_program._check(program, opt)
-- no check script? attempt to run it directly
if not opt.check then
- return 0 == os.execv(program, {"--version"}, {stdout = os.nuldev(), stderr = os.nuldev()})
+ return 0 == os.execv(program, {"--version"}, {stdout = os.nuldev(), stderr = os.nuldev(), envs = opt.envs})
end
-- check it
local ok = false
local errors = nil
if type(opt.check) == "string" then
- ok, errors = os.runv(program, {opt.check})
+ ok, errors = os.runv(program, {opt.check}, {envs = opt.envs})
else
ok, errors = sandbox.load(opt.check, program)
end
@@ -71,8 +71,6 @@ function sandbox_lib_detect_find_program._check(program, opt)
if not ok and option.get("diagnosis") then
utils.cprint("${color.warning}checkinfo: ${clear dim}" .. errors)
end
-
- -- ok?
return ok
end
@@ -233,6 +231,7 @@ end
-- local program = find_program("ccache", {pathes = {"/usr/bin", "/usr/local/bin"}, check = function (program) os.run("%s -h", program) end})
-- local program = find_program("ccache", {pathes = {"$(env PATH)", "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger)"}})
-- local program = find_program("ccache", {pathes = {"$(env PATH)", function () return "/usr/local/bin" end}})
+-- local program = find_program("ccache", {envs = {PATH = "xxx"}})
--
-- @endcode
--
@@ -259,16 +258,27 @@ function sandbox_lib_detect_find_program.main(name, opt)
local cacheinfo = cache.load(cachekey)
local result = cacheinfo[name]
if result ~= nil and not opt.force then
- return utils.ifelse(result, result, nil)
+ return result and result or nil
+ end
+
+ -- get pathes from the opt.envs.PATH
+ local envs = opt.envs
+ local pathes = opt.pathes
+ if envs and (envs.PATH or envs.path) then
+ local pathenv = envs.PATH or envs.path
+ if type(pathenv) == "string" then
+ pathenv = path.splitenv(pathenv)
+ end
+ pathes = table.join(table.wrap(opt.pathes), pathenv)
end
-- find executable program
- checking = utils.ifelse(coroutine_running, name, nil)
- result = sandbox_lib_detect_find_program._find(name, opt.pathes, opt)
+ checking = coroutine_running and name or nil
+ result = sandbox_lib_detect_find_program._find(name, pathes, opt)
checking = nil
-- cache result
- cacheinfo[name] = utils.ifelse(result, result, false)
+ cacheinfo[name] = result and result or false
-- save cache info
cache.save(cachekey, cacheinfo)
@@ -276,13 +286,11 @@ function sandbox_lib_detect_find_program.main(name, opt)
-- trace
if option.get("verbose") or opt.verbose then
if result then
- utils.cprint("checking for the %s ... ${color.success}%s", name, utils.ifelse(name == result, "${text.success}", result))
+ utils.cprint("checking for the %s ... ${color.success}%s", name, (name == result and "${text.success}" or result))
else
utils.cprint("checking for the %s ... ${color.nothing}${text.nothing}", name)
end
end
-
- -- ok?
return result
end
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
index e48fb6d9e..ae70b17a8 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua
@@ -78,7 +78,7 @@ function sandbox_lib_detect_find_programver.main(program, opt)
utils.cprint("${color.warning}checkinfo: ${clear dim}" .. outdata)
end
else
- ok, outdata = os.iorunv(program, {command or "--version"})
+ ok, outdata = os.iorunv(program, {command or "--version"}, {envs = opt.envs})
end
-- find version info
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua
index 12470394b..e405fe1f8 100644
--- a/xmake/core/tool/toolchain.lua
+++ b/xmake/core/tool/toolchain.lua
@@ -161,23 +161,6 @@ function _instance:sdkdir()
return config.get("sdk") or self:get("sdkdir")
end
--- do load, @note we need load it repeatly for each architectures
-function _instance:_load()
- local info = self:info()
- if not info:get("__loaded") and not info:get("__loading") then
- local on_load = info:get("load")
- if on_load then
- info:set("__loading", true)
- local ok, errors = sandbox.load(on_load, self)
- info:set("__loading", false)
- if not ok then
- os.raise(errors)
- end
- end
- info:set("__loaded", true)
- end
-end
-
-- do check, we only check it once for all architectures
function _instance:check()
local checkok = true
@@ -196,6 +179,23 @@ function _instance:check()
return checkok
end
+-- do load, @note we need load it repeatly for each architectures
+function _instance:_load()
+ local info = self:info()
+ if not info:get("__loaded") and not info:get("__loading") then
+ local on_load = info:get("load")
+ if on_load then
+ info:set("__loading", true)
+ local ok, errors = sandbox.load(on_load, self)
+ info:set("__loading", false)
+ if not ok then
+ os.raise(errors)
+ end
+ end
+ info:set("__loaded", true)
+ end
+end
+
-- get the tool description from the tool kind
function _instance:_description(toolkind)
local descriptions = self._DESCRIPTIONS
@@ -262,7 +262,7 @@ function _instance:_checktool(toolkind, toolpath)
-- find tool program
local program, toolname
- local tool = find_tool(toolpath, {program = toolpath, pathes = self:bindir()})
+ local tool = find_tool(toolpath, {program = toolpath, pathes = self:bindir(), envs = self:get("runenvs")})
if tool then
program = tool.program
toolname = tool.name
diff --git a/xmake/modules/detect/tools/find_cl.lua b/xmake/modules/detect/tools/find_cl.lua
index 48289cfbc..a6f5d2fa6 100644
--- a/xmake/modules/detect/tools/find_cl.lua
+++ b/xmake/modules/detect/tools/find_cl.lua
@@ -38,7 +38,7 @@ function main(opt)
-- init options
opt = opt or {}
- opt.check = opt.check or function (program) os.run(program) end
+ opt.check = opt.check or function (program) os.runv(program, {}, {envs = opt.envs}) end
-- find program
local program = find_program(opt.program or "cl.exe", opt)
diff --git a/xmake/modules/detect/tools/find_lib.lua b/xmake/modules/detect/tools/find_lib.lua
index 9c5b4be74..2b65c978b 100644
--- a/xmake/modules/detect/tools/find_lib.lua
+++ b/xmake/modules/detect/tools/find_lib.lua
@@ -50,9 +50,9 @@ function main(opt)
io.writefile(sourcefile, "int test(void)\n{return 0;}")
-- check it
- os.run("cl -c -Fo%s %s", objectfile, sourcefile)
- os.run("link -lib -out:%s %s", libraryfile, objectfile)
- verinfo = os.iorun("%s -list %s", program, libraryfile)
+ os.runv("cl", {"-c", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs})
+ os.runv("link", {"-lib", "-out:" .. libraryfile, objectfile}, {envs = opt.envs})
+ verinfo = os.iorunv(program, {"-list", libraryfile}, {envs = opt.envs})
-- remove files
os.rm(objectfile)
diff --git a/xmake/modules/detect/tools/find_link.lua b/xmake/modules/detect/tools/find_link.lua
index 71fba5323..5814cba09 100644
--- a/xmake/modules/detect/tools/find_link.lua
+++ b/xmake/modules/detect/tools/find_link.lua
@@ -21,6 +21,7 @@
-- imports
import("lib.detect.find_program")
import("lib.detect.find_programver")
+import("lib.detect.find_tool")
-- find link
--
@@ -43,17 +44,20 @@ function main(opt)
opt = opt or {}
opt.check = opt.check or function (program)
+ -- find cl
+ local cl = assert(find_tool("cl", {envs = opt.envs}))
+
-- make an stub source file
local binaryfile = os.tmpfile() .. ".exe"
local objectfile = os.tmpfile() .. ".obj"
local sourcefile = os.tmpfile() .. ".c"
- -- main entry
+ -- compile sourcefile first
io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}")
+ os.runv(cl.program, {"-c", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs})
- -- check it
- os.run("cl -c -Fo%s %s", objectfile, sourcefile)
- verinfo = os.iorun("%s -out:%s %s", program, binaryfile, objectfile)
+ -- do link
+ verinfo = os.iorunv(program, {"-lib", "-out:" .. binaryfile, objectfile}, {envs = opt.envs})
-- remove files
os.rm(objectfile)
diff --git a/xmake/modules/detect/tools/find_ml.lua b/xmake/modules/detect/tools/find_ml.lua
index dda0da3e1..c5da1eaee 100644
--- a/xmake/modules/detect/tools/find_ml.lua
+++ b/xmake/modules/detect/tools/find_ml.lua
@@ -38,7 +38,7 @@ function main(opt)
-- init options
opt = opt or {}
- opt.check = opt.check or function (program) os.run(program) end
+ opt.check = opt.check or function (program) os.runv(program, {}, {envs = opt.envs}) end
-- find program
local program = find_program(opt.program or "ml.exe", opt)
@@ -46,7 +46,7 @@ function main(opt)
-- find program version
local version = nil
if program and opt and opt.version then
- opt.command = opt.command or function () local _, info = os.iorun(program); return info end
+ opt.command = opt.command or function () local _, info = os.iorunv(program, {}, {envs = opt.envs}); return info end
opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end
version = find_programver(program, opt)
end
diff --git a/xmake/modules/detect/tools/find_ml64.lua b/xmake/modules/detect/tools/find_ml64.lua
index bb2083ae7..f446fbeeb 100644
--- a/xmake/modules/detect/tools/find_ml64.lua
+++ b/xmake/modules/detect/tools/find_ml64.lua
@@ -38,7 +38,7 @@ function main(opt)
-- init options
opt = opt or {}
- opt.check = opt.check or function (program) os.run(program) end
+ opt.check = opt.check or function (program) os.runv(program, {}, {envs = opt.envs}) end
-- find program
local program = find_program(opt.program or "ml64.exe", opt)
@@ -46,7 +46,7 @@ function main(opt)
-- find program version
local version = nil
if program and opt and opt.version then
- opt.command = opt.command or function () local _, info = os.iorun(program); return info end
+ opt.command = opt.command or function () local _, info = os.iorunv(program, {}, {envs = opt.envs}); return info end
opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end
version = find_programver(program, opt)
end
diff --git a/xmake/modules/lib/detect/find_tool.lua b/xmake/modules/lib/detect/find_tool.lua
index 7e40c0b0e..83f543ebf 100644
--- a/xmake/modules/lib/detect/find_tool.lua
+++ b/xmake/modules/lib/detect/find_tool.lua
@@ -41,7 +41,7 @@ end
-- @param name the tool name
-- @param opt the options, e.g. {program = "xcrun -sdk macosx clang", pathes = {"/usr/bin"},
-- check = function (tool) os.run("%s -h", tool) end, version = true
--- force = true, cachekey = "xxx"}
+-- force = true, cachekey = "xxx", envs = {PATH = "xxx"}}
--
-- @return {name = "", program = "", version = ""} or nil
--
diff --git a/xmake/toolchains/msvc/check.lua b/xmake/toolchains/msvc/check.lua
index bf42ca64f..d4861e16d 100644
--- a/xmake/toolchains/msvc/check.lua
+++ b/xmake/toolchains/msvc/check.lua
@@ -59,21 +59,11 @@ function _check_vsenv(toolchain)
config.set("__vcvarsall", vcvarsall)
-- check compiler
- local oldenvs = {}
- oldenvs.PATH = os.getenv("PATH")
- oldenvs.LIB = os.getenv("LIB")
- os.setenv("PATH", vsenv.path .. ';' .. (oldenvs.PATH or ""))
- os.setenv("LIB", vsenv.lib .. ';' .. (oldenvs.LIB or ""))
local program = nil
- local tool = find_tool("cl.exe", {force = true})
+ local tool = find_tool("cl.exe", {force = true, envs = vsenv})
if tool then
program = tool.program
end
- for name, values in pairs(oldenvs) do
- os.setenv(name, values)
- end
-
- -- ok?
if program then
return vsver
end
diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua
index c6d53f86a..3b25a298f 100644
--- a/xmake/toolchains/msvc/load.lua
+++ b/xmake/toolchains/msvc/load.lua
@@ -75,8 +75,8 @@ function main(toolchain)
toolchain:set("toolset", "as", "ml.exe")
end
toolchain:set("toolset", "ld", "link.exe")
- toolchain:set("toolset", "sh", "link.exe -dll")
- toolchain:set("toolset", "ar", "link.exe -lib")
+ toolchain:set("toolset", "sh", "link.exe")
+ toolchain:set("toolset", "ar", "link.exe")
toolchain:set("toolset", "ex", "lib.exe")
-- add vs environments