Skip to content

Commit

Permalink
fix package with 3rd namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jan 7, 2025
1 parent 9021afe commit bd6ded5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tests/apis/namespace/package/test.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function main()
os.exec("xmake -vD")
os.exec("xmake -vD -y")
end
21 changes: 12 additions & 9 deletions tests/apis/namespace/package/xmake.lua
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion xmake/core/base/interpreter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
22 changes: 17 additions & 5 deletions xmake/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions xmake/modules/private/action/require/impl/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bd6ded5

Please sign in to comment.