summaryrefslogtreecommitdiff
path: root/xmake/scripts/base
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-16 17:00:07 +0800
committerruki <[email protected]>2015-05-16 17:00:07 +0800
commit5fefc1a0bc38a6917c38590d08bf14a4c43dd886 (patch)
tree9d1e8d5708a5a2bff68797b422d432b25b8ddfc8 /xmake/scripts/base
parent05c2b5a567c1e2174ae136e18ca254d98a6b257c (diff)
add filter to preprocessor
Diffstat (limited to 'xmake/scripts/base')
-rw-r--r--xmake/scripts/base/preprocessor.lua31
-rw-r--r--xmake/scripts/base/project.lua35
2 files changed, 35 insertions, 31 deletions
diff --git a/xmake/scripts/base/preprocessor.lua b/xmake/scripts/base/preprocessor.lua
index 02d6fbd55..ed651932e 100644
--- a/xmake/scripts/base/preprocessor.lua
+++ b/xmake/scripts/base/preprocessor.lua
@@ -23,11 +23,26 @@
-- define module: preprocessor
local preprocessor = preprocessor or {}
+-- filter value
+function preprocessor._filter(value, filter)
+
+ -- the value is string?
+ if filter and type(value) == "string" then
+
+ -- replace $(variable)
+ value = value:gsub("%$%((.*)%)", filter)
+ end
+
+ -- ok
+ return value
+end
+
-- register configures
-function preprocessor._register(env, names)
+function preprocessor._register(env, names, filter)
-- check
assert(env and names and type(names) == "table")
+ assert(not filter or type(filter) == "function")
-- register all configures
for _, name in ipairs(names) do
@@ -49,11 +64,11 @@ function preprocessor._register(env, names)
_current[name] = nil
elseif table.getn(arg) == 1 then
-- save only one argument
- _current[name] = arg[1]
+ _current[name] = preprocessor._filter(arg[1], filter)
else
-- save all arguments
for i, v in ipairs(arg) do
- _current[name][i] = v
+ _current[name][i] = preprocessor._filter(v, filter)
end
end
end
@@ -61,7 +76,7 @@ function preprocessor._register(env, names)
end
-- init configures
-function preprocessor._init(root, configures, scopes)
+function preprocessor._init(root, configures, scopes, filter)
-- check
assert(root and configures)
@@ -73,7 +88,7 @@ function preprocessor._init(root, configures, scopes)
setfenv(1, newenv)
-- register all configures
- preprocessor._register(newenv, configures)
+ preprocessor._register(newenv, configures, filter)
-- configure scope end
newenv["_end"] = function ()
@@ -158,9 +173,9 @@ end
--
-- @code
-- local configs, errors = preprocessor.loadfile("xmake.xconf", "config", {"plat", "host", "arch", ...}, {"target"})
--- local configs, errors = preprocessor.loadfile("xmake.xproj", "project", {"links", "files", "ldflags", ...}, {"target", "platforms"})
+-- local configs, errors = preprocessor.loadfile("xmake.xproj", "project", {"links", "files", "ldflags", ...}, {"target", "platforms"}, filter)
-- @endcode
-function preprocessor.loadfile(path, root, configures, scopes)
+function preprocessor.loadfile(path, root, configures, scopes, filter)
-- check
assert(path and root and configures)
@@ -170,7 +185,7 @@ function preprocessor.loadfile(path, root, configures, scopes)
if script then
-- init a new envirnoment
- local newenv = preprocessor._init(root, configures, scopes)
+ local newenv = preprocessor._init(root, configures, scopes, filter)
assert(newenv)
-- bind this envirnoment
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index a85941b78..6b93b32fc 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -28,28 +28,6 @@ local utils = require("base/utils")
local config = require("base/config")
local preprocessor = require("base/preprocessor")
--- preprocess value
-function _preprocess(value)
-
- -- the value is string?
- if type(value) == "string" then
-
- -- replace $(variable)
- value = value:gsub("%$%((.*)%)", function (v)
- if v == "buildir" then
- local target = config.getarget()
- return utils.ifelse(target, target.output, nil);
- elseif v == "projectdir" then
- return xmake._OPTIONS.project
- end
- return v
- end)
- end
-
- -- ok
- return value
-end
-
-- load xproj
function project.loadxproj(file)
@@ -74,8 +52,19 @@ function project.loadxproj(file)
, "mxflags"
, "defines"}
+ -- init filter
+ local filter = function (v)
+ if v == "buildir" then
+ local target = config.getarget()
+ return utils.ifelse(target, target.output, nil);
+ elseif v == "projectdir" then
+ return xmake._OPTIONS.project
+ end
+ return v
+ end
+
-- load and execute the xmake.xproj
- local configs, errors = preprocessor.loadfile(file, "project", configures, {"target", "platforms"})
+ local configs, errors = preprocessor.loadfile(file, "project", configures, {"target", "platforms"}, filter)
if configs then
-- ok
project._CONFIGS = configs