summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-29 22:44:51 +0800
committerruki <[email protected]>2020-05-29 10:29:06 +0800
commitb97000a954e935efa53de7327178caf1a740f7d0 (patch)
treec81a9014e006b83ff5bd072704d0d4e27be4d0ab
parent38c79adcfe3e0d29e1da7b10f3f51bfdbdab8bc6 (diff)
improve to show toolchains
-rw-r--r--xmake/actions/config/xmake.lua9
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/toolchain.lua49
-rw-r--r--xmake/plugins/show/lists/toolchains.lua16
-rw-r--r--xmake/toolchains/envs/xmake.lua3
4 files changed, 62 insertions, 15 deletions
diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua
index 621037f53..28c6ebb50 100644
--- a/xmake/actions/config/xmake.lua
+++ b/xmake/actions/config/xmake.lua
@@ -158,13 +158,8 @@ task("config")
, " - run `xmake show -l toolchains` to get all toolchains"
, values = function (complete, opt)
if complete then
- import("core.project.project")
- import("core.platform.platform")
- local names = table.copy(platform.toolchains())
- for name, _ in pairs(project.toolchains()) do
- table.insert(names, name)
- end
- return names
+ import("core.tool.toolchain")
+ return toolchain.list()
end
end }
diff --git a/xmake/core/sandbox/modules/import/core/tool/toolchain.lua b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua
new file mode 100644
index 000000000..83071811d
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua
@@ -0,0 +1,49 @@
+--!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 toolchain.lua
+--
+
+-- define module
+local sandbox_core_tool_toolchain = sandbox_core_tool_toolchain or {}
+
+-- load modules
+local platform = require("platform/platform")
+local toolchain = require("tool/toolchain")
+local project = require("project/project")
+local raise = require("sandbox/modules/raise")
+
+-- get all toolchains list
+function sandbox_core_tool_toolchain.list()
+ local names = table.copy(platform.toolchains())
+ for name, _ in pairs(project.toolchains()) do
+ table.insert(names, name)
+ end
+ return names
+end
+
+-- load the toolchain from the given name
+function sandbox_core_tool_toolchain.load(name)
+ local instance, errors = toolchain.load(name)
+ if not instance then
+ raise(errors)
+ end
+ return instance
+end
+
+-- return module
+return sandbox_core_tool_toolchain
diff --git a/xmake/plugins/show/lists/toolchains.lua b/xmake/plugins/show/lists/toolchains.lua
index 911fd801c..621d09295 100644
--- a/xmake/plugins/show/lists/toolchains.lua
+++ b/xmake/plugins/show/lists/toolchains.lua
@@ -19,16 +19,16 @@
--
-- imports
-import("core.base.option")
-import("core.project.project")
-import("core.platform.platform")
-import(".showlist")
+import("core.tool.toolchain")
+import("core.base.text")
-- show all toolchains
function main()
- local names = table.copy(platform.toolchains())
- for name, _ in pairs(project.toolchains()) do
- table.insert(names, name)
+
+ local tbl = {align = 'l', sep = " "}
+ for _, name in ipairs(toolchain.list()) do
+ local t = toolchain.load(name)
+ table.insert(tbl, {name, t:get("description")})
end
- showlist(names)
+ print(text.table(tbl))
end
diff --git a/xmake/toolchains/envs/xmake.lua b/xmake/toolchains/envs/xmake.lua
index f5dda488b..46ef2f23a 100644
--- a/xmake/toolchains/envs/xmake.lua
+++ b/xmake/toolchains/envs/xmake.lua
@@ -20,6 +20,9 @@
-- define toolchain
toolchain("envs")
+
+ -- set description
+ set_description("Environment variables toolchain")
-- set toolsets
set_toolsets("cc", "$(env CC)")