diff options
| author | ruki <[email protected]> | 2021-02-13 10:37:00 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-02-13 10:37:00 +0800 |
| commit | 3e1f4c096a20cadbefa55bc3e38d900845f0ec9c (patch) | |
| tree | 17e4e95518b1cf2ae9300b153daf5a2b2ba24c36 | |
| parent | 9f09d39ed2e59a9bf4f1beecee0f79f27645ece3 (diff) | |
improve toolconfig
| -rw-r--r-- | xmake/core/platform/platform.lua | 27 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 52 | ||||
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 40 |
3 files changed, 52 insertions, 67 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index a6aff0bf6..5b8a0d663 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -226,32 +226,7 @@ end -- get tool configuration from the toolchains function _instance:toolconfig(name) - - -- init tool configs - local toolconfigs = self._TOOLCONFIGS - if not toolconfigs then - toolconfigs = {} - self._TOOLCONFIGS = toolconfigs - end - - -- get configuration - local toolconfig = toolconfigs[name] - if toolconfig == nil then - - -- get them from all toolchains - for _, toolchain_inst in ipairs(self:toolchains()) do - local values = toolchain_inst:get(name) - if values then - toolconfig = toolconfig or {} - table.join2(toolconfig, values) - end - end - - -- cache it - toolconfig = toolconfig or false - toolconfigs[name] = toolconfig - end - return toolconfig or nil + return toolchain.toolconfig(self:toolchains(), name, {cachekey = "platform"}) end -- get the platform script diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index ee3577087..e9d73846c 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -38,6 +38,7 @@ local project_package = require("project/package") local tool = require("tool/tool") local linker = require("tool/linker") local compiler = require("tool/compiler") +local toolchain = require("tool/toolchain") local platform = require("platform/platform") local environment = require("platform/environment") local language = require("language/language") @@ -1811,49 +1812,18 @@ end -- get tool configuration from the toolchains function _instance:toolconfig(name) - - -- init tool configs - local toolconfigs = self._TOOLCONFIGS - if not toolconfigs then - toolconfigs = {} - self._TOOLCONFIGS = toolconfigs - end - - -- get configuration - local toolconfig = toolconfigs[name] - if toolconfig == nil then - - -- get them from all toolchains - for _, toolchain_inst in ipairs(self:toolchains()) do - - -- get xxflags - local values = toolchain_inst:get(name) - if values then - toolconfig = toolconfig or {} - table.join2(toolconfig, values) - end - - -- get flags from target.on_xxflags() - local script = toolchain_inst:get("target.on_" .. name) - if type(script) == "function" then - local ok, result_or_errors = utils.trycall(script, nil, self) - if ok then - values = result_or_errors - if values then - toolconfig = toolconfig or {} - table.join2(toolconfig, values) - end - else - os.raise(result_or_errors) - end + return toolchain.toolconfig(self:toolchains(), name, {cachekey = "target", after_get = function(toolchain_inst) + -- get flags from target.on_xxflags() + local script = toolchain_inst:get("target.on_" .. name) + if type(script) == "function" then + local ok, result_or_errors = utils.trycall(script, nil, self) + if ok then + return result_or_errors + else + os.raise(result_or_errors) end end - - -- cache it - toolconfig = toolconfig or false - toolconfigs[name] = toolconfig - end - return toolconfig or nil + end}) end -- get target apis diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index eb880932e..7a1ca6c05 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -600,5 +600,45 @@ function toolchain.load_withinfo(name, info, opt) return instance end +-- get tool configuration from the toolchains +function toolchain.toolconfig(toolchains, name, opt) + + -- init tool configs cache + opt = opt or {} + local toolconfigs = toolchain._TOOLCONFIGS + if not toolconfigs then + toolconfigs = {} + toolchain._TOOLCONFIGS = toolconfigs + end + + -- get configuration + local cachekey = (opt.cachekey or "") .. name + local toolconfig = toolconfigs[cachekey] + if toolconfig == nil then + + -- get them from all toolchains + for _, toolchain_inst in ipairs(toolchains) do + local values = toolchain_inst:get(name) + if values then + toolconfig = toolconfig or {} + table.join2(toolconfig, values) + end + local after_get = opt.after_get + if after_get then + values = after_get(toolchain_inst, name) + if values then + toolconfig = toolconfig or {} + table.join2(toolconfig, values) + end + end + end + + -- cache it + toolconfig = toolconfig or false + toolconfigs[cachekey] = toolconfig + end + return toolconfig or nil +end + -- return module return toolchain |
