summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-01-06 23:46:48 +0800
committerruki <[email protected]>2025-01-06 18:12:52 +0800
commit7447e9505f48633ea7536fb195c59511d3e93fe1 (patch)
treecbeda6171d4a6a9eb501455eac1d102cab666c43
parentd630e9c0ef7819be09caf4b70ec6fbe1f974fbb7 (diff)
fix root namespace values order
-rw-r--r--xmake/core/base/interpreter.lua58
1 files changed, 45 insertions, 13 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index d976268c1..b3c32f280 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -111,8 +111,6 @@ function interpreter:_merge_root_scope(root, root_prev, override)
root_prev[scope_kind_and_name] = scope_values
end
end
-
- -- ok?
return root_prev
end
@@ -126,21 +124,55 @@ function interpreter:_fetch_root_scope(root)
if #scope_kind_and_name == 2 then
local scope_kind = scope_kind_and_name[1]
local scope_name = scope_kind_and_name[2]
- local scope_values = root[scope_kind .. "@@" .. scope_name] or {}
- local scope_root = root[scope_kind] or {}
- for name, values in pairs(scope_root) do
- if not name:startswith("__override_") then
- if scope_root["__override_" .. name] then
- if scope_values[name] == nil then
- scope_values[name] = values
- scope_values["__override_" .. name] = true
+
+ -- we only fetch the root values to the target values, e.g. target@@ns1::ns2::bar"
+ -- and ignore root namespace values, e.g. target@@ns1::ns2::
+ if not scope_name:endswith("::") then
+ local scope_values = root[scope_kind .. "@@" .. scope_name] or {}
+ local namespaces = scope_name:split("::", {plain = true})
+ table.remove(namespaces)
+ table.insert(namespaces, 1, "")
+
+ -- add values in global root scope, all namespace root scopes
+ local namespace
+ local scope_rootkeys = {}
+ for idx, namespace_part in ipairs(namespaces) do
+ local scope_rootkey = scope_kind
+ if idx ~= 1 then
+ if not namespace then
+ namespace = namespace_part
+ else
+ namespace = namespace .. "::" .. namespace_part
+ end
+ scope_rootkey = scope_kind .. "@@" .. namespace .. "::"
+ end
+ table.insert(scope_rootkeys, scope_rootkey)
+ end
+ -- we need to add root values in head
+ --
+ -- e.g.
+ -- add root values to ns1::ns2::bar from target@@ns1::ns2::
+ -- add root values to ns1::ns2::bar from target@@ns1::
+ -- add root values to ns1::ns2::bar from target
+ --
+ for idx = #scope_rootkeys, 1, -1 do
+ local scope_rootkey = scope_rootkeys[idx]
+ local scope_root = root[scope_rootkey] or {}
+ for name, values in pairs(scope_root) do
+ if not name:startswith("__override_") then
+ if scope_root["__override_" .. name] then
+ if scope_values[name] == nil then
+ scope_values[name] = values
+ scope_values["__override_" .. name] = true
+ end
+ else
+ scope_values[name] = table.join(values, scope_values[name] or {})
+ end
end
- else
- scope_values[name] = table.join(values, scope_values[name] or {})
end
end
+ root[scope_kind .. "@@" .. scope_name] = scope_values
end
- root[scope_kind .. "@@" .. scope_name] = scope_values
end
end
end