summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-11-29 16:25:37 +0800
committerGitHub <[email protected]>2022-11-29 16:25:37 +0800
commit67408d6c9109fa506f2fc64e15ed0d792828155e (patch)
tree9bcadc70d4826aae0d4bc616d40432a01dad8b35
parentb8ec603576e2d856384d12afdaeda941512be657 (diff)
parent50ae995612f0985e27001d61aef0717fd1d5d541 (diff)
Merge pull request #3109 from xmake-io/package
improve package info #3106
-rw-r--r--xmake/core/project/package.lua58
-rw-r--r--xmake/core/project/project.lua12
-rw-r--r--xmake/modules/private/action/require/impl/register_packages.lua6
3 files changed, 54 insertions, 22 deletions
diff --git a/xmake/core/project/package.lua b/xmake/core/project/package.lua
index 7181480c4..fcd89afa3 100644
--- a/xmake/core/project/package.lua
+++ b/xmake/core/project/package.lua
@@ -107,9 +107,33 @@ function _instance:requirestr()
return self:get("__requirestr")
end
+-- get the require configuration from the given name
+--
+-- e.g.
+--
+-- add_requires("xxx", {system = true, configs = {shared = true}})
+--
+-- local configs = pkg:requireconf()
+-- local system = pkg:requireconf("system")
+-- local shared = pkg:requireconf("configs", "shared")
+--
+function _instance:requireconf(name, key)
+ local requireconfs = self:get("__requireconfs")
+ local value = requireconfs
+ if name then
+ value = requireconfs and requireconfs[name] or nil
+ if value and key then
+ value = value[key]
+ end
+ end
+ return value
+end
+
-- get the install directory
+-- @see https://github.com/xmake-io/xmake/issues/3106
function _instance:installdir()
- return self:get("__installdir")
+ return self:get("installdir")
+ or self:get("__installdir") -- deprecated
end
-- get library files
@@ -132,6 +156,25 @@ function _instance:components_deps()
return self:get("__components_deps")
end
+-- get other extra information from package/on_fetch
+--
+-- e.g.
+--
+-- @code
+-- package("xxx")
+-- on_fetch(function (package)
+-- return {includedirs = "", links = "", extra = {foo = ""}}
+-- end)
+--
+-- @endcode
+function _instance:extra(name)
+ local extra = self:get("extra")
+ if extra and name then
+ extra = extra[name]
+ end
+ return extra
+end
+
-- get order dependencies of the given component
function _instance:component_orderdeps(name)
local component_orderdeps = self._COMPONENT_ORDERDEPS
@@ -149,19 +192,6 @@ function _instance:component_orderdeps(name)
return orderdeps
end
--- get the extra info from the given name
-function _instance:extra(name)
- local extrainfo = self:extrainfo()
- if extrainfo then
- return extrainfo[name]
- end
-end
-
--- get the extra info
-function _instance:extrainfo()
- return self:get("__extrainfo")
-end
-
-- set the value to the requires info
function _instance:set(name_or_info, ...)
if type(name_or_info) == "string" then
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index da1966e8c..b7fee40eb 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -487,18 +487,18 @@ function project._load_requires()
-- get the package name
local packagename = requirestr:split("%s")[1]
- -- get alias
+ -- get alias and requireconfs
local alias = nil
- local extrainfo = requires_extra[requirestr]
- if extrainfo then
- alias = extrainfo.alias
+ local requireconfs = requires_extra[requirestr]
+ if requireconfs then
+ alias = requireconfs.alias
end
- -- load it from cache first (@note will discard scripts in extrainfo)
+ -- load it from cache first
local name = alias or packagename
local instance = project_package.load(name)
if not instance then
- local info = {__requirestr = requirestr, __extrainfo = extrainfo}
+ local info = {__requirestr = requirestr, __requireconfs = requireconfs}
instance = project_package.load_withinfo(name, info)
end
diff --git a/xmake/modules/private/action/require/impl/register_packages.lua b/xmake/modules/private/action/require/impl/register_packages.lua
index 26918e0aa..840667d04 100644
--- a/xmake/modules/private/action/require/impl/register_packages.lua
+++ b/xmake/modules/private/action/require/impl/register_packages.lua
@@ -36,7 +36,7 @@ function _register_required_package_libs(instance, required_package, is_deps)
if instance:is_library() then
local fetchinfo = table.clone(instance:fetch())
if fetchinfo then
- fetchinfo.name = nil
+ fetchinfo.name = nil
if is_deps then
-- we need only reserve license for root package
--
@@ -49,6 +49,8 @@ function _register_required_package_libs(instance, required_package, is_deps)
fetchinfo.version = nil
fetchinfo.static = nil
fetchinfo.shared = nil
+ fetchinfo.installdir = nil
+ fetchinfo.extra = nil
end
-- merge into the root values
@@ -82,7 +84,7 @@ end
-- register the base info of required package
function _register_required_package_base(instance, required_package)
if not instance:is_system() and not instance:is_thirdparty() then
- required_package:set("__installdir", instance:installdir())
+ required_package:set("installdir", instance:installdir())
end
end