diff options
| author | ruki <[email protected]> | 2016-03-03 13:36:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-03-03 13:36:30 +0800 |
| commit | 5cf23fadbd11d5c6aaf6c69da322f9150d10cf49 (patch) | |
| tree | 5953e689f525681d02cd11cb7a206ac3133c0776 | |
| parent | af8e19e9b32faeadc816087a8d0b86e13e8f948c (diff) | |
remove global
| -rw-r--r-- | xmake/core/base/config.lua | 388 | ||||
| -rw-r--r-- | xmake/core/base/global.lua | 239 | ||||
| -rw-r--r-- | xmake/core/base/task.lua | 13 |
3 files changed, 1 insertions, 639 deletions
diff --git a/xmake/core/base/config.lua b/xmake/core/base/config.lua deleted file mode 100644 index 65187fd4b..000000000 --- a/xmake/core/base/config.lua +++ /dev/null @@ -1,388 +0,0 @@ ---!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) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file config.lua --- - --- define module: config -local config = config or {} - --- load modules -local io = require("base/io") -local os = require("base/os") -local path = require("base/path") -local utils = require("base/utils") -local option = require("base/option") -local global = require("base/global") - --- make configure for the current target -function config._make(configs) - - -- init current target configure - local current = {} - - -- get configs from the default configure - if configs._DEFAULTS then - for k, v in pairs(configs._DEFAULTS) do - if type(v) ~= "string" or v ~= "auto" then current[k] = v end - end - end - - -- get configs from the global configure - if global._CURRENT then - for k, v in pairs(global._CURRENT) do - current[k] = v - end - end - - -- get configs from all targets - for k, v in pairs(configs) do - if type(k) == "string" and not k:find("^_%u+") then - current[k] = v - end - end - - -- get configs from the current target - if configs._TARGETS and current.target ~= "all" then - - -- get the target config - local target_config = configs._TARGETS[current.target] - if target_config then - - -- merge it - for k, v in pairs(target_config) do - current[k] = v - end - end - end - - -- ok? - return current -end - --- get the configure file -function config._file() - - -- get it - return path.join(config.directory(), "xmake.conf") -end - --- need configure? -function config._need(name) - return name and name ~= "target" and name ~= "file" and name ~= "project" and name ~= "verbose" and name ~= "clean" -end - --- get the current target scope -function config._target() - - -- check - local configs = config._CONFIGS - assert(configs) - - -- the target name - local name = option.get("target") - assert(name and type(name) == "string") - - -- for all targets? - if name == "all" then - return configs - elseif configs._TARGETS then - -- get it - return configs._TARGETS[name] - end -end - --- get the given configure from the current -function config.get(name) - - -- the configure has been not loaded - if not config._CURRENT then return end - - -- get it - return config._CURRENT[name] -end - --- set the given configure to the current -function config.set(name, value) - - -- check - assert(config._CURRENT and name) - - -- get the current target - local target = config._target() - assert(target) - - -- set it to the current target configure for saving to file - target[name] = value - - -- set it to the current configure - config._CURRENT[name] = value -end - --- the given configure need probe automatically -function config.auto(name) - - -- the configs - local configs = config._CONFIGS - assert(configs) - - -- need probe it automatically? - if configs._DEFAULTS then - local value = configs._DEFAULTS[name] - if value then - if type(value) == "string" and value == "auto" then - return true - end - end - end - - -- need not probe it if have been setted manually - if config._CURRENT and nil ~= config._CURRENT[name] then - return false - end - - -- attempt to probe it if not exists - return true -end - --- get the configure directory -function config.directory() - - -- the directory - local dir = path.join(xmake._PROJECT_DIR, ".xmake") - - -- create it directly first if not exists - if not os.isdir(dir) then - assert(os.mkdir(dir)) - end - - -- get it - return dir -end - --- save xmake.conf -function config.save() - - -- the configs - local configs = config._CONFIGS - assert(configs) - - -- save to the configure file - return io.save(config._file(), configs) -end - -function config.load() - - -- the options - local options = option.options() - assert(options) - - -- check - assert(option._MENU) - assert(option._MENU.config) - - -- the target name - local name = option.get("target") - if not name then - return "no given target name!" - end - - -- does not clean the cached configure? - if not option.get("clean") then - - -- load and execute the xmake.xconf - local filepath = config._file() - if os.isfile(filepath) then - - -- load the configure file - local configs, errors = io.load(filepath) - - -- exists local configures? - if configs then - - -- save configs - config._CONFIGS = configs - - -- make the current target configs - local current = config._make(configs) - - -- clear configs and mark as "rebuild" and "reconfig" if the host has been changed - if (current and current.host ~= xmake._HOST) then - - -- clear configs and mark as "rebuild" - config._CONFIGS = { __rebuild = true } - - -- mark as "reconfig" if the current action is not "config" - if option.task() ~= "config" then - config._RECONFIG = true - end - end - - -- clear configs and mark as "rebuild" if the plat has been changed - if current and current.plat and options.plat and current.plat ~= options.plat then - - -- clear configs and mark as "rebuild" - config._CONFIGS = { __rebuild = true } - end - - -- mark as "rebuild" if the arch has been changed - if current and current.arch and options.arch and current.arch ~= options.arch then - - -- mark as "rebuild" - config._CONFIGS.__rebuild = true - end - - -- mark as "rebuild" if the mode has been changed - if current and current.mode and options.mode and current.mode ~= options.mode then - - -- mark as "rebuild" - config._CONFIGS.__rebuild = true - end - elseif errors then - -- error - utils.error(errors) - end - end - end - - -- init configs if not exists - if not config._CONFIGS then - -- clear configs and mark as "rebuild" - config._CONFIGS = { __rebuild = true } - - -- mark as "reconfig" if the current action is not "config" - if option.task() ~= "config" then - config._RECONFIG = true - end - end - - -- the configs - local configs = config._CONFIGS - - -- mark as "rebuild" if clean the cached configure - if option.get("clean") then - configs.__rebuild = true - end - - -- init the defaults - local defaults = nil - if not configs._DEFAULTS then - if config._RECONFIG then defaults = option.defaults("config") - elseif option.task() == "config" then defaults = option.defaults() - end - if defaults then - for k, v in pairs(defaults) do - - -- check - assert(type(k) == "string") - - -- skip some options - if config._need(k) then - - -- save the default option - configs._DEFAULTS = configs._DEFAULTS or {} - configs._DEFAULTS[k] = v - end - end - end - end - defaults = configs._DEFAULTS - - -- init targets - configs._TARGETS = configs._TARGETS or {} - if name ~= "all" then - configs._TARGETS[name] = configs._TARGETS[name] or {} - end - - -- get the current target scope - local target = config._target() - assert(target and type(target) == "table") - - -- merge option.options() to target - if option.task() == "config" then - for k, v in pairs(options) do - - -- check - assert(type(k) == "string") - - -- skip some options - if not k:startswith("_") and config._need(k) then - - -- save the option to the target - target[k] = v - - -- remove it from the defaults, because we have setted it manually - if defaults then defaults[k] = nil end - end - end - end - - -- make the current config - config._CURRENT = config._make(config._CONFIGS) -end - --- clear up and remove all auto values -function config.clearup() - - -- clear up the current configure - local current = config._CURRENT - if current then - for k, v in pairs(current) do - if type(v) == "string" and v == "auto" then - current[k] = nil - end - end - end - - -- clear up the current target configure - local target = config._target() - if target then - for k, v in pairs(target) do - if type(v) == "string" and v == "auto" then - target[k] = nil - end - end - end - -end - --- reload configure -function config.reload() - - -- clear the old configure - config._CURRENT = nil - config._CONFIGS = nil - - -- load it - return config.load() -end - --- dump the current configure -function config.dump() - - -- check - assert(config._CURRENT) - - -- dump - utils.dump(config._CURRENT, "__%w*", "configure") - -end - --- return module: config -return config diff --git a/xmake/core/base/global.lua b/xmake/core/base/global.lua deleted file mode 100644 index 0be86e136..000000000 --- a/xmake/core/base/global.lua +++ /dev/null @@ -1,239 +0,0 @@ ---!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) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file global.lua --- - --- define module: global -local global = global or {} - --- load modules -local io = require("base/io") -local os = require("base/os") -local utils = require("base/utils") -local option = require("base/option") - --- make configure -function global._make() - - -- the configs - local configs = global._CONFIGS - assert(configs) - - -- init current global configure - global._CURRENT = global._CURRENT or {} - local current = global._CURRENT - - -- make current global configure - for k, v in pairs(configs) do - if type(k) == "string" and not k:find("^_%u+") then - current[k] = v - end - end -end - --- get the configure file -function global._file() - - -- get it - return global.directory() .. "/xmake.conf" -end - --- need configure? -function global._need(name) - return name and name ~= "verbose" and name ~= "clean" -end - --- get the given configure from the current -function global.get(name) - - -- check - assert(global._CURRENT) - - -- the value - local value = global._CURRENT[name] - if value and value == "auto" then - value = nil - end - - -- get it - return value -end - --- set the given configure to the current -function global.set(name, value) - - -- check - assert(global._CURRENT and global._CONFIGS) - assert(name and type(value) ~= "table") - - -- set it to the current configure - global._CURRENT[name] = value - - -- set it to the configure for saving to file - global._CONFIGS[name] = value - -end - --- get the global configure directory -function global.directory() - - -- the directory - local dir = path.translate("~/.xmake") - - -- create it directly first if not exists - if not os.isdir(dir) then - assert(os.mkdir(dir)) - end - - -- get it - return dir -end - --- save the global configure -function global.save() - - -- the configs - local configs = global._CONFIGS - assert(configs) - - -- save to the configure file - return io.save(global._file(), configs) -end - --- load the global configure -function global.load() - - -- load configure from the file first - local filepath = global._file() - if os.isfile(filepath) then - - -- load configs - local configs, errors = io.load(filepath) - - -- error? - if not configs and errors then - utils.error(errors) - end - - -- save configs - global._CONFIGS = configs - end - - -- init configs - global._CONFIGS = global._CONFIGS or {} - - -- make the current configs - global._CURRENT = global._make(global._CONFIGS) - - -- ok - return true - - --[[ - -- the options - local options = option.options() - assert(options) - - -- does not clean the cached configure? - if not option.get("clean") then - - TODO - end - ]] - - --[[ - - -- xmake global? - if option.task() == "global" then - - -- merge option.options() to the global configure - for k, v in pairs(options) do - - -- check - assert(type(k) == "string") - - -- need configure it? - if not k:startswith("_") and global._need(k) then - configs[k] = v - end - end - - -- merge the default global configure options to the global configure - local defaults = option.defaults() - if defaults then - for k, v in pairs(defaults) do - - -- check - assert(type(k) == "string") - - -- need configure it? - if global._need(k) then - - -- save the default option - if nil == configs[k] then - configs[k] = v - end - end - end - end - end - ]] - -end - --- TODO move into probe() --- clear up and remove all auto values ---[[ -function global.clearup() - - -- clear up the current configure - local current = global._CURRENT - if current then - for k, v in pairs(current) do - if v and type(v) and v == "auto" then - current[k] = nil - end - end - end - - -- clear up the configure - local configs = global._CONFIGS - if configs then - for k, v in pairs(configs) do - if v and type(v) and v == "auto" then - configs[k] = nil - end - end - end -end -]] - --- dump the current configure -function global.dump() - - -- check - assert(global._CURRENT) - - -- dump - utils.dump(global._CURRENT, "__%w*", "configure") - -end - --- return module: global -return global diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua index d58844862..c7eb18f5a 100644 --- a/xmake/core/base/task.lua +++ b/xmake/core/base/task.lua @@ -29,15 +29,13 @@ local table = require("base/table") local utils = require("base/utils") local filter = require("base/filter") local string = require("base/string") -local global = require("base/global") local sandbox = require("base/sandbox") local interpreter = require("base/interpreter") -- the directories of tasks function task._directories() - return { path.join(global.directory(), "plugins") - , path.join(xmake._PROGRAM_DIR, "plugins") + return { path.join(xmake._PROGRAM_DIR, "plugins") , path.join(xmake._PROGRAM_DIR, "actions") } end @@ -81,7 +79,6 @@ function task._interpreter() local maps = { host = xmake._HOST - , globaldir = global.directory() } -- map it @@ -274,14 +271,6 @@ function task.run(name) return false end - -- load global - if not global.load() then - - -- trace - utils.error("load global configure failed!") - return false - end - -- run on_before, on_run, on_after local ok = true local on_scripts = {taskinfo.before, taskinfo.run, taskinfo.after} |
