From b29d4891a97dda8bc7a8b805651a77c0bb7698c0 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 12 Feb 2021 22:47:46 +0800 Subject: rename project.requireinfo to package --- xmake/actions/require/install.lua | 34 ++-- xmake/core/project/package.lua | 190 +++++++++++++++++++++ xmake/core/project/project.lua | 18 +- xmake/core/project/requireinfo.lua | 190 --------------------- xmake/core/project/target.lua | 42 ++--- xmake/core/sandbox/modules/has_package.lua | 2 +- .../modules/import/core/project/project.lua | 52 +++--- xmake/core/tool/toolchain.lua | 2 +- 8 files changed, 265 insertions(+), 265 deletions(-) create mode 100644 xmake/core/project/package.lua delete mode 100644 xmake/core/project/requireinfo.lua diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua index c2deeac90..674adf203 100644 --- a/xmake/actions/require/install.lua +++ b/xmake/actions/require/install.lua @@ -50,7 +50,7 @@ end -- register required package libraries -- libs: includedirs, links, linkdirs ... -function _register_required_package_libs(instance, requireinfo, is_deps) +function _register_required_package_libs(instance, required_package, is_deps) if instance:is_library() then local fetchinfo = instance:fetch() if fetchinfo then @@ -68,32 +68,32 @@ function _register_required_package_libs(instance, requireinfo, is_deps) fetchinfo.static = nil fetchinfo.shared = nil end - requireinfo:add(fetchinfo) + required_package:add(fetchinfo) end end end -- register the base info of required package -function _register_required_package_base(instance, requireinfo) +function _register_required_package_base(instance, required_package) if not instance:isSys() and not instance:is3rd() then - requireinfo:set("__installdir", instance:installdir()) + required_package:set("__installdir", instance:installdir()) end end -- register the required local package -function _register_required_package(instance, requireinfo) +function _register_required_package(instance, required_package) -- disable it if this package is optional and missing if _g.optional_missing[instance:name()] then - requireinfo:enable(false) + required_package:enable(false) else -- clear require info first - requireinfo:clear() + required_package:clear() -- add packages info with all dependencies local envs = {} - _register_required_package_base(instance, requireinfo) - _register_required_package_libs(instance, requireinfo) + _register_required_package_base(instance, required_package) + _register_required_package_libs(instance, required_package) _register_required_package_envs(instance, envs) local orderdeps = instance:orderdeps() if orderdeps then @@ -101,21 +101,21 @@ function _register_required_package(instance, requireinfo) for idx, _ in ipairs(orderdeps) do local dep = orderdeps[total + 1 - idx] if dep then - _register_required_package_libs(dep, requireinfo, true) + _register_required_package_libs(dep, required_package, true) _register_required_package_envs(dep, envs) end end end if #table.keys(envs) > 0 then - requireinfo:add({envs = envs}) + required_package:add({envs = envs}) end -- enable this require info - requireinfo:enable(true) + required_package:enable(true) end -- save this require info and flush the whole cache file - requireinfo:save() + required_package:save() end -- register all required local packages @@ -127,10 +127,10 @@ function _register_required_packages(packages) local group = instance:group() if not instance:parents() and (not group or not registered_in_group[group]) then - -- do not register binary package - local requireinfo = project.require(instance:alias() or instance:name()) - if requireinfo then - _register_required_package(instance, requireinfo) + -- register required package + local required_package = project.required_package(instance:alias() or instance:name()) + if required_package then + _register_required_package(instance, required_package) end -- mark as registered in group diff --git a/xmake/core/project/package.lua b/xmake/core/project/package.lua new file mode 100644 index 000000000..f2790581d --- /dev/null +++ b/xmake/core/project/package.lua @@ -0,0 +1,190 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file package.lua +-- + +-- define module +local package = package or {} + +-- load modules +local io = require("base/io") +local os = require("base/os") +local path = require("base/path") +local table = require("base/table") +local utils = require("base/utils") +local config = require("project/config") +local semver = require("base/semver") +local sandbox = require("sandbox/sandbox") +local localcache = require("cache/localcache") + +-- get cache +function package._cache() + return localcache.cache("package") +end + +-- save the requires info to the cache +function package:save() + package._cache():set(self:name(), self._INFO) + package._cache():save() +end + +-- clear the package +function package:clear() + local info = self._INFO + if info then + for k, v in pairs(info) do + if not k:startswith("__") then + info[k] = nil + end + end + end +end + +-- dump this package +function package:dump() + utils.dump(self._INFO) +end + +-- get the require info +function package:get(infoname) + return self._INFO[infoname] +end + +-- get the require name +function package:name() + return self._NAME +end + +-- get the package version +function package:version() + + -- get it from cache first + if self._VERSION ~= nil then + return self._VERSION + end + + -- get version + local version = nil + local verstr = self:get("version") + if verstr then + version = semver.new(verstr) + end + self._VERSION = version or false + return version +end + +-- get the package license +function package:license() + return self:get("license") +end + +-- has static libraries? +function package:has_static() + return self:get("static") +end + +-- has shared libraries? +function package:has_shared() + return self:get("shared") +end + +-- get the require string +function package:requirestr() + return self:get("__requirestr") +end + +-- get the install directory +function package:installdir() + return self:get("__installdir") +end + +-- get the extra info from the given name +function package:extra(name) + local extrainfo = self:extrainfo() + if extrainfo then + return extrainfo[name] + end +end + +-- get the extra info +function package:extrainfo() + return self:get("__extrainfo") +end + +-- set the value to the requires info +function package:set(name_or_info, ...) + if type(name_or_info) == "string" then + local args = ... + if args ~= nil then + self._INFO[name_or_info] = table.unwrap(table.unique(table.join(...))) + else + self._INFO[name_or_info] = nil + end + elseif table.is_dictionary(name_or_info) then + for name, info in pairs(table.join(name_or_info, ...)) do + self:set(name, info) + end + end +end + +-- add the value to the requires info +function package:add(name_or_info, ...) + if type(name_or_info) == "string" then + local info = table.wrap(self._INFO[name_or_info]) + self._INFO[name_or_info] = table.unwrap(table.unique(table.join(info, ...))) + elseif table.is_dictionary(name_or_info) then + for name, info in pairs(table.join(name_or_info, ...)) do + self:add(name, info) + end + end +end + +-- this require info is enabled? +function package:enabled() + return self:get("__enabled") +end + +-- enable or disable this require info +-- +-- @param enabled enable it? +-- +function package:enable(enabled) + self:set("__enabled", enabled) +end + +-- load the requires info from the cache +function package.load(name) + + -- check + assert(name) + + -- get info + local info = package._cache():get(name) + if info == nil then + return + end + + -- init package instance + local instance = table.inherit(package) + instance._INFO = info + instance._NAME = name + return instance +end + +-- return module +return package diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index f9ee0d0db..ebdf5d2e0 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -38,7 +38,7 @@ local target = require("project/target") local config = require("project/config") local option = require("project/option") local policy = require("project/policy") -local requireinfo = require("project/requireinfo") +local project_package = require("project/package") local deprecated_project = require("project/deprecated/project") local package = require("package/package") local platform = require("platform/platform") @@ -406,7 +406,7 @@ function project._load_targets() project._memcache():set("targets_loaded", true) -- load all requires first and reload the project file to ensure has_package() works for targets - local requires = project.requires() + local requires = project.required_packages() local ok, errors = project._load(true) if not ok then return nil, errors @@ -616,9 +616,9 @@ function project._load_requires() end -- load it from cache first (@note will discard scripts in extrainfo) - local instance = requireinfo.load(alias or packagename) + local instance = project_package.load(alias or packagename) if not instance then - instance = table.inherit(requireinfo) + instance = table.inherit(project_package) instance._NAME = alias or packagename instance._INFO = { __requirestr = requirestr, __extrainfo = extrainfo } end @@ -979,13 +979,13 @@ function project.options() return options end --- get the given require info -function project.require(name) - return project.requires()[name] +-- get the given required package +function project.required_package(name) + return project.required_packages()[name] end --- get requires info -function project.requires() +-- get required packages +function project.required_packages() local requires = project._memcache():get("requires") if not requires then local errors diff --git a/xmake/core/project/requireinfo.lua b/xmake/core/project/requireinfo.lua deleted file mode 100644 index 218f346ff..000000000 --- a/xmake/core/project/requireinfo.lua +++ /dev/null @@ -1,190 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed 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-present, TBOOX Open Source Group. --- --- @author ruki --- @file requireinfo.lua --- - --- define module -local requireinfo = requireinfo or {} - --- load modules -local io = require("base/io") -local os = require("base/os") -local path = require("base/path") -local table = require("base/table") -local utils = require("base/utils") -local config = require("project/config") -local semver = require("base/semver") -local sandbox = require("sandbox/sandbox") -local localcache = require("cache/localcache") - --- get cache -function requireinfo._cache() - return localcache.cache("package") -end - --- save the requires info to the cache -function requireinfo:save() - requireinfo._cache():set(self:name(), self._INFO) - requireinfo._cache():save() -end - --- clear the requireinfo -function requireinfo:clear() - local info = self._INFO - if info then - for k, v in pairs(info) do - if not k:startswith("__") then - info[k] = nil - end - end - end -end - --- dump this requireinfo -function requireinfo:dump() - utils.dump(self._INFO) -end - --- get the require info -function requireinfo:get(infoname) - return self._INFO[infoname] -end - --- get the require name -function requireinfo:name() - return self._NAME -end - --- get the package version -function requireinfo:version() - - -- get it from cache first - if self._VERSION ~= nil then - return self._VERSION - end - - -- get version - local version = nil - local verstr = self:get("version") - if verstr then - version = semver.new(verstr) - end - self._VERSION = version or false - return version -end - --- get the package license -function requireinfo:license() - return self:get("license") -end - --- has static libraries? -function requireinfo:has_static() - return self:get("static") -end - --- has shared libraries? -function requireinfo:has_shared() - return self:get("shared") -end - --- get the require string -function requireinfo:requirestr() - return self:get("__requirestr") -end - --- get the install directory -function requireinfo:installdir() - return self:get("__installdir") -end - --- get the extra info from the given name -function requireinfo:extra(name) - local extrainfo = self:extrainfo() - if extrainfo then - return extrainfo[name] - end -end - --- get the extra info -function requireinfo:extrainfo() - return self:get("__extrainfo") -end - --- set the value to the requires info -function requireinfo:set(name_or_info, ...) - if type(name_or_info) == "string" then - local args = ... - if args ~= nil then - self._INFO[name_or_info] = table.unwrap(table.unique(table.join(...))) - else - self._INFO[name_or_info] = nil - end - elseif table.is_dictionary(name_or_info) then - for name, info in pairs(table.join(name_or_info, ...)) do - self:set(name, info) - end - end -end - --- add the value to the requires info -function requireinfo:add(name_or_info, ...) - if type(name_or_info) == "string" then - local info = table.wrap(self._INFO[name_or_info]) - self._INFO[name_or_info] = table.unwrap(table.unique(table.join(info, ...))) - elseif table.is_dictionary(name_or_info) then - for name, info in pairs(table.join(name_or_info, ...)) do - self:add(name, info) - end - end -end - --- this require info is enabled? -function requireinfo:enabled() - return self:get("__enabled") -end - --- enable or disable this require info --- --- @param enabled enable it? --- -function requireinfo:enable(enabled) - self:set("__enabled", enabled) -end - --- load the requires info from the cache -function requireinfo.load(name) - - -- check - assert(name) - - -- get info - local info = requireinfo._cache():get(name) - if info == nil then - return - end - - -- init requireinfo instance - local instance = table.inherit(requireinfo) - instance._INFO = info - instance._NAME = name - return instance -end - --- return module -return requireinfo diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index b51e3dff5..ee3577087 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -23,26 +23,26 @@ local target = target or {} local _instance = _instance or {} -- load modules -local bit = require("bit") -local os = require("base/os") -local path = require("base/path") -local utils = require("base/utils") -local table = require("base/table") -local baseoption = require("base/option") -local deprecated = require("base/deprecated") -local rule = require("project/rule") -local option = require("project/option") -local config = require("project/config") -local policy = require("project/policy") -local requireinfo = require("project/requireinfo") -local tool = require("tool/tool") -local linker = require("tool/linker") -local compiler = require("tool/compiler") -local platform = require("platform/platform") -local environment = require("platform/environment") -local language = require("language/language") -local sandbox = require("sandbox/sandbox") -local sandbox_module = require("sandbox/modules/import/core/sandbox/module") +local bit = require("bit") +local os = require("base/os") +local path = require("base/path") +local utils = require("base/utils") +local table = require("base/table") +local baseoption = require("base/option") +local deprecated = require("base/deprecated") +local rule = require("project/rule") +local option = require("project/option") +local config = require("project/config") +local policy = require("project/policy") +local project_package = require("project/package") +local tool = require("tool/tool") +local linker = require("tool/linker") +local compiler = require("tool/compiler") +local platform = require("platform/platform") +local environment = require("platform/environment") +local language = require("language/language") +local sandbox = require("sandbox/sandbox") +local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new a target instance function _instance.new(name, info, project) @@ -668,7 +668,7 @@ function _instance:orderopts() -- load options from packages if no require info, be compatible with the option package in (*.pkg) for _, name in ipairs(table.wrap(self:get("packages"))) do - if not requireinfo.load(name) then + if not project_package.load(name) then local opt = nil if config.get(name) then opt = option.load(name) end if opt then diff --git a/xmake/core/sandbox/modules/has_package.lua b/xmake/core/sandbox/modules/has_package.lua index de9359b6f..8d6c8ec3f 100644 --- a/xmake/core/sandbox/modules/has_package.lua +++ b/xmake/core/sandbox/modules/has_package.lua @@ -21,7 +21,7 @@ -- return module return function (...) require("sandbox/modules/import/core/sandbox/module").import("core.project.project") - local requires = project.requires() + local requires = project.required_packages() if requires then for _, name in ipairs(table.join(...)) do local pkg = requires[name] diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 24e146ee9..3d36e7463 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -36,32 +36,32 @@ local package = require("package/package") local import = require("sandbox/modules/import") -- export some readonly interfaces -sandbox_core_project.get = project.get -sandbox_core_project.rule = project.rule -sandbox_core_project.rules = project.rules -sandbox_core_project.toolchain = project.toolchain -sandbox_core_project.toolchains = project.toolchains -sandbox_core_project.target = project.target -sandbox_core_project.targets = project.targets -sandbox_core_project.ordertargets = project.ordertargets -sandbox_core_project.option = project.option -sandbox_core_project.options = project.options -sandbox_core_project.rootfile = project.rootfile -sandbox_core_project.allfiles = project.allfiles -sandbox_core_project.rcfiles = project.rcfiles -sandbox_core_project.directory = project.directory -sandbox_core_project.name = project.name -sandbox_core_project.modes = project.modes -sandbox_core_project.mtimes = project.mtimes -sandbox_core_project.version = project.version -sandbox_core_project.require = project.require -sandbox_core_project.requires = project.requires -sandbox_core_project.requires_str = project.requires_str -sandbox_core_project.requireconfs_str = project.requireconfs_str -sandbox_core_project.policy = project.policy -sandbox_core_project.tmpdir = project.tmpdir -sandbox_core_project.tmpfile = project.tmpfile -sandbox_core_project.is_loaded = project.is_loaded +sandbox_core_project.get = project.get +sandbox_core_project.rule = project.rule +sandbox_core_project.rules = project.rules +sandbox_core_project.toolchain = project.toolchain +sandbox_core_project.toolchains = project.toolchains +sandbox_core_project.target = project.target +sandbox_core_project.targets = project.targets +sandbox_core_project.ordertargets = project.ordertargets +sandbox_core_project.option = project.option +sandbox_core_project.options = project.options +sandbox_core_project.rootfile = project.rootfile +sandbox_core_project.allfiles = project.allfiles +sandbox_core_project.rcfiles = project.rcfiles +sandbox_core_project.directory = project.directory +sandbox_core_project.name = project.name +sandbox_core_project.modes = project.modes +sandbox_core_project.mtimes = project.mtimes +sandbox_core_project.version = project.version +sandbox_core_project.required_package = project.required_package +sandbox_core_project.required_packages = project.required_packages +sandbox_core_project.requires_str = project.requires_str +sandbox_core_project.requireconfs_str = project.requireconfs_str +sandbox_core_project.policy = project.policy +sandbox_core_project.tmpdir = project.tmpdir +sandbox_core_project.tmpfile = project.tmpfile +sandbox_core_project.is_loaded = project.is_loaded -- check project options function sandbox_core_project.check() diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index ee3412f07..eb880932e 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -276,7 +276,7 @@ function _instance:packages() local project = require("project/project") -- we will get packages from `set_toolchains("foo", {packages})` or `set_toolchains("foo@packages")` for _, pkgname in ipairs(table.wrap(self:config("packages"))) do - local requires = project.requires() + local requires = project.required_packages() if requires then local pkginfo = requires[pkgname] if pkginfo then -- cgit v1.3.1