Skip to content

Commit

Permalink
Generate resource_configuration_filters for android_binary target…
Browse files Browse the repository at this point in the history
…s and update lint basline
  • Loading branch information
arunkumar9t2 committed Apr 3, 2024
1 parent e874d04 commit f926b40
Show file tree
Hide file tree
Showing 14 changed files with 289 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .bazel/.test.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
test --build_tests_only
test --test_verbose_timeout_warnings
test --test_output=errors # Print test logs for failed tests
test --test_summary=terse # Print information only about unsuccessful tests that were run
test --ui_event_filters=-DEBUG
test --test_summary=terse # Print information only about unsuccessful tests that were run
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "grab_bazel_common",
commit = "7ce14f2063b19b1e700bb9fa51cc944626545450",
commit = "46e70d673d86c1aae4b317f05506601b19c2b4c9",
remote = "https://github.com/grab/grab-bazel-common.git",
)

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ grazel {
rules {
bazelCommon {
gitRepository {
commit = "7ce14f2063b19b1e700bb9fa51cc944626545450"
commit = "46e70d673d86c1aae4b317f05506601b19c2b4c9"
remote = "https://github.com/grab/grab-bazel-common.git"
}
toolchains {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ internal fun StatementsBuilder.androidBinary(
assetsDir: String? = null,
buildConfigData: BuildConfigData,
lintConfigs: LintConfigs? = null,
resConfigFilters: Set<String> = emptySet(),
) {
load("@$GRAB_BAZEL_COMMON//rules:defs.bzl", "android_binary")
rule("android_binary") {
Expand Down Expand Up @@ -168,6 +169,9 @@ internal fun StatementsBuilder.androidBinary(
transform = Assignee::asString
)
}
resConfigFilters.notEmpty {
"resource_configuration_filters" `=` resConfigFilters.quote
}
resources?.let { "resources" `=` resources }
deps.notEmpty {
"deps" `=` array(deps.map(BazelDependency::toString).quote)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ internal data class AndroidBinaryData(
override val tags: List<String> = emptyList(),
override val lintConfigs: LintConfigs,
val manifestValues: Map<String, String?> = emptyMap(),
val resConfigs: Set<String> = emptySet(),
val multidex: Multidex = Multidex.Native,
val dexShards: Int? = null,
val incrementalDexing: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ constructor(

val lintConfigs = lintConfigs(extension.lintOptions, project)

val resourceConfiguration = matchedVariant.variant
.productFlavors
.flatMap { it.resourceConfigurations }
.toSortedSet()

return AndroidBinaryData(
name = project.name,
manifestValues = manifestValues,
Expand All @@ -234,6 +239,7 @@ constructor(
compose = project.hasCompose,
databinding = project.hasDatabinding,
lintConfigs = lintConfigs,
resConfigs = resourceConfiguration
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ internal data class AndroidBinaryTarget(
val debugKey: String? = null,
val dexShards: Int? = null,
val manifestValues: Map<String, String?> = mapOf(),
val resConfigFilters: Set<String> = emptySet(),
val customPackage: String,
val incrementalDexing: Boolean = false,
) : AndroidTarget {
Expand All @@ -121,6 +122,7 @@ internal data class AndroidBinaryTarget(
srcsGlob = srcs,
manifest = manifest,
manifestValues = manifestValues,
resConfigFilters = resConfigFilters,
resources = buildResources(resDirs),
resValuesData = resValuesData,
deps = deps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ constructor(
packageName = androidBinaryData.packageName,
manifest = androidLibraryData.manifestFile,
manifestValues = androidBinaryData.manifestValues,
resConfigFilters = androidBinaryData.resConfigs,
resDirs = androidLibraryData.res,
resValuesData = androidLibraryData.resValuesData,
assetsGlob = androidLibraryData.assets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
android:layout_gravity="center"
android:lineHeight="12dp" />

<TextView
android:id="@+id/text2"
Expand All @@ -48,5 +49,10 @@
android:layout_gravity="center"
app:text="@{viewModel}" />

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@android:color/background_dark"></ImageView>

</LinearLayout>
</layout>
52 changes: 52 additions & 0 deletions sample-android/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ android_binary(
"flavor": "free",
},
},
resource_configuration_filters = [
"en",
"id",
"in",
"ja",
"km",
"ko",
"ms",
"my",
"th",
"vi",
"zh",
],
resources = {
"src/main/res-debug": {
},
Expand Down Expand Up @@ -147,6 +160,19 @@ android_binary(
"flavor": "paid",
},
},
resource_configuration_filters = [
"en",
"id",
"in",
"ja",
"km",
"ko",
"ms",
"my",
"th",
"vi",
"zh",
],
resources = {
"src/main/res-debug": {
},
Expand Down Expand Up @@ -238,6 +264,19 @@ android_binary(
"flavor": "free",
},
},
resource_configuration_filters = [
"en",
"id",
"in",
"ja",
"km",
"ko",
"ms",
"my",
"th",
"vi",
"zh",
],
resources = {
"src/main/res-debug": {
},
Expand Down Expand Up @@ -329,6 +368,19 @@ android_binary(
"flavor": "paid",
},
},
resource_configuration_filters = [
"en",
"id",
"in",
"ja",
"km",
"ko",
"ms",
"my",
"th",
"vi",
"zh",
],
resources = {
"src/main/res-debug": {
},
Expand Down
5 changes: 5 additions & 0 deletions sample-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,24 @@ android {
}

flavorDimensions "service", "release"
def resConfigs = ["en", "id", "in", "km", "ms", "my", "th", "vi", "zh", "ko", "ja"]
productFlavors {
flavor1 {
resourceConfigurations += resConfigs
dimension "service"
}
flavor2 {
resourceConfigurations += resConfigs
dimension "service"
}
free {
resourceConfigurations += resConfigs
dimension "release"
applicationIdSuffix ".free"
resValue("string", "flavor", "free")
}
paid {
resourceConfigurations += resConfigs
dimension "release"
applicationIdSuffix ".paid"
resValue("string", "flavor", "paid")
Expand Down
Loading

0 comments on commit f926b40

Please sign in to comment.