summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-03-04 16:30:37 +0800
committerruki <[email protected]>2016-03-04 16:30:37 +0800
commitf81e2102271015548d991db6fe420c9942de7a69 (patch)
tree325c0714a953de7f9137d6b84a38ee96f39308a3
parent1f2256373162935addf69ce870369adb1b17dc5f (diff)
impl global action
-rwxr-xr-xxmake/actions/global/xmake.lua41
-rw-r--r--xmake/core/base/io.lua14
-rw-r--r--xmake/core/base/option.lua8
-rw-r--r--xmake/core/project/global.lua157
-rw-r--r--xmake/core/sandbox/modules/import/core/base/option.lua58
-rw-r--r--xmake/core/sandbox/modules/import/core/project/global.lua34
6 files changed, 199 insertions, 113 deletions
diff --git a/xmake/actions/global/xmake.lua b/xmake/actions/global/xmake.lua
index b74d07315..d93b6e524 100755
--- a/xmake/actions/global/xmake.lua
+++ b/xmake/actions/global/xmake.lua
@@ -29,12 +29,43 @@ task("global")
-- on run
on_task_run(function ()
- printf("$(tmpdir)")
- printf("$(curdir)")
- printf("$(configdir)")
- printf("$(globaldir)")
- printf("$(projectdir)")
+ -- imports
+ import("core.base.option")
+ import("core.project.global")
+ -- clean the cached configure?
+ if option.get("clean") then
+
+ -- clean it
+ global.clean()
+ end
+
+ -- merge the options
+ for name, value in pairs(option.options()) do
+ if name ~= "verbose" and name ~= "clean" then
+ global.set(name, value)
+ end
+ end
+
+ -- merge the default options
+ for name, value in pairs(option.defaults()) do
+ if name ~= "verbose" and name ~= "clean" then
+ global.set(name, value)
+ end
+ end
+
+ -- probe the configure with value: "auto"
+ global.probe()
+
+ -- save it
+ global.save()
+
+ -- dump it
+ global.dump()
+
+ -- trace
+ print("configure ok!")
+
end)
-- set menu
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua
index 14b6e37a3..3b04b9fdd 100644
--- a/xmake/core/base/io.lua
+++ b/xmake/core/base/io.lua
@@ -139,9 +139,18 @@ end
-- save object the the given filepath
function io.save(filepath, object)
+
+ -- check
+ assert(filepath and object)
+
+ -- ensure directory
+ local dir = path.directory(filepath)
+ if not os.isdir(dir) then
+ os.mkdir(dir)
+ end
-- open the file
- local file = io.openmk(filepath)
+ local file = io.open(filepath, "w")
if not file then
-- error
return false, string.format("open %s failed!", filepath)
@@ -164,6 +173,9 @@ end
-- load object from the given file
function io.load(filepath)
+ -- check
+ assert(filepath)
+
-- open the file
local file = io.open(filepath, "r")
if not file then
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua
index 28f52dee3..5a98a6eff 100644
--- a/xmake/core/base/option.lua
+++ b/xmake/core/base/option.lua
@@ -70,7 +70,7 @@ function option.init(argv, menu)
-- init _OPTIONS
option._OPTIONS = {}
- option._OPTIONS._DEFAULTS = {}
+ option._DEFAULTS = {}
-- parse _ARGV to _OPTIONS
local _iter, _s, _k = ipairs(argv)
@@ -308,11 +308,11 @@ function option.init(argv, menu)
assert(key)
-- save the default value
- option._OPTIONS._DEFAULTS[key] = o[4]
+ option._DEFAULTS[key] = o[4]
-- value with name?
elseif o[3] == "v" and o[2] then
-- save the default value
- option._OPTIONS._DEFAULTS[o[2]] = o[4]
+ option._DEFAULTS[o[2]] = o[4]
end
end
@@ -399,7 +399,7 @@ function option.defaults(task)
-- get the default options for the current task
if task == nil then
- return option._OPTIONS._DEFAULTS
+ return option._DEFAULTS
end
-- get the default options for the given task
diff --git a/xmake/core/project/global.lua b/xmake/core/project/global.lua
index 0be86e136..4dc98ccfc 100644
--- a/xmake/core/project/global.lua
+++ b/xmake/core/project/global.lua
@@ -26,38 +26,33 @@ local global = global or {}
-- load modules
local io = require("base/io")
local os = require("base/os")
+local path = require("base/path")
local utils = require("base/utils")
local option = require("base/option")
-- make configure
-function global._make()
+function global._make(configs)
- -- the configs
- local configs = global._CONFIGS
+ -- check
assert(configs)
- -- init current global configure
- global._CURRENT = global._CURRENT or {}
- local current = global._CURRENT
-
-- make current global configure
+ local current = {}
for k, v in pairs(configs) do
if type(k) == "string" and not k:find("^_%u+") then
current[k] = v
end
end
+
+ -- ok
+ return current
end
-- get the configure file
function global._file()
-- get it
- return global.directory() .. "/xmake.conf"
-end
-
--- need configure?
-function global._need(name)
- return name and name ~= "verbose" and name ~= "clean"
+ return path.join(global.directory(), "/xmake.conf")
end
-- get the given configure from the current
@@ -68,7 +63,7 @@ function global.get(name)
-- the value
local value = global._CURRENT[name]
- if value and value == "auto" then
+ if type(value) == "string" and value == "auto" then
value = nil
end
@@ -91,32 +86,39 @@ function global.set(name, value)
end
--- get the global configure directory
-function global.directory()
+-- clean the global configure
+function global.clean()
+
+ -- check
+ assert(global._CURRENT and global._CONFIGS)
- -- the directory
- local dir = path.translate("~/.xmake")
+ -- clean it
+ global._CURRENT = {}
+ global._CONFIGS = {}
- -- create it directly first if not exists
- if not os.isdir(dir) then
- assert(os.mkdir(dir))
+ -- save it
+ if os.isfile(global._file()) then
+ local ok, errors = os.rm(global._file())
+ if not ok then
+ os.raise(errors)
+ end
end
+end
+-- get all options
+function global.options()
+
-- get it
- return dir
+ return global._CURRENT
end
--- save the global configure
-function global.save()
-
- -- the configs
- local configs = global._CONFIGS
- assert(configs)
+-- get the global configure directory
+function global.directory()
- -- save to the configure file
- return io.save(global._file(), configs)
+ -- get it
+ return path.translate("~/.xmake")
end
-
+
-- load the global configure
function global.load()
@@ -145,93 +147,42 @@ function global.load()
-- ok
return true
- --[[
- -- the options
- local options = option.options()
- assert(options)
-
- -- does not clean the cached configure?
- if not option.get("clean") then
-
- TODO
- end
- ]]
-
- --[[
-
- -- xmake global?
- if option.task() == "global" then
-
- -- merge option.options() to the global configure
- for k, v in pairs(options) do
-
- -- check
- assert(type(k) == "string")
-
- -- need configure it?
- if not k:startswith("_") and global._need(k) then
- configs[k] = v
- end
- end
-
- -- merge the default global configure options to the global configure
- local defaults = option.defaults()
- if defaults then
- for k, v in pairs(defaults) do
-
- -- check
- assert(type(k) == "string")
-
- -- need configure it?
- if global._need(k) then
-
- -- save the default option
- if nil == configs[k] then
- configs[k] = v
- end
- end
- end
- end
- end
- ]]
-
end
--- TODO move into probe()
--- clear up and remove all auto values
---[[
-function global.clearup()
+-- save the global configure
+function global.save()
- -- clear up the current configure
- local current = global._CURRENT
- if current then
- for k, v in pairs(current) do
- if v and type(v) and v == "auto" then
- current[k] = nil
- end
+ -- check
+ assert(global._CONFIGS)
+
+ -- remove values with "auto" from the configure
+ local configs = {}
+ for name, value in pairs(global._CONFIGS) do
+ if type(value) ~= "string" or value ~= "auto" then
+ configs[name] = value
end
end
- -- clear up the configure
- local configs = global._CONFIGS
- if configs then
- for k, v in pairs(configs) do
- if v and type(v) and v == "auto" then
- configs[k] = nil
- end
- end
- end
+ -- save it
+ return io.save(global._file(), configs)
end
-]]
-- dump the current configure
function global.dump()
-- check
assert(global._CURRENT)
+
+ -- remove values with "auto" from the configure
+ local configs = {}
+ for name, value in pairs(global._CURRENT) do
+ if type(value) ~= "string" or value ~= "auto" then
+ configs[name] = value
+ end
+ end
-- dump
- utils.dump(global._CURRENT, "__%w*", "configure")
+ utils.dump(configs, "__%w*", "configure")
end
diff --git a/xmake/core/sandbox/modules/import/core/base/option.lua b/xmake/core/sandbox/modules/import/core/base/option.lua
new file mode 100644
index 000000000..21066ce32
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/base/option.lua
@@ -0,0 +1,58 @@
+--!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_core_base_option = sandbox_core_base_option or {}
+
+-- load modules
+local option = require("base/option")
+
+-- get the option value
+function sandbox_core_base_option.get(name)
+
+ -- get it
+ return option.get(name)
+end
+
+-- get the default option value
+function sandbox_core_base_option.default(name)
+
+ -- get it
+ return option.default(name)
+end
+
+-- get the options
+function sandbox_core_base_option.options()
+
+ -- get it
+ return assert(option.options())
+end
+
+-- get the defaults
+function sandbox_core_base_option.defaults()
+
+ -- get it
+ return option.defaults() or {}
+end
+
+-- return module
+return sandbox_core_base_option
diff --git a/xmake/core/sandbox/modules/import/core/project/global.lua b/xmake/core/sandbox/modules/import/core/project/global.lua
index 210df52a3..c8e0af30e 100644
--- a/xmake/core/sandbox/modules/import/core/project/global.lua
+++ b/xmake/core/sandbox/modules/import/core/project/global.lua
@@ -25,6 +25,7 @@ local sandbox_core_project_global = sandbox_core_project_global or {}
-- load modules
local global = require("project/global")
+local platform = require("platform/platform")
local raise = require("sandbox/modules/raise")
-- get the configure
@@ -41,6 +42,39 @@ function sandbox_core_project_global.set(name, value)
global.set(name, value)
end
+-- dump the configure
+function sandbox_core_project_global.dump()
+
+ -- dump it
+ global.dump()
+end
+
+-- save the configure
+function sandbox_core_project_global.save()
+
+ -- get all
+ local ok, errors = global.save()
+ if not ok then
+ raise(errors)
+ end
+end
+
+-- clean the configure
+function sandbox_core_project_global.clean()
+
+ -- clean it
+ global.clean()
+end
+
+-- probe the configure
+function sandbox_core_project_global.probe()
+
+ -- probe it
+ if not platform.probe(true) then
+ raise("probe the global configure failed!")
+ end
+end
+
-- get the configure directory
function sandbox_core_project_global.directory()