summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-10-27 22:55:21 +0800
committerruki <[email protected]>2023-10-27 22:55:21 +0800
commit677b872797053405054861dd4c60fec8153bec78 (patch)
tree59f8c7594897386fb8039e9ea02909bef851f9cc
parentee9a61fdad8d0755b600864092de468a7d2b2364 (diff)
improve package links
-rw-r--r--xmake/core/tool/builder.lua59
-rw-r--r--xmake/modules/package/manager/xmake/find_package.lua58
2 files changed, 41 insertions, 76 deletions
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index 204c930f3..82248665e 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -254,7 +254,7 @@ function builder:_add_flags_from_target(flags, target)
-- add flags from language
targetflags = {}
- self:_add_flags_from_language(targetflags, target)
+ self:_add_flags_from_language(targetflags, {target = target})
-- add flags for the target
if target_type == "target" then
@@ -291,7 +291,7 @@ function builder:_add_flags_from_argument(flags, target, args)
end
-- add flags (named) from the language
- self:_add_flags_from_language(flags, nil, {
+ self:_add_flags_from_language(flags, {linkorders = args.linkorders, linkgroups = args.linkgroups, getters = {
target = function (name)
-- we need also to get extra from arguments
-- @see https://github.com/xmake-io/xmake/issues/4274
@@ -314,7 +314,7 @@ function builder:_add_flags_from_argument(flags, target, args)
arch = target:arch()
end
return platform.toolconfig(name, plat, arch)
- end})
+ end}})
end
-- add items from getter
@@ -408,10 +408,12 @@ function builder:_add_items_from_target(items, name, opt)
end
-- add flags from the language
-function builder:_add_flags_from_language(flags, target, getters)
+function builder:_add_flags_from_language(flags, opt)
+ opt = opt or {}
-- get order named items
local items = {}
+ local target = opt.target
for _, flaginfo in ipairs(self:_nameflags()) do
-- get flag info
@@ -441,29 +443,49 @@ function builder:_add_flags_from_language(flags, target, getters)
-- map named flags to real flags
local mapper = self:_tool()["nf_" .. apiname]
if mapper then
- local opt = {target = target, check = checkstate, multival = multival, mapper = mapper}
- if getters then
- local getter = getters[flagscope]
+ local opt_ = {target = target, check = checkstate, multival = multival, mapper = mapper}
+ if opt.getters then
+ local getter = opt.getters[flagscope]
if getter then
- opt.getter = getter
- self:_add_items_from_getter(items, flagname, opt)
+ opt_.getter = getter
+ self:_add_items_from_getter(items, flagname, opt_)
end
elseif flagscope == "target" and target and target:type() == "target" then
- self:_add_items_from_target(items, flagname, opt)
+ self:_add_items_from_target(items, flagname, opt_)
elseif flagscope == "target" and target and target:type() == "option" then
- self:_add_items_from_option(items, flagname, opt)
+ self:_add_items_from_option(items, flagname, opt_)
elseif flagscope == "config" then
- self:_add_items_from_config(items, flagname, opt)
+ self:_add_items_from_config(items, flagname, opt_)
elseif flagscope == "toolchain" then
- self:_add_items_from_toolchain(items, flagname, opt)
+ self:_add_items_from_toolchain(items, flagname, opt_)
end
end
end
-- sort links
local kind = self:kind()
- if (kind == "ld" or kind == "sh") and target and target:type() == "target" then
- self:_sort_links_of_items(target, items)
+ if kind == "ld" or kind == "sh" then
+ local linkorders = table.wrap(opt.linkorders)
+ local linkgroups = table.wrap(opt.linkgroups)
+ if target and target:type() == "target" then
+ local values = target:get_from("linkorders", "*")
+ if values then
+ for _, value in ipairs(values) do
+ table.join2(linkorders, value)
+ end
+ end
+ values = target:get_from("linkgroups", "*")
+ if values then
+ for _, value in ipairs(values) do
+ table.join2(linkgroups, value)
+ end
+ end
+ end
+ utils.dump(linkorders)
+ utils.dump(linkgroups)
+ if #linkorders > 0 or #linkgroups > 0 then
+ self:_sort_links_of_items(items, {linkorders = linkorders, linkgroups = linkgroups})
+ end
end
-- get flags from the items
@@ -492,14 +514,15 @@ function builder:_add_flags_from_language(flags, target, getters)
end
-- sort links of items
-function builder:_sort_links_of_items(target, items)
+function builder:_sort_links_of_items(items, opt)
+ opt = opt or {}
local sortlinks = false
local makegroups = false
- local linkorders = table.wrap(target:get("linkorders"))
+ local linkorders = table.wrap(opt.linkorders)
if #linkorders > 0 then
sortlinks = true
end
- local linkgroups = table.wrap(target:get("linkgroups"))
+ local linkgroups = table.wrap(opt.linkgroups)
local linkgroups_set = hashset.new()
if #linkgroups > 0 then
makegroups = true
diff --git a/xmake/modules/package/manager/xmake/find_package.lua b/xmake/modules/package/manager/xmake/find_package.lua
index c3c09902b..0d5336fe4 100644
--- a/xmake/modules/package/manager/xmake/find_package.lua
+++ b/xmake/modules/package/manager/xmake/find_package.lua
@@ -20,7 +20,6 @@
-- imports
import("core.base.global")
-import("core.base.graph")
import("core.project.config")
import("core.project.option")
import("core.project.target")
@@ -43,58 +42,6 @@ function _deduplicate_values(values)
end
end
--- sort links
-function _sort_links(result)
- print("sork_links")
- print(result)
-
- local sortlinks = false
- local makegroups = false
- local linkorders = table.wrap(result.linkorders)
- if #linkorders > 0 then
- sortlinks = true
- end
- local linkgroups = table.wrap(result.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
-
- -- get all links
- --[[
- local links = {}
- local linkgroups_map = {}
- 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
- if not linkgroups_set:has(value) then
- table.insert(links, value)
- end
- removed = true
- elseif name == "frameworks" then
- table.insert(links, "framework::" .. value)
- removed = true
- elseif name == "linkgroups" then
- --local key = extra and extra.name or tostring(value)
- table.insert(links, "linkgroup::" .. key)
- linkgroups_map[key] = value
- removed = true
- end
- end
- return removed
- end)
- links = table.reverse_unique(links)
- end]]
-end
-
-- find package from the repository (maybe only include and no links)
function _find_package_from_repo(name, opt)
@@ -283,11 +230,6 @@ function _find_package_from_repo(name, opt)
end
end
- -- sort links
- if result.linkorders or result.linkgroups then
- _sort_links(result)
- end
-
-- deduplicate result
_deduplicate_values(result)