summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-12-13 21:00:41 +0800
committerruki <[email protected]>2020-12-13 21:00:41 +0800
commit38b7c45ae4b1c58d4734ab027fd520d9a397a383 (patch)
tree2dec2c20e7f1bfe01cdd97f762b5aae9471f15cb
parentd313c481f3bc4288ca06ba0a043ae36234c151da (diff)
pass config to toolchain
-rw-r--r--xmake/core/tool/toolchain.lua37
1 files changed, 16 insertions, 21 deletions
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua
index a411b4db5..0accd5eb4 100644
--- a/xmake/core/tool/toolchain.lua
+++ b/xmake/core/tool/toolchain.lua
@@ -36,12 +36,10 @@ local sandbox = require("sandbox/sandbox")
local sandbox_module = require("sandbox/modules/import/core/sandbox/module")
-- new an instance
-function _instance.new(name, info, plat, arch, configs)
+function _instance.new(name, info, configs)
local instance = table.inherit(_instance)
instance._NAME = name
instance._INFO = info
- instance._PLAT = plat
- instance._ARCH = arch
instance._CONFIGS = configs
return instance
end
@@ -53,12 +51,12 @@ end
-- get toolchain platform
function _instance:plat()
- return self._PLAT
+ return self:config("plat")
end
-- get toolchain architecture
function _instance:arch()
- return self._ARCH
+ return self:config("arch")
end
-- the current platform is belong to the given platforms?
@@ -391,14 +389,11 @@ function toolchain._interpreter()
end
-- get cache key
-function toolchain._cachekey(name, plat, arch, configs)
- local cachekey = name .. plat .. arch
- local configs = configs
- if configs then
- for _, k in ipairs(table.orderkeys(configs)) do
- local v = configs[k]
- cachekey = cachekey .. "_" .. k .. "_" .. tostring(v)
- end
+function toolchain._cachekey(name, opt)
+ local cachekey = name
+ for _, k in ipairs(table.orderkeys(opt)) do
+ local v = opt[k]
+ cachekey = cachekey .. "_" .. k .. "_" .. tostring(v)
end
return cachekey
end
@@ -449,9 +444,9 @@ function toolchain.load(name, opt)
-- init cache key
opt = opt or {}
- local plat = opt.plat or config.get("plat") or os.host()
- local arch = opt.arch or config.get("arch") or os.arch()
- local cachekey = toolchain._cachekey(name, plat, arch, opt.configs)
+ opt.plat = opt.plat or config.get("plat") or os.host()
+ opt.arch = opt.arch or config.get("arch") or os.arch()
+ local cachekey = toolchain._cachekey(name, opt)
-- get it directly from cache dirst
toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {}
@@ -493,7 +488,7 @@ function toolchain.load(name, opt)
end
-- save instance to the cache
- local instance = _instance.new(name, result, plat, arch, opt.configs)
+ local instance = _instance.new(name, result, opt)
toolchain._TOOLCHAINS[cachekey] = instance
return instance
end
@@ -503,9 +498,9 @@ function toolchain.load_withinfo(name, info, opt)
-- init cache key
opt = opt or {}
- local plat = opt.plat or config.get("plat") or os.host()
- local arch = opt.arch or config.get("arch") or os.arch()
- local cachekey = toolchain._cachekey(name, plat, arch, opt.configs)
+ opt.plat = opt.plat or config.get("plat") or os.host()
+ opt.arch = opt.arch or config.get("arch") or os.arch()
+ local cachekey = toolchain._cachekey(name, opt)
-- get it directly from cache dirst
toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {}
@@ -514,7 +509,7 @@ function toolchain.load_withinfo(name, info, opt)
end
-- save instance to the cache
- local instance = _instance.new(name, info, plat, arch, opt.configs)
+ local instance = _instance.new(name, info, opt)
toolchain._TOOLCHAINS[cachekey] = instance
return instance
end