summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-12-04 22:41:35 +0800
committerruki <[email protected]>2024-12-04 22:41:35 +0800
commit720cf65b54d50394a5a4110dff364734f6e54f0e (patch)
tree6f20bb63067ba21f9fa05256e16698014795f9b7
parent34ee1cb9ceeec762cf986dc23a68d466e100e6e2 (diff)
impl sync_requires_to_deps
-rw-r--r--tests/projects/package/compatibility/sync_requires_to_deps/xmake.lua2
-rw-r--r--xmake/core/project/project.lua36
-rw-r--r--xmake/modules/private/action/require/impl/package.lua5
3 files changed, 42 insertions, 1 deletions
diff --git a/tests/projects/package/compatibility/sync_requires_to_deps/xmake.lua b/tests/projects/package/compatibility/sync_requires_to_deps/xmake.lua
index 2d3d0b029..439e322e9 100644
--- a/tests/projects/package/compatibility/sync_requires_to_deps/xmake.lua
+++ b/tests/projects/package/compatibility/sync_requires_to_deps/xmake.lua
@@ -25,7 +25,7 @@ package_end()
set_policy("package.sync_requires_to_deps", true)
add_requires("test")
-add_requires("zlib", {system = false, configs = {shared = true}})
+add_requires("zlib >=1.2.13", {system = false, configs = {shared = true}})
target("test")
set_kind("binary")
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 6c896dde5..77793d3e5 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -1030,6 +1030,42 @@ function project.requireconfs_str()
project.requires_str()
local requireconfs_str = project._memcache():get("requireconfs_str")
local requireconfs_extra = project._memcache():get("requireconfs_extra")
+ -- synchronize requires configuration to all package dependencies.
+ -- @see https://github.com/xmake-io/xmake/issues/5745#issuecomment-2513951471
+ if project.policy("package.sync_requires_to_deps") then
+ local requires_str = project._memcache():get("requires_str")
+ local requires_extra = project._memcache():get("requires_extra")
+ local sync_requires_to_deps = project._memcache():get("package.sync_requires_to_deps")
+ if requires_str and not sync_requires_to_deps then
+ requires_extra = requires_extra and table.wrap(requires_extra) or {}
+ requireconfs_str = requireconfs_str and table.wrap(requireconfs_str) or {}
+ requireconfs_extra = requireconfs_extra and table.wrap(requireconfs_extra) or {}
+ for _, require_str in ipairs(table.wrap(requires_str)) do
+ if not require_str:find("::", 1, true) then
+ local splitinfo = require_str:split("%s")
+ local packagename = splitinfo[1]
+ local packageversion = splitinfo[2]
+ local requireconf_str = "**." .. packagename
+ local requireconf_extra = table.clone(requires_extra[require_str])
+ if requireconf_extra then
+ requireconf_extra.configs = table.clone(requireconf_extra.configs) or {}
+ end
+ if packageversion then
+ requireconf_extra = requireconf_extra or {configs = {}}
+ requireconf_extra.configs.version = packageversion
+ end
+ if requireconf_extra then
+ requireconf_extra.override = true
+ table.insert(requireconfs_str, requireconf_str)
+ requireconfs_extra[requireconf_str] = requireconf_extra
+ end
+ end
+ end
+ project._memcache():set("requireconfs_str", requireconfs_str)
+ project._memcache():set("requireconfs_extra", requireconfs_extra)
+ project._memcache():set("package.sync_requires_to_deps", true)
+ end
+ end
return requireconfs_str, requireconfs_extra
end
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index e3700af9d..30c571592 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -1211,6 +1211,11 @@ function _get_requirepaths(package)
table.insert(requirepaths, requirepath .. "." .. package:name())
end
end
+ -- we also need to resolve requires conflict in toplevel, if `package.sync_requires_to_deps` policy is enabled.
+ -- @see https://github.com/xmake-io/xmake/issues/5745#issuecomment-2513951471
+ if project.policy("package.sync_requires_to_deps") then
+ table.insert(requirepaths, package:name())
+ end
else
table.insert(requirepaths, package:name())
end