diff options
| author | ruki <[email protected]> | 2016-01-21 17:20:34 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-02-15 19:10:25 +0800 |
| commit | cc07a77f59a0024698b8261f866010c8b72481fe (patch) | |
| tree | 6aa804828b6eca61aeb9c27cb4cc5ddcd3dfff6d | |
| parent | 1242c86015675ef739347efd3af67c91c4067867 (diff) | |
impl filter for interpreter
| -rw-r--r-- | tests/interpreter/scope.lua | 1 | ||||
| -rw-r--r-- | tests/interpreter/tests.lua | 8 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 55 |
3 files changed, 59 insertions, 5 deletions
diff --git a/tests/interpreter/scope.lua b/tests/interpreter/scope.lua index f15c2da98..2893dfeaf 100644 --- a/tests/interpreter/scope.lua +++ b/tests/interpreter/scope.lua @@ -6,6 +6,7 @@ add_target("target1") set_kind("static") add_files("*.c", "hello.c") + add_files("$(projectdir)/test.c") add_option("option1") diff --git a/tests/interpreter/tests.lua b/tests/interpreter/tests.lua index dc659edd1..49ea4787e 100644 --- a/tests/interpreter/tests.lua +++ b/tests/interpreter/tests.lua @@ -109,9 +109,15 @@ function tests.main(self, file) interp:api_register_add_pathes("option", "option", "linkdirs" , "includedirs") + -- init filter + local filter = function (variable) + if variable == "projectdir" then + return xmake._PROJECT_DIR + end + end -- load targets - local targets, errors = interp:load(file[1], "target", true) + local targets, errors = interp:load(file[1], "target", true, filter) if not targets then print(errors) return false diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index cac14895c..b77979377 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -239,8 +239,53 @@ function interpreter._clear(self) self._PRIVATE._MTIMES = {} end +-- filter values +function interpreter._filter(self, values, filter) + + -- check + assert(self and values and filter) + + -- done + local results = {} + for _, value in ipairs(utils.wrap(values)) do + + -- only filter string value + if type(value) == "string" then + + -- replace the builtin variables + value = value:gsub("%$%((.-)%)", function (variable) + + -- check + assert(variable) + + -- is upper? + local isupper = false + local c = string.char(variable:byte()) + if c >= 'A' and c <= 'Z' then isupper = true end + + -- filter it + local result = filter(variable:lower()) + + -- convert to upper? + if isupper and result and type(result) == "string" then + result = result:upper() + end + + -- ok? + return result + end) + end + + -- append value + table.insert(results, value) + end + + -- ok? + return results +end + -- make results -function interpreter._make(self, scope_kind, remove_repeat) +function interpreter._make(self, scope_kind, remove_repeat, filter) -- check assert(self and self._PRIVATE and scope_kind) @@ -297,7 +342,9 @@ function interpreter._make(self, scope_kind, remove_repeat) end -- filter values - -- TODO + if filter and type(filter) == "function" then + values = self:_filter(values, filter) + end -- unwrap it if be only one values = utils.unwrap(values) @@ -342,7 +389,7 @@ function interpreter.init(rootdir) end -- load results -function interpreter.load(self, file, scope_kind, remove_repeat) +function interpreter.load(self, file, scope_kind, remove_repeat, filter) -- check assert(self and self._PUBLIC and self._PRIVATE and file and scope_kind) @@ -372,7 +419,7 @@ function interpreter.load(self, file, scope_kind, remove_repeat) end -- make results - return self:_make(scope_kind, remove_repeat) + return self:_make(scope_kind, remove_repeat, filter) end -- get mtimes |
