aboutsummaryrefslogtreecommitdiffstats
path: root/build-logic/android-plugins/src/main/kotlin/flavors
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2021-11-29 01:41:24 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2021-12-03 12:59:56 +0530
commitdfee170bd813d267272d0d4a8c64a4cbef965619 (patch)
treef1ca7eeeded257f3957b94136572db9709597a6f /build-logic/android-plugins/src/main/kotlin/flavors
parent553a9e849263f3f86c2fecfdf5b98b8eb93f2fba (diff)
downloadHardenedPass-dfee170bd813d267272d0d4a8c64a4cbef965619.tar.gz
HardenedPass-dfee170bd813d267272d0d4a8c64a4cbef965619.zip
build-logic: add android convention plugins
Diffstat (limited to 'build-logic/android-plugins/src/main/kotlin/flavors')
-rw-r--r--build-logic/android-plugins/src/main/kotlin/flavors/ProductFlavors.kt15
-rw-r--r--build-logic/android-plugins/src/main/kotlin/flavors/SlimTests.kt44
2 files changed, 59 insertions, 0 deletions
diff --git a/build-logic/android-plugins/src/main/kotlin/flavors/ProductFlavors.kt b/build-logic/android-plugins/src/main/kotlin/flavors/ProductFlavors.kt
new file mode 100644
index 00000000..a3185f65
--- /dev/null
+++ b/build-logic/android-plugins/src/main/kotlin/flavors/ProductFlavors.kt
@@ -0,0 +1,15 @@
+/*
+ * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+package flavors
+
+object FlavorDimensions {
+ const val FREE = "free"
+}
+
+object ProductFlavors {
+ const val FREE = "free"
+ const val NON_FREE = "nonFree"
+}
diff --git a/build-logic/android-plugins/src/main/kotlin/flavors/SlimTests.kt b/build-logic/android-plugins/src/main/kotlin/flavors/SlimTests.kt
new file mode 100644
index 00000000..ae14fdab
--- /dev/null
+++ b/build-logic/android-plugins/src/main/kotlin/flavors/SlimTests.kt
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+package flavors
+
+import com.android.build.api.variant.ApplicationAndroidComponentsExtension
+import com.android.build.api.variant.LibraryAndroidComponentsExtension
+import org.gradle.api.Project
+import org.gradle.kotlin.dsl.findByType
+import org.gradle.language.nativeplatform.internal.BuildType
+
+/**
+ * When the "slimTests" project property is provided, disable the unit test tasks on `release` build
+ * type and `nonFree` product flavor to avoid running the same tests repeatedly in different build
+ * variants.
+ *
+ * Examples: `./gradlew test -PslimTests` will run unit tests for `nonFreeDebug` and `debug` build
+ * variants in Android App and Library projects, and all tests in JVM projects.
+ */
+internal fun Project.configureSlimTests() {
+ if (providers.gradleProperty(SLIM_TESTS_PROPERTY).forUseAtConfigurationTime().isPresent) {
+ // disable unit test tasks on the release build type for Android Library projects
+ extensions.findByType<LibraryAndroidComponentsExtension>()?.run {
+ beforeVariants(selector().withBuildType(BuildType.RELEASE.name)) {
+ it.enableUnitTest = false
+ it.enableAndroidTest = false
+ }
+ }
+
+ // disable unit test tasks on the release build type and free flavor for Android Application
+ // projects.
+ extensions.findByType<ApplicationAndroidComponentsExtension>()?.run {
+ beforeVariants(selector().withBuildType(BuildType.RELEASE.name)) { it.enableUnitTest = false }
+ beforeVariants(selector().withFlavor(FlavorDimensions.FREE to ProductFlavors.NON_FREE)) {
+ it.enableUnitTest = false
+ it.enableAndroidTest = false
+ }
+ }
+ }
+}
+
+private const val SLIM_TESTS_PROPERTY = "slimTests"