summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-09-28 23:11:18 +0800
committerruki <[email protected]>2023-09-28 23:11:18 +0800
commitca1eba2d96ed24fd2070b45de35c42ce3b37b066 (patch)
treeaab939deefcce6901d6add8fd4a38239bdd6b76e
parent2aa8a4a793f3a7281487d6bc8334f975fa6bd26d (diff)
remove linkgroups from links
-rw-r--r--xmake/core/base/interpreter.lua2
-rw-r--r--xmake/core/base/scopeinfo.lua3
-rw-r--r--xmake/core/tool/builder.lua34
-rw-r--r--xmake/modules/core/tools/gcc.lua8
4 files changed, 36 insertions, 11 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 6e30552b8..4733a3369 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -1231,6 +1231,7 @@ function interpreter:api_register_set_groups(scope_kind, ...)
-- expand values
values = table.join(table.unpack(values))
+ table.wrap_lock(values)
-- save values
scope[name] = values
@@ -1268,6 +1269,7 @@ function interpreter:api_register_add_groups(scope_kind, ...)
-- save values
scope[name] = scope[name] or {}
+ table.wrap_lock(values)
table.insert(scope[name], values)
-- save extra config
diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua
index 0ca401237..68d87706b 100644
--- a/xmake/core/base/scopeinfo.lua
+++ b/xmake/core/base/scopeinfo.lua
@@ -207,7 +207,9 @@ function _instance:_api_set_groups(name, ...)
values = table.join(table.unpack(values))
-- save values
+ table.wrap_lock(values)
scope[name] = values
+ scope[name] = self:_api_handle(name, scope[name])
-- save extra config
if extra_config then
@@ -238,6 +240,7 @@ function _instance:_api_add_groups(name, ...)
-- save values
scope[name] = scope[name] or {}
+ table.wrap_lock(values)
table.insert(scope[name], values)
scope[name] = self:_api_handle(name, scope[name])
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index 9c44c2c71..f867304b1 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -441,33 +441,48 @@ end
function builder:_sort_links_of_items(target, items)
local sortlinks = false
local makegroups = false
- local linkorders = target:get("linkorders")
- if linkorders and type(linkorders) == "table" and #linkorders > 1 then
+ local linkorders = table.wrap(target:get("linkorders"))
+ if #linkorders > 0 then
sortlinks = true
end
- local linkgroups = target:get("linkgroups")
- if linkgroups and type(linkgroups) == "table" and #linkgroups > 1 then
+ local linkgroups = table.wrap(target:get("linkgroups"))
+ local linkgroups_set = hashset.new()
+ if #linkgroups > 0 then
makegroups = true
+ for _, linkgroup in ipairs(linkgroups) do
+ for _, link in ipairs(linkgroup) do
+ linkgroups_set:insert(link)
+ end
+ end
end
- utils.dump(linkorders)
-- get all links
local links = {}
+ local linkgroups_map = {}
local link_mapper
local framework_mapper
+ local linkgroup_mapper
if sortlinks or makegroups then
table.remove_if(items, function (_, item)
local name = item.name
local removed = false
for _, value in ipairs(item.values) do
if name == "links" or name == "syslinks" then
- table.insert(links, value)
+ if not linkgroups_set:has(value) then
+ table.insert(links, value)
+ end
link_mapper = item.mapper
removed = true
elseif name == "frameworks" then
table.insert(links, "framework::" .. value)
framework_mapper = item.mapper
removed = true
+ elseif name == "linkgroups" then
+ local key = tostring(value)
+ table.insert(links, "linkgroup::" .. key)
+ linkgroups_map[key] = value
+ linkgroup_mapper = item.mapper
+ removed = true
end
end
return removed
@@ -476,6 +491,7 @@ function builder:_sort_links_of_items(target, items)
end
-- sort sublinks
+ --[[
if sortlinks then
local linkorders_set = hashset.from(linkorders)
local sublinks = {}
@@ -500,7 +516,7 @@ function builder:_sort_links_of_items(target, items)
end
end
end
- end
+ end]]
-- re-generate links to items list
if sortlinks or makegroups then
@@ -508,6 +524,10 @@ function builder:_sort_links_of_items(target, items)
if link:startswith("framework::") then
link = link:sub(12)
table.insert(items, {name = "frameworks", values = table.wrap(link), check = false, multival = false, mapper = framework_mapper})
+ elseif link:startswith("linkgroup::") then
+ local key = link:sub(12)
+ local value = linkgroups_map[key]
+ table.insert(items, {name = "linkgroups", values = table.wrap(value), check = false, multival = false, mapper = linkgroup_mapper})
else
table.insert(items, {name = "links", values = table.wrap(link), check = false, multival = false, mapper = link_mapper})
end
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 864e894e5..7cff1d48d 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -305,13 +305,13 @@ function nf_syslink(self, lib)
end
-- make the link group flag
-function nf_linkgroups(self, libs, target)
+function nf_linkgroup(self, linkgroup, target)
local flags = {}
- for _, lib in ipairs(libs) do
+ for _, lib in ipairs(linkgroup) do
table.insert(flags, nf_link(self, lib))
end
if not target:is_plat("macosx", "windows", "mingw") then
- local whole = target:extraconf("linkgroups", libs, "whole")
+ local whole = target:extraconf("linkgroups", linkgroup, "whole")
if whole then
table.insert(flags, 1, "-Wl,--whole-archive")
table.insert(flags, "-Wl,--no-whole-archive")
@@ -320,7 +320,7 @@ function nf_linkgroups(self, libs, target)
table.insert(flags, "-Wl,--end-group")
end
end
- return {flags}
+ return flags
end
-- make the linkdir flag