Skip to content

Commit

Permalink
impl sync_requires_to_deps
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Dec 4, 2024
1 parent 34ee1cb commit 720cf65
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
36 changes: 36 additions & 0 deletions xmake/core/project/project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions xmake/modules/private/action/require/impl/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 720cf65

Please sign in to comment.