diff options
| author | ruki <[email protected]> | 2016-02-25 09:01:33 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-02-25 09:01:33 +0800 |
| commit | a077113ea61e7544e8f702104a0f3ca7535a72cd (patch) | |
| tree | b3f3401b28adfa3ed51260d00ec683ca8615ba4d | |
| parent | 3456f0e1f8fb59aed918075250b2f112b91a2255 (diff) | |
filter the default value for task menu
| -rw-r--r-- | xmake/core/base/interpreter.lua | 12 | ||||
| -rw-r--r-- | xmake/core/base/project.lua | 1 | ||||
| -rw-r--r-- | xmake/core/base/task.lua | 38 | ||||
| -rwxr-xr-x | xmake/core/tasks/config.lua | 6 |
4 files changed, 52 insertions, 5 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index c6384529c..e8cf8841e 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -277,7 +277,11 @@ function interpreter._filter(self, values) if table.is_dictionary(values) then -- filter keyvalues for key, value in pairs(values) do - results[filter:handle(key)] = filter:handle(value) + if type(value) == "string" then + results[filter:handle(key)] = filter:handle(value) + else + results[filter:handle(key)] = value + end end else for _, value in ipairs(utils.wrap(values)) do @@ -294,7 +298,11 @@ function interpreter._filter(self, values) -- replace values local values = {} for _, v in ipairs(value) do - table.insert(values, filter:handle(v)) + if type(v) == "string" then + table.insert(values, filter:handle(v)) + else + table.insert(values, v) + end end value = values end diff --git a/xmake/core/base/project.lua b/xmake/core/base/project.lua index b9e0edd24..d50400755 100644 --- a/xmake/core/base/project.lua +++ b/xmake/core/base/project.lua @@ -454,6 +454,7 @@ function project._interpreter() local maps = { os = platform.os() + , host = xmake._HOST , prefix = "$(prefix)" , projectdir = xmake._PROJECT_DIR } diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua index d7893d674..bbf12d8a2 100644 --- a/xmake/core/base/task.lua +++ b/xmake/core/base/task.lua @@ -27,6 +27,7 @@ local task = task or {} local os = require("base/os") local table = require("base/table") local utils = require("base/utils") +local filter = require("base/filter") local string = require("base/string") local global = require("base/global") local interpreter = require("base/interpreter") @@ -63,6 +64,25 @@ function task._interpreter() -- register api: set_task_menu() interp:api_register_set_values("task", "task", "menu") + -- set filter + interp:filter_set(filter.init(function (variable) + + -- check + assert(variable) + + -- init maps + local maps = + { + host = xmake._HOST + } + + -- map it + result = maps[variable] + + -- ok? + return result + end)) + -- save interpreter task._INTERPRETER = interp @@ -130,6 +150,10 @@ function task.menu() local tasks = task.tasks() assert(tasks) + -- the interpreter + local interp = task._interpreter() + assert(interp) + -- make menu local menu = {} for taskname, taskinfo in pairs(tasks) do @@ -153,6 +177,20 @@ function task.menu() table.insert(options, 7, {}) end + -- filter options + if options and interp:filter() then + + -- filter option + for _, option in ipairs(options) do + + -- filter default + local default = option[4] + if type(default) == "string" then + option[4] = interp:filter():handle(default) + end + end + end + -- main? if taskinfo.category == "main" then menu.main = taskinfo.menu diff --git a/xmake/core/tasks/config.lua b/xmake/core/tasks/config.lua index 29426bef9..6abd41a01 100755 --- a/xmake/core/tasks/config.lua +++ b/xmake/core/tasks/config.lua @@ -79,14 +79,14 @@ task("config") , " - static" , " - shared" , " - binary" } --- , {nil, "host", "kv", xmake._HOST, "The current host environment." } + , {nil, "host", "kv", "$(host)", "The current host environment." } -- the options for project -- , function () return project.menu() end , {} - , {nil, "make", "kv", "auto", "Set the make path." } - , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." } + , {nil, "make", "kv", "auto", "Set the make path." } + , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." } , {} , {nil, "cross", "kv", nil, "The cross toolchains prefix" |
