Skip to content

Commit 012ebad

Browse files
committed
Fix resource merge priority so consumer library overrides dependency 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.
1 parent 8936d9e commit 012ebad

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

rules/busybox.bzl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,17 @@ def _package(
311311
map_each = _make_package_resources_flags,
312312
join_with = ",",
313313
)
314+
# Reverse so the current library's node (first in preorder) ends up last,
315+
# matching busybox last-wins semantics: a library's resources override its deps.
314316
args.add_joined(
315317
"--directData",
316-
direct_resources_nodes,
318+
reversed(direct_resources_nodes.to_list()),
317319
map_each = _make_package_resources_flags,
318320
join_with = ",",
319321
)
320322
args.add_joined(
321323
"--directAssets",
322-
direct_resources_nodes,
324+
reversed(direct_resources_nodes.to_list()),
323325
map_each = _make_package_assets_flags,
324326
join_with = "&",
325327
omit_if_empty = True,
@@ -532,9 +534,11 @@ def _merge_assets(
532534
symbols = symbols,
533535
),
534536
)
537+
# Reverse so the current library's node (first in preorder) ends up last,
538+
# matching busybox last-wins semantics.
535539
args.add_joined(
536540
"--directData",
537-
direct_resources_nodes,
541+
reversed(direct_resources_nodes.to_list()),
538542
map_each = _make_merge_assets_flags,
539543
join_with = "&",
540544
)
@@ -782,9 +786,11 @@ def _merge_compiled(
782786
),
783787
)
784788
input_files.append(compiled_resources)
789+
# Reverse so the current library's node (first in preorder) ends up last,
790+
# matching busybox last-wins semantics.
785791
args.add_joined(
786792
"--directData",
787-
direct_resources_nodes,
793+
reversed(direct_resources_nodes.to_list()),
788794
map_each = _make_merge_compiled_flags,
789795
join_with = "&",
790796
)

0 commit comments

Comments
 (0)