summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-06-27 20:57:03 +0800
committerruki <[email protected]>2017-06-27 21:52:59 +0800
commitf71dd757c0294508d2e937d907bc6ec11f38f3ec (patch)
tree45f2d404f88f9fab5606f49515f00c0e239f8001
parent02089d7955813aee5d34671f2a92639d8b8bd7d3 (diff)
impl check options with multi-jobs
-rw-r--r--xmake/core/project/project.lua44
-rw-r--r--xmake/core/sandbox/modules/import/core/project/project.lua42
-rw-r--r--xmake/core/sandbox/sandbox.lua44
3 files changed, 70 insertions, 60 deletions
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 649d41141..06d578066 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -31,6 +31,7 @@ local io = require("base/io")
local path = require("base/path")
local utils = require("base/utils")
local table = require("base/table")
+local process = require("base/process")
local deprecated = require("base/deprecated")
local interpreter = require("base/interpreter")
local target = require("project/target")
@@ -40,7 +41,6 @@ local option = require("project/option")
local package = require("project/package")
local deprecated_project = require("project/deprecated/project")
local platform = require("platform/platform")
-local environment = require("platform/environment")
local language = require("language/language")
local sandbox_os = require("sandbox/modules/os")
@@ -370,42 +370,6 @@ function project.directory()
return xmake._PROJECT_DIR
end
--- check the project
-function project.check(force)
-
- -- enter the project directory
- local ok, errors = os.cd(project.directory())
- if not ok then
- return false, errors
- end
-
- -- load the options from the the project file
- local options, errors = project.options(true)
- if not options then
- return false, errors
- end
-
- -- enter toolchains environment
- environment.enter("toolchains")
-
- -- check all options
- for _, opt in pairs(options) do
- opt:check(force)
- end
-
- -- leave toolchains environment
- environment.leave("toolchains")
-
- -- leave the project directory
- ok, errors = os.cd("-")
- if not ok then
- return false, errors
- end
-
- -- ok
- return true
-end
-
-- get the project info from the given name
function project.get(name)
@@ -521,7 +485,7 @@ function project.options(enable_filter)
instance._INFO = optioninfo
-- save it
- options[optionname] = instance
+ table.insert(options,instance)
end
-- ok?
@@ -579,7 +543,7 @@ function project.menu()
-- arrange options by category
local options_by_category = {}
- for name, opt in pairs(options) do
+ for _, opt in ipairs(options) do
-- make the category
local category = "default"
@@ -587,7 +551,7 @@ function project.menu()
options_by_category[category] = options_by_category[category] or {}
-- append option to the current category
- options_by_category[category][name] = opt
+ options_by_category[category][opt:name()] = opt
end
-- make menu by category
diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua
index 2b5643e90..c099ec61b 100644
--- a/xmake/core/sandbox/modules/import/core/project/project.lua
+++ b/xmake/core/sandbox/modules/import/core/project/project.lua
@@ -26,10 +26,12 @@
local sandbox_core_project = sandbox_core_project or {}
-- load modules
-local table = require("base/table")
-local config = require("project/config")
-local project = require("project/project")
-local raise = require("sandbox/modules/raise")
+local table = require("base/table")
+local config = require("project/config")
+local project = require("project/project")
+local sandbox = require("sandbox/sandbox")
+local raise = require("sandbox/modules/raise")
+local environment = require("platform/environment")
-- load project
function sandbox_core_project.load()
@@ -44,8 +46,36 @@ end
-- check project options
function sandbox_core_project.check(force)
- -- check it
- local ok, errors = project.check(force)
+ -- enter the project directory
+ local ok, errors = os.cd(project.directory())
+ if not ok then
+ raise(errors)
+ end
+
+ -- load the options from the the project file
+ local options, errors = project.options(true)
+ if not options then
+ raise(errors)
+ end
+
+ -- get sandbox instance
+ local instance = sandbox:instance()
+ assert(instance)
+
+ -- enter toolchains environment
+ environment.enter("toolchains")
+
+ -- check all options
+ ok, errors = process.runjobs(instance:bind(function (index) options[index]:check(force) end), #options, 4)
+ if not ok then
+ raise(errors)
+ end
+
+ -- leave toolchains environment
+ environment.leave("toolchains")
+
+ -- leave the project directory
+ ok, errors = os.cd("-")
if not ok then
raise(errors)
end
diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua
index 222312b1c..dec8c0a78 100644
--- a/xmake/core/sandbox/sandbox.lua
+++ b/xmake/core/sandbox/sandbox.lua
@@ -134,19 +134,8 @@ function sandbox._new()
end
end
- -- save instance
- setmetatable(instance._PUBLIC, { __index = function (tbl, key)
- if type(key) == "string" and key == "_SANDBOX" and rawget(tbl, "_SANDBOX_READABLE") then
- return instance
- end
- return rawget(tbl, key)
- end
- , __newindex = function (tbl, key, val)
- if type(key) == "string" and (key == "_SANDBOX" or key == "_SANDBOX_READABLE") then
- return
- end
- rawset(tbl, key, val)
- end})
+ -- bind instance to the public script envirnoment
+ instance:bind(instance._PUBLIC)
-- ok?
return instance
@@ -192,7 +181,34 @@ function sandbox.load(script, ...)
return xpcall(script, sandbox._traceback, ...)
end
--- fork a new sandbox from the given sandbox
+-- bind self instance to the given script or envirnoment
+function sandbox:bind(script_or_env)
+
+ -- get envirnoment
+ local env = script_or_env
+ if type(script_or_env) == "function" then
+ env = getfenv(script_or_env)
+ end
+
+ -- bind instance to the script envirnoment
+ setmetatable(env, { __index = function (tbl, key)
+ if type(key) == "string" and key == "_SANDBOX" and rawget(tbl, "_SANDBOX_READABLE") then
+ return self
+ end
+ return rawget(tbl, key)
+ end
+ , __newindex = function (tbl, key, val)
+ if type(key) == "string" and (key == "_SANDBOX" or key == "_SANDBOX_READABLE") then
+ return
+ end
+ rawset(tbl, key, val)
+ end})
+
+ -- ok
+ return script_or_env
+end
+
+-- fork a new sandbox from the self sandbox
function sandbox:fork(script, rootdir)
-- invalid script?