summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-11-17 22:39:53 +0800
committerruki <[email protected]>2022-11-17 22:39:53 +0800
commit6eda4ea531300a72984127253c0b79beefd96f56 (patch)
tree2e6220833d0fc9e9c7b155536939a92a77e3fa1c
parent8c0fe2e25914c2ccf2ede485ea6306a067007cd7 (diff)
improve package parents
-rw-r--r--xmake/core/package/package.lua23
-rw-r--r--xmake/modules/private/action/require/impl/package.lua38
2 files changed, 38 insertions, 23 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 57f7c1b78..e82691534 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -384,20 +384,39 @@ function _instance:librarydeps()
end
-- get parents
-function _instance:parents()
- return self._PARENTS
+function _instance:parents(packagename)
+ local parents = self._PARENTS
+ if parents then
+ if packagename then
+ return parents[packagename]
+ else
+ local results = self._PARENTS_PLAIN
+ if not results then
+ results = {}
+ for _, parentpkgs in pairs(parents) do
+ table.join2(results, parentpkgs)
+ end
+ results = table.unique(results)
+ self._PARENTS_PLAIN = results
+ end
+ return results
+ end
+ end
end
-- add parents
function _instance:parents_add(...)
self._PARENTS = self._PARENTS or {}
for _, parent in ipairs({...}) do
+ -- maybe multiple parents will depend on it
+ -- @see https://github.com/xmake-io/xmake/issues/3065
local parentpkgs = self._PARENTS[parent:name()]
if not parentpkgs then
parentpkgs = {}
self._PARENTS[parent:name()] = parentpkgs
end
table.insert(parentpkgs, parent)
+ self._PARENTS_PLAIN = nil
end
end
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index 2ff51a609..372b72ae9 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -904,10 +904,8 @@ function _get_parents_str(package)
local parents = package:parents()
if parents then
local parentnames = {}
- for _, parentpkgs in pairs(parents) do
- for _, parent in ipairs(parentpkgs) do
- table.insert(parentnames, parent:displayname())
- end
+ for _, parent in ipairs(parents) do
+ table.insert(parentnames, parent:displayname())
end
if #parentnames == 0 then
return
@@ -1064,25 +1062,23 @@ function should_install(package, opt)
end
if package:parents() then
-- if all the packages that depend on it already exist, then there is no need to install it
- for _, parentpkgs in pairs(package:parents()) do
- for _, parent in ipairs(parentpkgs) do
- if should_install(parent, opt) and not parent:exists() then
- return true
- end
+ for _, parent in ipairs(package:parents()) do
+ if should_install(parent, opt) and not parent:exists() then
+ return true
+ end
- -- if the existing parent package is already using it,
- -- then even if it is an optional package, you must make sure to install it
- --
- -- @see https://github.com/xmake-io/xmake/issues/1460
- --
- if parent:exists() and not option.get("force") and _must_depend_on(parent, package) then
- -- mark this package as non-optional because parent package need it
- local requireinfo = package:requireinfo()
- if requireinfo.optional then
- requireinfo.optional = nil
- end
- return true
+ -- if the existing parent package is already using it,
+ -- then even if it is an optional package, you must make sure to install it
+ --
+ -- @see https://github.com/xmake-io/xmake/issues/1460
+ --
+ if parent:exists() and not option.get("force") and _must_depend_on(parent, package) then
+ -- mark this package as non-optional because parent package need it
+ local requireinfo = package:requireinfo()
+ if requireinfo.optional then
+ requireinfo.optional = nil
end
+ return true
end
end
else