summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xxmake/actions/config/main.lua29
-rwxr-xr-xxmake/actions/global/xmake.lua7
-rw-r--r--xmake/core/project/config.lua130
-rw-r--r--xmake/core/project/global.lua74
-rw-r--r--xmake/core/project/task.lua6
-rw-r--r--xmake/core/sandbox/modules/import/core/project/config.lua10
-rw-r--r--xmake/core/sandbox/modules/import/core/project/global.lua19
7 files changed, 174 insertions, 101 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 6e60c4793..84aa468fb 100755
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -23,10 +23,22 @@
-- imports
import("core.base.option")
import("core.project.config")
+import("core.project.global")
+
+-- filter option
+function _option_filter(name)
+ return name and name ~= "target" and name ~= "file" and name ~= "project" and name ~= "verbose" and name ~= "clean"
+end
-- main
function main()
+ -- load global configure
+ global.load()
+
+ -- load project configure
+ config.load(option.get("target"))
+
-- clean the cached configure?
if option.get("clean") then
@@ -34,23 +46,28 @@ function main()
config.clean()
end
- --[[
- -- merge the options
+ -- override the configure for the current options
for name, value in pairs(option.options()) do
- if name ~= "verbose" and name ~= "clean" then
+ if _option_filter(name) then
+ config.set(name, value)
+ end
+ end
+
+ -- merge the global configure
+ for name, value in pairs(global.options()) do
+ if config.get(name) == nil 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
+ if _option_filter(name) and config.get(name) == nil then
config.set(name, value)
end
end
- ]]
-- probe the configure with value: "auto"
--- config.probe()
+ config.probe()
end
diff --git a/xmake/actions/global/xmake.lua b/xmake/actions/global/xmake.lua
index d93b6e524..35b36cda6 100755
--- a/xmake/actions/global/xmake.lua
+++ b/xmake/actions/global/xmake.lua
@@ -33,6 +33,9 @@ task("global")
import("core.base.option")
import("core.project.global")
+ -- load configure
+ global.load()
+
-- clean the cached configure?
if option.get("clean") then
@@ -40,7 +43,7 @@ task("global")
global.clean()
end
- -- merge the options
+ -- 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)
@@ -49,7 +52,7 @@ task("global")
-- merge the default options
for name, value in pairs(option.defaults()) do
- if name ~= "verbose" and name ~= "clean" then
+ if name ~= "verbose" and name ~= "clean" and global.get(name) == nil then
global.set(name, value)
end
end
diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua
index 35748ee78..08b9d72eb 100644
--- a/xmake/core/project/config.lua
+++ b/xmake/core/project/config.lua
@@ -38,60 +38,94 @@ function config._file()
return path.join(config.directory(), "/xmake.conf")
end
--- make configure
-function config._make(configs)
+-- 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)
- -- init current target configure
- local current = {}
+ -- for all targets?
+ if targetname == "all" then
+ return configs
+ elseif configs._TARGETS then
+ -- get it
+ return configs._TARGETS[targetname]
+ end
+end
- --[[
- -- 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
+-- get the current given configure
+function config.get(name)
+
+ -- get the target
+ local target = config._target()
+ if not target then
+ return
end
- ]]
- -- make current configure from the global configure
- for k, v in pairs(global.options()) do
- current[k] = v
+ -- the value
+ local value = target[name]
+ if type(value) == "string" and value == "auto" then
+ value = nil
end
- -- 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
+ -- 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 configs from the current target
- if configs._TARGETS and current.target ~= "all" then
+ -- get it
+ return value
+end
+
+-- set the given configure to the current
+function config.set(name, value)
+
+ -- check
+ assert(name)
+
+ -- get the current target
+ local target = config._target()
+ assert(target)
+
+ -- set it
+ target[name] = value
+end
- -- get the target config
- local target_config = configs._TARGETS[current.target]
- if target_config then
+-- get all options
+function config.options()
- -- merge it
- for k, v in pairs(target_config) do
- current[k] = v
- end
+ -- check
+ assert(config._CONFIGS)
+
+ -- remove values with "auto" and private item
+ local configs = {}
+ for name, value in pairs(config._CONFIGS) do
+ if not name:find("^_%u+") and (type(value) ~= "string" or value ~= "auto") then
+ configs[name] = value
end
- end]]
+ end
- -- ok
- return current
+ -- get it
+ return configs
end
-- clean the project configure
function config.clean()
-- check
- assert(config._CURRENT and config._CONFIGS)
+ assert(config._CONFIGS)
-- clean it
- config._CURRENT = {}
config._CONFIGS = {}
-- save it
@@ -113,9 +147,14 @@ function config.directory()
return path.join(xmake._PROJECT_DIR, ".xmake")
end
--- TODO: reconfig, rebuild, defaults, targets
+-- TODO: reconfig, rebuild
-- load the project configure
-function config.load()
+function config.load(targetname)
+
+ -- check
+ if not targetname then
+ return false, "no target name!"
+ end
-- load configure from the file first
local filepath = config._file()
@@ -135,10 +174,27 @@ function config.load()
-- init configs
config._CONFIGS = config._CONFIGS or {}
+ local configs = config._CONFIGS
- -- make the current configs
- config._CURRENT = config._make(global._CONFIGS)
+ -- init targets
+ configs._TARGETS = configs._TARGETS or {}
+ if targetname ~= "all" then
+ configs._TARGETS[targetname] = configs._TARGETS[targetname] or {}
+ end
+
+ -- save the target name
+ config._TARGETNAME = targetname
+
+ -- ok
+ return true
+end
+-- dump the configure
+function config.dump()
+
+ -- dump
+ utils.dump(config.options(), "__%w*", "configure")
+
end
-- return module
diff --git a/xmake/core/project/global.lua b/xmake/core/project/global.lua
index 95b11984d..410eab08b 100644
--- a/xmake/core/project/global.lua
+++ b/xmake/core/project/global.lua
@@ -37,32 +37,14 @@ function global._file()
return path.join(global.directory(), "/xmake.conf")
end
--- make configure
-function global._make(configs)
-
- -- check
- assert(configs)
-
- -- make current 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 given configure from the current
+-- get the current given configure from
function global.get(name)
-- check
- assert(global._CURRENT)
+ assert(name and global._CONFIGS)
-- the value
- local value = global._CURRENT[name]
+ local value = global._CONFIGS[name]
if type(value) == "string" and value == "auto" then
value = nil
end
@@ -71,17 +53,13 @@ function global.get(name)
return value
end
--- set the given configure to the current
+-- set the current given configure
function global.set(name, value)
-- check
- assert(global._CURRENT and global._CONFIGS)
- assert(name and type(value) ~= "table")
-
- -- set it to the current configure
- global._CURRENT[name] = value
+ assert(global._CONFIGS and name)
- -- set it to the configure for saving to file
+ -- set it
global._CONFIGS[name] = value
end
@@ -90,10 +68,9 @@ end
function global.clean()
-- check
- assert(global._CURRENT and global._CONFIGS)
+ assert(global._CONFIGS)
-- clean it
- global._CURRENT = {}
global._CONFIGS = {}
-- save it
@@ -110,9 +87,20 @@ end
-- get all options
function global.options()
-
+
+ -- check
+ assert(global._CONFIGS)
+
+ -- remove values with "auto" and private item
+ local configs = {}
+ for name, value in pairs(global._CONFIGS) do
+ if not name:find("^_%u+") and (type(value) ~= "string" or value ~= "auto") then
+ configs[name] = value
+ end
+ end
+
-- get it
- return global._CURRENT
+ return configs
end
-- get the global configure directory
@@ -144,9 +132,8 @@ function global.load()
-- init configs
global._CONFIGS = global._CONFIGS or {}
- -- make the current configs
- global._CURRENT = global._make(global._CONFIGS)
-
+ -- ok
+ return true
end
-- save the global configure
@@ -170,22 +157,11 @@ function global.save()
return io.save(global._file(), configs)
end
--- dump the current configure
+-- dump the 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(configs, "__%w*", "configure")
+ utils.dump(global.options(), "__%w*", "configure")
end
diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua
index d8a1150ad..1d882c278 100644
--- a/xmake/core/project/task.lua
+++ b/xmake/core/project/task.lua
@@ -277,12 +277,6 @@ function task.run(name)
return false
end
- -- load global
- global.load()
-
- -- load config
- config.load()
-
-- 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/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua
index a13a73312..01e50f253 100644
--- a/xmake/core/sandbox/modules/import/core/project/config.lua
+++ b/xmake/core/sandbox/modules/import/core/project/config.lua
@@ -88,6 +88,16 @@ function sandbox_core_project_config.set(name, value)
return config.set(name, value)
end
+-- load the configure
+function sandbox_core_project_config.load(targetname)
+
+ -- load it
+ local ok, errors = config.load(targetname)
+ if not ok then
+ raise(errors)
+ end
+end
+
-- clean the configure
function sandbox_core_project_config.clean()
diff --git a/xmake/core/sandbox/modules/import/core/project/global.lua b/xmake/core/sandbox/modules/import/core/project/global.lua
index 61e1d00cd..b6f321167 100644
--- a/xmake/core/sandbox/modules/import/core/project/global.lua
+++ b/xmake/core/sandbox/modules/import/core/project/global.lua
@@ -49,10 +49,20 @@ function sandbox_core_project_global.dump()
global.dump()
end
+-- load the configure
+function sandbox_core_project_global.load()
+
+ -- load it
+ local ok, errors = global.load()
+ if not ok then
+ raise(errors)
+ end
+end
+
-- save the configure
function sandbox_core_project_global.save()
- -- get all
+ -- save it
local ok, errors = global.save()
if not ok then
raise(errors)
@@ -78,6 +88,13 @@ function sandbox_core_project_global.probe()
end
end
+-- get all options
+function sandbox_core_project_global.options()
+
+ -- get it
+ return global.options()
+end
+
-- get the configure directory
function sandbox_core_project_global.directory()