summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-21 22:42:23 +0800
committerruki <[email protected]>2020-05-21 10:14:21 +0800
commit7ddbf1f6cb9a11ef792d256bee7da417f4058168 (patch)
treed966cf35cd939243e988ca2df29ad097036fb024
parent38b0a926dfdab29c5c1aaeb182bdba6bda5a2970 (diff)
add platform.toolchains
-rw-r--r--xmake/actions/config/xmake.lua21
-rw-r--r--xmake/core/platform/platform.lua29
-rw-r--r--xmake/core/sandbox/modules/import/core/platform/platform.lua5
3 files changed, 40 insertions, 15 deletions
diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua
index 3b02846d1..2756a3bf1 100644
--- a/xmake/actions/config/xmake.lua
+++ b/xmake/actions/config/xmake.lua
@@ -55,7 +55,7 @@ task("config")
, {'p', "plat", "kv", "$(subhost)" , "Compile for the given platform."
, values = function (complete, opt)
- -- import
+ -- imports
import("core.platform.platform")
import("core.base.hashset")
@@ -77,10 +77,10 @@ task("config")
-- show the description of all architectures
function ()
- -- import platform
+ -- imports
import("core.platform.platform")
- -- make description
+ -- get all architectures
local description = {}
for i, plat in ipairs(platform.plats()) do
local archs = platform.archs(plat)
@@ -91,20 +91,17 @@ task("config")
end
end
end
-
- -- get it
return description
end
, values = function (complete, opt)
if not complete then return end
- -- import
+ -- imports
import("core.platform.platform")
import("core.base.hashset")
- -- get archs
+ -- get all architectures
local archset = hashset.new()
-
for _, plat in ipairs(opt.plat and { opt.plat } or platform.plats()) do
local archs = platform.archs(plat)
if archs then
@@ -113,8 +110,6 @@ task("config")
end
end
end
-
- -- get it
return archset:to_array()
end }
, {'m', "mode", "kv", "release" , "Compile for the given mode."
@@ -157,8 +152,10 @@ task("config")
, " - sdk/lib"
, " - sdk/include" }
, {nil, "toolchain", "kv", nil, "The Toolchain Name"
- , "e.g."
- , " - llvm" }
+ , values = function (complete, opt)
+ import("core.platform.platform")
+ return platform.toolchains()
+ end }
-- show language menu options
, function ()
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index 3fc92be63..182ae17d9 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -503,9 +503,7 @@ function platform.plats()
local plats = {}
local dirs = platform.directories()
for _, dir in ipairs(dirs) do
-
- -- get the platform list
- local platpathes = os.match(path.join(dir, "*"), true)
+ local platpathes = os.dirs(path.join(dir, "*"))
if platpathes then
for _, platpath in ipairs(platpathes) do
if os.isfile(path.join(platpath, "xmake.lua")) then
@@ -518,6 +516,31 @@ function platform.plats()
return plats
end
+-- get the all toolchains
+function platform.toolchains()
+
+ -- return it directly if exists
+ if platform._TOOLCHAINS then
+ return platform._TOOLCHAINS
+ end
+
+ -- get all toolchains
+ local toolchains = {}
+ local dirs = toolchain.directories()
+ for _, dir in ipairs(dirs) do
+ local dirs = os.dirs(path.join(dir, "*"))
+ if dirs then
+ for _, dir in ipairs(dirs) do
+ if os.isfile(path.join(dir, "xmake.lua")) then
+ table.insert(toolchains, path.basename(dir))
+ end
+ end
+ end
+ end
+ platform._TOOLCHAINS = toolchains
+ return toolchains
+end
+
-- get the platform os
function platform.os(plat)
return platform.get("os", plat)
diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua
index 6919010e6..d9730f830 100644
--- a/xmake/core/sandbox/modules/import/core/platform/platform.lua
+++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua
@@ -45,6 +45,11 @@ function sandbox_core_platform.plats()
return assert(platform.plats())
end
+-- get the all toolchains
+function sandbox_core_platform.toolchains()
+ return assert(platform.toolchains())
+end
+
-- get the all architectures for the given platform
function sandbox_core_platform.archs(plat)
return platform.archs(plat)