diff options
| author | ruki <[email protected]> | 2018-02-01 23:20:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-02-01 14:05:36 +0800 |
| commit | 7338d6b1e13648f3175555b1f1c4c69301f5bbd0 (patch) | |
| tree | f838f2569ee75c8f2b0f4b268fb761659eae1018 | |
| parent | dc29eb443366d6ff754c7f0c05e51e7d1aab3c21 (diff) | |
add choice to config menu
| -rw-r--r-- | xmake/actions/config/menuconf.lua | 27 | ||||
| -rw-r--r-- | xmake/actions/config/xmake.lua | 10 | ||||
| -rw-r--r-- | xmake/core/base/task.lua | 54 |
3 files changed, 69 insertions, 22 deletions
diff --git a/xmake/actions/config/menuconf.lua b/xmake/actions/config/menuconf.lua index 8f0c267a1..4df099590 100644 --- a/xmake/actions/config/menuconf.lua +++ b/xmake/actions/config/menuconf.lua @@ -200,6 +200,29 @@ function app:_basic_configs(cache) -- make configs by category self._BASIC_CONFIGS = self:_make_configs_by_category(options_by_category, function (opt) + + -- get default + local default = opt[4] + + -- get kind + local kind = (opt[3] == "k" or type(default) == "boolean") and "boolean" or "string" + + -- choice option? + local values = opt.values + if values then + kind = "choice" + if type(values) == "function" then + values = values() + end + for idx, value in ipairs(values) do + if default == value then + default = idx + break + end + end + end + + -- get description local description = {} for i = 5, 64 do local desc = opt[i] @@ -214,7 +237,9 @@ function app:_basic_configs(cache) break end end - return {name = opt[2] or opt[1], kind = (opt[3] == "k") and "boolean" or "string", default = opt[4], description = description} + + -- make option info + return {name = opt[2] or opt[1], kind = kind, default = default, values = values, description = description} end) return self._BASIC_CONFIGS end diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 84616caf1..5641d0624 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -68,7 +68,10 @@ task("config") -- get it return description - end } + end + , values = function () + return import("core.platform.platform").plats() + end } , {'a', "arch", "kv", "auto", "Compile for the given architecture." -- show the description of all architectures @@ -99,7 +102,10 @@ task("config") , {'k', "kind", "kv", "static", "Compile for the given target kind." , " - static" , " - shared" - , " - binary" } + , " - binary" + , values = function () + return {"static", "shared", "binary"} + end } , {nil, "host", "kv", "$(host)", "The Current Host Environment." } -- show project menu options diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua index 92a74ff3d..7288f966f 100644 --- a/xmake/core/base/task.lua +++ b/xmake/core/base/task.lua @@ -210,7 +210,23 @@ function task._interpreter() return interp end --- bind tasks for menu with an sandbox instance +-- bind script with a sandbox instance +function task._bind_script(interp, script) + + -- make sandbox instance with the given script + local instance, errors = sandbox.new(script, interp:filter(), interp:rootdir()) + if not instance then + return nil, errors + end + + -- check + assert(instance:script()) + + -- update option script + return instance:script() +end + +-- bind tasks for menu with a sandbox instance function task._bind(tasks, interp) -- check @@ -231,20 +247,16 @@ function task._bind(tasks, interp) if options then -- make full options + local errors = nil local options_full = {} for _, opt in ipairs(options) do -- this option is function? translate it if type(opt) == "function" then - - -- make sandbox instance with the given script - local instance, errors = sandbox.new(opt, interp:filter(), interp:rootdir()) - if not instance then + opt, errors = task._bind_script(interp, opt) + if not opt then return false, errors end - - -- update option script - opt = instance:script() end -- insert option @@ -255,11 +267,13 @@ function task._bind(tasks, interp) options = options_full taskinfo.menu.options = options_full - -- bind sandbox for option description + -- bind sandbox for scripts in option for _, opt in ipairs(options) do - -- bind description + -- bind description and values if type(opt) == "table" then + + -- bind description for i = 5, 64 do -- the description, @note some option may be nil @@ -268,19 +282,21 @@ function task._bind(tasks, interp) -- the description is function? wrap it for calling it in the sandbox if type(description) == "function" then - - -- make sandbox instance with the given script - local instance, errors = sandbox.new(description, interp:filter(), interp:rootdir()) - if not instance then + description, errors = task._bind_script(interp, description) + if not description then return false, errors end + opt[i] = description + end + end - -- check - assert(instance:script()) - - -- update option script - opt[i] = instance:script() + -- bind values + if type(opt.values) == "function" then + local values, errors = task._bind_script(interp, opt.values) + if not values then + return false, errors end + opt.values = values end end end |
