summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-16 20:00:45 +0800
committerruki <[email protected]>2015-05-16 20:00:45 +0800
commitb7344cd33b93ba1a1aa96eea057adf4b71f7139a (patch)
tree2bf15a9edab8fdce2777ca0b46d7cedf24d4fac6 /xmake/scripts
parent94c489e0b0c07d8187d96ca7659357c5c71d5944 (diff)
add import for the configure file
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/base/config.lua12
-rw-r--r--xmake/scripts/base/main.lua2
-rw-r--r--xmake/scripts/base/preprocessor.lua15
-rw-r--r--xmake/scripts/base/project.lua35
4 files changed, 49 insertions, 15 deletions
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua
index cb169550e..31fb4dd81 100644
--- a/xmake/scripts/base/config.lua
+++ b/xmake/scripts/base/config.lua
@@ -223,13 +223,13 @@ function config.loadxconf()
-- load and execute the xmake.xconf
local path = options.project .. "/xmake.xconf"
- local configs, errors = preprocessor.loadfile(path, "config", configures, {"target"})
-
- -- save configs
- config._CONFIGS = configs
+ local newenv, errors = preprocessor.loadfile(path, "config", configures, {"target"})
-- exists local configures?
- if configs then
+ if newenv then
+
+ -- save configs
+ config._CONFIGS = newenv._CONFIGS
-- clear configs if the host environment has been changed
local target = config.getarget()
@@ -248,7 +248,7 @@ function config.loadxconf()
-- init configs
config._CONFIGS = config._CONFIGS or {}
- configs = config._CONFIGS
+ local configs = config._CONFIGS
-- init targets
configs._TARGET = configs._TARGET or {}
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index 4b404a73e..17f0af74b 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -150,7 +150,7 @@ local menu =
, {'-', "host", "kv", "auto", "The current host environment." }
, {}
- , {'o', "output", "kv", "build", "Set the build directory" }
+ , {'o', "buildir", "kv", "build", "Set the build directory" }
, {'k', "packages", "kv", "pkg", "Set the packages directory" }
, {}
diff --git a/xmake/scripts/base/preprocessor.lua b/xmake/scripts/base/preprocessor.lua
index 7f2cd8c02..235ae8011 100644
--- a/xmake/scripts/base/preprocessor.lua
+++ b/xmake/scripts/base/preprocessor.lua
@@ -101,7 +101,7 @@ function preprocessor._register(env, names, filter)
end
-- init configures
-function preprocessor._init(root, configures, scopes, filter)
+function preprocessor._init(root, configures, scopes, filter, import)
-- check
assert(root and configures)
@@ -115,6 +115,11 @@ function preprocessor._init(root, configures, scopes, filter)
-- register all configures
preprocessor._register(newenv, configures, filter)
+ -- configure import
+ if import then
+ newenv["import"] = import
+ end
+
-- configure scope end
newenv["_end"] = function ()
@@ -198,9 +203,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"}, filter)
+-- local configs, errors = preprocessor.loadfile("xmake.xproj", "project", {"links", "files", "ldflags", ...}, {"target", "platforms"}, filter, import)
-- @endcode
-function preprocessor.loadfile(path, root, configures, scopes, filter)
+function preprocessor.loadfile(path, root, configures, scopes, filter, import)
-- check
assert(path and root and configures)
@@ -210,7 +215,7 @@ function preprocessor.loadfile(path, root, configures, scopes, filter)
if script then
-- init a new envirnoment
- local newenv = preprocessor._init(root, configures, scopes, filter)
+ local newenv = preprocessor._init(root, configures, scopes, filter, import)
assert(newenv)
-- bind this envirnoment
@@ -224,7 +229,7 @@ function preprocessor.loadfile(path, root, configures, scopes, filter)
end
-- ok?
- return newenv._CONFIGS
+ return newenv
else
-- error
return nil, string.format("load %s failed!", path)
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 6b93b32fc..1a25b9bda 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -63,11 +63,39 @@ function project.loadxproj(file)
return v
end
+ -- init import
+ local import = function (name)
+
+ -- import configs?
+ if name == "configs" then
+
+ -- init configs
+ local configs = {}
+
+ -- get the config for the current target
+ local target = config.getarget()
+ if target then
+ for k, v in pairs(target) do
+ if k and type(k) == "string" and not k:startswith("_") then
+ configs[k] = v
+ end
+ end
+ end
+
+ -- init the project directory
+ configs.projectdir = xmake._OPTIONS.project
+
+ -- import it
+ return configs
+ end
+
+ end
+
-- load and execute the xmake.xproj
- local configs, errors = preprocessor.loadfile(file, "project", configures, {"target", "platforms"}, filter)
- if configs then
+ local newenv, errors = preprocessor.loadfile(file, "project", configures, {"target", "platforms"}, filter, import)
+ if newenv and newenv._CONFIGS then
-- ok
- project._CONFIGS = configs
+ project._CONFIGS = newenv._CONFIGS
elseif errors then
-- error
return errors
@@ -75,6 +103,7 @@ function project.loadxproj(file)
-- error
return string.format("load %s failed!", file)
end
+
end
-- dump configs