diff options
| author | ruki <[email protected]> | 2015-05-15 08:39:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-15 08:39:20 +0800 |
| commit | ab36dca23f1cd80720e9d0eb2c3ce72d5895ba3e (patch) | |
| tree | 719784494abe3ae5a3c96f779658893fe09061c0 /xmake/scripts | |
| parent | a2c560f7c2f1f4501516d39225d5afdd06dc9c55 (diff) | |
load xmake.xconf before loading project
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/action/_config.lua | 48 | ||||
| -rw-r--r-- | xmake/scripts/action/action.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/base/config.lua (renamed from xmake/scripts/action/config.lua) | 61 | ||||
| -rw-r--r-- | xmake/scripts/base/main.lua | 26 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 38 |
5 files changed, 115 insertions, 60 deletions
diff --git a/xmake/scripts/action/_config.lua b/xmake/scripts/action/_config.lua new file mode 100644 index 000000000..a627c61d9 --- /dev/null +++ b/xmake/scripts/action/_config.lua @@ -0,0 +1,48 @@ +--!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") +local config = require("base/config") + +-- done the given config +function _config.done() + + -- dump configs + config.dump() + + -- save configs + if not config.savexconf() then + return false + end + + -- ok + print("configure ok!") + return true +end + +-- return module: _config +return _config diff --git a/xmake/scripts/action/action.lua b/xmake/scripts/action/action.lua index dbb00a5b2..eab768364 100644 --- a/xmake/scripts/action/action.lua +++ b/xmake/scripts/action/action.lua @@ -27,7 +27,7 @@ local action = action or {} function action.done(name) -- load the given action - local a = require("action/" .. name) + local a = require("action/_" .. name) if not a then return false end -- done the given action diff --git a/xmake/scripts/action/config.lua b/xmake/scripts/base/config.lua index 13b5ffac5..ae73b61d8 100644 --- a/xmake/scripts/action/config.lua +++ b/xmake/scripts/base/config.lua @@ -27,8 +27,24 @@ local config = config or {} local io = require("base/io") local utils = require("base/utils") --- save configs -function config._save() +-- 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 @@ -58,8 +74,8 @@ function config._save() return true end --- load configs -function config._load() +-- load xmake.xconf +function config.loadxconf() -- the options local options = xmake._OPTIONS @@ -139,24 +155,8 @@ function config._load() end end --- 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 - -- dump configs -function config._dump() +function config.dump() -- dump if xmake._OPTIONS.verbose then @@ -164,25 +164,6 @@ function config._dump() end end - --- done the given config -function config.done() - - -- load configs - config._load() - - -- dump configs - config._dump() - - -- save configs - if not config._save() then - return false - end - - -- ok - print("configure ok!") - return true -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" |
