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/preprocessor.lua | |
| parent | 38fdeea020e688ada83a61783e5af9a9cb47ad0c (diff) | |
register scopes for configure
Diffstat (limited to 'xmake/scripts/base/preprocessor.lua')
| -rw-r--r-- | xmake/scripts/base/preprocessor.lua | 62 |
1 files changed, 43 insertions, 19 deletions
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 |
