summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-03-15 11:53:09 +0800
committerruki <[email protected]>2016-03-15 11:53:09 +0800
commitbc40eac3e633a4120313e95abb54da103fc48c39 (patch)
tree25efc1557fdd45617b1bbb6d11bacc6244cec198
parent27ee91d65fe054439195781808da6cb57316238e (diff)
load config for task
-rwxr-xr-xxmake/actions/config/main.lua31
-rw-r--r--xmake/core/project/config.lua339
-rw-r--r--xmake/core/project/global.lua28
-rw-r--r--xmake/core/project/task.lua12
-rw-r--r--xmake/core/sandbox/modules/import.lua1
-rw-r--r--xmake/core/sandbox/modules/import/core/project/config.lua25
-rw-r--r--xmake/core/sandbox/modules/import/core/project/global.lua5
7 files changed, 122 insertions, 319 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index b213e5e7d..6e60c4793 100755
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -20,8 +20,37 @@
-- @file main.lua
--
+-- imports
+import("core.base.option")
+import("core.project.config")
+
+-- main
function main()
- print("main")
+ -- clean the cached configure?
+ if option.get("clean") then
+
+ -- clean it
+ config.clean()
+ end
+
+ --[[
+ -- merge the options
+ for name, value in pairs(option.options()) do
+ if name ~= "verbose" and name ~= "clean" then
+ config.set(name, value)
+ end
+ end
+
+ -- merge the default options
+ for name, value in pairs(option.defaults()) do
+ if name ~= "verbose" and name ~= "clean" then
+ config.set(name, value)
+ end
+ end
+ ]]
+
+ -- probe the configure with value: "auto"
+-- config.probe()
end
diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua
index e1bb9a961..35748ee78 100644
--- a/xmake/core/project/config.lua
+++ b/xmake/core/project/config.lua
@@ -20,7 +20,7 @@
-- @file config.lua
--
--- define module: config
+-- define module
local config = config or {}
-- load modules
@@ -31,33 +31,41 @@ local utils = require("base/utils")
local option = require("base/option")
local global = require("project/global")
--- make configure for the current target
+-- get the configure file
+function config._file()
+
+ -- get it
+ return path.join(config.directory(), "/xmake.conf")
+end
+
+-- make configure
function config._make(configs)
-- init current target configure
local current = {}
+ --[[
-- get configs from the default configure
if configs._DEFAULTS then
for k, v in pairs(configs._DEFAULTS) do
if type(v) ~= "string" or v ~= "auto" then current[k] = v end
end
end
+ ]]
- -- get configs from the global configure
- if global._CURRENT then
- for k, v in pairs(global._CURRENT) do
- current[k] = v
- end
+ -- make current configure from the global configure
+ for k, v in pairs(global.options()) do
+ current[k] = v
end
- -- get configs from all targets
+ -- make current configure from the project configure
for k, v in pairs(configs) do
if type(k) == "string" and not k:find("^_%u+") then
current[k] = v
end
end
+ --[[
-- get configs from the current target
if configs._TARGETS and current.target ~= "all" then
@@ -70,319 +78,68 @@ function config._make(configs)
current[k] = v
end
end
- end
+ end]]
- -- ok?
+ -- ok
return current
end
--- get the configure file
-function config._file()
-
- -- get it
- return path.join(config.directory(), "xmake.conf")
-end
-
--- need configure?
-function config._need(name)
- return name and name ~= "target" and name ~= "file" and name ~= "project" and name ~= "verbose" and name ~= "clean"
-end
-
--- get the current target scope
-function config._target()
-
- -- check
- local configs = config._CONFIGS
- assert(configs)
-
- -- the target name
- local name = option.get("target")
- assert(name and type(name) == "string")
-
- -- for all targets?
- if name == "all" then
- return configs
- elseif configs._TARGETS then
- -- get it
- return configs._TARGETS[name]
- end
-end
-
--- get the given configure from the current
-function config.get(name)
-
- -- the configure has been not loaded
- if not config._CURRENT then return end
-
- -- get it
- return config._CURRENT[name]
-end
-
--- set the given configure to the current
-function config.set(name, value)
+-- clean the project configure
+function config.clean()
-- check
- assert(config._CURRENT and name)
+ assert(config._CURRENT and config._CONFIGS)
- -- get the current target
- local target = config._target()
- assert(target)
+ -- clean it
+ config._CURRENT = {}
+ config._CONFIGS = {}
- -- set it to the current target configure for saving to file
- target[name] = value
-
- -- set it to the current configure
- config._CURRENT[name] = value
-end
-
--- the given configure need probe automatically
-function config.auto(name)
-
- -- the configs
- local configs = config._CONFIGS
- assert(configs)
-
- -- need probe it automatically?
- if configs._DEFAULTS then
- local value = configs._DEFAULTS[name]
- if value then
- if type(value) == "string" and value == "auto" then
- return true
- end
+ -- save it
+ if os.isfile(config._file()) then
+ local ok, errors = os.rm(config._file())
+ if not ok then
+ return false, errors
end
end
- -- need not probe it if have been setted manually
- if config._CURRENT and nil ~= config._CURRENT[name] then
- return false
- end
-
- -- attempt to probe it if not exists
+ -- ok
return true
end
-- get the configure directory
function config.directory()
- -- the directory
- local dir = path.join(xmake._PROJECT_DIR, ".xmake")
-
- -- create it directly first if not exists
- if not os.isdir(dir) then
- assert(os.mkdir(dir))
- end
-
-- get it
- return dir
-end
-
--- save xmake.conf
-function config.save()
-
- -- the configs
- local configs = config._CONFIGS
- assert(configs)
-
- -- save to the configure file
- return io.save(config._file(), configs)
+ return path.join(xmake._PROJECT_DIR, ".xmake")
end
+-- TODO: reconfig, rebuild, defaults, targets
+-- load the project configure
function config.load()
- -- the options
- local options = option.options()
- assert(options)
-
- -- check
- assert(option._MENU)
- assert(option._MENU.config)
-
- -- the target name
- local name = option.get("target")
- if not name then
- return "no given target name!"
- end
-
- -- does not clean the cached configure?
- if not option.get("clean") then
-
- -- load and execute the xmake.xconf
- local filepath = config._file()
- if os.isfile(filepath) then
-
- -- load the configure file
- local configs, errors = io.load(filepath)
-
- -- exists local configures?
- if configs then
-
- -- save configs
- config._CONFIGS = configs
-
- -- make the current target configs
- local current = config._make(configs)
+ -- load configure from the file first
+ local filepath = config._file()
+ if os.isfile(filepath) then
- -- clear configs and mark as "rebuild" and "reconfig" if the host has been changed
- if (current and current.host ~= xmake._HOST) then
+ -- load configs
+ local configs, errors = io.load(filepath)
- -- clear configs and mark as "rebuild"
- config._CONFIGS = { __rebuild = true }
-
- -- mark as "reconfig" if the current action is not "config"
- if option.task() ~= "config" then
- config._RECONFIG = true
- end
- end
-
- -- clear configs and mark as "rebuild" if the plat has been changed
- if current and current.plat and options.plat and current.plat ~= options.plat then
-
- -- clear configs and mark as "rebuild"
- config._CONFIGS = { __rebuild = true }
- end
-
- -- mark as "rebuild" if the arch has been changed
- if current and current.arch and options.arch and current.arch ~= options.arch then
-
- -- mark as "rebuild"
- config._CONFIGS.__rebuild = true
- end
-
- -- mark as "rebuild" if the mode has been changed
- if current and current.mode and options.mode and current.mode ~= options.mode then
-
- -- mark as "rebuild"
- config._CONFIGS.__rebuild = true
- end
- elseif errors then
- -- error
- utils.error(errors)
- end
- end
- end
-
- -- init configs if not exists
- if not config._CONFIGS then
- -- clear configs and mark as "rebuild"
- config._CONFIGS = { __rebuild = true }
-
- -- mark as "reconfig" if the current action is not "config"
- if option.task() ~= "config" then
- config._RECONFIG = true
- end
- end
-
- -- the configs
- local configs = config._CONFIGS
-
- -- mark as "rebuild" if clean the cached configure
- if option.get("clean") then
- configs.__rebuild = true
- end
-
- -- init the defaults
- local defaults = nil
- if not configs._DEFAULTS then
- if config._RECONFIG then defaults = option.defaults("config")
- elseif option.task() == "config" then defaults = option.defaults()
+ -- error?
+ if not configs and errors then
+ utils.error(errors)
end
- if defaults then
- for k, v in pairs(defaults) do
-
- -- check
- assert(type(k) == "string")
-
- -- skip some options
- if config._need(k) then
- -- save the default option
- configs._DEFAULTS = configs._DEFAULTS or {}
- configs._DEFAULTS[k] = v
- end
- end
- end
- end
- defaults = configs._DEFAULTS
-
- -- init targets
- configs._TARGETS = configs._TARGETS or {}
- if name ~= "all" then
- configs._TARGETS[name] = configs._TARGETS[name] or {}
+ -- save configs
+ config._CONFIGS = configs
end
- -- get the current target scope
- local target = config._target()
- assert(target and type(target) == "table")
-
- -- merge option.options() to target
- if option.task() == "config" then
- for k, v in pairs(options) do
-
- -- check
- assert(type(k) == "string")
+ -- init configs
+ config._CONFIGS = config._CONFIGS or {}
- -- skip some options
- if not k:startswith("_") and config._need(k) then
-
- -- save the option to the target
- target[k] = v
-
- -- remove it from the defaults, because we have setted it manually
- if defaults then defaults[k] = nil end
- end
- end
- end
-
- -- make the current config
- config._CURRENT = config._make(config._CONFIGS)
-end
-
--- clear up and remove all auto values
-function config.clearup()
-
- -- clear up the current configure
- local current = config._CURRENT
- if current then
- for k, v in pairs(current) do
- if type(v) == "string" and v == "auto" then
- current[k] = nil
- end
- end
- end
-
- -- clear up the current target configure
- local target = config._target()
- if target then
- for k, v in pairs(target) do
- if type(v) == "string" and v == "auto" then
- target[k] = nil
- end
- end
- end
-
-end
-
--- reload configure
-function config.reload()
-
- -- clear the old configure
- config._CURRENT = nil
- config._CONFIGS = nil
-
- -- load it
- return config.load()
-end
-
--- dump the current configure
-function config.dump()
-
- -- check
- assert(config._CURRENT)
+ -- make the current configs
+ config._CURRENT = config._make(global._CONFIGS)
- -- dump
- utils.dump(config._CURRENT, "__%w*", "configure")
-
end
--- return module: config
+-- return module
return config
diff --git a/xmake/core/project/global.lua b/xmake/core/project/global.lua
index 6b600d51b..95b11984d 100644
--- a/xmake/core/project/global.lua
+++ b/xmake/core/project/global.lua
@@ -20,7 +20,7 @@
-- @file global.lua
--
--- define module: global
+-- define module
local global = global or {}
-- load modules
@@ -30,13 +30,20 @@ local path = require("base/path")
local utils = require("base/utils")
local option = require("base/option")
+-- get the configure file
+function global._file()
+
+ -- get it
+ return path.join(global.directory(), "/xmake.conf")
+end
+
-- make configure
function global._make(configs)
-- check
assert(configs)
- -- make current global configure
+ -- make current configure
local current = {}
for k, v in pairs(configs) do
if type(k) == "string" and not k:find("^_%u+") then
@@ -48,13 +55,6 @@ function global._make(configs)
return current
end
--- get the configure file
-function global._file()
-
- -- get it
- return path.join(global.directory(), "/xmake.conf")
-end
-
-- get the given configure from the current
function global.get(name)
@@ -100,9 +100,12 @@ function global.clean()
if os.isfile(global._file()) then
local ok, errors = os.rm(global._file())
if not ok then
- os.raise(errors)
+ return false, errors
end
end
+
+ -- ok
+ return true
end
-- get all options
@@ -144,9 +147,6 @@ function global.load()
-- make the current configs
global._CURRENT = global._make(global._CONFIGS)
- -- ok
- return true
-
end
-- save the global configure
@@ -189,5 +189,5 @@ function global.dump()
end
--- return module: global
+-- return module
return global
diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua
index 8e4fcb57d..d8a1150ad 100644
--- a/xmake/core/project/task.lua
+++ b/xmake/core/project/task.lua
@@ -267,27 +267,21 @@ function task.run(name)
-- get the task info
local taskinfo = tasks[name]
if not taskinfo then
-
- -- trace
utils.error("task(\"%s\"): unknown task", name)
return false
end
-- check
if not taskinfo.run then
-
- -- trace
utils.error("task(\"%s\"): no run script, please call on_task_run() first!", name)
return false
end
-- load global
- if not global.load() then
+ global.load()
- -- trace
- utils.error("load global configure failed!")
- return false
- end
+ -- load config
+ config.load()
-- run on_before, on_run, on_after
local ok = true
diff --git a/xmake/core/sandbox/modules/import.lua b/xmake/core/sandbox/modules/import.lua
index bdb23f896..abee9d999 100644
--- a/xmake/core/sandbox/modules/import.lua
+++ b/xmake/core/sandbox/modules/import.lua
@@ -220,6 +220,7 @@ function sandbox_import.import(name, alias)
-- check
if not module then
+ print(errors)
os.raise("cannot import module: %s, %s", name, errors)
end
diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua
index 6fb601961..a13a73312 100644
--- a/xmake/core/sandbox/modules/import/core/project/config.lua
+++ b/xmake/core/sandbox/modules/import/core/project/config.lua
@@ -24,9 +24,9 @@
local sandbox_core_project_config = sandbox_core_project_config or {}
-- load modules
-local rule = require("project/rule")
local config = require("project/config")
-local project = require("project/project")
+local platform = require("platform/platform")
+local raise = require("sandbox/modules/raise")
-- get the build directory
function sandbox_core_project_config.buildir()
@@ -64,7 +64,7 @@ function sandbox_core_project_config.mode()
end
-- get the configure directory
-function sandbox_core_project_global.directory()
+function sandbox_core_project_config.directory()
-- get it
local dir = config.directory()
@@ -88,6 +88,25 @@ function sandbox_core_project_config.set(name, value)
return config.set(name, value)
end
+-- clean the configure
+function sandbox_core_project_config.clean()
+
+ -- clean it
+ local ok, errors = config.clean()
+ if not ok then
+ raise(errors)
+ end
+end
+
+-- probe the configure
+function sandbox_core_project_config.probe()
+
+ -- probe it
+ if not platform.probe(false) then
+ raise("probe the project configure failed!")
+ end
+end
+
-- return module
return sandbox_core_project_config
diff --git a/xmake/core/sandbox/modules/import/core/project/global.lua b/xmake/core/sandbox/modules/import/core/project/global.lua
index c8e0af30e..61e1d00cd 100644
--- a/xmake/core/sandbox/modules/import/core/project/global.lua
+++ b/xmake/core/sandbox/modules/import/core/project/global.lua
@@ -63,7 +63,10 @@ end
function sandbox_core_project_global.clean()
-- clean it
- global.clean()
+ local ok, errors = global.clean()
+ if not ok then
+ raise(errors)
+ end
end
-- probe the configure