summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-02-01 22:52:05 +0800
committerruki <[email protected]>2018-02-01 11:12:31 +0800
commitfa98fd2e588f56713df258b6c5639db8d3bc9ad5 (patch)
tree719b50ffa4d17a995d3565deeda41950f4c9cbfd
parent3e77043082f8d183ca9417513bd3df28ffaaddd8 (diff)
impl path category for menuconf
-rw-r--r--xmake/actions/config/menuconf.lua158
-rw-r--r--xmake/actions/config/xmake.lua2
-rw-r--r--xmake/languages/asm/xmake.lua32
-rw-r--r--xmake/languages/c++/xmake.lua6
-rw-r--r--xmake/languages/dlang/xmake.lua20
-rw-r--r--xmake/languages/golang/xmake.lua20
-rw-r--r--xmake/languages/msrc/xmake.lua12
-rw-r--r--xmake/languages/objc++/xmake.lua4
-rw-r--r--xmake/languages/rust/xmake.lua16
-rw-r--r--xmake/languages/swift/xmake.lua4
-rw-r--r--xmake/platforms/windows/check.lua2
11 files changed, 158 insertions, 118 deletions
diff --git a/xmake/actions/config/menuconf.lua b/xmake/actions/config/menuconf.lua
index 47829b02a..2c9601fe7 100644
--- a/xmake/actions/config/menuconf.lua
+++ b/xmake/actions/config/menuconf.lua
@@ -74,7 +74,7 @@ function app:mconfdialog()
end
-- filter option
-function app:filter_option(name)
+function app:_filter_option(name)
local options =
{
target = true
@@ -95,49 +95,49 @@ function app:filter_option(name)
return not options[name] and not project.option(name)
end
--- get basic configs
-function app:basic_configs(cache)
-
- -- get configs from the cache first
- local configs = self._BASIC_CONFIGS
- if configs then
- return configs
+-- get or make menu by category
+function app:_menu_by_category(configs, menus, category)
+
+ -- is root?
+ if category == "." or category == "" then
+ return
end
- -- get config menu
- local menu = option.taskmenu("config")
+ -- attempt to get menu first
+ local menu = menus[category]
+ if not menu then
- -- merge options by category
- local category = "Root Configuration"
- 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
+ -- make a new menu
+ menu = menuconf.menu {name = category, description = path.basename(category), configs = {}}
+ menus[category] = menu
+
+ -- insert to the parent or root configs
+ local parent = self:_menu_by_category(configs, menus, path.directory(category))
+ table.insert(parent and parent.configs or configs, menu)
end
+ return menu
+end
- -- make configs from options
+-- make configs by category
+function app:_make_configs_by_category(options_by_category)
+
+ -- make configs category
+ --
+ -- root category: "."
+ -- category path: "a", "a/b", "a/b/c" ...
+ --
+ local menus = {}
local configs = {}
- for category, opts in pairs(options_by_category) do
+ for category, options in pairs(options_by_category) do
- -- insert configs
- local first = true
- local submenu = nil
- for _, opt in ipairs(opts) do
+ -- get or make menu by category
+ local menu = self:_menu_by_category(configs, menus, category)
- -- is first? init a sub-menu
- if first then
- if category ~= "Root Configuration" then
- submenu = menuconf.menu {name = category, description = category, configs = {}}
- table.insert(configs, submenu)
- end
- first = false
- end
+ -- get sub-configs
+ local subconfigs = menu and menu.configs or configs
+
+ -- insert options to sub-configs
+ for _, opt in ipairs(options) do
-- get name
local name = opt[2] or opt[1]
@@ -158,23 +158,63 @@ function app:basic_configs(cache)
value = config.get(value)
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
+
+ -- insert config before all sub-menus
-- key=value?
if kind == "kv" then
- table.insert(submenu and submenu.configs or configs, menuconf.string {name = name, value = value, default = default, description = description})
+ table.insert(subconfigs, menu_index, menuconf.string {name = name, value = value, default = default, description = description})
-- --key?
elseif kind == "k" then
- table.insert(submenu and submenu.configs or configs, menuconf.boolean {name = name, value = value, default = default, description = description})
+ table.insert(subconfigs, menu_index, menuconf.boolean {name = name, value = value, default = default, description = description})
end
end
end
- -- cache configs
- self._BASIC_CONFIGS = configs
+ -- done
return configs
end
+-- get basic configs
+function app:_basic_configs(cache)
+
+ -- get configs from the cache first
+ local configs = self._BASIC_CONFIGS
+ if configs then
+ return configs
+ end
+
+ -- get config menu
+ local menu = option.taskmenu("config")
+
+ -- 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._BASIC_CONFIGS = self:_make_configs_by_category(options_by_category)
+ return self._BASIC_CONFIGS
+end
+
-- get project configs
-function app:project_configs(cache)
+function app:_project_configs(cache)
-- get configs from the cache first
local configs = self._PROJECT_CONFIGS
@@ -243,6 +283,20 @@ function app:project_configs(cache)
return 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)
@@ -253,29 +307,15 @@ function app:load(cache)
-- load configs
local configs = {}
- table.insert(configs, menuconf.menu {description = "Basic Configuration", configs = self:basic_configs(cache)})
- table.insert(configs, menuconf.menu {description = "Project Configuration", configs = self:project_configs(cache)})
+ table.insert(configs, menuconf.menu {description = "Basic Configuration", configs = self:_basic_configs(cache)})
+ table.insert(configs, menuconf.menu {description = "Project Configuration", configs = self:_project_configs(cache)})
self:mconfdialog():load(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
-
-- save configs to options
function app:save()
- self:save_configs(self:basic_configs())
- self:save_configs(self:project_configs())
+ self:_save_configs(self:_basic_configs())
+ self:_save_configs(self:_project_configs())
end
-- main entry
diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua
index de03f8e17..336572b5c 100644
--- a/xmake/actions/config/xmake.lua
+++ b/xmake/actions/config/xmake.lua
@@ -51,7 +51,7 @@ task("config")
" - y: force to enable",
" - n: disable" }
- , {category = "Root Configuration"}
+ , {category = "."}
, {'p', "plat", "kv", "$(host)", "Compile for the given platform."
-- show the description of all platforms
diff --git a/xmake/languages/asm/xmake.lua b/xmake/languages/asm/xmake.lua
index 0e55544c6..8afe36d10 100644
--- a/xmake/languages/asm/xmake.lua
+++ b/xmake/languages/asm/xmake.lua
@@ -118,24 +118,24 @@ language("asm")
set_menu {
config =
{
- {category = "Compiler and Linker Configuration" }
- , {nil, "as", "kv", nil, "The Assembler" }
- , {nil, "ar", "kv", nil, "The Static Library Linker" }
- , {nil, "ld", "kv", nil, "The Linker" }
- , {nil, "sh", "kv", nil, "The Shared Library Linker" }
+ {category = "Cross Complation Configuration/Compiler and Linker Configuration" }
+ , {nil, "as", "kv", nil, "The Assembler" }
+ , {nil, "ar", "kv", nil, "The Static Library Linker" }
+ , {nil, "ld", "kv", nil, "The Linker" }
+ , {nil, "sh", "kv", nil, "The Shared Library Linker" }
- , {category = "Compiler and Linker Flags Configuration" }
- , {nil, "asflags", "kv", nil, "The Assembler Flags" }
- , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" }
- , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" }
- , {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" }
+ , {category = "Cross Complation Configuration/Compiler and Linker Flags Configuration" }
+ , {nil, "asflags", "kv", nil, "The Assembler Flags" }
+ , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" }
+ , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" }
+ , {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" }
- , { }
- , {nil, "links", "kv", nil, "The Link Libraries" }
- , {nil, "linkdirs", "kv", nil, "The Link Search Directories" }
- , {nil, "includedirs","kv", nil, "The Include Search Directories" }
- }
- }
+ , { }
+ , {nil, "links", "kv", nil, "The Link Libraries" }
+ , {nil, "linkdirs", "kv", nil, "The Link Search Directories" }
+ , {nil, "includedirs","kv", nil, "The Include Search Directories" }
+ }
+ }
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index 35ed72825..f0f3c370f 100644
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -147,14 +147,14 @@ language("c++")
set_menu {
config =
{
- {category = "Compiler and Linker Configuration" }
+ {category = "Cross Complation Configuration/Compiler and Linker Configuration" }
, {nil, "cc", "kv", nil, "The C Compiler" }
, {nil, "cxx", "kv", nil, "The C++ Compiler" }
, {nil, "ld", "kv", nil, "The Linker" }
, {nil, "ar", "kv", nil, "The Static Library Linker" }
, {nil, "sh", "kv", nil, "The Shared Library Linker" }
- , {category = "Compiler and Linker Flags Configuration" }
+ , {category = "Cross Complation Configuration/Compiler and Linker Flags Configuration" }
, {nil, "cflags", "kv", nil, "The C Compiler Flags" }
, {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" }
, {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" }
@@ -169,7 +169,7 @@ language("c++")
, {nil, "includedirs", "kv", nil, "The Include Search Directories" }
, {nil, "frameworks", "kv", nil, "The Include and Link Frameworks" }
, {nil, "frameworkdirs", "kv", nil, "The Include and Link Frameworks Search Directories" }
- }
+ }
}
diff --git a/xmake/languages/dlang/xmake.lua b/xmake/languages/dlang/xmake.lua
index 7f1dd7c07..d89c47085 100644
--- a/xmake/languages/dlang/xmake.lua
+++ b/xmake/languages/dlang/xmake.lua
@@ -102,16 +102,16 @@ language("dlang")
set_menu {
config =
{
- {category = "Compiler and Linker Configuration" }
- , {nil, "dc", "kv", nil, "The Dlang Compiler" }
- , {nil, "dc-ld", "kv", nil, "The Dlang Linker" }
- , {nil, "dc-ar", "kv", nil, "The Dlang Static Library Archiver" }
- , {nil, "dc-sh", "kv", nil, "The Dlang Shared Library Linker" }
+ {category = "Cross Complation Configuration/Compiler and Linker Configuration" }
+ , {nil, "dc", "kv", nil, "The Dlang Compiler" }
+ , {nil, "dc-ld", "kv", nil, "The Dlang Linker" }
+ , {nil, "dc-ar", "kv", nil, "The Dlang Static Library Archiver" }
+ , {nil, "dc-sh", "kv", nil, "The Dlang Shared Library Linker" }
- , {category = "Compiler and Linker Flags Configuration" }
- , {nil, "links", "kv", nil, "The Link Libraries" }
- , {nil, "linkdirs", "kv", nil, "The Link Search Directories" }
- , {nil, "includedirs","kv", nil, "The Include Search Directories" }
- }
+ , {category = "Cross Complation Configuration/Compiler and Linker Flags Configuration" }
+ , {nil, "links", "kv", nil, "The Link Libraries" }
+ , {nil, "linkdirs", "kv", nil, "The Link Search Directories" }
+ , {nil, "includedirs","kv", nil, "The Include Search Directories" }
+ }
}
diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua
index b6ab48b6c..afef8d641 100644
--- a/xmake/languages/golang/xmake.lua
+++ b/xmake/languages/golang/xmake.lua
@@ -98,15 +98,15 @@ language("golang")
set_menu {
config =
{
- {category = "Compiler and Linker Configuration" }
- , {nil, "go", "kv", nil, "The Golang Compiler" }
- , {nil, "gc-ld", "kv", nil, "The Golang Linker" }
- , {nil, "go-ar", "kv", nil, "The Golang Static Library Linker" }
+ {category = "Cross Complation Configuration/Compiler and Linker Configuration" }
+ , {nil, "go", "kv", nil, "The Golang Compiler" }
+ , {nil, "gc-ld", "kv", nil, "The Golang Linker" }
+ , {nil, "go-ar", "kv", nil, "The Golang Static Library Linker" }
- , {category = "Compiler and Linker Flags Configuration" }
- , {nil, "links", "kv", nil, "The Link Libraries" }
- , {nil, "linkdirs", "kv", nil, "The Link Search Directories" }
- , {nil, "includedirs","kv", nil, "The Include Search Directories" }
- }
- }
+ , {category = "Cross Complation Configuration/Compiler and Linker Flags Configuration" }
+ , {nil, "links", "kv", nil, "The Link Libraries" }
+ , {nil, "linkdirs", "kv", nil, "The Link Search Directories" }
+ , {nil, "includedirs","kv", nil, "The Include Search Directories" }
+ }
+ }
diff --git a/xmake/languages/msrc/xmake.lua b/xmake/languages/msrc/xmake.lua
index f1786a20d..7d8a7f3c4 100644
--- a/xmake/languages/msrc/xmake.lua
+++ b/xmake/languages/msrc/xmake.lua
@@ -63,14 +63,14 @@ language("msrc")
set_menu {
config =
{
- {category = "Compiler and Linker Configuration" }
- , {nil, "mrc", "kv", nil, "The Microsoft Resource Compiler" }
+ {category = "Cross Complation Configuration/Compiler and Linker Configuration" }
+ , {nil, "mrc", "kv", nil, "The Microsoft Resource Compiler" }
- , {category = "Compiler and Linker Flags Configuration" }
- , {nil, "mrcflags", "kv", nil, "The Microsoft Resource Flags" }
+ , {category = "Cross Complation Configuration/Compiler and Linker Flags Configuration" }
+ , {nil, "mrcflags", "kv", nil, "The Microsoft Resource Flags" }
- , { }
- , {nil, "includedirs","kv", nil, "The Include Search Directories" }
+ , { }
+ , {nil, "includedirs","kv", nil, "The Include Search Directories" }
}
}
diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua
index 2f80969cd..c740c52f7 100644
--- a/xmake/languages/objc++/xmake.lua
+++ b/xmake/languages/objc++/xmake.lua
@@ -147,14 +147,14 @@ language("objc++")
set_menu {
config =
{
- {category = "Compiler and Linker Configuration" }
+ {category = "Cross Complation Configuration/Compiler and Linker Configuration" }
, {nil, "mm", "kv", nil, "The Objc Compiler" }
, {nil, "mxx", "kv", nil, "The Objc++ Compiler" }
, {nil, "ld", "kv", nil, "The Linker" }
, {nil, "ar", "kv", nil, "The Static Library Linker" }
, {nil, "sh", "kv", nil, "The Shared Library Linker" }
- , {category = "Compiler and Linker Flags Configuration" }
+ , {category = "Cross Complation Configuration/Compiler and Linker Flags Configuration" }
, {nil, "mflags", "kv", nil, "The Objc Compiler Flags" }
, {nil, "mxflags", "kv", nil, "The Objc/c++ Compiler Flags" }
, {nil, "mxxflags", "kv", nil, "The Objc++ Compiler Flags" }
diff --git a/xmake/languages/rust/xmake.lua b/xmake/languages/rust/xmake.lua
index 942a30cfa..2525a4db6 100644
--- a/xmake/languages/rust/xmake.lua
+++ b/xmake/languages/rust/xmake.lua
@@ -91,14 +91,14 @@ language("rust")
set_menu {
config =
{
- {category = "Compiler and Linker Configuration" }
- , {nil, "rc", "kv", nil, "The Rust Compiler" }
- , {nil, "rc-ld", "kv", nil, "The Rust Linker" }
- , {nil, "rc-ar", "kv", nil, "The Rust Static Library Archiver" }
- , {nil, "rc-sh", "kv", nil, "The Rust Shared Library Linker" }
+ {category = "Cross Complation Configuration/Compiler and Linker Configuration" }
+ , {nil, "rc", "kv", nil, "The Rust Compiler" }
+ , {nil, "rc-ld", "kv", nil, "The Rust Linker" }
+ , {nil, "rc-ar", "kv", nil, "The Rust Static Library Archiver" }
+ , {nil, "rc-sh", "kv", nil, "The Rust Shared Library Linker" }
- , {category = "Compiler and Linker Flags Configuration" }
- , {nil, "linkdirs", "kv", nil, "The Link Search Directories" }
- }
+ , {category = "Cross Complation Configuration/Compiler and Linker Flags Configuration" }
+ , {nil, "linkdirs", "kv", nil, "The Link Search Directories" }
+ }
}
diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua
index dddc235ab..8682d979a 100644
--- a/xmake/languages/swift/xmake.lua
+++ b/xmake/languages/swift/xmake.lua
@@ -142,12 +142,12 @@ language("swift")
set_menu {
config =
{
- { category = "Compiler and Linker Configuration" }
+ {category = "Cross Complation Configuration/Compiler and Linker Configuration" }
, { nil, "sc", "kv", nil, "The Swift Compiler" }
, { nil, "sc-ld", "kv", nil, "The Swift Linker" }
, { nil, "sc-sh", "kv", nil, "The Swift Shared Library Linker" }
- , { category = "Compiler and Linker Flags Configuration" }
+ , { category = "Cross Complation Configuration/Compiler and Linker Flags Configuration" }
, { nil, "links", "kv", nil, "The Link Libraries" }
, { nil, "linkdirs", "kv", nil, "The Link Search Directories" }
, { nil, "includedirs", "kv", nil, "The Include Search Directories" }
diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua
index 65096ed78..157491f43 100644
--- a/xmake/platforms/windows/check.lua
+++ b/xmake/platforms/windows/check.lua
@@ -66,7 +66,7 @@ function _check_vsenv(config)
-- check compiler
environment.enter("toolchains")
local program = nil
- local tool = find_tool("cl.exe")
+ local tool = find_tool("cl.exe", {force = true})
if tool then
program = tool.program
end