From e5ea7bc6347ce4c4a62468138753cedea663bfa9 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 7 Jan 2025 22:45:32 +0800 Subject: add package for namespace --- xmake/modules/private/action/require/impl/package.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'xmake/modules/private/action/require/impl/package.lua') diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 30c571592..a06ee7a29 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -1064,6 +1064,9 @@ function _load_package(packagename, requireinfo, opt) end _memcache():set2("packageids", packagename, (packageid or 0) + 1) end + if displayname and package:namespace() then + displayname = package:namespace() .. "::" .. displayname + end package:displayname_set(displayname) -- disable parallelize if the package cache directory conflicts -- cgit v1.3.1 From bd6ded54efbea8fe01040941ce8d39951a8431c9 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 7 Jan 2025 23:19:03 +0800 Subject: fix package with 3rd namespace --- tests/apis/namespace/package/test.lua | 2 +- tests/apis/namespace/package/xmake.lua | 21 ++++++++++++--------- xmake/core/base/interpreter.lua | 2 +- xmake/core/package/package.lua | 22 +++++++++++++++++----- .../private/action/require/impl/package.lua | 3 --- 5 files changed, 31 insertions(+), 19 deletions(-) (limited to 'xmake/modules/private/action/require/impl/package.lua') diff --git a/tests/apis/namespace/package/test.lua b/tests/apis/namespace/package/test.lua index 83c0a9546..bff75b066 100644 --- a/tests/apis/namespace/package/test.lua +++ b/tests/apis/namespace/package/test.lua @@ -1,3 +1,3 @@ function main() - os.exec("xmake -vD") + os.exec("xmake -vD -y") end diff --git a/tests/apis/namespace/package/xmake.lua b/tests/apis/namespace/package/xmake.lua index b2bc61d73..9f01f4bdb 100644 --- a/tests/apis/namespace/package/xmake.lua +++ b/tests/apis/namespace/package/xmake.lua @@ -1,19 +1,21 @@ -add_requires("package0") +add_requires("package0", {system = false}) package("package0") - on_fetch(function (package) - return {defines = "PACKAGE0"} + on_load(function (package) + package:add("defines", "PACKAGE0") end) + on_install(function (package) end) namespace("ns1", function () - add_requires("package1") + add_requires("package1", {system = false}) package("package1") - on_fetch(function (package) - return {defines = "NS1_PACKAGE1"} + on_load(function (package) + package:add("defines", "NS1_PACKAGE1") end) + on_install(function (package) end) target("foo") set_kind("static") @@ -22,12 +24,13 @@ namespace("ns1", function () namespace("ns2", function() - add_requires("package2") + add_requires("package2", {system = false}) package("package2") - on_fetch(function (package) - return {defines = "NS2_PACKAGE2"} + on_load(function (package) + package:add("defines", "NS2_PACKAGE2") end) + on_install(function (package) end) target("bar") set_kind("static") diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 5ae08de33..2ae021f79 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -260,7 +260,7 @@ function interpreter:_api_register_xxx_values(scope_kind, action, apifunc, ...) -- init current root scope local rootkey = scope_kind - if namespace then + if namespace and scope_kind ~= "__rootkind" then rootkey = scope_kind .. "@@" .. namespace .. "::" end local root = scopes._ROOT[rootkey] or {} diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index d3032f15b..05be6af8c 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -55,12 +55,24 @@ local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance function _instance.new(name, info, opt) opt = opt or {} - local instance = table.inherit(_instance) local parts = name:split("::", {plain = true}) - instance._NAME = parts[#parts] - table.remove(parts) - if #parts > 0 then - instance._NAMESPACE = table.concat(parts, "::") + local instance = table.inherit(_instance) + local managers = package._memcache():get("managers") + if managers == nil and #parts == 2 then + managers = hashset.new() + for _, dir in ipairs(os.dirs(path.join(os.programdir(), "modules/package/manager/*"))) do + managers:insert(path.filename(dir)) + end + package._memcache():set("managers", managers) + end + if #parts == 2 and managers and managers:has(parts[1]) then + instance._NAME = name + else + instance._NAME = parts[#parts] + table.remove(parts) + if #parts > 0 then + instance._NAMESPACE = table.concat(parts, "::") + end end instance._INFO = info instance._REPO = opt.repo diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index a06ee7a29..30c571592 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -1064,9 +1064,6 @@ function _load_package(packagename, requireinfo, opt) end _memcache():set2("packageids", packagename, (packageid or 0) + 1) end - if displayname and package:namespace() then - displayname = package:namespace() .. "::" .. displayname - end package:displayname_set(displayname) -- disable parallelize if the package cache directory conflicts -- cgit v1.3.1 From 4ad00835a9070c32b6ce17248e5702ef0eae5a37 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 8 Jan 2025 00:59:28 +0800 Subject: fix package error --- xmake/core/package/package.lua | 11 ++++++++- xmake/core/project/project.lua | 27 ++++++++++++++++++++++ .../private/action/require/impl/package.lua | 6 +++++ 3 files changed, 43 insertions(+), 1 deletion(-) (limited to 'xmake/modules/private/action/require/impl/package.lua') diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 05be6af8c..be736d2f0 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -3001,7 +3001,16 @@ function package.load_from_project(packagename, project) -- get package info local packageinfo = packages[packagename] - if not packageinfo then + if packageinfo == nil and project.namespaces() then + for _, namespace in ipairs(project.namespaces()) do + packageinfo = packages[namespace .. "::" .. packagename] + if packageinfo then + packagename = namespace .. "::" .. packagename + break + end + end + end + if packageinfo == nil then return end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index c283e1e36..7a24a298a 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -1030,11 +1030,38 @@ function project.requires_str() -- get raw requires requires_str, requires_extra = project.get("requires"), project.get("__extra_requires") + local namespaces = project.namespaces() + if namespaces then + for _, namespace in ipairs(namespaces) do + local ns_requires_str, ns_requires_extra = project.get(namespace .. "::requires"), project.get(namespace .. "::__extra_requires") + if ns_requires_str then + requires_str = table.wrap(requires_str) + table.insert(requires_str, ns_requires_str) + end + if ns_requires_extra then + requires_extra = table.wrap(requires_extra) + table.join2(requires_extra, ns_requires_extra) + end + end + end project._memcache():set("requires_str", requires_str or false) project._memcache():set("requires_extra", requires_extra) -- get raw requireconfs local requireconfs_str, requireconfs_extra = project.get("requireconfs"), project.get("__extra_requireconfs") + if namespaces then + for _, namespace in ipairs(project.namespaces()) do + local ns_requireconfs_str, ns_requireconfs_extra = project.get(namespace .. "::requireconfs"), project.get(namespace .. "::__extra_requireconfs") + if ns_requireconfs_str then + requireconfs_str = table.wrap(requireconfs_str) + table.insert(requireconfs_str, ns_requireconfs_str) + end + if ns_requireconfs_extra then + requireconfs_extra = table.wrap(requireconfs_extra) + table.join2(requireconfs_extra, ns_requireconfs_extra) + end + end + end project._memcache():set("requireconfs_str", requireconfs_str or false) project._memcache():set("requireconfs_extra", requireconfs_extra) end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 30c571592..840814040 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -961,6 +961,12 @@ function _load_package(packagename, requireinfo, opt) local package if os.isfile(os.projectfile()) then package = _load_package_from_project(packagename) + if package and package:namespace() then + packagename = package:namespace() .. "::" .. packagename + if displayname then + displayname = package:namespace() .. "::" .. displayname + end + end end -- load package from repositories -- cgit v1.3.1