summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-04-04 17:30:26 +0800
committerruki <[email protected]>2016-04-04 17:30:26 +0800
commitfedf748ddd3353f6065dc2502eaec2e396bc2c2a (patch)
tree28d1794396831d5b40c6e7554837372632873f0c
parent70e2500e9a37a57622c7b4875171e6f07fd523ae (diff)
reimpl config
-rwxr-xr-xxmake/actions/config/main.lua38
-rwxr-xr-xxmake/actions/global/xmake.lua19
-rw-r--r--xmake/core/project/config.lua138
-rw-r--r--xmake/core/project/project.lua31
-rw-r--r--xmake/core/sandbox/modules/import/core/project/config.lua14
-rw-r--r--xmake/core/sandbox/modules/import/core/project/task.lua3
-rw-r--r--xmake/core/sandbox/modules/os.lua2
7 files changed, 90 insertions, 155 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 468afbca4..3a9305361 100755
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -34,20 +34,6 @@ function _option_filter(name)
return name and name ~= "target" and name ~= "file" and name ~= "project" and name ~= "verbose" and name ~= "clean"
end
--- need clean the cached configure?
-function _need_clean_cache()
-
- -- the host has been changed? clean it
- if config.host() ~= vformat("$(host)") then
- return true
- end
-
- -- the plat has been changed? clean it
- if option.get("plat") and config.plat() and option.get("plat") ~= config.plat() then
- return true
- end
-end
-
-- main
function main()
@@ -62,17 +48,10 @@ function main()
-- load global configure
global.load()
- -- load project configure
- config.load(targetname)
-
- -- clean the cached configure?
- if option.get("clean") or _need_clean_cache() then
-
- -- clean it
- config.clean()
- end
-
- -- override the configure for the current options
+ -- override the option configure
+ --
+ -- priority: option > global > option_default > config_check > config_cache
+ --
for name, value in pairs(option.options()) do
if _option_filter(name) then
config.set(name, value)
@@ -93,9 +72,14 @@ function main()
end
end
- -- probe the configure with value: "auto"
+ -- merge the checked configure
config.probe()
+ -- merge the cached configure
+ if not option.get("clean") then
+ config.load(targetname)
+ end
+
-- load platform
platform.load(config.plat())
@@ -122,7 +106,7 @@ function main()
end
-- save the project configure
- config.save()
+ config.save(targetname)
-- make the config.h
config_h.make()
diff --git a/xmake/actions/global/xmake.lua b/xmake/actions/global/xmake.lua
index 35b36cda6..748866e27 100755
--- a/xmake/actions/global/xmake.lua
+++ b/xmake/actions/global/xmake.lua
@@ -34,6 +34,9 @@ task("global")
import("core.project.global")
-- load configure
+ --
+ -- priority: option > config_check > global_cache > option_default
+ --
global.load()
-- clean the cached configure?
@@ -43,13 +46,6 @@ task("global")
global.clean()
end
- -- override the configure for the current 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" and global.get(name) == nil then
@@ -57,9 +53,16 @@ task("global")
end
end
- -- probe the configure with value: "auto"
+ -- override the checked configure
global.probe()
+ -- override the option configure
+ for name, value in pairs(option.options()) do
+ if name ~= "verbose" and name ~= "clean" then
+ global.set(name, value)
+ end
+ end
+
-- save it
global.save()
diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua
index 58c04b256..f6e94fda4 100644
--- a/xmake/core/project/config.lua
+++ b/xmake/core/project/config.lua
@@ -27,6 +27,7 @@ local config = config or {}
local io = require("base/io")
local os = require("base/os")
local path = require("base/path")
+local table = require("base/table")
local utils = require("base/utils")
local option = require("base/option")
local global = require("project/global")
@@ -38,51 +39,18 @@ function config._file()
return path.join(config.directory(), "/xmake.conf")
end
--- get the target scope
-function config._target()
-
- -- check
- local configs = config._CONFIGS
- if not configs then
- return
- end
-
- -- the target name
- local targetname = config._TARGETNAME
- assert(targetname)
-
- -- for all targets?
- if targetname == "all" then
- return configs
- elseif configs._TARGETS then
- -- get it
- return configs._TARGETS[targetname]
- end
-end
-
-- get the current given configure
function config.get(name)
- -- get the target
- local target = config._target()
- if not target then
- return
- end
+ -- get configs
+ local configs = config._CONFIGS or {}
- -- the value
- local value = target[name]
+ -- get it
+ local value = configs[name]
if type(value) == "string" and value == "auto" then
value = nil
end
- -- get it from the root scope if not found
- if value == nil then
- value = config._CONFIGS[name]
- if type(value) == "string" and value == "auto" then
- value = nil
- end
- end
-
-- get it
return value
end
@@ -93,12 +61,12 @@ function config.set(name, value)
-- check
assert(name)
- -- get the current target
- local target = config._target()
- assert(target)
+ -- get configs
+ local configs = config._CONFIGS or {}
+ config._CONFIGS = configs
-- set it
- target[name] = value
+ configs[name] = value
end
-- get all options
@@ -119,27 +87,6 @@ function config.options()
return configs
end
--- clean the project configure
-function config.clean()
-
- -- check
- assert(config._CONFIGS)
-
- -- clean it
- config._CONFIGS = {}
-
- -- save it
- if os.isfile(config._file()) then
- local ok, errors = os.rm(config._file())
- if not ok then
- return false, errors
- end
- end
-
- -- ok
- return true
-end
-
-- get the configure directory
function config.directory()
@@ -158,47 +105,68 @@ function config.load(targetname)
local filepath = config._file()
if os.isfile(filepath) then
- -- load configs
- local configs, errors = io.load(filepath)
+ -- load it
+ local results, errors = io.load(filepath)
-- error?
- if not configs and errors then
+ if not results and errors then
utils.error(errors)
end
- -- save configs
- config._CONFIGS = configs
- end
-
- -- init configs
- config._CONFIGS = config._CONFIGS or {}
- local configs = config._CONFIGS
+ -- merge the target configure first
+ if targetname ~= "all" and results._TARGETS then
+ for name, value in pairs(table.wrap(results._TARGETS[targetname])) do
+ if config.get(name) == nil then
+ config.set(name, value)
+ end
+ end
+ end
- -- init targets
- configs._TARGETS = configs._TARGETS or {}
- if targetname ~= "all" then
- configs._TARGETS[targetname] = configs._TARGETS[targetname] or {}
+ -- merge the root configure
+ for name, value in pairs(results) do
+ if config.get(name) == nil then
+ config.set(name, value)
+ end
+ end
end
- -- save the target name
- config._TARGETNAME = targetname
-
-- ok
return true
end
-- save the project configure
-function config.save()
+function config.save(targetname)
- -- the options
- local options = config.options()
- assert(options)
+ -- get the target name
+ targetname = targetname or "all"
+
+ -- load configure from the file first
+ local results = {}
+ local filepath = config._file()
+ if os.isfile(filepath) then
+ results = io.load(filepath)
+ end
-- add version
- options.__version = xmake._VERSION
+ results.__version = xmake._VERSION
+
+ -- update options for the given target
+ local target = results
+ if targetname ~= "all" then
+
+ -- get target
+ target = results._TARGETS or {}
+ results._TARGETS = target
+
+ end
+
+ -- update it
+ for name, value in pairs(config.options()) do
+ target[name] = value
+ end
-- save it
- return io.save(config._file(), options)
+ return io.save(config._file(), results)
end
-- dump the configure
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 6a98df001..eaa8a74e1 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -504,32 +504,23 @@ function project.probe()
-- make all options
for name, opt in pairs(options) do
- -- this option need be probed automatically?
- if config.get(name) == nil then
-
- -- check option
- if opt:check(cfile, cxxfile, objectfile, targetfile) then
-
- -- enable this option
- config.set(name, true)
-
- -- save this option to configure
- opt:save()
+ -- check option
+ if opt:check(cfile, cxxfile, objectfile, targetfile) then
- else
+ -- enable this option
+ config.set(name, true)
- -- disable this option
- config.set(name, false)
+ -- save this option to configure
+ opt:save()
- -- clear this option to configure
- opt:clear()
+ else
- end
+ -- disable this option
+ config.set(name, false)
- elseif nil == option.load(name) then
+ -- clear this option to configure
+ opt:clear()
- -- save this option to configure
- opt:save()
end
end
diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua
index 2c43c2696..e1fe93e20 100644
--- a/xmake/core/sandbox/modules/import/core/project/config.lua
+++ b/xmake/core/sandbox/modules/import/core/project/config.lua
@@ -106,20 +106,10 @@ function sandbox_core_project_config.load(targetname)
end
-- save the configure
-function sandbox_core_project_config.save()
+function sandbox_core_project_config.save(targetname)
-- save it
- local ok, errors = config.save()
- if not ok then
- raise(errors)
- end
-end
-
--- clean the configure
-function sandbox_core_project_config.clean()
-
- -- clean it
- local ok, errors = config.clean()
+ local ok, errors = config.save(targetname)
if not ok then
raise(errors)
end
diff --git a/xmake/core/sandbox/modules/import/core/project/task.lua b/xmake/core/sandbox/modules/import/core/project/task.lua
index 82e550d99..cd7161e38 100644
--- a/xmake/core/sandbox/modules/import/core/project/task.lua
+++ b/xmake/core/sandbox/modules/import/core/project/task.lua
@@ -59,7 +59,6 @@ function sandbox_core_project_task.run(taskname, options, ...)
-- run command
if 0 ~= os.execute(cmd) then
- io.cat(log)
os.raise("run task: %s failed!", taskname or cmd)
end
end
@@ -90,7 +89,7 @@ function sandbox_core_project_task.qrun(taskname, options, ...)
end
-- make temporary log file
- log = os.tmpname()
+ local log = os.tmpname()
-- run command
if 0 ~= os.execute(cmd .. string.format(" > %s 2>&1", log)) then
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index f3a3c0702..8b2ab34ff 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -178,7 +178,7 @@ function sandbox_os.qrun(cmd, ...)
cmd = vformat(cmd, ...)
-- make temporary log file
- log = os.tmpname()
+ local log = os.tmpname()
-- run command
if 0 ~= os.execute(cmd .. string.format(" > %s 2>&1", log)) then