grab-bazel-common
grab-bazel-common copied to clipboard
Implement resource merging for flavored source sets - Part 2
#89 introduced ability to merge multiple flavored source sets similar to what is done on Gradle. However it only supported resources (blocks few variants internally), this PR however supports assets as well as manifests. This PR also deprecates the resource_files
attribute for unified macro which can be noisy especially when the resources layout don't match it's layout.
This PR updates the API to be more descriptive as updated in the tests. This brings feature parity to AGP variants.
android_binary(
name = "android_binary_sample",
srcs = glob([
"src/main/java/**/*.kt",
]),
custom_package = "com.grab.test",
manifest = "src/main/AndroidManifest.xml",
resource_sets = {
"flavor": {
"res": "src/flavor/res",
"manifest": "src/flavor/AndroidManifest.xml",
"assets": "src/flavor/assets",
},
"main": {
"res": "src/main/res",
"manifest": "src/main/AndroidManifest.xml",
"assets": "src/main/assets",
},
},
)
The new resource_sets
is the source of truth of all resources and follows Gradle semantics. The entries are sorted based on priority with the top one being higher priority.
Implementation notes:
- New manifest merger is implemented in resource merger which allows manifest merging while retaining placeholders. This is the same impl AGP uses to merge manifests
- Updated
resources.bzl
to consider assets and manifest
Alternative approaches
- Instead of preprocessing, we could create multiple
android_library
targets per folder and have the default rules handle the merging however this is inefficient as well as does not handle manifests properly. The resource merger used here is multiplex compatible and is much more efficient than creating multiple internal targets.
Grazel changes to generate this new format will follow.