summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-20 22:36:58 +0800
committerruki <[email protected]>2020-05-20 09:41:49 +0800
commit5627a51d82327a2d694be53d1587e6a10671278c (patch)
tree40e952d8ced292c410e063007981558fc1ae0b2e
parentf518249b35a6eda0f73bb82ec346c2ddfa77fc64 (diff)
improve linux/bsd platforms
-rw-r--r--xmake/platforms/bsd/check.lua21
-rw-r--r--xmake/platforms/linux/check.lua21
-rw-r--r--xmake/platforms/linux/xmake.lua2
-rw-r--r--xmake/toolchains/cross/check.lua16
4 files changed, 49 insertions, 11 deletions
diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua
index c435b7ad9..3cd6b8980 100644
--- a/xmake/platforms/bsd/check.lua
+++ b/xmake/platforms/bsd/check.lua
@@ -22,6 +22,12 @@
import("core.project.config")
import("private.platform.check_arch")
+-- is basic toolchain?
+function _is_basic_toolchain(toolchain)
+ local name = toolchain:name()
+ return name == "clang" or name == "gcc"
+end
+
-- check it
function main(platform)
@@ -30,9 +36,20 @@ function main(platform)
-- check toolchains
local toolchains = platform:toolchains()
- for idx, toolchain in irpairs(toolchains) do
- if not toolchain:check() then
+ local idx = 1
+ local num = #toolchains
+ local has_basic = false
+ while idx <= num do
+ local toolchain = toolchains[idx]
+ -- we need remove other same basic toolchains if basic toolchain found
+ if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then
table.remove(toolchains, idx)
+ num = num - 1
+ else
+ if _is_basic_toolchain(toolchain) then
+ has_basic = true
+ end
+ idx = idx + 1
end
end
assert(#toolchains > 0, "toolchains not found!")
diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua
index c435b7ad9..a851256e5 100644
--- a/xmake/platforms/linux/check.lua
+++ b/xmake/platforms/linux/check.lua
@@ -22,6 +22,12 @@
import("core.project.config")
import("private.platform.check_arch")
+-- is basic toolchain?
+function _is_basic_toolchain(toolchain)
+ local name = toolchain:name()
+ return name == "cross" or name == "clang" or name == "gcc"
+end
+
-- check it
function main(platform)
@@ -30,9 +36,20 @@ function main(platform)
-- check toolchains
local toolchains = platform:toolchains()
- for idx, toolchain in irpairs(toolchains) do
- if not toolchain:check() then
+ local idx = 1
+ local num = #toolchains
+ local has_basic = false
+ while idx <= num do
+ local toolchain = toolchains[idx]
+ -- we need remove other same basic toolchains if basic toolchain found
+ if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then
table.remove(toolchains, idx)
+ num = num - 1
+ else
+ if _is_basic_toolchain(toolchain) then
+ has_basic = true
+ end
+ idx = idx + 1
end
end
assert(#toolchains > 0, "toolchains not found!")
diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua
index 250441a68..0b13c1a5b 100644
--- a/xmake/platforms/linux/xmake.lua
+++ b/xmake/platforms/linux/xmake.lua
@@ -40,7 +40,7 @@ platform("linux")
on_check("check")
-- set toolchains
- set_toolchains("envs", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust")
+ set_toolchains("envs", "cross", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust")
-- set menu
set_menu {
diff --git a/xmake/toolchains/cross/check.lua b/xmake/toolchains/cross/check.lua
index 6a5bd874d..34b62ccc0 100644
--- a/xmake/toolchains/cross/check.lua
+++ b/xmake/toolchains/cross/check.lua
@@ -25,17 +25,21 @@ import("detect.sdks.find_cross_toolchain")
-- check the cross toolchain
function main(toolchain)
+ -- is cross?
+ local sdkdir = config.get("sdk")
+ local bindir = config.get("bin")
+ local cross = config.get("cross")
+ if not sdkdir and not bindir and not cross then
+ return
+ end
+
-- find cross toolchain
- local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")})
+ local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir, cross = cross})
if cross_toolchain then
config.set("cross", cross_toolchain.cross, {readonly = true, force = true})
config.set("bin", cross_toolchain.bindir, {readonly = true, force = true})
else
- -- failed
- cprint("${bright color.error}cross toolchain not found, please run:")
- cprint(" - xmake config --sdk=xxx")
- cprint("or - xmake global --sdk=xxx")
- raise()
+ raise("cross toolchain not found!")
end
return cross_toolchain
end