diff options
| author | ruki <[email protected]> | 2020-05-16 10:24:27 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-05-16 10:24:27 +0800 |
| commit | 82bf1252a0104734b8f3b5d7ef154d3025b9f96f (patch) | |
| tree | 063d6736c649895c6c567c5116755b757d479761 | |
| parent | c6c71612e034c2e741add2b9deb69be4c93a8388 (diff) | |
get tool from toolchains
| -rw-r--r-- | xmake/core/platform/platform.lua | 62 | ||||
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 4 | ||||
| -rw-r--r-- | xmake/platforms/macosx/xmake.lua | 3 |
3 files changed, 58 insertions, 11 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index b6574584e..9a3aff93a 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -28,6 +28,7 @@ local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local interpreter = require("base/interpreter") +local toolchain = require("tool/toolchain") local sandbox = require("sandbox/sandbox") local config = require("project/config") local global = require("base/global") @@ -105,7 +106,40 @@ end -- get the toolchains function _instance:toolchains() - return self._INFO:get("toolchains") + local toolchains = self._TOOLCHAINS + if not toolchains then + local names = {} + if config.get("toolchain") then + table.insert(names, config.get("toolchain")) + end + if self._INFO:get("toolchains") then + table.join2(names, self._INFO:get("toolchains")) + end + toolchains = {} + for _, name in ipairs(names) do + local toolchain_inst, errors = toolchain.load(name, self:name()) + if not toolchain_inst then + os.raise(errors) + end + table.insert(toolchains, toolchain_inst) + end + self._TOOLCHAINS = toolchains + end + return toolchains +end + +-- get the program and name of the given tool kind +function _instance:tool(toolkind) + local toolchains = self:toolchains() + for idx, toolchain_inst in ipairs(toolchains) do + local program, toolname = toolchain_inst:tool(toolkind) + if program then + -- move this toolchain to head + table.remove(toolchains, idx) + table.insert(toolchains, 1, toolchain_inst) + return program, toolname + end + end end -- get the platform script @@ -327,16 +361,24 @@ function platform.tool(toolkind, plat) if not instance then os.raise(errors) end - - -- check it first - local on_check = instance:script("config_check") - if on_check then - on_check(instance, toolkind) - end - -- get it again - program = config.get(toolkind) - toolname = config.get("__toolname_" .. toolkind) + -- get it from the platform toolchains + program, toolname = instance:tool(toolkind) + if program then + config.set(toolkind, program, {force = true, readonly = true}) + config.set("__toolname_" .. toolkind, toolname) + else + -- TODO deprecated + -- check it first + local on_check = instance:script("config_check") + if on_check then + on_check(instance, toolkind) + end + + -- get it again + program = config.get(toolkind) + toolname = config.get("__toolname_" .. toolkind) + end end -- contain toolname? parse it, e.g. '[email protected]' diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index ba5640126..ef2b4eda6 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -80,6 +80,10 @@ function _instance:get(name) return self._INFO:get(name) end +-- get the program and name of the given tool kind +function _instance:tool(toolkind) +end + -- get the toolchain script function _instance:script(name) return self._INFO:get(name) diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index d65c03a9e..b7abea032 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -46,7 +46,8 @@ platform("macosx") on_load("load") -- set toolchains - set_toolchains("envs", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") +-- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") + set_toolchains("xcode") -- set menu set_menu { |
