Skip to content

Comments

Fix resource merge priority so consumer library overrides dependency resources#464

Open
olbapmar wants to merge 1 commit intobazelbuild:mainfrom
olbapmar:pablomartin/fix-resource-merge-priority-for-consumer-libraries
Open

Fix resource merge priority so consumer library overrides dependency resources#464
olbapmar wants to merge 1 commit intobazelbuild:mainfrom
olbapmar:pablomartin/fix-resource-merge-priority-for-consumer-libraries

Conversation

@olbapmar
Copy link

@olbapmar olbapmar commented Feb 19, 2026

The Android resource busybox uses last-wins semantics when merging duplicate resource names. The current library's ResourcesNodeInfo was placed as the first direct item of the direct_resources_nodes preorder depset, causing it to be processed before its dependencies and lose to them on conflicts.

Fix the ordering at the consumption point in busybox.bzl: reverse the direct_resources_nodes list when building --directData (and --directAssets) arguments. This ensures the current library's node (first in preorder) ends up last in the busybox flag, so its resources correctly override those of its dependencies (matching native Bazel and Gradle behavior)

A regression test was not added because the fix is only observable in non-legacy manifest_merge_order mode. In legacy mode, _process_starlark swaps each library's dep nodes out of direct_resources_nodes into transitive_resources_nodes before building the provider, so every library exposes only its own node in direct_resources_nodes. Downstream targets therefore see exactly one node per direct dep in --directData, making the reversal a no-op. All CI resource tests run exclusively with --//rules/flags:manifest_merge_order=legacy, so the fix cannot be exercised through the existing analysis-time test framework without adding a non-legacy CI configuration or a configuration transition on the test target.

However, this has caused issues in our repos and the this patch fixed them.

@olbapmar olbapmar marked this pull request as draft February 19, 2026 15:54
@olbapmar olbapmar force-pushed the pablomartin/fix-resource-merge-priority-for-consumer-libraries branch from d2d535f to d4abac2 Compare February 19, 2026 17:03
…resources

The Android resource busybox uses last-wins semantics when merging duplicate
resource names. The current library's ResourcesNodeInfo was placed as the
first direct item of the direct_resources_nodes preorder depset, causing it
to be processed before its dependencies and lose to them on conflicts.

Fix the ordering at the consumption point in busybox.bzl: reverse the
direct_resources_nodes list when building --directData (and --directAssets)
arguments. This ensures the current library's node (first in preorder) ends
up last in the busybox flag, so its resources correctly override those of its
dependencies — matching native Bazel and Gradle behavior.

A regression test was not added because the fix is only observable in
non-legacy manifest_merge_order mode. In legacy mode, _process_starlark
swaps each library's dep nodes out of direct_resources_nodes into
transitive_resources_nodes before building the provider, so every library
exposes only its own node in direct_resources_nodes. Downstream targets
therefore see exactly one node per direct dep in --directData, making the
reversal a no-op. All CI resource tests run exclusively with
--//rules/flags:manifest_merge_order=legacy, so the fix cannot be exercised
through the existing analysis-time test framework without adding a non-legacy
CI configuration or a configuration transition on the test target.
@olbapmar olbapmar force-pushed the pablomartin/fix-resource-merge-priority-for-consumer-libraries branch from d4abac2 to 012ebad Compare February 19, 2026 22:32
@olbapmar olbapmar marked this pull request as ready for review February 19, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant