summaryrefslogtreecommitdiff
path: root/xmake/core/project/config.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2016-03-15 21:01:32 +0800
committerruki <[email protected]>2016-03-15 21:01:32 +0800
commitef9342cfecbcbf2f95220e08132e6530bf754f5f (patch)
treeeef4c52c57fb3fafe549d3962d1fed102e0b1ec6 /xmake/core/project/config.lua
parentda7bc7414f499ec3420c1d1e062a8913b88935b7 (diff)
load config
Diffstat (limited to 'xmake/core/project/config.lua')
-rw-r--r--xmake/core/project/config.lua130
1 files changed, 93 insertions, 37 deletions
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