summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-08 11:37:42 +0800
committerruki <[email protected]>2015-06-08 11:37:42 +0800
commitc0a3b7585c3dc8f0b0c9c776ae2785359ae1b651 (patch)
tree2e7f3b34e23b828a2d567fa055c252a66648565e
parent5d7ee81b32dc42aa82a12a2898e4ddc3466afcdc (diff)
improve switches
-rw-r--r--tests/console/xmake.xproj15
-rw-r--r--xmake/scripts/base/preprocessor.lua3
-rw-r--r--xmake/scripts/base/project.lua66
3 files changed, 47 insertions, 37 deletions
diff --git a/tests/console/xmake.xproj b/tests/console/xmake.xproj
index bbf52e5c7..43eb93e4d 100644
--- a/tests/console/xmake.xproj
+++ b/tests/console/xmake.xproj
@@ -36,8 +36,6 @@ project: console
optimize: fastest
}
- switches: bbb
-
target: hello1
{
kind: static
@@ -84,12 +82,15 @@ project: console
files: src/demo/*.cpp
linkdirs: $(buildir)
includedirs: $(buildir)
- switches: aaa, ccc
+ switches: aaa
+ switches: ccc
+ switches: fff, kkk
cxxflags: -DHELLO1
- , [_if("aaa", "-DAAA")]
- , [_if("bbb", "-DBBB")]
- , [_if("ccc", "-DCCC")]
- , [_ifelse("ddd", "-DDDD", "-DEEE")]
+ , [_if(aaa, "-DAAA")]
+ , [_if(bbb, "-DBBB")]
+ , [_if(ccc, "-DCCC")]
+ , [_ifelse(ddd, "-DDDD", "-DEEE")]
+ , [_ifelse(kkk, "-DKKK", "-DFFF")]
}
platforms: macosx, ios
diff --git a/xmake/scripts/base/preprocessor.lua b/xmake/scripts/base/preprocessor.lua
index 1a9c1b650..a8fd9fa39 100644
--- a/xmake/scripts/base/preprocessor.lua
+++ b/xmake/scripts/base/preprocessor.lua
@@ -94,9 +94,6 @@ function preprocessor._register(env, names, filter)
if table.getn(arg) == 0 then
-- no argument
_current[name] = nil
- elseif table.getn(arg) == 1 then
- -- save only one argument
- _current[name] = preprocessor._filter(env, arg[1], filter)
else
-- save all arguments
for _, v in ipairs(arg) do
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 3db260ef2..8b8873983 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -101,11 +101,13 @@ function project._make_configs(scope, configs)
-- wrap it first
local values = utils.wrap(v)
- if table.getn(values) == 1 then
-
- -- replace it
- item[1] = values[1]
+ if #values > 1 then
+ utils.error("the %s cannot have multiple values in xmake.xproj!", k)
+ assert(false)
end
+
+ -- replace it
+ item[1] = values[1]
end
end
end
@@ -119,24 +121,6 @@ function project._make_for_switches(target, values)
-- wrap values first
values = utils.wrap(values)
- -- _if x return v
- target["_if"] = function (x, v)
-
- if target._SWITCHES and target._SWITCHES[x] then
- return v
- end
- return nil
- end
-
- -- _if x return a else return b
- target["_ifelse"] = function (x, a, b)
-
- if target._SWITCHES and target._SWITCHES[x] then
- return a
- end
- return b
- end
-
-- done
local newvals = {}
for _, v in ipairs(values) do
@@ -160,10 +144,6 @@ function project._make_for_switches(target, values)
end
end
- -- remove if and ifelse
- target["_if"] = nil
- target["_ifelse"] = nil
-
-- ok?
return newvals
end
@@ -174,12 +154,40 @@ function project._init_switches(target)
-- make switches
target._SWITCHES = target._SWITCHES or {}
+ -- _if x return v
+ target["_if"] = function (x, v)
+
+ if x and type(x) == "boolean" then return v end
+ return nil
+ end
+
+ -- _if x return a else return b
+ target["_ifelse"] = function (x, a, b)
+
+ if x and type(x) == "boolean" then return a end
+ return b
+ end
+
-- init switches
if target.switches then
for _, switch in ipairs(target.switches) do
target._SWITCHES[switch] = true
end
end
+
+ -- attempt to get it from the switches
+ setmetatable(target,
+ {
+ __index = function(tbl, key)
+
+ local switches = rawget(tbl, "_SWITCHES")
+ if switches and switches[key] then
+ return switches[key]
+ end
+ return rawget(tbl, key)
+ end
+ })
+
end
-- exit switches
@@ -187,6 +195,10 @@ function project._exit_switches(target)
-- remove it
target._SWITCHES = nil
+
+ -- remove if and ifelse
+ target["_if"] = nil
+ target["_ifelse"] = nil
end
-- make the current project configure
@@ -223,7 +235,7 @@ function project._make()
-- remove repeat values and unwrap it
for k, v in pairs(target) do
- if k and k ~= "_SWITCHES" then
+ if k and not k:startswith("_") then
-- make values for switches
v = project._make_for_switches(target, v)