summaryrefslogtreecommitdiff
path: root/xmake/scripts/base
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-15 08:39:20 +0800
committerruki <[email protected]>2015-05-15 08:39:20 +0800
commitab36dca23f1cd80720e9d0eb2c3ce72d5895ba3e (patch)
tree719784494abe3ae5a3c96f779658893fe09061c0 /xmake/scripts/base
parenta2c560f7c2f1f4501516d39225d5afdd06dc9c55 (diff)
load xmake.xconf before loading project
Diffstat (limited to 'xmake/scripts/base')
-rw-r--r--xmake/scripts/base/config.lua169
-rw-r--r--xmake/scripts/base/main.lua26
-rw-r--r--xmake/scripts/base/project.lua38
3 files changed, 214 insertions, 19 deletions
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua
new file mode 100644
index 000000000..ae73b61d8
--- /dev/null
+++ b/xmake/scripts/base/config.lua
@@ -0,0 +1,169 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file config.lua
+--
+
+-- define module: config
+local config = config or {}
+
+-- load modules
+local io = require("base/io")
+local utils = require("base/utils")
+
+-- auto configs
+function config._auto(name)
+
+ -- get platform or host
+ if name == "plat" or name == "host" then
+ return xmake._HOST
+ -- get architecture
+ elseif name == "arch" then
+ return xmake._ARCH
+ end
+
+ -- unknown
+ utils.error("unknown config: %s", name)
+ return "unknown"
+end
+
+-- save xmake.xconf
+function config.savexconf()
+
+ -- the options
+ local options = xmake._OPTIONS
+ assert(options)
+
+ -- open the configure file
+ local path = options.project .. "/xmake.xconf"
+ local file = io.open(path, "w")
+ if not file then
+ -- error
+ utils.error("open %s failed!", path)
+ return false
+ end
+
+ -- save configs to file
+ if not io.save(file, xmake._CONFIGS, "return") then
+ -- error
+ utils.error("save %s failed!", path)
+ file:close()
+ return false
+ end
+
+ -- close file
+ file:close()
+
+ -- ok
+ return true
+end
+
+-- load xmake.xconf
+function config.loadxconf()
+
+ -- the options
+ local options = xmake._OPTIONS
+ assert(options)
+
+ -- the target
+ local target = options.target or options._DEFAULTS.target
+ assert(target)
+
+ -- open the configure file
+ local path = options.project .. "/xmake.xconf"
+ local file = loadfile(path)
+ if file then
+ -- execute it
+ local ok, cfg = pcall(file)
+ if not ok then
+ -- error
+ utils.error("load %s failed!", path)
+ utils.error(cfg)
+ return
+ end
+
+ -- check
+ assert(cfg and type(cfg) == "table")
+
+ -- clear configs if the host environment has been changed
+ if cfg[target] and cfg[target].host ~= xmake._HOST then
+ cfg = {}
+ end
+ if cfg.all and cfg.all.host ~= xmake._HOST then
+ cfg = {}
+ end
+
+ -- merges configs to xmake._CONFIGS
+ xmake._CONFIGS = cfg
+ end
+
+ -- the configs
+ xmake._CONFIGS = xmake._CONFIGS or {}
+ local configs = xmake._CONFIGS
+
+ -- init the configs for the target
+ configs[target] = configs[target] or {}
+
+ -- merge xmake._OPTIONS to xmake._CONFIGS[target]
+ for k, v in pairs(options) do
+
+ -- check
+ assert(type(k) == "string")
+
+ -- skip some options
+ if not k:startswith("_") and k ~= "project" and k ~= "file" and k ~= "verbose" and k ~= "target" then
+
+ -- save the option to the target
+ configs[target][k] = v
+ end
+ end
+
+ -- merge xmake._OPTIONS._DEFAULTS to xmake._CONFIGS[target]
+ for k, v in pairs(options._DEFAULTS) do
+
+ -- check
+ assert(type(k) == "string")
+
+ -- skip some options
+ if k ~= "project" and k ~= "file" and k ~= "verbose" and k ~= "target" then
+
+ -- save the default option to the target
+ if not configs[target][k] then
+ if v == "auto" then
+ configs[target][k] = config._auto(k)
+ else
+ configs[target][k] = v
+ end
+ end
+ end
+ end
+end
+
+-- dump configs
+function config.dump()
+
+ -- dump
+ if xmake._OPTIONS.verbose then
+ utils.dump(xmake._CONFIGS, "configs = ")
+ end
+
+end
+
+-- return module: config
+return config
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index 04d3d9e52..3b9f3d57a 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -27,6 +27,7 @@ local main = main or {}
local path = require("base/path")
local utils = require("base/utils")
local option = require("base/option")
+local config = require("base/config")
local project = require("base/project")
local preprocessor = require("base/preprocessor")
local action = require("action/action")
@@ -276,24 +277,11 @@ function main._done_option()
end
assert(options.file)
- -- load and execute the xmake.xproj
- local errors = nil
- local script = preprocessor.load_xproj(options.file)
- if script then
+ -- load xmake.xconf file
+ config.loadxconf()
- -- init the project envirnoment
- setfenv(script, project)
-
- -- execute it
- local ok, err = pcall(script)
- if not ok then
- -- error
- errors = err
- end
- else
- -- error
- errors = string.format("load %s failed!", options.file)
- end
+ -- load xmake.xproj file
+ local _, errors = project.loadxproj(options.file)
-- done help
if options.help then
@@ -328,8 +316,8 @@ function main._done_option()
-- save project
xmake._PROJECT = project
- -- dump project configs
--- utils.dump(xmake._PROJECT._CONFIGS, "", "_PARENT")
+ -- dump project
+ project.dump()
-- done action
return action.done(options._ACTION or "build")
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 5ed4229f0..f2cf1a9f0 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -155,6 +155,44 @@ function _register(names)
end
end
+-- load xproj
+function loadxproj(file)
+
+ -- check
+ assert(file)
+
+ -- load and execute the xmake.xproj
+ local script = preprocessor.load_xproj(file)
+ if script then
+
+ -- init the project envirnoment
+ setfenv(script, _PROJECT)
+
+ -- execute it
+ local ok, err = pcall(script)
+ if not ok then
+ -- error
+ return false, err
+ end
+ else
+ -- error
+ return false, string.format("load %s failed!", file)
+ end
+
+ -- ok
+ return true
+end
+
+-- dump all configures
+function dump()
+
+ -- dump
+ if xmake._OPTIONS.verbose then
+ utils.dump(xmake._PROJECT._CONFIGS, "", "_PARENT")
+ end
+
+end
+
-- register all configures
_register { "kind"
, "deps"