summaryrefslogtreecommitdiff
path: root/xmake/core/project
diff options
context:
space:
mode:
authorruki <[email protected]>2021-02-13 22:37:46 +0800
committerruki <[email protected]>2021-02-13 22:37:46 +0800
commitd99e19ac256c00f965b4f39c8f4243844393e256 (patch)
tree11bc8c4e7b9877bd84c8753df5b75718b63024a3 /xmake/core/project
parent3e1f4c096a20cadbefa55bc3e38d900845f0ec9c (diff)
rewrite target/platform.tool
Diffstat (limited to 'xmake/core/project')
-rw-r--r--xmake/core/project/target.lua72
1 files changed, 9 insertions, 63 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index e9d73846c..1f0cf5232 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1737,82 +1737,28 @@ end
-- get the program and name of the given tool kind
function _instance:tool(toolkind)
-
- -- init tools
- local tools = self._TOOLS
- if not tools then
- tools = {}
- self._TOOLS = tools
- end
-
- -- get tool program
- local key = self:name() .. "_" .. toolkind .. "_" .. self:plat() .. "_" .. self:arch()
- local program, toolname, toolchain_info
- local toolinfo = tools[key]
- if toolinfo == nil then
- toolinfo = {}
-
+ return toolchain.tool(self:toolchains(), toolkind, {cachekey = "target_" .. self:name(), plat = self:plat(), arch = self:arch(),
+ before_get = function()
-- get program from set_toolchain/set_tools (deprecated)
- program = self:get("toolset." .. toolkind) or self:get("toolchain." .. toolkind)
+ local program = self:get("toolset." .. toolkind) or self:get("toolchain." .. toolkind)
if not program then
local tools = self:get("tools") -- TODO: deprecated
if tools then
program = tools[toolkind]
end
end
-
- -- attempt to get program from config first if no the given toolchains in target
+ -- get program from `xmake f --cc`
if not program and not self:get("toolchains") then
- program = config.get(toolkind) or config.get("__tool_" .. key)
- toolname = config.get("__toolname_" .. key)
- toolchain_info = config.get("__toolchain_info_" .. key)
- end
-
- -- get program from target/toolchains
- if not program then
- local toolchains = self:toolchains()
- for idx, toolchain_inst in ipairs(toolchains) do
- program, toolname = toolchain_inst:tool(toolkind)
- if program then
- toolchain_info = {name = toolchain_inst:name(),
- plat = toolchain_inst:plat(),
- arch = toolchain_inst:arch(),
- cachekey = toolchain_inst:cachekey()}
- break
- end
- end
+ program = config.get(toolkind)
end
-
- -- contain toolname? parse it, e.g. '[email protected]'
- if program and type(program) == "string" then
- local pos = program:find('@', 1, true)
- if pos then
- toolname = program:sub(1, pos - 1)
- program = program:sub(pos + 1)
- end
- end
-
- if program then
- toolinfo[1] = program
- toolinfo[2] = toolname
- toolinfo[3] = toolchain_info
- config.set("__tool_" .. key, program, {force = true, readonly = true})
- config.set("__toolname_" .. key, toolname)
- config.set("__toolchain_info_" .. key, toolchain_info)
- config.save()
- end
- tools[key] = toolinfo
- else
- program = toolinfo[1]
- toolname = toolinfo[2]
- toolchain_info = toolinfo[3]
- end
- return program, toolname, toolchain_info
+ return program
+ end})
end
-- get tool configuration from the toolchains
function _instance:toolconfig(name)
- return toolchain.toolconfig(self:toolchains(), name, {cachekey = "target", after_get = function(toolchain_inst)
+ return toolchain.toolconfig(self:toolchains(), name, {cachekey = "target_" .. self:name(), plat = self:plat(), arch = self:arch(),
+ after_get = function(toolchain_inst)
-- get flags from target.on_xxflags()
local script = toolchain_inst:get("target.on_" .. name)
if type(script) == "function" then