From 33144e73eae59ee7d934fd77673aac5a5a5cb0d1 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 17 Jul 2017 21:24:15 +0800 Subject: move global to base module --- xmake/actions/clean/main.lua | 2 +- xmake/actions/config/main.lua | 2 +- xmake/actions/global/main.lua | 2 +- xmake/actions/package/main.lua | 2 +- xmake/actions/run/main.lua | 2 +- xmake/core/base/global.lua | 147 ++++++++++++++++++++ xmake/core/language/language.lua | 6 +- xmake/core/platform/platform.lua | 12 +- xmake/core/project/cache.lua | 2 +- xmake/core/project/config.lua | 11 +- xmake/core/project/global.lua | 152 --------------------- xmake/core/project/project.lua | 44 +++--- xmake/core/project/task.lua | 4 +- xmake/core/sandbox/modules/import.lua | 22 ++- .../sandbox/modules/import/core/base/global.lua | 123 +++++++++++++++++ .../sandbox/modules/import/core/project/global.lua | 133 ------------------ .../modules/import/core/project/project.lua | 6 - xmake/platforms/windows/environment.lua | 2 +- 18 files changed, 314 insertions(+), 360 deletions(-) create mode 100644 xmake/core/base/global.lua delete mode 100644 xmake/core/project/global.lua create mode 100644 xmake/core/sandbox/modules/import/core/base/global.lua delete mode 100644 xmake/core/sandbox/modules/import/core/project/global.lua diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index 3d439e008..07a10d72e 100644 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -26,7 +26,7 @@ import("core.base.option") import("core.project.task") import("core.project.config") -import("core.project.global") +import("core.base.global") import("core.project.project") import("core.platform.platform") diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 07588378c..36a5c50c2 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -25,7 +25,7 @@ -- imports import("core.base.option") import("core.project.config") -import("core.project.global") +import("core.base.global") import("core.project.project") import("core.platform.platform") import("core.project.cache", {nocache = true}) diff --git a/xmake/actions/global/main.lua b/xmake/actions/global/main.lua index 14b98fc07..13bf19354 100644 --- a/xmake/actions/global/main.lua +++ b/xmake/actions/global/main.lua @@ -24,7 +24,7 @@ -- imports import("core.base.option") -import("core.project.global") +import("core.base.global") -- main function main() diff --git a/xmake/actions/package/main.lua b/xmake/actions/package/main.lua index e9255635b..80d6ac70c 100644 --- a/xmake/actions/package/main.lua +++ b/xmake/actions/package/main.lua @@ -26,7 +26,7 @@ import("core.base.option") import("core.project.task") import("core.project.config") -import("core.project.global") +import("core.base.global") import("core.project.project") import("core.platform.platform") diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index c87c12b70..571c5d10e 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -26,7 +26,7 @@ import("core.base.option") import("core.project.task") import("core.project.config") -import("core.project.global") +import("core.base.global") import("core.project.project") import("core.platform.platform") import("devel.debugger") diff --git a/xmake/core/base/global.lua b/xmake/core/base/global.lua new file mode 100644 index 000000000..daa6a6e54 --- /dev/null +++ b/xmake/core/base/global.lua @@ -0,0 +1,147 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file global.lua +-- + +-- define module +local global = global 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") + +-- get the configure file +function global._file() + return path.join(global.directory(), "xmake.conf") +end + +-- get the current given configure from +function global.get(name) + + -- get configs + local configs = global._CONFIGS or {} + + -- the value + local value = configs[name] + if type(value) == "string" and value == "auto" then + value = nil + end + + -- get it + return value +end + +-- set the current given configure +function global.set(name, value) + + -- get configs + local configs = global._CONFIGS or {} + global._CONFIGS = configs + + -- set it + configs[name] = value +end + +-- get all options +function global.options() + + -- remove values with "auto" and private item + local configs = {} + for name, value in pairs(table.wrap(global._CONFIGS)) do + if not name:find("^_%u+") and name ~= "__version" and (type(value) ~= "string" or value ~= "auto") then + configs[name] = value + end + end + + -- get it + return configs +end + +-- get the global configure directory +function global.directory() + return path.translate("~/.xmake") +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 results, errors = io.load(filepath) + + -- error? + if not results then + utils.error(errors) + return true + end + + -- merge the configure + for name, value in pairs(results) do + if global.get(name) == nil then + global.set(name, value) + end + end + end + + -- ok + return true +end + +-- save the global configure +function global.save() + + -- the options + local options = global.options() + assert(options) + + -- add version + options.__version = xmake._VERSION_SHORT + + -- save it + return io.save(global._file(), options) +end + +-- init the config +function global.init() + + -- clear it + global._CONFIGS = {} + +end + +-- dump the configure +function global.dump() + + -- dump + if not option.get("quiet") then + table.dump(global.options(), "__%w*", "configure") + end +end + +-- return module +return global diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index a1f2015f8..8bf9395ae 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -34,7 +34,7 @@ local table = require("base/table") local interpreter = require("base/interpreter") local sandbox = require("sandbox/sandbox") local config = require("project/config") -local global = require("project/global") +local global = require("base/global") -- new an instance function _instance.new(name, info, rootdir) @@ -213,9 +213,7 @@ end -- the directory of language function language._directory() - - -- the directory - return path.join(xmake._PROGRAM_DIR, "languages") + return path.join(os.programdir(), "languages") end -- the interpreter diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 26852b60e..9e66824d0 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -34,7 +34,7 @@ local table = require("base/table") local interpreter = require("base/interpreter") local sandbox = require("sandbox/sandbox") local config = require("project/config") -local global = require("project/global") +local global = require("base/global") -- new an instance function _instance.new(name, info, rootdir) @@ -82,29 +82,21 @@ end -- get the platform os function _instance:os() - - -- get it return self._INFO.os end -- get the platform menu function _instance:menu() - - -- get it return self._INFO.menu end -- get the platform hosts function _instance:hosts() - - -- get it return self._INFO.hosts end -- get the platform archs function _instance:archs() - - -- get it return self._INFO.archs end @@ -114,7 +106,7 @@ function platform._directories() -- the directories return { path.join(config.directory(), "platforms") , path.join(global.directory(), "platforms") - , path.join(xmake._PROGRAM_DIR, "platforms") + , path.join(os.programdir(), "platforms") } end diff --git a/xmake/core/project/cache.lua b/xmake/core/project/cache.lua index d96f12e00..7dfbd9956 100644 --- a/xmake/core/project/cache.lua +++ b/xmake/core/project/cache.lua @@ -32,7 +32,7 @@ local path = require("base/path") local table = require("base/table") local utils = require("base/utils") local config = require("project/config") -local global = require("project/global") +local global = require("base/global") -- the cache instance -- diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index 8fb1c160d..6d5925c42 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -32,12 +32,9 @@ local path = require("base/path") local table = require("base/table") local utils = require("base/utils") local option = require("base/option") -local global = require("project/global") -- get the configure file function config._file() - - -- get it return path.join(config.directory(), "xmake.conf") end @@ -95,7 +92,6 @@ function config.set(name, value) -- set it configs[name] = value - end -- get all options @@ -138,9 +134,7 @@ end -- get the configure directory function config.directory() - - -- get it - return path.join(xmake._PROJECT_DIR, ".xmake") + return path.join(os.projectdir(), ".xmake") end -- load the project configure @@ -218,10 +212,7 @@ end -- init the config function config.init() - - -- clear it config._CONFIGS = {} - end -- dump the configure diff --git a/xmake/core/project/global.lua b/xmake/core/project/global.lua deleted file mode 100644 index 788afd1f3..000000000 --- a/xmake/core/project/global.lua +++ /dev/null @@ -1,152 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- define module -local global = global 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") - --- get the configure file -function global._file() - - -- get it - return path.join(global.directory(), "xmake.conf") -end - --- get the current given configure from -function global.get(name) - - -- get configs - local configs = global._CONFIGS or {} - - -- the value - local value = configs[name] - if type(value) == "string" and value == "auto" then - value = nil - end - - -- get it - return value -end - --- set the current given configure -function global.set(name, value) - - -- get configs - local configs = global._CONFIGS or {} - global._CONFIGS = configs - - -- set it - configs[name] = value - -end - --- get all options -function global.options() - - -- remove values with "auto" and private item - local configs = {} - for name, value in pairs(table.wrap(global._CONFIGS)) do - if not name:find("^_%u+") and name ~= "__version" and (type(value) ~= "string" or value ~= "auto") then - configs[name] = value - end - end - - -- get it - return configs -end - --- get the global configure directory -function global.directory() - - -- get it - return path.translate("~/.xmake") -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 results, errors = io.load(filepath) - - -- error? - if not results then - utils.error(errors) - return true - end - - -- merge the configure - for name, value in pairs(results) do - if global.get(name) == nil then - global.set(name, value) - end - end - end - - -- ok - return true -end - --- save the global configure -function global.save() - - -- the options - local options = global.options() - assert(options) - - -- add version - options.__version = xmake._VERSION_SHORT - - -- save it - return io.save(global._file(), options) -end - --- init the config -function global.init() - - -- clear it - global._CONFIGS = {} - -end - --- dump the configure -function global.dump() - - -- dump - if not option.get("quiet") then - table.dump(global.options(), "__%w*", "configure") - end -end - --- return module -return global diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index aca63f67e..692d504b3 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -36,7 +36,7 @@ local deprecated = require("base/deprecated") local interpreter = require("base/interpreter") local target = require("project/target") local config = require("project/config") -local global = require("project/global") +local global = require("base/global") local option = require("project/option") local package = require("project/package") local deprecated_project = require("project/deprecated/project") @@ -146,32 +146,32 @@ function project._api_is_option(interp, ...) end end --- load all packages from the given directories -function project._api_add_pkgdirs(interp, ...) +-- load all plugins from the given directories +function project._api_add_plugindirs(interp, ...) -- get all directories - local pkgdirs = {} + local plugindirs = {} local dirs = table.join(...) for _, dir in ipairs(dirs) do - table.insert(pkgdirs, dir .. "/*.pkg") + table.insert(plugindirs, dir .. "/*") end - -- add all packages - interp:api_builtin_add_subdirs(pkgdirs) + -- add all plugins + interp:api_builtin_add_subdirs(plugindirs) end --- load all plugins from the given directories -function project._api_add_plugindirs(interp, ...) +-- load all packages from the given directories +function project._api_add_packagedirs(interp, ...) -- get all directories - local plugindirs = {} + local pkgdirs = {} local dirs = table.join(...) for _, dir in ipairs(dirs) do - table.insert(plugindirs, dir .. "/*") + table.insert(pkgdirs, dir .. "/*.pkg") end - -- add all plugins - interp:api_builtin_add_subdirs(plugindirs) + -- add all packages + interp:api_builtin_add_subdirs(pkgdirs) end -- get interpreter @@ -279,16 +279,16 @@ function project._interpreter() , custom = { -- is_xxx - {"is_os", project._api_is_os } - , {"is_kind", project._api_is_kind } - , {"is_host", project._api_is_host } - , {"is_mode", project._api_is_mode } - , {"is_plat", project._api_is_plat } - , {"is_arch", project._api_is_arch } - , {"is_option", project._api_is_option } + {"is_os", project._api_is_os } + , {"is_kind", project._api_is_kind } + , {"is_host", project._api_is_host } + , {"is_mode", project._api_is_mode } + , {"is_plat", project._api_is_plat } + , {"is_arch", project._api_is_arch } + , {"is_option", project._api_is_option } -- add_xxx - , {"add_packagedirs", project._api_add_pkgdirs } - , {"add_plugindirs", project._api_add_plugindirs } + , {"add_plugindirs", project._api_add_plugindirs } + , {"add_packagedirs", project._api_add_packagedirs } } } diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua index f1aad65a0..1f7770881 100644 --- a/xmake/core/project/task.lua +++ b/xmake/core/project/task.lua @@ -32,7 +32,7 @@ local utils = require("base/utils") local string = require("base/string") local interpreter = require("base/interpreter") local sandbox = require("sandbox/sandbox") -local global = require("project/global") +local global = require("base/global") local config = require("project/config") local project = require("project/project") local package = require("project/package") @@ -201,7 +201,7 @@ function task._interpreter() , scriptdir = function () return sandbox_os.scriptdir() end , globaldir = global.directory() , configdir = config.directory() - , projectdir = xmake._PROJECT_DIR + , projectdir = os.projectdir() , packagedir = package.directory() , programdir = os.programdir() } diff --git a/xmake/core/sandbox/modules/import.lua b/xmake/core/sandbox/modules/import.lua index 5317efa6e..7f19159df 100644 --- a/xmake/core/sandbox/modules/import.lua +++ b/xmake/core/sandbox/modules/import.lua @@ -31,7 +31,7 @@ local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local string = require("base/string") -local global = require("project/global") +local global = require("base/global") local sandbox = require("sandbox/sandbox") local raise = require("sandbox/modules/raise") @@ -299,23 +299,17 @@ function sandbox_import.import(name, args) local rootdir = args.rootdir or instance:rootdir() assert(rootdir) - -- the sandbox modules directory - local modules_sandbox_dir = path.join(os.programdir(), "core/sandbox/modules/import") + -- the global modules directory of users + local modules_global_dir = path.join(global.directory(), "modules") - -- the extension modules directory - local modules_extension_dir = path.join(os.programdir(), "modules") + -- the program modules directory + local modules_program_dir = path.join(os.programdir(), "modules") - -- the global modules directory for users - local modules_global_dir = path.join(global.directory(), "modules") + -- the sandbox modules directory + local modules_sandbox_dir = path.join(os.programdir(), "core/sandbox/modules/import") -- init module directories - local modules_directories = - { - rootdir -- load module from the given root directory first - , path.join(global.directory(), "modules") -- load module from the user global modules directory - , path.join(os.programdir(), "modules") -- load module from the extension modules directory - , path.join(os.programdir(), "core/sandbox/modules/import") -- load module from the sandbox core modules directory - } + local modules_directories = table.join(rootdir, modules_global_dir, modules_program_dir, modules_sandbox_dir) -- load module local errors = nil diff --git a/xmake/core/sandbox/modules/import/core/base/global.lua b/xmake/core/sandbox/modules/import/core/base/global.lua new file mode 100644 index 000000000..925fcbf78 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/base/global.lua @@ -0,0 +1,123 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file global.lua +-- + +-- define module +local sandbox_core_base_global = sandbox_core_base_global or {} + +-- load modules +local table = require("base/table") +local global = require("base/global") +local platform = require("platform/platform") +local raise = require("sandbox/modules/raise") + +-- get the configure +function sandbox_core_base_global.get(name) + return global.get(name) +end + +-- set the configure +function sandbox_core_base_global.set(name, value) + global.set(name, value) +end + +-- dump the configure +function sandbox_core_base_global.dump() + global.dump() +end + +-- load the configure +function sandbox_core_base_global.load() + + -- load it + local ok, errors = global.load() + if not ok then + raise(errors) + end +end + +-- save the configure +function sandbox_core_base_global.save() + + -- save it + local ok, errors = global.save() + if not ok then + raise(errors) + end +end + +-- init the configure +function sandbox_core_base_global.init() + global.init() +end + +-- check the configure +function sandbox_core_base_global.check() + + -- check all platforms with the current host + for _, plat in ipairs(table.wrap(platform.plats())) do + + -- load platform + local instance, errors = platform.load(plat) + if not instance then + raise(errors) + end + + -- belong to the current host? + for _, host in ipairs(table.wrap(instance:hosts())) do + if host == xmake._HOST then + + -- get the check script + local check = instance:get("check") + if check ~= nil then + + -- check it + check("global") + end + + -- ok + break + end + end + end +end + +-- get all options +function sandbox_core_base_global.options() + return global.options() +end + +-- get the configure directory +function sandbox_core_base_global.directory() + + -- get it + local dir = global.directory() + assert(dir) + + -- ok? + return dir +end + + +-- return module +return sandbox_core_base_global diff --git a/xmake/core/sandbox/modules/import/core/project/global.lua b/xmake/core/sandbox/modules/import/core/project/global.lua deleted file mode 100644 index 6cd890d63..000000000 --- a/xmake/core/sandbox/modules/import/core/project/global.lua +++ /dev/null @@ -1,133 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- define module -local sandbox_core_project_global = sandbox_core_project_global or {} - --- load modules -local table = require("base/table") -local global = require("project/global") -local platform = require("platform/platform") -local raise = require("sandbox/modules/raise") - --- get the configure -function sandbox_core_project_global.get(name) - - -- get it - return global.get(name) -end - --- set the configure -function sandbox_core_project_global.set(name, value) - - -- set it - global.set(name, value) -end - --- dump the configure -function sandbox_core_project_global.dump() - - -- dump it - global.dump() -end - --- load the configure -function sandbox_core_project_global.load() - - -- load it - local ok, errors = global.load() - if not ok then - raise(errors) - end -end - --- save the configure -function sandbox_core_project_global.save() - - -- save it - local ok, errors = global.save() - if not ok then - raise(errors) - end -end - --- init the configure -function sandbox_core_project_global.init() - - -- init it - global.init() -end - --- check the configure -function sandbox_core_project_global.check() - - -- check all platforms with the current host - for _, plat in ipairs(table.wrap(platform.plats())) do - - -- load platform - local instance, errors = platform.load(plat) - if not instance then - raise(errors) - end - - -- belong to the current host? - for _, host in ipairs(table.wrap(instance:hosts())) do - if host == xmake._HOST then - - -- get the check script - local check = instance:get("check") - if check ~= nil then - - -- check it - check("global") - end - - -- ok - break - end - end - end -end - --- get all options -function sandbox_core_project_global.options() - - -- get it - return global.options() -end - --- get the configure directory -function sandbox_core_project_global.directory() - - -- get it - local dir = global.directory() - assert(dir) - - -- ok? - return dir -end - - --- return module -return sandbox_core_project_global diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 164d79fe0..c78185a5a 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -101,22 +101,16 @@ end -- get the project file function sandbox_core_project.file() - - -- get it return project.file() end -- get the project directory function sandbox_core_project.directory() - - -- get it return project.directory() end -- get the project mtimes function sandbox_core_project.mtimes() - - -- get it return project.mtimes() end diff --git a/xmake/platforms/windows/environment.lua b/xmake/platforms/windows/environment.lua index 11c9a6534..961be68b8 100644 --- a/xmake/platforms/windows/environment.lua +++ b/xmake/platforms/windows/environment.lua @@ -24,7 +24,7 @@ -- imports import("core.project.config") -import("core.project.global") +import("core.base.global") -- enter the given environment function _enter(name) -- cgit v1.3.1