summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-21 23:07:29 +0800
committerruki <[email protected]>2020-05-21 12:44:59 +0800
commitcf943ea441cdb49e426e2a3cedc1134922529644 (patch)
treefd9b623c42c6b0d91217d95580bef8f87fb2bc4a
parent7ddbf1f6cb9a11ef792d256bee7da417f4058168 (diff)
improve to check toolchains
-rw-r--r--xmake/core/platform/platform.lua70
-rw-r--r--xmake/core/sandbox/modules/import/core/project/config.lua5
-rw-r--r--xmake/platforms/android/check.lua11
-rw-r--r--xmake/platforms/bsd/check.lua22
-rw-r--r--xmake/platforms/cross/check.lua11
-rw-r--r--xmake/platforms/cygwin/check.lua23
-rw-r--r--xmake/platforms/iphoneos/check.lua12
-rw-r--r--xmake/platforms/linux/check.lua23
-rw-r--r--xmake/platforms/macosx/check.lua23
-rw-r--r--xmake/platforms/mingw/check.lua12
-rw-r--r--xmake/platforms/msys/check.lua23
-rw-r--r--xmake/platforms/watchos/check.lua11
-rw-r--r--xmake/platforms/windows/check.lua23
13 files changed, 60 insertions, 209 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index 182ae17d9..0131895ec 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -122,25 +122,34 @@ function _instance:runenvs()
end
-- get the toolchains
-function _instance:toolchains()
+function _instance:toolchains(opt)
local toolchains = self._TOOLCHAINS
if not toolchains then
- -- get the given toolchain
+ -- get current valid toolchains from configuration cache
+ local names = nil
toolchains = {}
- local toolchain_given = config.get("toolchain")
- if toolchain_given then
- local toolchain_inst, errors = toolchain.load(toolchain_given, self:name())
- if not toolchain_inst then
- os.raise(errors)
+ if not (opt and opt.all) then
+ names = config.get("__toolchains")
+ else
+ -- get the given toolchain
+ local toolchain_given = config.get("toolchain")
+ if toolchain_given then
+ local toolchain_inst, errors = toolchain.load(toolchain_given, self:name())
+ if not toolchain_inst then
+ os.raise(errors)
+ end
+ table.insert(toolchains, toolchain_inst)
+ toolchain_given = toolchain_inst
end
- table.insert(toolchains, toolchain_inst)
- toolchain_given = toolchain_inst
- end
- -- get the platform toolchains
- if (not toolchain_given or not toolchain_given:standalone()) and self._INFO:get("toolchains") then
- for _, name in ipairs(self._INFO:get("toolchains")) do
+ -- get the platform toolchains
+ if (not toolchain_given or not toolchain_given:standalone()) and self._INFO:get("toolchains") then
+ names = self._INFO:get("toolchains")
+ end
+ end
+ if names then
+ for _, name in ipairs(names) do
local toolchain_inst, errors = toolchain.load(name, self:name())
if not toolchain_inst then
os.raise(errors)
@@ -239,10 +248,43 @@ end
-- do check
function _instance:check()
+
+ -- check platform
local on_check = self:script("check")
if on_check then
- on_check(self)
+ local ok, errors = sandbox.load(on_check, self)
+ if not ok then
+ return false, errors
+ end
+ end
+
+ -- check toolchains
+ local toolchains = self:toolchains({all = true})
+ local idx = 1
+ local num = #toolchains
+ local standalone = false
+ local toolchains_valid = {}
+ while idx <= num do
+ local toolchain = toolchains[idx]
+ -- we need remove other standalone toolchains if standalone toolchain found
+ if (standalone and toolchain:standalone()) or not toolchain:check() then
+ table.remove(toolchains, idx)
+ num = num - 1
+ else
+ if toolchain:standalone() then
+ standalone = true
+ end
+ idx = idx + 1
+ table.insert(toolchains_valid, toolchain:name())
+ end
end
+ if #toolchains == 0 then
+ return false, "toolchains not found!"
+ end
+
+ -- save valid toolchains
+ config.set("__toolchains", toolchains_valid)
+ return true
end
-- get formats
diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua
index c7121a8a4..3ea6d3a30 100644
--- a/xmake/core/sandbox/modules/import/core/project/config.lua
+++ b/xmake/core/sandbox/modules/import/core/project/config.lua
@@ -116,7 +116,10 @@ function sandbox_core_project_config.check()
-- get the current platform
local instance, errors = platform.load()
if instance then
- instance:check()
+ local ok, errors = instance:check()
+ if not ok then
+ raise(errors)
+ end
else
raise(errors)
end
diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua
index c262e1bed..5db47502a 100644
--- a/xmake/platforms/android/check.lua
+++ b/xmake/platforms/android/check.lua
@@ -24,17 +24,6 @@ import("private.platform.check_arch")
-- check it
function main(platform)
-
- -- check arch
check_arch(config, "armeabi-v7a")
-
- -- check toolchains
- local toolchains = platform:toolchains()
- for idx, toolchain in irpairs(toolchains) do
- if not toolchain:check() then
- table.remove(toolchains, idx)
- end
- end
- assert(#toolchains > 0, "toolchains not found!")
end
diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua
index 71d2e555c..50c933cba 100644
--- a/xmake/platforms/bsd/check.lua
+++ b/xmake/platforms/bsd/check.lua
@@ -24,28 +24,6 @@ import("private.platform.check_arch")
-- check it
function main(platform)
-
- -- check arch
check_arch(config, os.arch())
-
- -- check toolchains
- local toolchains = platform:toolchains()
- local idx = 1
- local num = #toolchains
- local standalone = false
- while idx <= num do
- local toolchain = toolchains[idx]
- -- we need remove other standalone toolchains if standalone toolchain found
- if (standalone and toolchain:standalone()) or not toolchain:check() then
- table.remove(toolchains, idx)
- num = num - 1
- else
- if toolchain:standalone() then
- standalone = true
- end
- idx = idx + 1
- end
- end
- assert(#toolchains > 0, "toolchains not found!")
end
diff --git a/xmake/platforms/cross/check.lua b/xmake/platforms/cross/check.lua
index 0c95f43c9..6c02f12b5 100644
--- a/xmake/platforms/cross/check.lua
+++ b/xmake/platforms/cross/check.lua
@@ -33,17 +33,6 @@ end
-- check it
function main(platform)
-
- -- check arch
_check_arch()
-
- -- check toolchains
- local toolchains = platform:toolchains()
- for idx, toolchain in irpairs(toolchains) do
- if not toolchain:check() then
- table.remove(toolchains, idx)
- end
- end
- assert(#toolchains > 0, "toolchains not found!")
end
diff --git a/xmake/platforms/cygwin/check.lua b/xmake/platforms/cygwin/check.lua
index 8cd3cfbe0..5c5902225 100644
--- a/xmake/platforms/cygwin/check.lua
+++ b/xmake/platforms/cygwin/check.lua
@@ -24,28 +24,5 @@ import("private.platform.check_arch")
-- check it
function main(platform)
-
- -- check arch
check_arch(config, config.get("cross") and "none" or os.subarch())
-
- -- check toolchains
- local toolchains = platform:toolchains()
- local idx = 1
- local num = #toolchains
- local standalone = false
- while idx <= num do
- local toolchain = toolchains[idx]
- -- we need remove other standalone toolchains if standalone toolchain found
- if (standalone and toolchain:standalone()) or not toolchain:check() then
- table.remove(toolchains, idx)
- num = num - 1
- else
- if toolchain:standalone() then
- standalone = true
- end
- idx = idx + 1
- end
- end
- assert(#toolchains > 0, "toolchains not found!")
end
-
diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua
index ad0110b39..520420f84 100644
--- a/xmake/platforms/iphoneos/check.lua
+++ b/xmake/platforms/iphoneos/check.lua
@@ -24,17 +24,5 @@ import("private.platform.check_arch")
-- check it
function main(platform)
-
- -- check arch
check_arch(config, "arm64")
-
- -- check toolchains
- local toolchains = platform:toolchains()
- for idx, toolchain in irpairs(toolchains) do
- if not toolchain:check() then
- table.remove(toolchains, idx)
- end
- end
- assert(#toolchains > 0, "toolchains not found!")
end
-
diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua
index 71d2e555c..2d3a4a063 100644
--- a/xmake/platforms/linux/check.lua
+++ b/xmake/platforms/linux/check.lua
@@ -24,28 +24,5 @@ import("private.platform.check_arch")
-- check it
function main(platform)
-
- -- check arch
check_arch(config, os.arch())
-
- -- check toolchains
- local toolchains = platform:toolchains()
- local idx = 1
- local num = #toolchains
- local standalone = false
- while idx <= num do
- local toolchain = toolchains[idx]
- -- we need remove other standalone toolchains if standalone toolchain found
- if (standalone and toolchain:standalone()) or not toolchain:check() then
- table.remove(toolchains, idx)
- num = num - 1
- else
- if toolchain:standalone() then
- standalone = true
- end
- idx = idx + 1
- end
- end
- assert(#toolchains > 0, "toolchains not found!")
end
-
diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua
index b4eb3b73b..0885534cc 100644
--- a/xmake/platforms/macosx/check.lua
+++ b/xmake/platforms/macosx/check.lua
@@ -24,28 +24,5 @@ import("private.platform.check_arch")
-- check it
function main(platform)
-
- -- check arch
check_arch(config)
-
- -- check toolchains
- local toolchains = platform:toolchains()
- local idx = 1
- local num = #toolchains
- local standalone = false
- while idx <= num do
- local toolchain = toolchains[idx]
- -- we need remove other standalone toolchains if standalone toolchain found
- if (standalone and toolchain:standalone()) or not toolchain:check() then
- table.remove(toolchains, idx)
- num = num - 1
- else
- if toolchain:standalone() then
- standalone = true
- end
- idx = idx + 1
- end
- end
- assert(#toolchains > 0, "toolchains not found!")
end
-
diff --git a/xmake/platforms/mingw/check.lua b/xmake/platforms/mingw/check.lua
index a44983421..6b81b5d92 100644
--- a/xmake/platforms/mingw/check.lua
+++ b/xmake/platforms/mingw/check.lua
@@ -24,17 +24,5 @@ import("private.platform.check_arch")
-- check it
function main(platform)
-
- -- check arch
check_arch(config, "x86_64")
-
- -- check toolchains
- local toolchains = platform:toolchains()
- for idx, toolchain in irpairs(toolchains) do
- if not toolchain:check() then
- table.remove(toolchains, idx)
- end
- end
- assert(#toolchains > 0, "toolchains not found!")
end
-
diff --git a/xmake/platforms/msys/check.lua b/xmake/platforms/msys/check.lua
index 8cd3cfbe0..5c5902225 100644
--- a/xmake/platforms/msys/check.lua
+++ b/xmake/platforms/msys/check.lua
@@ -24,28 +24,5 @@ import("private.platform.check_arch")
-- check it
function main(platform)
-
- -- check arch
check_arch(config, config.get("cross") and "none" or os.subarch())
-
- -- check toolchains
- local toolchains = platform:toolchains()
- local idx = 1
- local num = #toolchains
- local standalone = false
- while idx <= num do
- local toolchain = toolchains[idx]
- -- we need remove other standalone toolchains if standalone toolchain found
- if (standalone and toolchain:standalone()) or not toolchain:check() then
- table.remove(toolchains, idx)
- num = num - 1
- else
- if toolchain:standalone() then
- standalone = true
- end
- idx = idx + 1
- end
- end
- assert(#toolchains > 0, "toolchains not found!")
end
-
diff --git a/xmake/platforms/watchos/check.lua b/xmake/platforms/watchos/check.lua
index e4e36f092..bd8852db3 100644
--- a/xmake/platforms/watchos/check.lua
+++ b/xmake/platforms/watchos/check.lua
@@ -24,16 +24,5 @@ import("private.platform.check_arch")
-- check it
function main(platform)
-
- -- check arch
check_arch(config, "armv7k")
-
- -- check toolchains
- local toolchains = platform:toolchains()
- for idx, toolchain in irpairs(toolchains) do
- if not toolchain:check() then
- table.remove(toolchains, idx)
- end
- end
- assert(#toolchains > 0, "toolchains not found!")
end
diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua
index 0dfc7b536..0885534cc 100644
--- a/xmake/platforms/windows/check.lua
+++ b/xmake/platforms/windows/check.lua
@@ -24,28 +24,5 @@ import("private.platform.check_arch")
-- check it
function main(platform)
-
- -- check arch
check_arch(config)
-
- -- check toolchains
- local toolchains = platform:toolchains()
- local idx = 1
- local num = #toolchains
- local standalone = false
- while idx <= num do
- local toolchain = toolchains[idx]
- -- we need remove other standalone toolchains if standalone toolchain found
- if (standalone and toolchain:standalone()) or not toolchain:check() then
- table.remove(toolchains, idx)
- num = num - 1
- else
- if toolchain:standalone() then
- standalone = true
- end
- idx = idx + 1
- end
- end
- assert(#toolchains > 0, "toolchains not found!")
end
-