summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-10-26 23:51:57 +0800
committerruki <[email protected]>2023-10-26 23:51:57 +0800
commit311171bcd0cee217855858b9c94502a40fbfad56 (patch)
treeecee776b38e23ca4a4e62aad070dee67a9181a16
parentd867bea8765d546abdbad08a3e573a88a8553b1c (diff)
fix sort and extra
-rw-r--r--xmake/core/base/table.lua12
-rw-r--r--xmake/core/package/package.lua24
-rw-r--r--xmake/core/tool/builder.lua46
-rw-r--r--xmake/modules/package/manager/xmake/find_package.lua10
4 files changed, 65 insertions, 27 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index a8050f0a3..0b368524a 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -349,6 +349,7 @@ function table.wrap_lock(value)
if type(value) == "table" then
value.__wrap_locked__ = true
end
+ return value
end
-- unlock table value to unwrap
@@ -356,6 +357,7 @@ function table.wrap_unlock(value)
if type(value) == "table" then
value.__wrap_locked__ = nil
end
+ return value
end
-- remove repeat from the given array
@@ -431,7 +433,15 @@ end
function table.orderkeys(tbl, callback)
local callback = type(callback) == "function" and callback or nil
local keys = table.keys(tbl)
- table.sort(keys, callback)
+ if callback then
+ table.sort(keys, callback)
+ else
+ local ok = pcall(table.sort, keys)
+ if not ok then
+ -- maybe sort strings and numbers, {1, 2, "a"}
+ table.sort(keys, function (a, b) return tostring(a) < tostring(b) end)
+ end
+ end
return keys
end
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 1ba408ff7..b9f6e8a06 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -905,13 +905,18 @@ function _instance:manifest_save()
local extras
local components
local apis = language.apis()
- for _, apiname in ipairs(table.join(apis.values, apis.paths)) do
+ for _, apiname in ipairs(table.join(apis.values, apis.paths, apis.groups)) do
if apiname:startswith("package.add_") or apiname:startswith("package.set_") then
local name = apiname:sub(13)
- local value = self:get(name)
- if value ~= nil then
+ local values = self:get(name)
+ if values ~= nil then
+ -- we need wrap locked value, e.g. linkgroups = {{"m", "pthread"}}
+ values = table.wrap(table.clone(values))
+ for _, value in ipairs(values) do
+ table.wrap_unlock(value)
+ end
vars = vars or {}
- vars[name] = value
+ vars[name] = values
local extra = self:extraconf(name)
if extra then
extras = extras or {}
@@ -921,12 +926,17 @@ function _instance:manifest_save()
for _, component_name in ipairs(table.wrap(self:get("components"))) do
local comp = self:component(component_name)
if comp then
- local component_value = comp:get(name)
- if component_value ~= nil then
+ local component_values = comp:get(name)
+ if component_values ~= nil then
+ -- we need wrap locked value, e.g. linkgroups = {{"m", "pthread"}}
+ component_values = table.wrap(table.clone(component_values))
+ for _, value in ipairs(component_values) do
+ table.wrap_unlock(value)
+ end
components = components or {}
components.vars = components.vars or {}
components.vars[component_name] = components.vars[component_name] or {}
- components.vars[component_name][name] = component_value
+ components.vars[component_name][name] = component_values
end
end
end
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index 3f5b3cbb4..204c930f3 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -125,6 +125,19 @@ function builder:_flagkinds()
return self._FLAGKINDS
end
+-- get the extra configuration from value
+function builder:_extraconf(extras, value)
+ local extra = extras
+ if extra then
+ if type(value) == "table" then
+ extra = extra[table.concat(value, "_")]
+ else
+ extra = extra[value]
+ end
+ end
+ return extra
+end
+
-- inherit flags (only for public/interface) from target deps
--
-- e.g.
@@ -278,7 +291,6 @@ function builder:_add_flags_from_argument(flags, target, args)
end
-- add flags (named) from the language
- local extras = args.extras
self:_add_flags_from_language(flags, nil, {
target = function (name)
-- we need also to get extra from arguments
@@ -290,15 +302,8 @@ function builder:_add_flags_from_argument(flags, target, args)
-- linkgroups = {z = {group = true}}
-- }}
local values = args[name]
- local extra = extras and extras[name]
- if extra then
- if type(values) == "table" then
- extra = extra[table.concat(values, "_")]
- else
- extra = extra[values]
- end
- end
- return values, extra
+ local extras = args.extras and args.extras[name]
+ return values, extras
end,
toolchain = function (name)
local plat, arch
@@ -314,7 +319,7 @@ end
-- add items from getter
function builder:_add_items_from_getter(items, name, opt)
- local values, extra = opt.getter(name)
+ local values, extras = opt.getter(name)
if values then
table.insert(items, {
name = name,
@@ -322,7 +327,7 @@ function builder:_add_items_from_getter(items, name, opt)
check = opt.check,
multival = opt.multival,
mapper = opt.mapper,
- extra = extra})
+ extras = extras})
end
end
@@ -386,13 +391,13 @@ function builder:_add_items_from_target(items, name, opt)
if result then
for idx, values in ipairs(result) do
local source = sources[idx]
- local extra = target:extraconf_from(source, name, values)
+ local extras = target:extraconf_from(source, name)
values = table.wrap(values)
if values and #values > 0 then
table.insert(items, {
name = name,
values = values,
- extra = extra,
+ extras = extras,
check = opt.check,
multival = opt.multival,
mapper = opt.mapper})
@@ -465,8 +470,9 @@ function builder:_add_flags_from_language(flags, target, getters)
for _, item in ipairs(items) do
local check = item.check
local mapper = item.mapper
- local extra = item.extra
+ local extras = item.extras
if item.multival then
+ local extra = self:_extraconf(extras, item.values)
local results = mapper(self:_tool(), item.values, {target = target, targetkind = self:_targetkind(), extra = extra})
for _, flag in ipairs(table.wrap(results)) do
if flag and flag ~= "" and (not check or self:has_flags(flag)) then
@@ -475,6 +481,7 @@ function builder:_add_flags_from_language(flags, target, getters)
end
else
for _, flagvalue in ipairs(item.values) do
+ local extra = self:_extraconf(extras, flagvalue)
local flag = mapper(self:_tool(), flagvalue, {target = target, targetkind = self:_targetkind(), extra = extra})
if flag and flag ~= "" and (not check or self:has_flags(flag)) then
table.insert(flags, flag)
@@ -526,11 +533,12 @@ function builder:_sort_links_of_items(target, items)
framework_mapper = item.mapper
removed = true
elseif name == "linkgroups" then
- local extra = item.extra
+ local extras = item.extras
+ local extra = self:_extraconf(extras, value)
local key = extra and extra.name or tostring(value)
table.insert(links, "linkgroup::" .. key)
linkgroups_map[key] = value
- extras_map[key] = extra
+ extras_map[key] = extras
linkgroup_mapper = item.mapper
removed = true
end
@@ -609,8 +617,8 @@ function builder:_sort_links_of_items(target, items)
elseif link:startswith("linkgroup::") then
local key = link:sub(12)
local values = linkgroups_map[key]
- local extra = extras_map[key]
- table.insert(items, {name = "linkgroups", values = table.wrap(values), extra = extra, check = false, multival = false, mapper = linkgroup_mapper})
+ local extras = extras_map[key]
+ table.insert(items, {name = "linkgroups", values = table.wrap(values), extras = extras, 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/package/manager/xmake/find_package.lua b/xmake/modules/package/manager/xmake/find_package.lua
index 0d5336fe4..d672f98b4 100644
--- a/xmake/modules/package/manager/xmake/find_package.lua
+++ b/xmake/modules/package/manager/xmake/find_package.lua
@@ -42,6 +42,11 @@ function _deduplicate_values(values)
end
end
+-- sort links
+function _sort_links(result, opt)
+ print(result)
+end
+
-- find package from the repository (maybe only include and no links)
function _find_package_from_repo(name, opt)
@@ -230,6 +235,11 @@ function _find_package_from_repo(name, opt)
end
end
+ -- sort links
+ if opt.linkorders or result.linkgroups then
+ _sort_links(result, opt)
+ end
+
-- deduplicate result
_deduplicate_values(result)