diff options
| author | ruki <[email protected]> | 2020-06-21 12:51:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-06-21 12:51:13 +0800 |
| commit | 08559a94893de4e5b0799f90f54c0009ef7eeb4d (patch) | |
| tree | eb004d2f7899b5abb188dff33cdb108b5e5873a5 | |
| parent | 4dea5c6453ec77f7fad59047fe9541f0739dd713 (diff) | |
improve to load toolchains for each plat/arch
| -rw-r--r-- | xmake/core/platform/platform.lua | 45 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 23 | ||||
| -rw-r--r-- | xmake/core/tool/tool.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 3 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 3 |
5 files changed, 50 insertions, 26 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 093f5b4bd..b15a4b4c7 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -34,9 +34,10 @@ local config = require("project/config") local global = require("base/global") -- new an instance -function _instance.new(name, info) +function _instance.new(name, arch, info) local instance = table.inherit(_instance) instance._NAME = name + instance._ARCH = arch instance._INFO = info return instance end @@ -46,6 +47,11 @@ function _instance:name() return self._NAME end +-- get platform architecture +function _instance:arch() + return self._ARCH or config.get("arch") +end + -- set the value to the platform configuration function _instance:set(name, ...) self._INFO:apival_set(name, ...) @@ -129,13 +135,13 @@ function _instance:toolchains(opt) local names = nil toolchains = {} if not (opt and opt.all) then - names = config.get("__toolchains") + names = config.get("__toolchains_" .. self:name() .. "_" .. self:arch()) end if not names then -- get the given toolchain local toolchain_given = config.get("toolchain") if toolchain_given then - local toolchain_inst, errors = toolchain.load(toolchain_given, {plat = self:name()}) + local toolchain_inst, errors = toolchain.load(toolchain_given, {plat = self:name(), arch = self:arch()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(toolchain_given) @@ -154,7 +160,7 @@ function _instance:toolchains(opt) end if names then for _, name in ipairs(names) do - local toolchain_inst, errors = toolchain.load(name, {plat = self:name()}) + local toolchain_inst, errors = toolchain.load(name, {plat = self:name(), arch = self:arch()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(name) @@ -294,7 +300,7 @@ function _instance:check() end -- save valid toolchains - config.set("__toolchains", toolchains_valid) + config.set("__toolchains_" .. self:name() .. "_" .. self:arch(), toolchains_valid) return true end @@ -418,16 +424,14 @@ function platform.add_directories(...) end -- load the given platform -function platform.load(plat) +function platform.load(plat, arch) -- get platform name plat = plat or config.get("plat") or os.host() - if not plat then - return nil, string.format("unknown platform!") - end + arch = arch or config.get("arch") or os.arch() -- get cache key - local cachekey = plat .. "_" .. (config.get("arch") or os.arch()) + local cachekey = plat .. "_" .. arch -- get it directly from cache dirst platform._PLATFORMS = platform._PLATFORMS or {} @@ -482,7 +486,7 @@ function platform.load(plat) end -- save instance to the cache - local instance = _instance.new(plat, result) + local instance = _instance.new(plat, arch, result) platform._PLATFORMS[cachekey] = instance return instance end @@ -501,16 +505,19 @@ end -- -- e.g. cc, cxx, mm, mxx, as, ar, ld, sh, .. -- -function platform.tool(toolkind, plat) +function platform.tool(toolkind, plat, arch) -- attempt to get program from config first - local program = config.get(toolkind) - local toolname = config.get("__toolname_" .. toolkind) - local toolchain_info = config.get("__toolchain_info_" .. toolkind) + plat = plat or config.get("plat") or os.host() + arch = arch or config.get("arch") or os.arch() + local key = toolkind .. "_" .. plat .. "_" .. arch + local program = config.get(toolkind) or config.get("__tool_" .. key) + local toolname = config.get("__toolname_" .. key) + local toolchain_info = config.get("__toolchain_info_" .. key) if program == nil then -- get the current platform - local instance, errors = platform.load(plat) + local instance, errors = platform.load(plat, arch) if not instance then os.raise(errors) end @@ -518,9 +525,9 @@ function platform.tool(toolkind, plat) -- get it from the platform toolchains program, toolname, toolchain_info = instance:tool(toolkind) if program then - config.set(toolkind, program, {force = true, readonly = true}) - config.set("__toolname_" .. toolkind, toolname) - config.set("__toolchain_info_" .. toolkind, 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 end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index dc337c8ac..1579cd133 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -444,6 +444,16 @@ function _instance:name() return self._NAME end +-- get the platform of this target +function _instance:plat() + return config.get("plat") or os.host() +end + +-- get the architecture of this target +function _instance:arch() + return config.get("arch") or os.arch() +end + -- get the cache key function _instance:cachekey() return string.format("%s_%d", tostring(self), self._CACHEID) @@ -1672,7 +1682,7 @@ end function _instance:toolchains() local toolchains = self._TOOLCHAINS if toolchains == nil then - local instance, errors = platform.load() + local instance, errors = platform.load(self:plat(), self:arch()) if not instance then os.raise(errors) end @@ -1693,8 +1703,9 @@ function _instance:tool(toolkind) end -- get tool program + local key = toolkind .. "_" .. self:plat() .. "_" .. self:arch() local program, toolname, toolchain_info - local toolinfo = tools[toolkind] + local toolinfo = tools[key] if toolinfo == nil then toolinfo = {} @@ -1709,9 +1720,9 @@ function _instance:tool(toolkind) -- attempt to get program from config first if no the given toolchains in target if not program and not self:get("toolchains") then - program = config.get(toolkind) - toolname = config.get("__toolname_" .. toolkind) - toolchain_info = config.get("__toolchain_info_" .. toolkind) + 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 @@ -1740,7 +1751,7 @@ function _instance:tool(toolkind) toolinfo[2] = toolname toolinfo[3] = toolchain_info end - tools[toolkind] = toolinfo + tools[key] = toolinfo else program = toolinfo[1] toolname = toolinfo[2] diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index 0a45c48c1..b8eb29ddd 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -193,7 +193,7 @@ function tool.load(kind, opt) -- get the tool program and name if not program then - program, toolname, toolchain_info = platform.tool(kind) + program, toolname, toolchain_info = platform.tool(kind, plat, arch) if toolchain_info then assert(toolchain_info.plat == plat) assert(toolchain_info.arch == arch) diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index be9b54580..01a38e670 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -233,6 +233,9 @@ function make(outputdir, vsinfo) -- clear project to reload and recheck it project.clear() + -- check configure + config.check() + -- check project options project.check() diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 5beb69e62..1cd51035b 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -284,6 +284,9 @@ function main(outputdir, vsinfo) -- clear project to reload and recheck it project.clear() + -- check configure + config.check() + -- check project options project.check() |
