diff options
| author | ruki <[email protected]> | 2020-05-19 22:35:36 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-05-19 09:33:37 +0800 |
| commit | 5dfb51f3e1c06c07097158153f39c45830029685 (patch) | |
| tree | 8b0932b4241526189860332e8b49f2db13794c04 | |
| parent | 694bff5b15ada2850b21ce0588d6963654ab0dc2 (diff) | |
add envs toolchain
| -rw-r--r-- | xmake/core/platform/platform.lua | 34 | ||||
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 9 | ||||
| -rw-r--r-- | xmake/platforms/macosx/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/envs/xmake.lua | 40 |
4 files changed, 76 insertions, 9 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 1bb76db92..3e3b537d1 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -129,16 +129,34 @@ 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 + + -- init tools + local tools = self._TOOLS + if not tools then + tools = {} + self._TOOLS = tools + end + + -- get tool program + local program, toolname + local toolinfo = tools[toolkind] + if toolinfo == nil then + toolinfo = {} + local toolchains = self:toolchains() + for idx, toolchain_inst in ipairs(toolchains) do + program, toolname = toolchain_inst:tool(toolkind) + if program then + toolinfo[1] = program + toolinfo[2] = toolname + break + end end + tools[toolkind] = toolinfo + else + program = toolinfo[1] + toolname = toolinfo[2] end + return program, toolname end -- get tool configuration from the toolchains diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 8f524b623..d915ffcf8 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -182,6 +182,15 @@ function _instance:_checktool(toolkind, toolpath) self._find_tool = find_tool end + -- do filter for toolpath variables, e.g. set_toolsets("cc", "$(env CC)") + local sandbox_inst = sandbox.instance() + if sandbox_inst then + local filter = sandbox_inst:filter() + if filter then + toolpath = filter:handle(toolpath) + end + end + -- find tool program local program, toolname local tool = find_tool(toolpath, {program = toolpath, pathes = self:bindir()}) diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 4cd22a2fd..85e646851 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -41,7 +41,7 @@ platform("macosx") -- set toolchains -- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") - set_toolchains("xcode", "clang", "gcc") + set_toolchains("envs", "xcode", "clang", "gcc") -- set menu set_menu { diff --git a/xmake/toolchains/envs/xmake.lua b/xmake/toolchains/envs/xmake.lua new file mode 100644 index 000000000..401f6d72b --- /dev/null +++ b/xmake/toolchains/envs/xmake.lua @@ -0,0 +1,40 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("envs") + + -- set toolsets + set_toolsets("cc", "$(env CC)") + set_toolsets("cxx", "$(env CXX)") + set_toolsets("ld", "$(env LD)") + set_toolsets("sh", "$(env SH)") + set_toolsets("ar", "$(env AR)") + set_toolsets("ex", "$(env EX)", "$(env AR)") + set_toolsets("strip", "$(env STRIP)") + set_toolsets("ranlib","$(env RANLIB)") + set_toolsets("mm", "$(env MM)") + set_toolsets("mxx", "$(env MXX)") + set_toolsets("as", "$(env AS)") + set_toolsets("dc", "$(env DC") + set_toolsets("sc", "$(env SC)") + set_toolsets("gc", "$(env GC)") + set_toolsets("rc", "$(env RC)") + |
