diff options
| author | ruki <[email protected]> | 2015-05-16 12:00:49 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-16 12:00:49 +0800 |
| commit | 9eb348a32a7472d533b9084d3b53491078987149 (patch) | |
| tree | 398634251825d4b816dc2e4dfa7705dcf6d81e6a /xmake/scripts/base | |
| parent | 38fdeea020e688ada83a61783e5af9a9cb47ad0c (diff) | |
register scopes for configure
Diffstat (limited to 'xmake/scripts/base')
| -rw-r--r-- | xmake/scripts/base/config.lua | 26 | ||||
| -rw-r--r-- | xmake/scripts/base/preprocessor.lua | 62 |
2 files changed, 60 insertions, 28 deletions
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua index ec2433026..26272fcf9 100644 --- a/xmake/scripts/base/config.lua +++ b/xmake/scripts/base/config.lua @@ -72,8 +72,8 @@ function config._save_with_level(file, object, level) -- save body for k, v in pairs(object) do - -- save _TARGETS - if type(k) == "string" and k == "_TARGETS" then + -- save _TARGET + if type(k) == "string" and k == "_TARGET" then for _k, _v in pairs(v) do @@ -157,9 +157,9 @@ function config.getarget() -- for all targets? if name == "all" then return configs - elseif configs._TARGETS then + elseif configs._TARGET then -- get it - return configs._TARGETS[name] + return configs._TARGET[name] end end @@ -221,16 +221,24 @@ function config.loadxconf() end -- load and execute the xmake.xproj - config._CONFIGS = preprocessor.loadfile(options.project .. "/xmake.xconf", "config", configures) + local path = options.project .. "/xmake.xconf" + local configs, errors = preprocessor.loadfile(path, "config", configures, {"target"}) + + -- save configs + config._CONFIGS = configs -- exists local configures? - if config._CONFIGS then + if configs then -- clear configs if the host environment has been changed local target = config.getarget() if target and target.host ~= xmake._HOST then config._CONFIGS = {} end + elseif errors then + -- error + utils.error("load %s failed!", path) + utils.error("%s", errors) end -- the target name @@ -239,12 +247,12 @@ function config.loadxconf() -- init configs config._CONFIGS = config._CONFIGS or {} - local configs = config._CONFIGS + configs = config._CONFIGS -- init targets - configs._TARGETS = configs._TARGETS or {} + configs._TARGET = configs._TARGET or {} if name ~= "all" then - configs._TARGETS[name] = configs._TARGETS[name] or {} + configs._TARGET[name] = configs._TARGET[name] or {} end -- get the current target scope diff --git a/xmake/scripts/base/preprocessor.lua b/xmake/scripts/base/preprocessor.lua index d2d9c1134..02d6fbd55 100644 --- a/xmake/scripts/base/preprocessor.lua +++ b/xmake/scripts/base/preprocessor.lua @@ -61,7 +61,7 @@ function preprocessor._register(env, names) end -- init configures -function preprocessor._init(root, configures) +function preprocessor._init(root, configures, scopes) -- check assert(root and configures) @@ -85,22 +85,47 @@ function preprocessor._init(root, configures) _current = _current._PARENT end - -- configure target - newenv["target"] = function (name) + -- configure scopes + if scopes then + for _, scope_name in ipairs(scopes) do + + newenv[scope_name] = function (...) - -- check - assert(name and _current) + -- check + assert(_current) + + -- init config name + local config_name = "_" .. scope_name:upper() + + -- init scope config + _current[config_name] = _current[config_name] or {} + local scope_config = _current[config_name] + + -- init scope + local scope = {} + + -- configure all + local arg = arg or {...} + for _, name in ipairs(arg) do - -- init targets - _current._TARGETS = _current._TARGETS or {} + -- check + if scope_config[name] then + -- error + utils.error("the %s: %s has been defined repeatly!", config_name, name) + assert(false) + end - -- init target scope - _current._TARGETS[name] = {} + -- init the scope + scope_config[name] = scope - -- enter target scope - local parent = _current - _current = _current._TARGETS[name] - _current._PARENT = parent + end + + -- enter scope + local parent = _current + _current = scope + _current._PARENT = parent + end + end end -- the root configure @@ -111,14 +136,13 @@ function preprocessor._init(root, configures) newenv._CONFIGS = {} else -- error - utils.error("exists double configs!") + utils.error("exists double %s!", root) return end -- init the current scope _current = newenv._CONFIGS _current._PARENT = nil - end -- enter old environment @@ -133,10 +157,10 @@ end -- xmake.xconf -- -- @code --- local configs, errors = preprocessor.loadfile("xmake.xconf", "config", {"plat", "host", "arch", ...}) --- local configs, errors = preprocessor.loadfile("xmake.xproj", "project", {"links", "files", "ldflags", ...}) +-- local configs, errors = preprocessor.loadfile("xmake.xconf", "config", {"plat", "host", "arch", ...}, {"target"}) +-- local configs, errors = preprocessor.loadfile("xmake.xproj", "project", {"links", "files", "ldflags", ...}, {"target", "platforms"}) -- @endcode -function preprocessor.loadfile(path, root, configures) +function preprocessor.loadfile(path, root, configures, scopes) -- check assert(path and root and configures) @@ -146,7 +170,7 @@ function preprocessor.loadfile(path, root, configures) if script then -- init a new envirnoment - local newenv = preprocessor._init(root, configures) + local newenv = preprocessor._init(root, configures, scopes) assert(newenv) -- bind this envirnoment |
