summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-03-02 21:06:09 +0800
committerruki <[email protected]>2016-03-02 21:06:09 +0800
commit4fa3ca927a032f57aaae44156ceeec6732c159f6 (patch)
tree1091a3ad18f67ac43262899fa49ea529c67beeff
parent8ee46b185347f31fa6f4380c887974cdbafbb1d1 (diff)
add option and global module for sandbox
-rwxr-xr-xxmake/actions/global/xmake.lua10
-rw-r--r--xmake/core/base/global.lua71
-rw-r--r--xmake/core/base/task.lua11
-rw-r--r--xmake/core/sandbox/import/core/global.lua69
-rw-r--r--xmake/core/sandbox/import/core/option.lua37
-rwxr-xr-xxmake/plugins/hello/xmake.lua2
6 files changed, 160 insertions, 40 deletions
diff --git a/xmake/actions/global/xmake.lua b/xmake/actions/global/xmake.lua
index 8c2b2495d..c71f27d15 100755
--- a/xmake/actions/global/xmake.lua
+++ b/xmake/actions/global/xmake.lua
@@ -26,6 +26,16 @@ task("global")
-- set category
set_task_category("action")
+ -- on run
+ on_task_run(function ()
+
+ -- imports
+ import("core.option")
+ import("core.global")
+
+
+ end)
+
-- set menu
set_task_menu({
-- usage
diff --git a/xmake/core/base/global.lua b/xmake/core/base/global.lua
index 2e1afcb13..0be86e136 100644
--- a/xmake/core/base/global.lua
+++ b/xmake/core/base/global.lua
@@ -106,7 +106,7 @@ function global.directory()
return dir
end
--- save xmake.conf
+-- save the global configure
function global.save()
-- the configs
@@ -117,52 +117,47 @@ function global.save()
return io.save(global._file(), configs)
end
--- load xmake.conf
+-- load the global configure
function global.load()
- -- the options
- local options = option.options()
- assert(options)
+ -- load configure from the file first
+ local filepath = global._file()
+ if os.isfile(filepath) then
- -- check
- assert(option._MENU)
- assert(option._MENU.global)
+ -- load configs
+ local configs, errors = io.load(filepath)
- -- get all configure names
- local i = 1
- local configures = {}
- for _, o in ipairs(option._MENU.global.options) do
- local name = o[2]
- if global._need(name) then
- configures[i] = name
- i = i + 1
+ -- error?
+ if not configs and errors then
+ utils.error(errors)
end
+
+ -- save configs
+ global._CONFIGS = configs
end
- -- does not clean the cached configure?
- if not option.get("clean") then
+ -- init configs
+ global._CONFIGS = global._CONFIGS or {}
- -- load and execute the xmake.conf
- local filepath = global._file()
- if os.isfile(filepath) then
+ -- make the current configs
+ global._CURRENT = global._make(global._CONFIGS)
- -- load the configure file
- local configs, errors = io.load(filepath)
+ -- ok
+ return true
- -- exists local configures?
- if configs then
- -- save configs
- global._CONFIGS = configs
- elseif errors then
- -- error
- utils.error(errors)
- end
- end
+ --[[
+ -- the options
+ local options = option.options()
+ assert(options)
+
+ -- does not clean the cached configure?
+ if not option.get("clean") then
+
+ TODO
end
+ ]]
- -- init configs
- global._CONFIGS = global._CONFIGS or {}
- local configs = global._CONFIGS
+ --[[
-- xmake global?
if option.task() == "global" then
@@ -198,12 +193,13 @@ function global.load()
end
end
end
+ ]]
- -- make the current global
- global._make()
end
+-- TODO move into probe()
-- clear up and remove all auto values
+--[[
function global.clearup()
-- clear up the current configure
@@ -226,6 +222,7 @@ function global.clearup()
end
end
end
+]]
-- dump the current configure
function global.dump()
diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua
index cda0c3356..d58844862 100644
--- a/xmake/core/base/task.lua
+++ b/xmake/core/base/task.lua
@@ -80,7 +80,8 @@ function task._interpreter()
-- init maps
local maps =
{
- host = xmake._HOST
+ host = xmake._HOST
+ , globaldir = global.directory()
}
-- map it
@@ -273,6 +274,14 @@ function task.run(name)
return false
end
+ -- load global
+ if not global.load() then
+
+ -- trace
+ utils.error("load global configure failed!")
+ return false
+ end
+
-- run on_before, on_run, on_after
local ok = true
local on_scripts = {taskinfo.before, taskinfo.run, taskinfo.after}
diff --git a/xmake/core/sandbox/import/core/global.lua b/xmake/core/sandbox/import/core/global.lua
new file mode 100644
index 000000000..b4f6460df
--- /dev/null
+++ b/xmake/core/sandbox/import/core/global.lua
@@ -0,0 +1,69 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file global.lua
+--
+
+-- define module
+local sandbox_global = sandbox_global or {}
+
+-- load modules
+local global = require("base/global")
+local raise = require("sandbox/raise")
+
+-- get the configure
+function sandbox_global.get(name)
+
+ -- get it
+ return global.get(name)
+end
+
+-- set the configure
+function sandbox_global.set(name, value)
+
+ -- set it
+ global.set(name, value)
+end
+
+-- get the configure directory
+function sandbox_global.directory()
+
+ -- get it
+ local dir = global.directory()
+ assert(dir)
+
+ -- ok?
+ return dir
+end
+
+-- save the current configure
+function sandbox_global.save()
+
+ -- save it
+ local ok, errors = global.save()
+ if not ok then
+ raise("cannot save global configure, %s", errors)
+ end
+
+ -- ok
+ return true
+end
+
+-- return module
+return sandbox_global
diff --git a/xmake/core/sandbox/import/core/option.lua b/xmake/core/sandbox/import/core/option.lua
new file mode 100644
index 000000000..d45363dbc
--- /dev/null
+++ b/xmake/core/sandbox/import/core/option.lua
@@ -0,0 +1,37 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file option.lua
+--
+
+-- define module
+local sandbox_option = sandbox_option or {}
+
+-- load modules
+local option = require("base/option")
+
+-- get the option
+function sandbox_option.get(name)
+
+ -- get it
+ return option.get(name)
+end
+
+-- return module
+return sandbox_option
diff --git a/xmake/plugins/hello/xmake.lua b/xmake/plugins/hello/xmake.lua
index 9289c2b14..2d291eb24 100755
--- a/xmake/plugins/hello/xmake.lua
+++ b/xmake/plugins/hello/xmake.lua
@@ -45,5 +45,3 @@ task("hello")
-- options
, options = {}
})
-
-