summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-01-08 23:28:02 +0800
committerruki <[email protected]>2025-01-08 23:28:02 +0800
commit7dec01ba2840236fc975d9213842108ed13e858d (patch)
tree81a647bbf3fece33bcdc87cec3a0f0df2faf26e8
parent4ad00835a9070c32b6ce17248e5702ef0eae5a37 (diff)
get packages with namespace
-rw-r--r--xmake/core/project/package.lua13
-rw-r--r--xmake/core/project/project.lua2
-rw-r--r--xmake/core/project/target.lua11
-rw-r--r--xmake/modules/private/action/require/impl/register_packages.lua5
4 files changed, 29 insertions, 2 deletions
diff --git a/xmake/core/project/package.lua b/xmake/core/project/package.lua
index 70f89a1f8..67000bdc6 100644
--- a/xmake/core/project/package.lua
+++ b/xmake/core/project/package.lua
@@ -69,6 +69,12 @@ function _instance:name()
return self._NAME
end
+-- get the full name
+function _instance:fullname()
+ local namespace = self:namespace()
+ return namespace and namespace .. "::" .. self:name() or self:name()
+end
+
-- get the package version
function _instance:version()
@@ -107,6 +113,11 @@ function _instance:requirestr()
return self:get("__requirestr")
end
+-- get the namespace
+function _instance:namespace()
+ return self:get("__namespace")
+end
+
-- get the require configuration from the given name
--
-- e.g.
@@ -369,7 +380,7 @@ end
-- we need to sort package set keys by this string
-- @see https://github.com/xmake-io/xmake/pull/2971#issuecomment-1290052169
function _instance:__tostring()
- return "<package: " .. self:name() .. ">"
+ return "<package: " .. self:fullname() .. ">"
end
-- get cache
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 7a24a298a..a41ecc0cf 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -524,7 +524,7 @@ function project._load_requires()
end
-- add require info
- requires[alias or packagename] = instance
+ requires[name] = instance
end
return requires
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 3f1875854..a8796076c 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1339,6 +1339,17 @@ function _instance:orderpkgs(opt)
if requires then
for _, packagename in ipairs(table.wrap(self:get("packages", opt))) do
local pkg = requires[packagename]
+ -- attempt to get package with namespace
+ if pkg == nil and packagename:find("::", 1, true) then
+ local parts = packagename:split("::", {plain = true})
+ local namespace_pkg = requires[parts[#parts]]
+ if namespace_pkg and namespace_pkg:namespace() then
+ local fullname = namespace_pkg:fullname()
+ if fullname:endswith(packagename) then
+ pkg = namespace_pkg
+ end
+ end
+ end
if pkg and pkg:enabled() then
table.insert(packages, pkg)
end
diff --git a/xmake/modules/private/action/require/impl/register_packages.lua b/xmake/modules/private/action/require/impl/register_packages.lua
index ed6079f29..5f428edf3 100644
--- a/xmake/modules/private/action/require/impl/register_packages.lua
+++ b/xmake/modules/private/action/require/impl/register_packages.lua
@@ -66,6 +66,11 @@ function _register_required_package_libs(instance, required_package, is_deps)
required_package:set("__components_orderlist", instance:components_orderlist())
end
+ -- save namespace
+ if instance:namespace() then
+ required_package:set("__namespace", instance:namespace())
+ end
+
-- merge into the components values
local required_components = required_package:get("components")
if required_components then