summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-06-15 11:17:26 +0800
committerruki <[email protected]>2016-06-15 11:17:26 +0800
commitcfd9db015cbb79b047280d0acfad5950530d4158 (patch)
tree768ee463a5bd63e26e1561c8ea24b27221e5a7ad
parentd960300a20f47a9787d4881dd4e7dd5d2f6150d9 (diff)
add bindings for option
-rwxr-xr-xxmake/actions/config/xmake.lua1
-rw-r--r--xmake/core/base/option.lua96
-rw-r--r--xmake/core/base/string.lua19
-rw-r--r--xmake/core/project/option.lua58
-rw-r--r--xmake/core/project/project.lua34
5 files changed, 137 insertions, 71 deletions
diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua
index 6fddd1213..6a27801dd 100755
--- a/xmake/actions/config/xmake.lua
+++ b/xmake/actions/config/xmake.lua
@@ -158,7 +158,6 @@ task("config")
, {'o', "buildir", "kv", "build", "Set the build directory." }
-
, {}
, {nil, "target", "v", "all", "Configure for the given target." }
}
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua
index 4172c816e..8ebe529ed 100644
--- a/xmake/core/base/option.lua
+++ b/xmake/core/base/option.lua
@@ -89,6 +89,41 @@ function option._context()
return contexts[#contexts]
end
+-- get longname
+function option._longname(name)
+
+ -- the long name and bindings
+ --
+ -- .e.g test:xxx1,xxx2,xxx3
+ --
+ -- longname: test
+ -- bindings: xxx1 xxx2 xxx3
+ --
+ if name ~= nil then
+ return name:split(':')[1]
+ end
+end
+
+-- get bindings
+function option._bindings(name)
+
+ -- the long name and bindings
+ --
+ -- .e.g test:xxx1,xxx2,xxx3
+ --
+ -- longname: test
+ -- bindings: xxx1 xxx2 xxx3
+ --
+ if name ~= nil then
+ local names = name:split(':')
+ if names then
+ if names[2] then
+ return names[2]:split(',')
+ end
+ end
+ end
+end
+
-- save context
function option.save(taskname)
@@ -209,17 +244,30 @@ function option.init(menu)
-- find this option
local opt = nil
+ local longname = nil
for _, o in ipairs(option._taskmenu().options) do
-- check
assert(o)
+ -- the short name
+ local shortname = o[1]
+
+ -- the long name and bindings
+ --
+ -- .e.g test:xxx1,xxx2,xxx3
+ --
+ -- longname: test
+ -- bindings: xxx1 xxx2 xxx3
+ --
+ longname = option._longname(o[2])
+
-- --key?
- if prefix == 2 and key == o[2] then
+ if prefix == 2 and key == longname then
opt = o
break
-- k?
- elseif prefix == 1 and key == o[1] then
+ elseif prefix == 1 and key == shortname then
opt = o
break
end
@@ -283,7 +331,21 @@ function option.init(menu)
end
-- save option
- context.options[option._ifelse(prefix == 1 and opt[2], opt[2], key)] = value
+ context.options[longname] = value
+
+ -- save bindings
+ local bindings = option._bindings(opt[2])
+ if bindings then
+ for _, bindname in ipairs(bindings) do
+ if bindname:startswith("!") then
+ if type(value) == "boolean" then
+ context.options[bindname:sub(2, -1)] = not value
+ end
+ else
+ context.options[bindname] = value
+ end
+ end
+ end
-- task?
elseif idx == 1 then
@@ -324,7 +386,7 @@ function option.init(menu)
local mode = o[3]
-- the name
- local name = o[2]
+ local name = option._longname(o[2])
-- check
assert(o and ((mode ~= "v" and mode ~= "vs") or name))
@@ -347,7 +409,7 @@ function option.init(menu)
local mode = opt[3]
-- the name
- local name = opt[2]
+ local name = option._longname(opt[2])
-- save value
if mode == "v" then
@@ -381,19 +443,22 @@ function option.init(menu)
-- init the default value
for _, o in ipairs(option._taskmenu().options) do
+ -- the long name
+ local longname = option._longname(o[2])
+
-- key=value?
if o[3] == "kv" then
-- the key
- local key = o[2] or o[1]
+ local key = longname or o[1]
assert(key)
-- save the default value
context.defaults[key] = o[4]
-- value with name?
- elseif o[3] == "v" and o[2] then
+ elseif o[3] == "v" and longname then
-- save the default value
- context.defaults[o[2]] = o[4]
+ context.defaults[longname] = o[4]
end
end
@@ -508,21 +573,24 @@ function option.defaults(task)
if taskmenu then
for _, o in ipairs(taskmenu.options) do
+ -- the long name
+ local longname = option._longname(o[2])
+
-- key=value?
if o[3] == "kv" then
-- the key
- local key = o[2] or o[1]
+ local key = longname or o[1]
assert(key)
-- save the default value
defaults[key] = o[4]
-- value with name?
- elseif o[3] == "v" and o[2] then
+ elseif o[3] == "v" and longname then
-- save the default value
- defaults[o[2]] = o[4]
+ defaults[longname] = o[4]
end
end
end
@@ -711,9 +779,9 @@ function option.show_options(options)
local option_info = ""
-- append the shortname
- local shortname = opt[1];
- local name = opt[2];
- local mode = opt[3];
+ local shortname = opt[1]
+ local name = option._longname(opt[2])
+ local mode = opt[3]
if shortname then
option_info = option_info .. " -" .. shortname
if mode == "kv" then
diff --git a/xmake/core/base/string.lua b/xmake/core/base/string.lua
index 7edbbde2d..b3abe36ec 100644
--- a/xmake/core/base/string.lua
+++ b/xmake/core/base/string.lua
@@ -110,6 +110,25 @@ function string:decode()
return (self:gsub("%%(%x%x)", function (w) return string.char(tonumber(w, 16)) end))
end
+-- join array to string with the given separator
+function string.join(items, sep)
+
+ -- join them
+ local str = ""
+ local index = 1
+ local count = #items
+ for _, item in ipairs(items) do
+ str = str .. item
+ if index ~= count and sep ~= nil then
+ str = str .. sep
+ end
+ index = index + 1
+ end
+
+ -- ok?
+ return str
+end
+
-- return module: string
return string
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index 9e7e0ede0..f225a01a1 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -437,46 +437,28 @@ function option:_check()
local enable = self:get("enable")
if enable ~= nil and enable then
- -- enable option
- self:enable()
+ -- enable this option
+ config.set(self:name(), true)
+
+ -- save this option to configure
+ self:save()
-- check option
elseif enable == nil and self:_check_condition() then
- -- enable option
- self:enable()
- else
-
- -- disable option
- self:disable()
- end
-end
-
--- enable this option
-function option:enable()
-
- -- enable this option
- config.set(self:name(), true)
-
- -- save this option to configure
- self:save()
-end
-
--- disable this option
-function option:disable()
-
- -- disable this option
- config.set(self:name(), false)
+ -- enable this option
+ config.set(self:name(), true)
- -- clear this option to configure
- self:clear()
-end
+ -- save this option to configure
+ self:save()
+ else
--- is enabled?
-function option:enabled()
+ -- disable this option
+ config.set(self:name(), false)
- -- ok?
- return config.get(self:name())
+ -- clear this option to configure
+ self:clear()
+ end
end
-- attempt to check option
@@ -542,16 +524,8 @@ end
-- save the option info to the cache
function option:save()
- -- remove functions first before saving option
- local info = {}
- for k, v in pairs(self._INFO) do
- if type(v) ~= "function" then
- info[k] = v
- end
- end
-
-- save it
- cache:set(self:name(), info)
+ cache:set(self:name(), self._INFO)
cache:flush()
end
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 8dec86a2b..948eab3a8 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -413,8 +413,7 @@ function project._interpreter()
, "description")
-- register api: add_values() to option
- interp:api_register_add_values("option", "deps"
- , "links"
+ interp:api_register_add_values("option", "links"
, "cincludes"
, "cxxincludes"
, "cfuncs"
@@ -429,6 +428,8 @@ function project._interpreter()
, "mxxflags"
, "ldflags"
, "vectorexts"
+ , "bindings"
+ , "rbindings"
, "defines"
, "defines_if_ok"
, "defines_h_if_ok"
@@ -440,16 +441,6 @@ function project._interpreter()
interp:api_register_add_pathes("option", "linkdirs"
, "includedirs")
- -- register api: on_action() to option
- interp:api_register_on_script("option", "check"
- , "result")
-
- -- register api: before_action() to option
- interp:api_register_before_script("option", "check")
-
- -- register api: after_action() to option
- interp:api_register_after_script("option", "check")
-
-- register api: add_cfunc() to target
interp:api_register("target", "add_cfunc", project._api_add_cfunc)
@@ -788,11 +779,26 @@ function project.menu()
first = false
end
+ -- make bindings
+ local bindings = nil
+ if opt:get("bindings") then
+ bindings = string.join(table.wrap(opt:get("bindings")), ',')
+ end
+ if opt:get("rbindings") then
+ bindings = "!" .. string.join(table.wrap(opt:get("rbindings")), ",!")
+ end
+
+ -- make longname
+ local longname = name
+ if bindings ~= nil then
+ longname = longname .. ":" .. bindings
+ end
+
-- append it
if opt:get("description") then
- table.insert(menu, {nil, name, "kv", default, opt:get("description")})
+ table.insert(menu, {nil, longname, "kv", default, opt:get("description")})
else
- table.insert(menu, {nil, name, "kv", default, nil})
+ table.insert(menu, {nil, longname, "kv", default, nil})
end
end
end