summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-01-07 23:37:28 +0800
committerruki <[email protected]>2025-01-07 23:37:28 +0800
commit76fd3aba7f38972943f3ad60471de04000e68c5a (patch)
tree362431d754d6ec424de541acd1bd42fa1fff9eb1
parent545c0558aff2883735ae6dddbf831567d29d21f1 (diff)
improve project.get
-rw-r--r--tests/apis/namespace/package/xmake.lua3
-rw-r--r--xmake/core/base/interpreter.lua41
-rw-r--r--xmake/core/project/project.lua1
3 files changed, 34 insertions, 11 deletions
diff --git a/tests/apis/namespace/package/xmake.lua b/tests/apis/namespace/package/xmake.lua
index 9f01f4bdb..eac4ab530 100644
--- a/tests/apis/namespace/package/xmake.lua
+++ b/tests/apis/namespace/package/xmake.lua
@@ -1,4 +1,5 @@
+set_version("1.0.0")
add_requires("package0", {system = false})
package("package0")
@@ -9,6 +10,7 @@ package("package0")
namespace("ns1", function ()
+ set_version("1.0.1")
add_requires("package1", {system = false})
package("package1")
@@ -24,6 +26,7 @@ namespace("ns1", function ()
namespace("ns2", function()
+ set_version("1.0.2")
add_requires("package2", {system = false})
package("package2")
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 6f006efff..7f43ca340 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -543,8 +543,25 @@ function interpreter:_make(scope_kind, deduplicate, enable_filter)
local results = {}
local scope_opt = {interpreter = self, deduplicate = deduplicate, enable_filter = enable_filter}
if scope_kind and scope_kind:startswith("root.") then
- local root_scope = scopes._ROOT[scope_kind:sub(6)]
- if root_scope then
+ local root_scope = {}
+ local empty = true
+ local kind_prefix = scope_kind:sub(6)
+ for kind, scope in pairs(scopes._ROOT) do
+ if kind:startswith(kind_prefix) then
+ local namespace = kind:match(kind_prefix .. "@@(.+)::")
+ if namespace or kind == kind_prefix then
+ for k, v in pairs(scope) do
+ if namespace then
+ root_scope[namespace .. "::" .. k] = v
+ else
+ root_scope[k] = v
+ end
+ end
+ end
+ empty = false
+ end
+ end
+ if root_scope and not empty then
results = self:_handle(root_scope, deduplicate, enable_filter)
end
return scopeinfo.new(scope_kind, results, scope_opt)
@@ -553,20 +570,22 @@ function interpreter:_make(scope_kind, deduplicate, enable_filter)
elseif scope_kind == "root" or scope_kind == nil then
local root_scope = {}
local empty = true
- for scopekind, scope in pairs(scopes._ROOT) do
- if scopekind:startswith("__rootkind") then
- local namespace = scopekind:match("__rootkind@@(.+)::")
- for k, v in pairs(scope) do
- if namespace then
- root_scope[namespace .. "::" .. k] = v
- else
- root_scope[k] = v
+ for kind, scope in pairs(scopes._ROOT) do
+ if kind:startswith("__rootkind") then
+ local namespace = kind:match("__rootkind@@(.+)::")
+ if namespace or kind == "__rootkind" then
+ for k, v in pairs(scope) do
+ if namespace then
+ root_scope[namespace .. "::" .. k] = v
+ else
+ root_scope[k] = v
+ end
end
end
empty = false
end
end
- if root_scope then
+ if root_scope and not empty then
results = self:_handle(root_scope, deduplicate, enable_filter)
end
return scopeinfo.new(scope_kind, results, scope_opt)
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 72bec34d5..b92872d64 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -785,6 +785,7 @@ function project.filelock()
end
-- get the root configuration
+-- and we get values in namespace, e.g. project.get("ns1::ns2::name"), project.get("target.ns1::ns2::name")
function project.get(name)
local rootinfo
if name and name:startswith("target.") then