diff options
| author | ruki <[email protected]> | 2018-12-11 22:40:23 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-12-11 10:02:21 +0800 |
| commit | e429d90d867a8919b0480d1838f0d7d2bab94f27 (patch) | |
| tree | 4b5b39725eb08309687e0515ef0b0095a741fc00 | |
| parent | e9a6a15b91e979ef855749be60c1ddd50823b9d5 (diff) | |
add xmake g --menu
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/actions/global/main.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/global/menuconf.lua | 309 | ||||
| -rw-r--r-- | xmake/actions/global/xmake.lua | 15 | ||||
| -rw-r--r-- | xmake/core/base/global.lua | 6 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/global.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/devel/debugger/run.lua | 2 | ||||
| -rw-r--r-- | xmake/platforms/android/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/platforms/iphoneos/xmake.lua | 10 | ||||
| -rw-r--r-- | xmake/platforms/linux/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/platforms/macosx/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/platforms/watchos/xmake.lua | 10 | ||||
| -rw-r--r-- | xmake/platforms/windows/xmake.lua | 6 |
13 files changed, 348 insertions, 32 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 79a2a85aa..4dd47462b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### New features * Add `string.serialize` and `string.deserialize` to serialize and deserialize object, function and others. +* Add `xmake g --menu` ### Changes @@ -533,6 +534,7 @@ ### 新特性 * 添加`string.serialize`和`string.deserialize`去序列化,反序列化对象,函数以及其他类型 +* 添加`xmake g --menu`去图形化配置全局选项 ### 改进 diff --git a/xmake/actions/global/main.lua b/xmake/actions/global/main.lua index a54cd5cd9..21d62aaa9 100644 --- a/xmake/actions/global/main.lua +++ b/xmake/actions/global/main.lua @@ -25,10 +25,16 @@ -- imports import("core.base.option") import("core.base.global") +import("menuconf", {alias = "menuconf_show"}) -- main function main() + -- enter menu config + if option.get("menu") then + menuconf_show() + end + -- load the global configure -- -- priority: option > option_default > config_check > global_cache diff --git a/xmake/actions/global/menuconf.lua b/xmake/actions/global/menuconf.lua new file mode 100644 index 000000000..b4066d052 --- /dev/null +++ b/xmake/actions/global/menuconf.lua @@ -0,0 +1,309 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file menuconf.lua +-- + +-- imports +import("core.base.option") +import("core.base.global") +import("core.ui.log") +import("core.ui.rect") +import("core.ui.view") +import("core.ui.label") +import("core.ui.event") +import("core.ui.action") +import("core.ui.menuconf") +import("core.ui.mconfdialog") +import("core.ui.application") + +-- the app application +local app = application() + +-- init app +function app:init() + + -- init name + application.init(self, "app.config") + + -- init background + self:background_set("blue") + + -- insert menu config dialog + self:insert(self:mconfdialog()) + + -- load configs + self:load(not option.get("clean")) +end + +-- get menu config dialog +function app:mconfdialog() + if not self._MCONFDIALOG then + local mconfdialog = mconfdialog:new("app.config.mconfdialog", rect {1, 1, self:width() - 1, self:height() - 1}, "menu config") + mconfdialog:action_set(action.ac_on_exit, function (v) + self:quit() + os.exit() + end) + mconfdialog:action_set(action.ac_on_save, function (v) + self:save() + self:quit() + end) + self._MCONFDIALOG = mconfdialog + end + return self._MCONFDIALOG +end + +-- filter option +function app:_filter_option(name) + local options = + { + file = true + , root = true + , yes = true + , quiet = true + , profile = true + , project = true + , verbose = true + , backtrace = true + , diagnosis = true + , version = true + , help = true + , clean = true + , menu = true + } + return not options[name] +end + +-- get or make menu by category +function app:_menu_by_category(root, configs, menus, category) + + -- is root? + if category == "." or category == "" then + return + end + + -- attempt to get menu first + local menu = menus[category] + if not menu then + + -- get config path + local parentdir = path.directory(category) + local config_path = path.join(root, parentdir == "." and "" or parentdir) + + -- make a new menu + menu = menuconf.menu {name = category, path = config_path, description = path.basename(category), configs = {}} + menus[category] = menu + + -- insert to the parent or root configs + local parent = self:_menu_by_category(root, configs, menus, parentdir) + table.insert(parent and parent.configs or configs, menu) + end + return menu +end + +-- make configs by category +function app:_make_configs_by_category(root, options_by_category, cache, get_option_info) + + -- make configs category + -- + -- root category: "." + -- category path: "a", "a/b", "a/b/c" ... + -- + local menus = {} + local configs = {} + for category, options in pairs(options_by_category) do + + -- get or make menu by category + local menu = self:_menu_by_category(root, configs, menus, category) + + -- get sub-configs + local subconfigs = menu and menu.configs or configs + + -- insert options to sub-configs + for _, opt in ipairs(options) do + + -- get option info + local info = get_option_info(opt) + + -- new value? + local newvalue = true + + -- load value + local value = nil + if cache then + value = global.get(info.name) + if value ~= nil and info.kind == "choice" and info.values then + for idx, val in ipairs(info.values) do + if value == val then + value = idx + break + end + end + end + if value ~= nil then + newvalue = false + end + end + + -- find the menu index in subconfigs + local menu_index = #subconfigs + 1 + for idx, subconfig in ipairs(subconfigs) do + if subconfig.kind == "menu" then + menu_index = idx + break + end + end + + -- get config path + local config_path = path.join(root, category == "." and "" or category) + + -- insert config before all sub-menus + if info.kind == "string" then + table.insert(subconfigs, menu_index, menuconf.string {name = info.name, value = value, new = newvalue, default = info.default, path = config_path, description = info.description, sourceinfo = info.sourceinfo}) + elseif info.kind == "boolean" then + table.insert(subconfigs, menu_index, menuconf.boolean {name = info.name, value = value, new = newvalue, default = info.default, path = config_path, description = info.description, sourceinfo = info.sourceinfo}) + elseif info.kind == "choice" then + table.insert(subconfigs, menu_index, menuconf.choice {name = info.name, value = value, new = newvalue, default = info.default, path = config_path, values = info.values, description = info.description, sourceinfo = info.sourceinfo}) + end + end + end + + -- done + return configs +end + +-- get global configs +function app:_global_configs(cache) + + -- get configs from the cache first + local configs = self._GLOBAL_CONFIGS + if configs then + return configs + end + + -- get config menu + local menu = option.taskmenu("global") + + -- merge options by category + local category = "." + local options = menu and menu.options or {} + local options_by_category = {} + for _, opt in pairs(options) do + local name = opt[2] or opt[1] + if name and self:_filter_option(name) then + options_by_category[category] = options_by_category[category] or {} + table.insert(options_by_category[category], opt) + elseif opt.category then + category = opt.category + end + end + + -- make configs by category + self._GLOBAL_CONFIGS = self:_make_configs_by_category("Global Configuration", options_by_category, cache, 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] + if type(desc) == "function" then + desc = desc() + end + if type(desc) == "string" then + table.insert(description, desc) + elseif type(desc) == "table" then + table.join2(description, desc) + else + break + end + end + + -- make option info + return {name = opt[2] or opt[1], kind = kind, default = default, values = values, description = description} + end) + return self._GLOBAL_CONFIGS +end + +-- save the given configs +function app:_save_configs(configs) + local options = option.options() + for _, conf in pairs(configs) do + if conf.kind == "menu" then + self:_save_configs(conf.configs) + elseif not conf.new and (conf.kind == "boolean" or conf.kind == "string") then + options[conf.name] = conf.value + elseif not conf.new and (conf.kind == "choice") then + options[conf.name] = conf.values[conf.value] + end + end +end + +-- load configs from options +function app:load(cache) + + -- load config from cache + if cache then + cache = global.load() + end + + -- clear configs first + self._GLOBAL_CONFIGS = nil + + -- load configs + local configs = {} + table.insert(configs, menuconf.menu {description = "Global Configuration", configs = self:_global_configs(cache)}) + self:mconfdialog():load(configs) + + -- the previous config is only for loading menuconf, so clear config now + if cache then + global.clear() + end +end + +-- save configs to options +function app:save() + self:_save_configs(self:_global_configs()) +end + +-- main entry +function main(...) + app:run(...) +end diff --git a/xmake/actions/global/xmake.lua b/xmake/actions/global/xmake.lua index d1fd2b0de..ce9178407 100644 --- a/xmake/actions/global/xmake.lua +++ b/xmake/actions/global/xmake.lua @@ -45,19 +45,16 @@ task("global") -- options , options = { - {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } + {'c', "clean", "k", nil, "Clean the cached configure and configure all again." } + , {nil, "menu", "k", nil, "Configure with a menu-driven user interface." } - , {} - - , {nil, "make", "kv", "auto", "Set the make path." } + , {category = "."} , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache." - , " --ccache=[y|n]" } - - , {} - , {nil, "debugger", "kv", "auto", "The Debugger" } - , {} + , " --ccache=[y|n]" } + , {nil, "debugger", "kv", "auto", "The Debugger Program Path." } -- show platform menu options + , {category = "Platform Configuration"} , function () -- import platform menu diff --git a/xmake/core/base/global.lua b/xmake/core/base/global.lua index 62c9749fb..977af02dd 100644 --- a/xmake/core/base/global.lua +++ b/xmake/core/base/global.lua @@ -153,6 +153,12 @@ function global.save() return io.save(global._file(), options) end +-- clear config +function global.clear() + global._MODES = nil + global._CONFIGS = nil +end + -- dump the configure function global.dump() if not option.get("quiet") then diff --git a/xmake/core/sandbox/modules/import/core/base/global.lua b/xmake/core/sandbox/modules/import/core/base/global.lua index dd6d55603..6ae8c7811 100644 --- a/xmake/core/sandbox/modules/import/core/base/global.lua +++ b/xmake/core/sandbox/modules/import/core/base/global.lua @@ -71,6 +71,11 @@ function sandbox_core_base_global.save() end end +-- clear the configure +function sandbox_core_base_global.clear() + return global.clear() +end + -- check the configure function sandbox_core_base_global.check() diff --git a/xmake/modules/devel/debugger/run.lua b/xmake/modules/devel/debugger/run.lua index b284a31d2..7ccb226f9 100644 --- a/xmake/modules/devel/debugger/run.lua +++ b/xmake/modules/devel/debugger/run.lua @@ -211,5 +211,5 @@ function main(program, argv) end -- no debugger - raise("debugger not found!") + raise("debugger%s not found!", debugger and ("(" .. debugger .. ")") or "") end diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index be1c06a24..7d06c60ac 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -54,7 +54,7 @@ platform("android") , global = { - {} + {category = "Android NDK Configuration" } , {nil, "ndk", "kv", nil, "The NDK Directory" } , {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" } } diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 32d561898..a6dc69508 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -51,20 +51,12 @@ platform("iphoneos") , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } - , {} - , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" } - , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" } - , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" } } , global = { - {} + {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } - , {} - , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" } - , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" } - , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" } } } diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index b11d5eb05..b5b712df4 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -59,8 +59,9 @@ platform("linux") , global = { - {} + {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } + , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } } } diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index e77057779..ccd978120 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -63,9 +63,11 @@ platform("macosx") , global = { - {} + {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } + , {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } + , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } } } diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index c22deb3d5..8c472440f 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -51,20 +51,12 @@ platform("watchos") , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } - , { } - , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" } - , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" } - , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" } } , global = { - { } + {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } - , { } - , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" } - , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" } - , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" } } } diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 98ee28f76..a6cdcc6da 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -106,11 +106,15 @@ platform("windows") , global = { - { } + {category = "Visual Studio SDK Configuration" } , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio" } + , {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } + , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } + , {category = "WDK Configuration" } , {nil, "wdk", "kv", "auto", "The WDK Directory" } + , {category = "Vcpkg Configuration" } , {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" } } } |
