diff options
| author | ruki <[email protected]> | 2016-01-21 12:38:22 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-02-15 19:10:25 +0800 |
| commit | a187eafee62e611520b73b4942565e70747059e5 (patch) | |
| tree | 605fa6107e67632fbc8e79a7d233448a7eb6d8d0 | |
| parent | 72b0812fb90a31caf17e2c44ec1c9e21e82069c6 (diff) | |
make results and merge root values
| -rw-r--r-- | tests/interpreter/scope.lua | 1 | ||||
| -rw-r--r-- | tests/interpreter/tests.lua | 13 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 100 |
3 files changed, 98 insertions, 16 deletions
diff --git a/tests/interpreter/scope.lua b/tests/interpreter/scope.lua index 4690c3705..f15c2da98 100644 --- a/tests/interpreter/scope.lua +++ b/tests/interpreter/scope.lua @@ -1,5 +1,6 @@ set_kind("static") +add_files("root.c") add_target("target1") diff --git a/tests/interpreter/tests.lua b/tests/interpreter/tests.lua index ba9518021..a01d010f3 100644 --- a/tests/interpreter/tests.lua +++ b/tests/interpreter/tests.lua @@ -110,18 +110,15 @@ function tests.main(self, file) , "includedirs") - -- load interpreter - local ok, errors = interp:load(file[1]) - if not ok then + -- load targets + local targets, errors = interp:load(file[1], "target") + if not targets then print(errors) return false end - -- dump interpreter - utils.dump(interp) - - -- dump mtimes - utils.dump(interp:results("mtimes")) + -- dump targets + utils.dump(targets) -- ok return true diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 222aff0fe..98f3c354f 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -121,6 +121,11 @@ function interpreter._api_register_xxx_values(self, scope_kind, action, prefix, local scope = scopes._CURRENT or root assert(scope) + -- enter subscope and set values? override it + if scopes._CURRENT and apiname and action == "set" then + scope["_" .. apiname] = true + end + -- call function apifunc(self, scope, apiname, ...) end @@ -223,6 +228,73 @@ function interpreter._api_builtin_add_subdirfiles(self, isdirs, ...) self._PRIVATE._CURFILE = curfile end +-- clear results +function interpreter._clear(self) + + -- check + assert(self and self._PRIVATE) + + -- clear it + self._PRIVATE._SCOPES = {} + self._PRIVATE._MTIMES = {} +end + +-- make results +function interpreter._make(self, scope_kind) + + -- check + assert(self and self._PRIVATE and scope_kind) + + -- the scopes + local scopes = self._PRIVATE._SCOPES + assert(scopes and scopes._ROOT) + + -- the scope for kind + local scope_for_kind = scopes[scope_kind] + if not scope_for_kind then + return nil, string.format("this scope kind: %s not found!", scope_kind) + end + + -- the root scope + local scope_root = scopes._ROOT[scope_kind] + + -- make results + local results = {} + for scope_name, scope in pairs(scope_for_kind) do + + -- add scope values and merge root values + local scope_values = {} + for name, values in pairs(scope) do + if not name:startswith("_") then + + -- override values? + if scope["_" .. name] then + + -- override it + scope_values[name] = values + + -- merge root values? + elseif scope_root then + + -- the root values + local root_values = scope_root[name] + if root_values ~= nil then + scope_values[name] = table.join(root_values, values) + else + scope_values[name] = values + end + end + end + end + + -- add this scope + results[scope_name] = scope_values + end + + -- ok? + return results +end + -- init interpreter function interpreter.init(rootdir) @@ -251,10 +323,10 @@ function interpreter.init(rootdir) end -- load interpreter -function interpreter.load(self, file) +function interpreter.load(self, file, scope_kind) -- check - assert(self and self._PUBLIC and self._PRIVATE and file) + assert(self and self._PUBLIC and self._PRIVATE and file and scope_kind) -- load the script local script = loadfile(file) @@ -262,6 +334,9 @@ function interpreter.load(self, file) return nil, string.format("load %s failed!", file) end + -- clear first + self:_clear() + -- init the current file self._PRIVATE._CURFILE = file @@ -272,17 +347,23 @@ function interpreter.load(self, file) setfenv(script, self._PUBLIC) -- done interpreter - return xpcall(script, interpreter._traceback) + local ok, errors = xpcall(script, interpreter._traceback) + if not ok then + return nil, errors + end + + -- make results + return self:_make(scope_kind) end --- get results -function interpreter.results(self, name) +-- get mtimes +function interpreter.mtimes(self) -- check - assert(self and self._PRIVATE and name) + assert(self and self._PRIVATE) - -- get it - return self._PRIVATE["_" .. name:upper()] + -- get mtimes + return self._PRIVATE._MTIMES end -- register api @@ -417,6 +498,7 @@ end -- { -- scope_kind -- { +-- name2 = {"value3"} -- } -- } -- @@ -426,6 +508,8 @@ end -- { -- name1 = {"value1"} -- name2 = {"value1", "value2", ...} +-- +-- _name1 = true <- override -- } -- } -- } |
