From 6c4a6ba1809b3833d91db82f4326303e3e3d43af Mon Sep 17 00:00:00 2001 From: "mohammad.khaleghi" Date: Wed, 14 Sep 2022 13:02:01 +0800 Subject: [PATCH 1/2] add flavors support --- build.gradle | 6 +- constants.gradle | 2 +- grazel-gradle-plugin/build.gradle | 2 +- .../grazel/bazel/starlark/BazelDependency.kt | 16 +- .../grab/grazel/bazel/starlark/Functions.kt | 2 +- .../com/grab/grazel/gradle/BuildVariant.kt | 39 +- .../com/grab/grazel/gradle/Configuration.kt | 44 +- .../gradle/dependencies/BuildGraphType.kt | 28 ++ .../gradle/dependencies/Dependencies.kt | 70 ++- .../dependencies/DependenciesGraphsBuilder.kt | 150 ++++-- .../gradle/dependencies/DependencyGraphs.kt | 66 +-- .../GradleDependencyToBazelDependency.kt | 91 ++++ .../android/AndroidBinaryDataExtractor.kt | 7 +- .../migrate/android/AndroidBinaryTarget.kt | 18 +- .../android/AndroidLibraryDataExtractor.kt | 32 +- .../migrate/android/AndroidUnitTestData.kt | 1 + .../android/AndroidUnitTestDataExtractor.kt | 38 +- .../migrate/android/CrashlyticsTarget.kt | 43 ++ .../migrate/android/ManifestValuesBuilder.kt | 10 +- .../builder/AndroidBinaryTargetBuilder.kt | 150 ++++-- .../builder/AndroidLibTargetBuilder.kt | 20 +- .../builder/KtAndroidLibTargetBuilder.kt | 62 +-- .../migrate/builder/KtLibTargetBuilder.kt | 4 +- .../grazel/migrate/common/TestAssociates.kt | 8 +- .../kotlin/KotlinProjectDataExtractor.kt | 11 +- .../kotlin/KotlinUnitTestDataExtractor.kt | 19 +- .../grab/grazel/fake/FakeDependencyGraphs.kt | 8 +- .../DefaultAndroidVariantDataSourceTest.kt | 12 +- .../DefaultDependenciesDataSourceTest.kt | 14 +- .../dependencies/BuildGraphTypeKtTest.kt | 30 ++ .../DefaultDependencyGraphsTest.kt | 39 +- .../grazel/migrate/DaggerWorkspaceRuleTest.kt | 9 + .../grab/grazel/migrate/KotlinTargetsTest.kt | 2 +- ...DefaultAndroidUnitTestDataExtractorTest.kt | 28 +- .../DefaultManifestValuesBuilderTest.kt | 5 + sample-android-flavor/BUILD.bazel | 119 ++++- sample-android-flavor/build.gradle | 4 +- sample-android-lib/BUILD.bazel | 49 -- sample-android-library/BUILD.bazel | 99 ++++ .../build.gradle | 0 .../src/main/AndroidManifest.xml | 0 .../grazel/android/sample/SampleViewModel.kt | 0 .../android/sample/SampleViewModelTest.kt | 0 .../src/test/resources/mock-response.json | 0 .../src/test/resources/test.json | 0 sample-android/BUILD.bazel | 434 ++++++++++++++++-- sample-android/build.gradle | 4 +- .../.gitignore | 0 .../BUILD.bazel | 6 +- .../build.gradle | 0 .../java/com/grab/grazel/sample/HelloWorld.kt | 0 .../java/com/grab/grazel/sample/TestClass1.kt | 0 .../.gitignore | 0 .../BUILD.bazel | 6 +- .../build.gradle | 0 .../grab/grazel/android/flavor/ModuleName.kt | 0 .../com/grab/grazel/flavor1/ModuleNameTest.kt | 0 .../.gitignore | 0 .../BUILD.bazel | 6 +- .../build.gradle | 0 .../grab/grazel/android/flavor/ModuleName.kt | 0 .../com/grab/grazel/flavor2/ModuleNameTest.kt | 0 settings.gradle | 8 +- 63 files changed, 1400 insertions(+), 421 deletions(-) create mode 100644 grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/BuildGraphType.kt create mode 100644 grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/GradleDependencyToBazelDependency.kt create mode 100644 grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/CrashlyticsTarget.kt create mode 100644 grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/dependencies/BuildGraphTypeKtTest.kt delete mode 100644 sample-android-lib/BUILD.bazel create mode 100644 sample-android-library/BUILD.bazel rename {sample-android-lib => sample-android-library}/build.gradle (100%) rename {sample-android-lib => sample-android-library}/src/main/AndroidManifest.xml (100%) rename {sample-android-lib => sample-android-library}/src/main/java/com/grab/grazel/android/sample/SampleViewModel.kt (100%) rename {sample-android-lib => sample-android-library}/src/test/java/com/grab/grazel/android/sample/SampleViewModelTest.kt (100%) rename {sample-android-lib => sample-android-library}/src/test/resources/mock-response.json (100%) rename {sample-android-lib => sample-android-library}/src/test/resources/test.json (100%) rename {sample-kotlin-lib => sample-kotlin-library}/.gitignore (100%) rename {sample-kotlin-lib => sample-kotlin-library}/BUILD.bazel (80%) rename {sample-kotlin-lib => sample-kotlin-library}/build.gradle (100%) rename {sample-kotlin-lib => sample-kotlin-library}/src/main/java/com/grab/grazel/sample/HelloWorld.kt (100%) rename {sample-kotlin-lib => sample-kotlin-library}/src/test/java/com/grab/grazel/sample/TestClass1.kt (100%) rename {sample-lib-flavor1 => sample-library-flavor1}/.gitignore (100%) rename {sample-lib-flavor1 => sample-library-flavor1}/BUILD.bazel (80%) rename {sample-lib-flavor1 => sample-library-flavor1}/build.gradle (100%) rename {sample-lib-flavor1 => sample-library-flavor1}/src/main/java/com/grab/grazel/android/flavor/ModuleName.kt (100%) rename {sample-lib-flavor1 => sample-library-flavor1}/src/test/java/com/grab/grazel/flavor1/ModuleNameTest.kt (100%) rename {sample-lib-flavor2 => sample-library-flavor2}/.gitignore (100%) rename {sample-lib-flavor2 => sample-library-flavor2}/BUILD.bazel (80%) rename {sample-lib-flavor2 => sample-library-flavor2}/build.gradle (100%) rename {sample-lib-flavor2 => sample-library-flavor2}/src/main/java/com/grab/grazel/android/flavor/ModuleName.kt (100%) rename {sample-lib-flavor2 => sample-library-flavor2}/src/test/java/com/grab/grazel/flavor2/ModuleNameTest.kt (100%) diff --git a/build.gradle b/build.gradle index 1c496179..6f78f1b9 100644 --- a/build.gradle +++ b/build.gradle @@ -85,9 +85,9 @@ grazel { multiDexEnabled = true incrementalDexing = true variantFilter { variant -> - if (variant.name != "flavor1Debug" && variant.name != "debug" && variant.name != "debugUnitTest") { - variant.setIgnore(true) - } +// if (variant.name != "flavor1Debug" && variant.name != "debug" && variant.name != "debugUnitTest") { +// variant.setIgnore(true) +// } } features { dataBinding = true diff --git a/constants.gradle b/constants.gradle index cf4de3ca..6588a5cb 100644 --- a/constants.gradle +++ b/constants.gradle @@ -16,7 +16,7 @@ // TODO migrate to version catalogs ext { groupId = "com.grab.grazel" - versionName = "0.4.0-alpha15" + versionName = "0.4.0-alpha16" kotlinVersion = "1.6.10" agpVersion = "7.1.2" diff --git a/grazel-gradle-plugin/build.gradle b/grazel-gradle-plugin/build.gradle index 968cfb6f..342604ca 100644 --- a/grazel-gradle-plugin/build.gradle +++ b/grazel-gradle-plugin/build.gradle @@ -26,7 +26,7 @@ buildscript { plugins { id "java-gradle-plugin" - id "org.gradle.kotlin.kotlin-dsl" version "2.1.4" + id "org.gradle.kotlin.kotlin-dsl" version "2.1.6" id "com.gradle.plugin-publish" version "0.14.0" id "maven-publish" id "idea" diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/starlark/BazelDependency.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/starlark/BazelDependency.kt index d9565571..2875bd01 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/starlark/BazelDependency.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/starlark/BazelDependency.kt @@ -17,20 +17,26 @@ package com.grab.grazel.bazel.starlark import com.grab.grazel.gradle.buildTargetName +import com.grab.grazel.gradle.dependencies.BuildGraphType import org.gradle.api.Project import org.gradle.api.artifacts.Dependency - sealed class BazelDependency { - data class ProjectDependency(val project: Project) : BazelDependency() { + data class ProjectDependency( + val dependencyProject: Project, + val suffix: String = "" + ) : BazelDependency() { override fun toString(): String { - val relativeProjectPath = project.rootProject.relativePath(project.projectDir) + val relativeProjectPath = + dependencyProject.rootProject.relativePath(dependencyProject.projectDir) return if (relativeProjectPath.contains("/")) { val path = relativeProjectPath.split("/").dropLast(1).joinToString("/") - "//" + path + "/" + project.buildTargetName() + "//" + path + "/" + dependencyProject.buildTargetName() + ":" + + dependencyProject.buildTargetName() + suffix } else { - "//" + project.buildTargetName() + "//" + dependencyProject.buildTargetName() + ":" + + dependencyProject.buildTargetName() + suffix } } } diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/starlark/Functions.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/starlark/Functions.kt index 3876da26..3306e4aa 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/starlark/Functions.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/bazel/starlark/Functions.kt @@ -20,7 +20,7 @@ import com.grab.grazel.bazel.rules.Visibility import com.grab.grazel.bazel.rules.rule import java.io.PrintWriter -class FunctionStatement( +data class FunctionStatement( val name: String, private val params: List, private val multilineParams: Boolean = false diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/BuildVariant.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/BuildVariant.kt index f283a6f4..9c031ea2 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/BuildVariant.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/BuildVariant.kt @@ -21,6 +21,7 @@ import com.android.build.gradle.LibraryExtension import com.android.build.gradle.api.BaseVariant import com.android.build.gradle.api.TestVariant import com.android.build.gradle.api.UnitTestVariant +import com.android.builder.model.BuildType import com.android.builder.model.ProductFlavor import com.grab.grazel.extension.DefaultVariantFilter import com.grab.grazel.extension.VariantFilter @@ -86,8 +87,13 @@ internal class DefaultAndroidVariantDataSource( internal interface AndroidVariantsExtractor { fun getUnitTestVariants(project: Project): Set fun getTestVariants(project: Project): Set - fun getVariants(project: Project): Set + fun getVariants( + project: Project, + configurationScope: ConfigurationScope? = null + ): Set + fun getFlavors(project: Project): Set + fun getBuildTypes(project: Project): Set } @@ -96,11 +102,24 @@ internal class DefaultAndroidVariantsExtractor @Inject constructor() : AndroidVa private val Project.isAndroidAppOrDynFeature get() = project.isAndroidApplication || project.isAndroidDynamicFeature - override fun getVariants(project: Project): Set { - return when { - project.isAndroidAppOrDynFeature -> project.the().applicationVariants - project.isAndroidLibrary -> project.the().libraryVariants - else -> emptySet() + override fun getVariants( + project: Project, + configurationScope: ConfigurationScope? + ): Set { + return when (configurationScope) { + ConfigurationScope.TEST -> { + getUnitTestVariants(project) + } + ConfigurationScope.ANDROID_TEST -> { + getTestVariants(project) + } + else -> { + when { + project.isAndroidAppOrDynFeature -> project.the().applicationVariants + project.isAndroidLibrary -> project.the().libraryVariants + else -> emptySet() + } + } } } @@ -127,6 +146,14 @@ internal class DefaultAndroidVariantsExtractor @Inject constructor() : AndroidVa else -> emptySet() } } + + override fun getBuildTypes(project: Project): Set { + return when { + project.isAndroidAppOrDynFeature -> project.the().buildTypes + project.isAndroidLibrary -> project.the().buildTypes + else -> emptySet() + } + } } internal fun AndroidVariantDataSource.getMigratableBuildVariants(project: Project): List = diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/Configuration.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/Configuration.kt index 12338776..7f55959e 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/Configuration.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/Configuration.kt @@ -16,13 +16,16 @@ package com.grab.grazel.gradle +import com.android.build.gradle.api.BaseVariant +import com.android.build.gradle.internal.variant.BaseVariantFactory import com.grab.grazel.GrazelExtension +import com.grab.grazel.gradle.dependencies.BuildGraphType import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import javax.inject.Inject import javax.inject.Singleton -internal enum class ConfigurationScope { +enum class ConfigurationScope { BUILD, TEST, ANDROID_TEST; } @@ -41,14 +44,22 @@ internal interface ConfigurationDataSource { */ fun resolvedConfigurations( project: Project, - vararg scopes: ConfigurationScope + vararg buildGraphTypes: BuildGraphType ): Sequence /** * Return a sequence of the configurations filtered out by the ignore flavors, build variants and the configuration scopes * If the scopes is empty, the build scope will be used by default. */ - fun configurations(project: Project, vararg scopes: ConfigurationScope): Sequence + fun configurations( + project: Project, + vararg scope: ConfigurationScope + ): Sequence + + fun isThisConfigurationBelongsToThisVariants( + vararg variants: BaseVariant?, + configuration: Configuration + ): Boolean } @Singleton @@ -69,14 +80,14 @@ internal class DefaultConfigurationDataSource @Inject constructor( .filter { !it.name.contains("_internal_aapt2_binary") } .filter { !it.name.contains("archives") } .filter { !it.isDynamicConfiguration() } // Remove when Grazel support dynamic-feature plugin - .filter { + .filter { configuration -> when { - scopes.isEmpty() -> it.isNotTest() // If the scopes is empty, the build scope will be used by default. + scopes.isEmpty() -> configuration.isNotTest() // If the scopes is empty, the build scope will be used by default. else -> scopes.any { scope -> when (scope) { - ConfigurationScope.TEST -> !it.isAndroidTest() && it.isUnitTest() - ConfigurationScope.ANDROID_TEST -> !it.isUnitTest() - ConfigurationScope.BUILD -> it.isNotTest() + ConfigurationScope.TEST -> !configuration.isAndroidTest() && configuration.isUnitTest() + ConfigurationScope.ANDROID_TEST -> !configuration.isUnitTest() + ConfigurationScope.BUILD -> configuration.isNotTest() } } } @@ -90,11 +101,24 @@ internal class DefaultConfigurationDataSource @Inject constructor( } } + override fun isThisConfigurationBelongsToThisVariants( + vararg variants: BaseVariant?, + configuration: Configuration + ) = variants.any { variant -> + variant == null || + variant.compileConfiguration.hierarchy.contains(configuration) || + variant.runtimeConfiguration.hierarchy.contains(configuration) || + variant.annotationProcessorConfiguration.hierarchy.contains(configuration) + } + override fun resolvedConfigurations( project: Project, - vararg scopes: ConfigurationScope + vararg buildGraphTypes: BuildGraphType ): Sequence { - return configurations(project, *scopes).filter { it.isCanBeResolved } + return configurations( + project, + *buildGraphTypes.map { it.configurationScope }.toTypedArray() + ).filter { it.isCanBeResolved } } } diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/BuildGraphType.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/BuildGraphType.kt new file mode 100644 index 00000000..fd383083 --- /dev/null +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/BuildGraphType.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2022 Grabtaxi Holdings PTE LTD (GRAB) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.grab.grazel.gradle.dependencies + +import com.android.build.gradle.api.BaseVariant +import com.grab.grazel.gradle.ConfigurationScope + +data class BuildGraphType( + val configurationScope: ConfigurationScope, + val variant: BaseVariant? = null +) + +private val HUMPS = "(?<=.)(?=\\p{Upper})".toRegex() +fun String.variantNameSuffix() = "-${replace(HUMPS, "-").toLowerCase()}" diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/Dependencies.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/Dependencies.kt index 9f710964..584ca528 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/Dependencies.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/Dependencies.kt @@ -20,6 +20,7 @@ import com.grab.grazel.GrazelExtension import com.grab.grazel.bazel.rules.MavenInstallArtifact import com.grab.grazel.bazel.rules.MavenInstallArtifact.Exclusion.SimpleExclusion import com.grab.grazel.di.qualifiers.RootProject +import com.grab.grazel.gradle.AndroidVariantsExtractor import com.grab.grazel.gradle.ConfigurationDataSource import com.grab.grazel.gradle.ConfigurationScope import com.grab.grazel.gradle.RepositoryDataSource @@ -83,7 +84,10 @@ internal interface DependenciesDataSource { /** * Return the project's maven dependencies before the resolution strategy and any other custom substitution by Gradle */ - fun mavenDependencies(project: Project, vararg scopes: ConfigurationScope): Sequence + fun mavenDependencies( + project: Project, + vararg buildGraphTypes: BuildGraphType + ): Sequence /** * Return the project's project (module) dependencies before the resolution strategy and any other custom @@ -142,7 +146,8 @@ internal class DefaultDependenciesDataSource @Inject constructor( private val configurationDataSource: ConfigurationDataSource, private val artifactsConfig: ArtifactsConfig, private val repositoryDataSource: RepositoryDataSource, - private val dependencyResolutionService: GradleProvider + private val dependencyResolutionService: GradleProvider, + private val androidVariantsExtractor: AndroidVariantsExtractor ) : DependenciesDataSource { private val configurationScopes by lazy { grazelExtension.configurationScopes() } @@ -174,10 +179,12 @@ internal class DefaultDependenciesDataSource @Inject constructor( .toMap() } - private fun Project.resolvableConfigurations(): Sequence { - return configurationDataSource - .resolvedConfigurations(this, *configurationScopes) - } + private fun Project.buildGraphTypes() = + configurationScopes.flatMap { configurationScope -> + androidVariantsExtractor.getVariants(this).map { variant -> + BuildGraphType(configurationScope, variant) + } + } /** * Given a group, name and version will update version with following properties @@ -228,7 +235,12 @@ internal class DefaultDependenciesDataSource @Inject constructor( // Filter out configurations we are interested in. val configurations = projects .asSequence() - .flatMap { configurationDataSource.configurations(it, *configurationScopes) } + .flatMap { project -> + configurationDataSource.configurations( + project, + *configurationScopes + ) + } .toList() // Calculate all the external artifacts @@ -243,7 +255,12 @@ internal class DefaultDependenciesDataSource @Inject constructor( // (Perf fix) - collecting all projects' forced modules is costly, hence take the first sub project // TODO Provide option to consider all forced versions backed by a flag. val forcedVersions = sequenceOf(rootProject.subprojects.first()) - .flatMap { configurationDataSource.configurations(it, *configurationScopes) } + .flatMap { project -> + configurationDataSource.configurations( + project, + *configurationScopes + ) + } .let(::collectForcedVersions) return (DEFAULT_MAVEN_ARTIFACTS + externalArtifacts + forcedVersions) @@ -290,14 +307,25 @@ internal class DefaultDependenciesDataSource @Inject constructor( override fun mavenDependencies( project: Project, - vararg scopes: ConfigurationScope - ): Sequence = declaredDependencies(project, *scopes) - .map { it.second } - .filter { it.group != null && !DEP_GROUP_EMBEDDED_BY_RULES.contains(it.group) } - .filter { - val artifact = MavenArtifact(it.group, it.name) - !artifact.isExcluded && !artifact.isIgnored - }.filter { it !is ProjectDependency } + vararg buildGraphTypes: BuildGraphType + ): Sequence = + declaredDependencies(project, *buildGraphTypes.map { it.configurationScope }.toTypedArray()) + .filter { (configuration, _) -> + if (buildGraphTypes.isEmpty()) { + true + } else { + configurationDataSource.isThisConfigurationBelongsToThisVariants( + *buildGraphTypes.map { it.variant }.toTypedArray(), + configuration = configuration + ) + } + } + .map { it.second } + .filter { it.group != null && !DEP_GROUP_EMBEDDED_BY_RULES.contains(it.group) } + .filter { + val artifact = MavenArtifact(it.group, it.name) + !artifact.isExcluded && !artifact.isIgnored + }.filter { it !is ProjectDependency } override fun projectDependencies( project: Project, vararg scopes: ConfigurationScope @@ -343,7 +371,10 @@ internal class DefaultDependenciesDataSource @Inject constructor( private fun Project.externalResolvedDependencies() = dependencyResolutionService.get() .resolve( project = this, - configurations = resolvableConfigurations() + configurations = configurationDataSource.resolvedConfigurations( + this, + *buildGraphTypes().toTypedArray() + ) ) /** @@ -362,7 +393,10 @@ internal class DefaultDependenciesDataSource @Inject constructor( * @return Sequence of [DefaultResolvedDependency] in the first level */ private fun Project.firstLevelModuleDependencies(): Sequence { - return resolvableConfigurations() + return configurationDataSource.resolvedConfigurations( + this, + *buildGraphTypes().toTypedArray() + ) .map { it.resolvedConfiguration.lenientConfiguration } .flatMap { try { diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependenciesGraphsBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependenciesGraphsBuilder.kt index a819baac..847c0f77 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependenciesGraphsBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependenciesGraphsBuilder.kt @@ -20,54 +20,132 @@ import com.google.common.graph.ImmutableValueGraph import com.google.common.graph.MutableValueGraph import com.google.common.graph.ValueGraphBuilder import com.grab.grazel.di.qualifiers.RootProject +import com.grab.grazel.extension.TestExtension +import com.grab.grazel.gradle.AndroidVariantsExtractor +import com.grab.grazel.gradle.ConfigurationDataSource import com.grab.grazel.gradle.ConfigurationScope +import com.grab.grazel.gradle.isAndroid import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import javax.inject.Inject internal class DependenciesGraphsBuilder @Inject constructor( @param:RootProject private val rootProject: Project, - private val dependenciesDataSource: DependenciesDataSource + private val dependenciesDataSource: DependenciesDataSource, + private val configurationDataSource: ConfigurationDataSource, + private val androidVariantsExtractor: AndroidVariantsExtractor, + private val testExtension: TestExtension ) { - fun build(): DependencyGraphs { - val buildGraph: MutableValueGraph = - ValueGraphBuilder - .directed() - .allowsSelfLoops(false) - .expectedNodeCount(rootProject.subprojects.size) - .build() - val testGraph: MutableValueGraph = - ValueGraphBuilder - .directed() - .allowsSelfLoops(false) - .expectedNodeCount(rootProject.subprojects.size) - .build() - rootProject.subprojects - .forEach { sourceProject -> - buildGraph.addNode(sourceProject) - testGraph.addNode(sourceProject) - dependenciesDataSource.projectDependencies(sourceProject, ConfigurationScope.BUILD) + fun build(): DependencyGraphs { + val buildGraphs: MutableMap> = + mutableMapOf() + buildList { + add(ConfigurationScope.BUILD) + if (testExtension.enableTestMigration) { + add(ConfigurationScope.TEST) + } + }.forEach { configurationScope -> + rootProject.subprojects.forEach { sourceProject -> + addProjectAsNodeToAllOfItsVariantsGraphs( + sourceProject, + configurationScope, + buildGraphs + ) + addEdges(sourceProject, configurationScope, buildGraphs) + dependenciesDataSource.projectDependencies(sourceProject, configurationScope) .forEach { (configuration, projectDependency) -> - buildGraph.putEdgeValue( - sourceProject, - projectDependency.dependencyProject, - configuration - ) + androidVariantsExtractor.getVariants(sourceProject, configurationScope) + .forEach { variant -> + if (configurationDataSource.isThisConfigurationBelongsToThisVariants( + variant, + configuration = configuration + ) + ) { + buildGraphs.putEdgeValue( + BuildGraphType(configurationScope, variant), + sourceProject, + projectDependency.dependencyProject, + configuration + ) + } + } } + } + } - dependenciesDataSource.projectDependencies(sourceProject, ConfigurationScope.TEST) - .forEach { (configuration, projectDependency) -> - testGraph.putEdgeValue( - sourceProject, - projectDependency.dependencyProject, - configuration - ) + val immutableBuildGraphs = buildGraphs + .withDefault { buildGraph(0) } + .mapValues { (_, graph) -> + ImmutableValueGraph.copyOf(graph) + } + + return DefaultDependencyGraphs(buildGraphs = immutableBuildGraphs) + } + + private fun addEdges( + project: Project, + configurationScope: ConfigurationScope, + graph: MutableMap>, + ) { + dependenciesDataSource.projectDependencies(project, configurationScope) + .forEach { (configuration, projectDependency) -> + androidVariantsExtractor.getVariants(project, configurationScope) + .forEach { variant -> + if (variant.compileConfiguration.hierarchy.contains(configuration)) { + graph.putEdgeValue( + BuildGraphType(configurationScope, variant), + project, + projectDependency.dependencyProject, + configuration + ) + } } } - return DefaultDependencyGraphs( - buildGraph = ImmutableValueGraph.copyOf(buildGraph), - testGraph = ImmutableValueGraph.copyOf(testGraph) - ) } -} \ No newline at end of file + + private fun addProjectAsNodeToAllOfItsVariantsGraphs( + sourceProject: Project, + configurationScope: ConfigurationScope, + buildGraphs: MutableMap> + ) { + if (sourceProject.isAndroid) { + androidVariantsExtractor.getVariants(sourceProject, configurationScope) + .forEach { variant -> + buildGraphs.addNode(BuildGraphType(configurationScope, variant), sourceProject) + } + } else { + buildGraphs.addNode(BuildGraphType(configurationScope, null), sourceProject) + } + } +} + +private fun MutableMap>.putEdgeValue( + buildGraphType: BuildGraphType, + sourceProject: Project, + dependencyProject: Project, + configuration: Configuration +) { + computeIfAbsent(buildGraphType) { + buildGraph(sourceProject.subprojects.size) + } + get(buildGraphType)!!.putEdgeValue(sourceProject, dependencyProject, configuration) +} + +private fun MutableMap>.addNode( + buildGraphType: BuildGraphType, + sourceProject: Project +) { + computeIfAbsent(buildGraphType) { + buildGraph(sourceProject.subprojects.size) + } + get(buildGraphType)!!.addNode(sourceProject) +} + +fun buildGraph(size: Int): MutableValueGraph { + return ValueGraphBuilder + .directed() + .allowsSelfLoops(false) + .expectedNodeCount(size) + .build() +} diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependencyGraphs.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependencyGraphs.kt index cad76b54..1e48f1fa 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependencyGraphs.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependencyGraphs.kt @@ -3,43 +3,32 @@ package com.grab.grazel.gradle.dependencies import com.google.common.graph.Graphs import com.google.common.graph.ImmutableValueGraph import com.grab.grazel.bazel.starlark.BazelDependency -import com.grab.grazel.gradle.ConfigurationScope import org.gradle.api.Project import org.gradle.api.artifacts.Configuration internal interface DependencyGraphs { - fun nodes(vararg scopes: ConfigurationScope): Set + fun nodes(vararg buildGraphType: BuildGraphType): Set fun dependenciesSubGraph( project: Project, - scopes: Array = ConfigurationScope.values() + vararg buildGraphTypes: BuildGraphType ): Set fun directDependencies( project: Project, - scopes: Array = ConfigurationScope.values() + buildGraphType: BuildGraphType ): Set } -internal fun DependencyGraphs.directProjectDependencies( - project: Project, - vararg scopes: ConfigurationScope -) = directDependencies(project, *scopes).map { BazelDependency.ProjectDependency(it) } - internal class DefaultDependencyGraphs( - private val buildGraph: ImmutableValueGraph, - private val testGraph: ImmutableValueGraph + private val buildGraphs: Map> ) : DependencyGraphs { - override fun nodes(vararg scopes: ConfigurationScope): Set { + override fun nodes(vararg buildGraphType: BuildGraphType): Set { return when { - scopes.isEmpty() -> buildGraph.nodes() + testGraph.nodes() + buildGraphType.isEmpty() -> buildGraphs.values.flatMap { it.nodes() }.toSet() else -> { - scopes.flatMap { - when (it) { - ConfigurationScope.BUILD -> buildGraph.nodes() - ConfigurationScope.TEST -> testGraph.nodes() - else -> emptySet() - } + buildGraphType.flatMap { + buildGraphs.getValue(it).nodes() }.toSet() } } @@ -47,39 +36,20 @@ internal class DefaultDependencyGraphs( override fun dependenciesSubGraph( project: Project, - scopes: Array + vararg buildGraphTypes: BuildGraphType ): Set = - scopes.flatMap { - when (it) { - ConfigurationScope.BUILD -> Graphs.reachableNodes(buildGraph.asGraph(), project) - ConfigurationScope.TEST -> Graphs.reachableNodes(testGraph.asGraph(), project) - else -> emptySet() + if (buildGraphTypes.isEmpty()) { + buildGraphs.values.flatMap { + Graphs.reachableNodes(it.asGraph(), project) + } + } else { + buildGraphTypes.flatMap { buildGraphType -> + Graphs.reachableNodes(buildGraphs.getValue(buildGraphType).asGraph(), project) } }.toSet() override fun directDependencies( project: Project, - scopes: Array - ): Set = - scopes.flatMap { - when (it) { - ConfigurationScope.BUILD -> buildGraph.successors(project) - ConfigurationScope.TEST -> testGraph.successors(project) - else -> emptySet() - } - }.toSet() -} - -internal fun DependencyGraphs.dependenciesSubGraph( - project: Project, - vararg scopes: ConfigurationScope -): Set { - return dependenciesSubGraph(project, arrayOf(*scopes)) -} - -internal fun DependencyGraphs.directDependencies( - project: Project, - vararg scopes: ConfigurationScope -): Set { - return directDependencies(project, arrayOf(*scopes)) + buildGraphType: BuildGraphType + ): Set = buildGraphs.getValue(buildGraphType).successors(project).toSet() } \ No newline at end of file diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/GradleDependencyToBazelDependency.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/GradleDependencyToBazelDependency.kt new file mode 100644 index 00000000..efac898f --- /dev/null +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/GradleDependencyToBazelDependency.kt @@ -0,0 +1,91 @@ +/* + * Copyright 2022 Grabtaxi Holdings PTE LTD (GRAB) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.grab.grazel.gradle.dependencies + +import com.android.build.gradle.api.BaseVariant +import com.grab.grazel.bazel.starlark.BazelDependency +import com.grab.grazel.gradle.AndroidVariantsExtractor +import com.grab.grazel.gradle.isAndroid +import org.gradle.api.Project +import java.lang.IllegalStateException +import javax.inject.Inject + +internal class GradleDependencyToBazelDependency @Inject constructor( + private val androidVariantsExtractor: AndroidVariantsExtractor +) { + + /** + * [variant] can only be null if and only if the [project] is a Java/Kotlin project + */ + fun map( + project: Project, + dependency: Project, + variant: BaseVariant? = null + ): BazelDependency.ProjectDependency { + + return if (project.isAndroid) { + if (variant == null) { + throw IllegalStateException( + "please provide the variant for the android project=${project.name}" + ) + } + if (dependency.isAndroid) {// project is an android project, dependent is also + val dependentVariants = androidVariantsExtractor.getVariants(dependency) + + if (dependentVariants.firstOrNull { dependentVariant -> + dependentVariant.name == variant.name + } != null + ) { + BazelDependency.ProjectDependency(dependency, variant.name.variantNameSuffix()) + } else { + if (isThereAnyCompatibleDependentBuildType(dependentVariants, variant)) { + BazelDependency.ProjectDependency( + dependency, + variant.buildType.name.variantNameSuffix() + ) + } else { + throw IllegalStateException( + "${project.name} with variant=${variant.name}" + + " depends on ${dependency.name} which doesn't have that variant " + + "${dependentVariants.map { it.name }}" + ) + } + } + } else {// project is an android project, dependent is NOT + BazelDependency.ProjectDependency(dependency) + } + } else {// Kotlin/Java Library + if (dependency.isAndroid) { + throw IllegalStateException( + "${project.name} is not android project but it " + + "depends on ${dependency.name} which is an android project this is not a " + + "valid dependency" + ) + } else { + BazelDependency.ProjectDependency(dependency) + } + } + } + + + private fun isThereAnyCompatibleDependentBuildType( + dependentVariants: Set, + variant: BaseVariant + ) = dependentVariants.firstOrNull { dependentVariant -> + dependentVariant.name == variant.buildType.name + } != null +} \ No newline at end of file diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidBinaryDataExtractor.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidBinaryDataExtractor.kt index 7f14b74e..625d4760 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidBinaryDataExtractor.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidBinaryDataExtractor.kt @@ -17,6 +17,9 @@ package com.grab.grazel.migrate.android import com.android.build.gradle.BaseExtension +import com.android.build.gradle.api.BaseVariant +import com.android.build.gradle.internal.variant.BaseVariantFactory +import com.android.builder.model.Variant import com.grab.grazel.GrazelExtension import com.grab.grazel.bazel.rules.DATABINDING_ARTIFACTS import com.grab.grazel.bazel.rules.Multidex @@ -34,7 +37,7 @@ import javax.inject.Singleton internal interface AndroidBinaryDataExtractor { - fun extract(project: Project, androidLibraryData: AndroidLibraryData): AndroidBinaryData + fun extract(project: Project, variant: BaseVariant, androidLibraryData: AndroidLibraryData): AndroidBinaryData } @Singleton @@ -47,11 +50,13 @@ internal class DefaultAndroidBinaryDataExtractor @Inject constructor( override fun extract( project: Project, + variant: BaseVariant, androidLibraryData: AndroidLibraryData ): AndroidBinaryData { val extension = project.extensions.getByType() val manifestValues = manifestValuesBuilder.build( project, + variant, extension.defaultConfig, androidLibraryData.packageName ) diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidBinaryTarget.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidBinaryTarget.kt index 0ac240b1..db3dbc78 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidBinaryTarget.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidBinaryTarget.kt @@ -16,15 +16,14 @@ package com.grab.grazel.migrate.android +import com.grab.grazel.bazel.rules.GOOGLE_SERVICES_XML import com.grab.grazel.bazel.rules.Multidex import com.grab.grazel.bazel.rules.Visibility import com.grab.grazel.bazel.rules.androidBinary -import com.grab.grazel.bazel.rules.crashlyticsAndroidLibrary -import com.grab.grazel.bazel.rules.googleServicesXml import com.grab.grazel.bazel.starlark.BazelDependency import com.grab.grazel.bazel.starlark.Statement -import com.grab.grazel.bazel.starlark.asString import com.grab.grazel.bazel.starlark.statements +import com.grab.grazel.bazel.starlark.toStatement import com.grab.grazel.migrate.BazelBuildTarget internal data class AndroidBinaryTarget( @@ -54,18 +53,7 @@ internal data class AndroidBinaryTarget( var resourceFiles = buildResources(res, ResValues(), customResourceSets, name) var finalDeps = deps if (googleServicesJson != null) { - val googleServicesXmlRes = googleServicesXml( - packageName = packageName, - googleServicesJson = googleServicesJson - ) - resourceFiles += googleServicesXmlRes - if (hasCrashlytics && buildId != null) { - finalDeps += crashlyticsAndroidLibrary( - packageName = packageName, - buildId = buildId, - resourceFiles = googleServicesXmlRes.asString() - ) - } + resourceFiles += GOOGLE_SERVICES_XML.toStatement() } androidBinary( diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidLibraryDataExtractor.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidLibraryDataExtractor.kt index 239ee3e1..a17a6927 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidLibraryDataExtractor.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidLibraryDataExtractor.kt @@ -18,6 +18,7 @@ package com.grab.grazel.migrate.android import com.android.build.gradle.BaseExtension import com.android.build.gradle.api.AndroidSourceSet +import com.android.build.gradle.api.BaseVariant import com.grab.grazel.GrazelExtension import com.grab.grazel.bazel.rules.ANDROIDX_GROUP import com.grab.grazel.bazel.rules.ANNOTATION_ARTIFACT @@ -26,10 +27,10 @@ import com.grab.grazel.bazel.rules.DATABINDING_GROUP import com.grab.grazel.bazel.starlark.BazelDependency import com.grab.grazel.gradle.AndroidVariantDataSource import com.grab.grazel.gradle.ConfigurationScope +import com.grab.grazel.gradle.dependencies.BuildGraphType import com.grab.grazel.gradle.dependencies.DependenciesDataSource import com.grab.grazel.gradle.dependencies.DependencyGraphs -import com.grab.grazel.gradle.dependencies.directProjectDependencies -import com.grab.grazel.gradle.getMigratableBuildVariants +import com.grab.grazel.gradle.dependencies.GradleDependencyToBazelDependency import com.grab.grazel.gradle.hasDatabinding import com.grab.grazel.gradle.isAndroid import com.grab.grazel.migrate.dependencies.calculateDirectDependencyTags @@ -44,6 +45,7 @@ import javax.inject.Singleton internal interface AndroidLibraryDataExtractor { fun extract( project: Project, + variant: BaseVariant, sourceSetType: SourceSetType = SourceSetType.JAVA ): AndroidLibraryData } @@ -55,33 +57,41 @@ internal class DefaultAndroidLibraryDataExtractor @Inject constructor( private val dependencyGraphsProvider: Lazy, private val androidManifestParser: AndroidManifestParser, private val grazelExtension: GrazelExtension, + private val gradleDependencyToBazelDependency: GradleDependencyToBazelDependency ) : AndroidLibraryDataExtractor { private val projectDependencyGraphs get() = dependencyGraphsProvider.get() - override fun extract(project: Project, sourceSetType: SourceSetType): AndroidLibraryData { + override fun extract( + project: Project, + variant: BaseVariant, + sourceSetType: SourceSetType + ): AndroidLibraryData { if (project.isAndroid) { val extension = project.extensions.getByType() val deps = projectDependencyGraphs - .directProjectDependencies(project, ConfigurationScope.BUILD) + + .directDependencies( + project, + BuildGraphType(ConfigurationScope.BUILD, variant) + ).map { dependent -> + gradleDependencyToBazelDependency.map(project, dependent, variant) + } + dependenciesDataSource.collectMavenDeps(project) + project.kotlinParcelizeDeps() - return project.extract(extension, sourceSetType, deps) + return project.extract(variant, extension, sourceSetType, deps) } else { throw IllegalArgumentException("${project.name} is not an Android project") } } private fun Project.extract( + variant: BaseVariant, extension: BaseExtension, sourceSetType: SourceSetType = SourceSetType.JAVA, deps: List ): AndroidLibraryData { // Only consider source sets from migratable variants - val migratableSourceSets = variantDataSource - .getMigratableBuildVariants(this) - .asSequence() - .flatMap { it.sourceSets.asSequence() } + val migratableSourceSets = variant.sourceSets .filterIsInstance() .toList() @@ -197,8 +207,8 @@ internal class DefaultAndroidLibraryDataExtractor @Inject constructor( } internal fun DependenciesDataSource.collectMavenDeps( - project: Project, vararg scopes: ConfigurationScope -): List = mavenDependencies(project, *scopes) + project: Project, vararg buildGraphTypes: BuildGraphType +): List = mavenDependencies(project, *buildGraphTypes) .filter { if (project.hasDatabinding) { it.group != DATABINDING_GROUP && (it.group != ANDROIDX_GROUP && it.name != ANNOTATION_ARTIFACT) diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidUnitTestData.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidUnitTestData.kt index 6fc02be9..7abc052e 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidUnitTestData.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidUnitTestData.kt @@ -1,5 +1,6 @@ package com.grab.grazel.migrate.android +import com.android.build.gradle.api.BaseVariant import com.grab.grazel.bazel.starlark.BazelDependency data class AndroidUnitTestData( diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidUnitTestDataExtractor.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidUnitTestDataExtractor.kt index e480a8de..276f249b 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidUnitTestDataExtractor.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/AndroidUnitTestDataExtractor.kt @@ -16,14 +16,17 @@ package com.grab.grazel.migrate.android import com.android.build.gradle.api.AndroidSourceSet +import com.android.build.gradle.api.BaseVariant import com.grab.grazel.GrazelExtension import com.grab.grazel.bazel.starlark.BazelDependency import com.grab.grazel.extension.KotlinExtension import com.grab.grazel.gradle.AndroidVariantDataSource import com.grab.grazel.gradle.ConfigurationScope +import com.grab.grazel.gradle.dependencies.BuildGraphType import com.grab.grazel.gradle.dependencies.DependenciesDataSource import com.grab.grazel.gradle.dependencies.DependencyGraphs -import com.grab.grazel.gradle.dependencies.directProjectDependencies +import com.grab.grazel.gradle.dependencies.GradleDependencyToBazelDependency +import com.grab.grazel.gradle.dependencies.variantNameSuffix import com.grab.grazel.gradle.getMigratableBuildVariants import com.grab.grazel.gradle.getMigratableUnitTestVariants import com.grab.grazel.migrate.common.calculateTestAssociate @@ -39,7 +42,7 @@ import javax.inject.Singleton internal const val FORMAT_UNIT_TEST_NAME = "%s-test" internal interface AndroidUnitTestDataExtractor { - fun extract(project: Project): AndroidUnitTestData + fun extract(project: Project, variant: BaseVariant): AndroidUnitTestData } @Singleton @@ -49,19 +52,18 @@ internal class DefaultAndroidUnitTestDataExtractor @Inject constructor( private val dependencyGraphsProvider: Lazy, private val androidManifestParser: AndroidManifestParser, private val grazelExtension: GrazelExtension, + private val gradleDependencyToBazelDependency: GradleDependencyToBazelDependency ) : AndroidUnitTestDataExtractor { private val projectDependencyGraphs get() = dependencyGraphsProvider.get() private val kotlinExtension: KotlinExtension get() = grazelExtension.rules.kotlin - override fun extract(project: Project): AndroidUnitTestData { + override fun extract(project: Project, variant: BaseVariant): AndroidUnitTestData { val name = FORMAT_UNIT_TEST_NAME.format(project.name) - val migratableSourceSets = variantDataSource - .getMigratableUnitTestVariants(project) + val migratableSourceSets = variant.sourceSets .asSequence() - .flatMap { it.sourceSets.asSequence() } .filterIsInstance() val srcs = project.unitTestSources(migratableSourceSets).toList() @@ -69,20 +71,31 @@ internal class DefaultAndroidUnitTestDataExtractor @Inject constructor( val resources = project.unitTestResources(migratableSourceSets).toList() - val associate = calculateTestAssociate(project) + val associate = calculateTestAssociate(project, targetVariantSuffix(variant)) val deps = projectDependencyGraphs - .directProjectDependencies(project, ConfigurationScope.TEST) + - dependenciesDataSource.collectMavenDeps(project, ConfigurationScope.TEST) + + .directDependencies( + project, + BuildGraphType(ConfigurationScope.TEST, variant) + ).map { dependent -> + gradleDependencyToBazelDependency.map(project, dependent, variant) + } + + dependenciesDataSource.collectMavenDeps( + project, + BuildGraphType(ConfigurationScope.TEST, variant) + ) + project.kotlinParcelizeDeps() + - BazelDependency.ProjectDependency(project) + BazelDependency.ProjectDependency( + project, + targetVariantSuffix(variant) + ) val tags = if (kotlinExtension.enabledTransitiveReduction) { deps.calculateDirectDependencyTags(name) } else emptyList() return AndroidUnitTestData( - name = name, + name = "$name${variant.name.variantNameSuffix()}", srcs = srcs, additionalSrcSets = additionalSrcSets, deps = deps, @@ -93,6 +106,9 @@ internal class DefaultAndroidUnitTestDataExtractor @Inject constructor( ) } + private fun targetVariantSuffix(variant: BaseVariant) = + ("${variant.flavorName}${variant.buildType.name.capitalize()}".variantNameSuffix()) + private fun Project.unitTestSources( sourceSets: Sequence, sourceSetType: SourceSetType = SourceSetType.JAVA_KOTLIN diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/CrashlyticsTarget.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/CrashlyticsTarget.kt new file mode 100644 index 00000000..bd20bfab --- /dev/null +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/CrashlyticsTarget.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Grabtaxi Holdings PTE LTD (GRAB) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.grab.grazel.migrate.android + +import com.grab.grazel.bazel.rules.crashlyticsAndroidLibrary +import com.grab.grazel.bazel.rules.googleServicesXml +import com.grab.grazel.bazel.starlark.Statement +import com.grab.grazel.bazel.starlark.asString +import com.grab.grazel.migrate.BazelTarget + +class CrashlyticsTarget( + override val name: String = "crashlytics_lib", + val packageName: String, + private val buildId: String, + private val googleServicesJson: String +) : BazelTarget { + + override fun statements(): List = com.grab.grazel.bazel.starlark.statements { + val googleServicesXmlRes = googleServicesXml( + packageName = packageName, + googleServicesJson = googleServicesJson + ) + crashlyticsAndroidLibrary( + packageName = packageName, + buildId = buildId, + resourceFiles = googleServicesXmlRes.asString() + ) + } +} \ No newline at end of file diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/ManifestValuesBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/ManifestValuesBuilder.kt index 18606ae5..eb2c01be 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/ManifestValuesBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/android/ManifestValuesBuilder.kt @@ -17,11 +17,12 @@ package com.grab.grazel.migrate.android import com.android.build.gradle.BaseExtension +import com.android.build.gradle.api.BaseVariant import com.android.build.gradle.internal.dsl.DefaultConfig import com.grab.grazel.gradle.AndroidVariantDataSource import com.grab.grazel.gradle.ConfigurationScope +import com.grab.grazel.gradle.dependencies.BuildGraphType import com.grab.grazel.gradle.dependencies.DependencyGraphs -import com.grab.grazel.gradle.dependencies.dependenciesSubGraph import com.grab.grazel.gradle.getMigratableBuildVariants import com.grab.grazel.gradle.isAndroid import dagger.Lazy @@ -32,6 +33,7 @@ import javax.inject.Inject internal interface ManifestValuesBuilder { fun build( project: Project, + variant: BaseVariant, defaultConfig: DefaultConfig, packageName: String ): Map @@ -44,12 +46,16 @@ internal class DefaultManifestValuesBuilder @Inject constructor( private val projectDependencyGraphs get() = dependencyGraphsProvider.get() override fun build( project: Project, + variant: BaseVariant, defaultConfig: DefaultConfig, packageName: String ): Map { // Collect manifest values for all dependant projects val libraryFlavorManifestPlaceHolders = - projectDependencyGraphs.dependenciesSubGraph(project, ConfigurationScope.BUILD) + projectDependencyGraphs.dependenciesSubGraph( + project, + BuildGraphType(ConfigurationScope.BUILD, variant) + ) .asSequence() .filter(Project::isAndroid) .flatMap { depProject -> diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidBinaryTargetBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidBinaryTargetBuilder.kt index da83467a..1a190204 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidBinaryTargetBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidBinaryTargetBuilder.kt @@ -16,6 +16,8 @@ package com.grab.grazel.migrate.builder +import com.grab.grazel.gradle.AndroidVariantsExtractor +import com.grab.grazel.gradle.dependencies.variantNameSuffix import com.grab.grazel.gradle.isAndroidApplication import com.grab.grazel.gradle.isKotlin import com.grab.grazel.migrate.BazelTarget @@ -23,6 +25,7 @@ import com.grab.grazel.migrate.TargetBuilder import com.grab.grazel.migrate.android.AndroidBinaryDataExtractor import com.grab.grazel.migrate.android.AndroidBinaryTarget import com.grab.grazel.migrate.android.AndroidLibraryDataExtractor +import com.grab.grazel.migrate.android.CrashlyticsTarget import com.grab.grazel.migrate.android.DefaultAndroidBinaryDataExtractor import com.grab.grazel.migrate.android.DefaultKeyStoreExtractor import com.grab.grazel.migrate.android.DefaultManifestValuesBuilder @@ -37,7 +40,6 @@ import org.gradle.api.Project import javax.inject.Inject import javax.inject.Singleton - @Module internal interface AndroidBinaryTargetBuilderModule { @Binds @@ -57,7 +59,8 @@ internal interface AndroidBinaryTargetBuilderModule { @Singleton internal class AndroidBinaryTargetBuilder @Inject constructor( private val androidLibDataExtractor: AndroidLibraryDataExtractor, - private val androidBinDataExtractor: AndroidBinaryDataExtractor + private val androidBinDataExtractor: AndroidBinaryDataExtractor, + private val androidVariantsExtractor: AndroidVariantsExtractor ) : TargetBuilder { override fun build(project: Project): List { @@ -69,62 +72,107 @@ internal class AndroidBinaryTargetBuilder @Inject constructor( project: Project, intermediateTargets: List ): List { - var androidLibData = androidLibDataExtractor.extract(project) - val deps = if (project.isKotlin) { - // For kotlin project, don't duplicate Maven dependencies - intermediateTargets.map { it.toBazelDependency() } - } else { - intermediateTargets.map { it.toBazelDependency() } + androidLibData.deps - } - androidLibData = androidLibData.copy(deps = deps) - val binaryData = androidBinDataExtractor.extract(project, androidLibData) - - return intermediateTargets + AndroidBinaryTarget( - name = binaryData.name, - deps = androidLibData.deps + binaryData.deps, - srcs = androidLibData.srcs, - multidex = binaryData.multidex, - debugKey = binaryData.debugKey, - dexShards = binaryData.dexShards, - incrementalDexing = binaryData.incrementalDexing, - enableDataBinding = binaryData.hasDatabinding, - packageName = androidLibData.packageName, - manifest = androidLibData.manifestFile, - manifestValues = binaryData.manifestValues, - res = androidLibData.res, - resValues = androidLibData.resValues, - customResourceSets = androidLibData.extraRes, - assetsGlob = androidLibData.assets, - assetsDir = androidLibData.assetsDir, - buildId = binaryData.buildId, - googleServicesJson = binaryData.googleServicesJson, - hasCrashlytics = binaryData.hasCrashlytics - ) + var targets = androidVariantsExtractor.getVariants(project) + .flatMap { variant -> + var androidLibData = androidLibDataExtractor.extract(project, variant) + val deps = if (project.isKotlin) { + // For kotlin project, don't duplicate Maven dependencies + intermediateTargets.filter { it.name.endsWith(variant.name.variantNameSuffix()) } + .map { it.toBazelDependency() } + } else { + intermediateTargets.filter { it.name.endsWith(variant.name.variantNameSuffix()) } + .map { it.toBazelDependency() } + androidLibData.deps + } + + androidLibData = androidLibData.copy(deps = deps) + val binaryData = androidBinDataExtractor.extract(project, variant, androidLibData) + + listOf( + AndroidBinaryTarget( + name = "${binaryData.name}${variant.name.variantNameSuffix()}", + deps = androidLibData.deps + binaryData.deps, + srcs = androidLibData.srcs, + multidex = binaryData.multidex, + debugKey = binaryData.debugKey, + dexShards = binaryData.dexShards, + incrementalDexing = binaryData.incrementalDexing, + enableDataBinding = binaryData.hasDatabinding, + packageName = androidLibData.packageName, + manifest = androidLibData.manifestFile, + manifestValues = binaryData.manifestValues, + res = androidLibData.res, + resValues = androidLibData.resValues, + customResourceSets = androidLibData.extraRes, + assetsGlob = androidLibData.assets, + assetsDir = androidLibData.assetsDir, + buildId = binaryData.buildId, + googleServicesJson = binaryData.googleServicesJson, + hasCrashlytics = binaryData.hasCrashlytics + ) + ) + } + intermediateTargets + + targets = addCrashlyticsTarget(targets) + + return targets + } + + private fun addCrashlyticsTarget(targets: List): List { + var resultTargets = targets + val androidTargetWithCrashlytics = resultTargets.firstOrNull { bazelTarget -> + bazelTarget is AndroidBinaryTarget && + bazelTarget.hasCrashlytics && + bazelTarget.buildId != null && + bazelTarget.googleServicesJson != null + } as AndroidBinaryTarget? + if (androidTargetWithCrashlytics != null) { + val crashlyticsTarget = with(androidTargetWithCrashlytics) { + CrashlyticsTarget( + packageName = packageName, + buildId = buildId!!, + googleServicesJson = googleServicesJson!! + ) + } + + resultTargets = resultTargets.map { bazelTarget -> + if (bazelTarget is AndroidBinaryTarget) { + bazelTarget.copy(deps = bazelTarget.deps + crashlyticsTarget.toBazelDependency()) + } else { + bazelTarget + } + }.toMutableList() + resultTargets.add(0, crashlyticsTarget) + } + return resultTargets } private fun buildKtAndroidTargets(project: Project): List { return buildList { - val androidProjectData = androidLibDataExtractor.extract( - project = project, - sourceSetType = SourceSetType.JAVA_KOTLIN - ).copy(name = "${project.name}_lib", hasDatabinding = false) - var deps = androidProjectData.deps - - with(androidProjectData) { - toBuildConfigTarget().also { - deps += it.toBazelDependency() - add(it) + androidVariantsExtractor.getVariants(project).forEach { variant -> + val androidProjectData = androidLibDataExtractor.extract( + project = project, + sourceSetType = SourceSetType.JAVA_KOTLIN, + variant = variant + ).copy(name = "${project.name}_lib", hasDatabinding = false) + var deps = androidProjectData.deps + + with(androidProjectData) { + toBuildConfigTarget(variant.name.variantNameSuffix()).also { + deps += it.toBazelDependency() + add(it) + } } - } - androidProjectData - .copy( - deps = deps, - tags = emptyList() // Don't generate classpath reduction tags for final binary target - ) - .toKtLibraryTarget() - ?.also { add(it) } + androidProjectData + .copy( + name = "${androidProjectData.name}${variant.name.variantNameSuffix()}", + deps = deps, + tags = emptyList() // Don't generate classpath reduction tags for final binary target + ) + .toKtLibraryTarget() + ?.also { add(it) } + } } } diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidLibTargetBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidLibTargetBuilder.kt index 0f17db05..480487be 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidLibTargetBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidLibTargetBuilder.kt @@ -17,6 +17,7 @@ package com.grab.grazel.migrate.builder import com.grab.grazel.extension.TestExtension +import com.grab.grazel.gradle.AndroidVariantsExtractor import com.grab.grazel.gradle.isAndroid import com.grab.grazel.gradle.isAndroidApplication import com.grab.grazel.gradle.isKotlin @@ -45,17 +46,20 @@ internal interface AndroidLibTargetBuilderModule { internal class AndroidLibTargetBuilder @Inject constructor( private val projectDataExtractor: AndroidLibraryDataExtractor, private val unitTestDataExtractor: AndroidUnitTestDataExtractor, - private val testExtension: TestExtension + private val testExtension: TestExtension, + private val androidVariantsExtractor: AndroidVariantsExtractor ) : TargetBuilder { override fun build(project: Project): List { - return if (testExtension.enableTestMigration) { - listOf( - projectDataExtractor.extract(project).toAndroidLibTarget(), - unitTestDataExtractor.extract(project).toUnitTestTarget() - ) - } else { - listOf(projectDataExtractor.extract(project).toAndroidLibTarget()) + return androidVariantsExtractor.getVariants(project).flatMap { variant -> + if (testExtension.enableTestMigration) { + listOf( + projectDataExtractor.extract(project, variant).toAndroidLibTarget(), + unitTestDataExtractor.extract(project, variant).toUnitTestTarget() + ) + } else { + listOf(projectDataExtractor.extract(project, variant).toAndroidLibTarget()) + } } } diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtAndroidLibTargetBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtAndroidLibTargetBuilder.kt index 4685e753..6cad7e26 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtAndroidLibTargetBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtAndroidLibTargetBuilder.kt @@ -18,8 +18,9 @@ package com.grab.grazel.migrate.builder import com.grab.grazel.bazel.rules.KotlinProjectType import com.grab.grazel.bazel.rules.Visibility -import com.grab.grazel.extension.KotlinExtension import com.grab.grazel.extension.TestExtension +import com.grab.grazel.gradle.AndroidVariantsExtractor +import com.grab.grazel.gradle.dependencies.variantNameSuffix import com.grab.grazel.gradle.isAndroid import com.grab.grazel.gradle.isAndroidApplication import com.grab.grazel.gradle.isKotlin @@ -45,7 +46,6 @@ import org.gradle.api.Project import javax.inject.Inject import javax.inject.Singleton - @Module internal interface KtAndroidLibTargetBuilderModule { @Binds @@ -67,34 +67,42 @@ internal interface KtAndroidLibTargetBuilderModule { internal class KtAndroidLibTargetBuilder @Inject constructor( private val projectDataExtractor: AndroidLibraryDataExtractor, private val unitTestDataExtractor: AndroidUnitTestDataExtractor, - private val kotlinExtension: KotlinExtension, + private val androidVariantsExtractor: AndroidVariantsExtractor, private val testExtension: TestExtension ) : TargetBuilder { override fun build(project: Project): List { return mutableListOf().apply { - val projectData = projectDataExtractor.extract( - project, sourceSetType = SourceSetType.JAVA_KOTLIN - ) - var deps = projectData.deps - with(projectData) { - toAarResTarget()?.also { add(it) } - toBuildConfigTarget().also { - deps += it.toBazelDependency() - add(it) + androidVariantsExtractor.getVariants(project).forEach { variant -> + val projectData = projectDataExtractor.extract( + project, + sourceSetType = SourceSetType.JAVA_KOTLIN, + variant = variant + ) + var deps = projectData.deps + with(projectData) { + toAarResTarget(variant.name.variantNameSuffix())?.also { add(it) } + toBuildConfigTarget(variant.name.variantNameSuffix()).also { + deps += it.toBazelDependency() + add(it) + } + } + projectData + .copy(name = projectData.name + variant.name.variantNameSuffix(), deps = deps) + .toKtLibraryTarget() + ?.also { add(it) } + + + } + if (testExtension.enableTestMigration) { + androidVariantsExtractor.getUnitTestVariants(project).forEach { variant -> + add( + unitTestDataExtractor + .extract(project, variant) + .toUnitTestTarget() + ) } } - projectData - .copy(deps = deps) - .toKtLibraryTarget() - ?.also { add(it) } - - if (testExtension.enableTestMigration) - add( - unitTestDataExtractor - .extract(project) - .toUnitTestTarget() - ) } } @@ -123,11 +131,11 @@ internal fun AndroidLibraryData.toKtLibraryTarget(): KtLibraryTarget? = ) } else null -internal fun AndroidLibraryData.toAarResTarget(): AndroidLibraryTarget? { +internal fun AndroidLibraryData.toAarResTarget(variantName: String): AndroidLibraryTarget? { return if (res.isNotEmpty() && !hasDatabinding) { // For hybrid builds we need separate AAR for resources // When it is a pure resource module, keep the res target as the main target - val targetName = if (srcs.isEmpty()) name else "${name}-res" + val targetName = if (srcs.isEmpty()) name else "${name}-res$variantName" AndroidLibraryTarget( name = targetName, packageName = packageName, @@ -143,9 +151,9 @@ internal fun AndroidLibraryData.toAarResTarget(): AndroidLibraryTarget? { } else null } -internal fun AndroidLibraryData.toBuildConfigTarget(): BuildConfigTarget { +internal fun AndroidLibraryData.toBuildConfigTarget(variantName: String): BuildConfigTarget { return BuildConfigTarget( - name = "$name-build-config", + name = "$name$variantName-build-config", packageName = packageName, strings = buildConfigData.strings, booleans = buildConfigData.booleans, diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtLibTargetBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtLibTargetBuilder.kt index 1f6ea96c..5340a31b 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtLibTargetBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtLibTargetBuilder.kt @@ -18,6 +18,7 @@ package com.grab.grazel.migrate.builder import com.grab.grazel.extension.KotlinExtension import com.grab.grazel.extension.TestExtension +import com.grab.grazel.gradle.AndroidVariantsExtractor import com.grab.grazel.gradle.isAndroid import com.grab.grazel.gradle.isKotlin import com.grab.grazel.migrate.BazelTarget @@ -33,6 +34,7 @@ import dagger.Binds import dagger.Module import dagger.multibindings.IntoSet import org.gradle.api.Project +import org.gradle.api.internal.BuildType import javax.inject.Inject import javax.inject.Singleton @@ -59,9 +61,9 @@ internal class KtLibTargetBuilder @Inject constructor( ) : TargetBuilder { override fun build(project: Project): List { val projectData = projectDataExtractor.extract(project) - val unitTestData = kotlinUnitTestDataExtractor.extract(project) return if (testExtension.enableTestMigration) { + val unitTestData = kotlinUnitTestDataExtractor.extract(project) listOf( projectData.toKtLibraryTarget(kotlinExtension.enabledTransitiveReduction), unitTestData.toUnitTestTarget() diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/common/TestAssociates.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/common/TestAssociates.kt index ebcb6b9b..f5c11f2a 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/common/TestAssociates.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/common/TestAssociates.kt @@ -32,17 +32,17 @@ import org.gradle.api.Project * @param project The project for which associate needs to be calculated * @return The associate that was calculated, null otherwise */ -internal fun calculateTestAssociate(project: Project): BazelDependency? { +internal fun calculateTestAssociate(project: Project, suffix: String = ""): BazelDependency? { return when { project.isKotlin && project.hasDatabinding -> { return BazelDependency.StringDependency( - """${ProjectDependency(project)}:${project.buildTargetName()}-kotlin""" + """${ProjectDependency(project, suffix)}-kotlin""" ) } project.isKotlin && project.isAndroid -> return BazelDependency.StringDependency( - """${ProjectDependency(project)}:${project.buildTargetName()}_kt""" + """${ProjectDependency(project, suffix)}_kt""" ) - project.isKotlin -> return ProjectDependency(project) + project.isKotlin -> return ProjectDependency(project, suffix) else -> null } } \ No newline at end of file diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectDataExtractor.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectDataExtractor.kt index 954f8d5b..e7acddeb 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectDataExtractor.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinProjectDataExtractor.kt @@ -21,9 +21,10 @@ import com.grab.grazel.bazel.rules.KOTLIN_PARCELIZE_TARGET import com.grab.grazel.bazel.starlark.BazelDependency import com.grab.grazel.extension.KotlinExtension import com.grab.grazel.gradle.ConfigurationScope +import com.grab.grazel.gradle.dependencies.BuildGraphType import com.grab.grazel.gradle.dependencies.DependenciesDataSource import com.grab.grazel.gradle.dependencies.DependencyGraphs -import com.grab.grazel.gradle.dependencies.directProjectDependencies +import com.grab.grazel.gradle.dependencies.GradleDependencyToBazelDependency import com.grab.grazel.gradle.hasKotlinAndroidExtensions import com.grab.grazel.migrate.android.SourceSetType import com.grab.grazel.migrate.android.collectMavenDeps @@ -48,6 +49,7 @@ internal class DefaultKotlinProjectDataExtractor @Inject constructor( private val dependenciesDataSource: DependenciesDataSource, private val dependencyGraphsProvider: Lazy, private val grazelExtension: GrazelExtension, + private val gradleDependencyToBazelDependency: GradleDependencyToBazelDependency ) : KotlinProjectDataExtractor { private val kotlinExtension: KotlinExtension get() = grazelExtension.rules.kotlin @@ -61,7 +63,12 @@ internal class DefaultKotlinProjectDataExtractor @Inject constructor( val resources = project.kotlinSources(sourceSets, SourceSetType.RESOURCES).toList() val deps = projectDependencyGraphs - .directProjectDependencies(project, ConfigurationScope.BUILD) + + .directDependencies( + project, + BuildGraphType(ConfigurationScope.BUILD) + ).map { dependent -> + gradleDependencyToBazelDependency.map(project, dependent, null) + } + dependenciesDataSource.collectMavenDeps(project) + project.androidJarDeps() + project.kotlinParcelizeDeps() diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinUnitTestDataExtractor.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinUnitTestDataExtractor.kt index dbf052fd..a0fe4f3d 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinUnitTestDataExtractor.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/kotlin/KotlinUnitTestDataExtractor.kt @@ -20,9 +20,10 @@ import com.grab.grazel.GrazelExtension import com.grab.grazel.bazel.starlark.BazelDependency import com.grab.grazel.extension.KotlinExtension import com.grab.grazel.gradle.ConfigurationScope +import com.grab.grazel.gradle.dependencies.BuildGraphType import com.grab.grazel.gradle.dependencies.DependenciesDataSource import com.grab.grazel.gradle.dependencies.DependencyGraphs -import com.grab.grazel.gradle.dependencies.directProjectDependencies +import com.grab.grazel.gradle.dependencies.GradleDependencyToBazelDependency import com.grab.grazel.migrate.android.FORMAT_UNIT_TEST_NAME import com.grab.grazel.migrate.android.SourceSetType import com.grab.grazel.migrate.android.collectMavenDeps @@ -48,7 +49,8 @@ internal interface KotlinUnitTestDataExtractor { internal class DefaultKotlinUnitTestDataExtractor @Inject constructor( private val dependenciesDataSource: DependenciesDataSource, private val dependencyGraphsProvider: Lazy, - private val grazelExtension: GrazelExtension + private val grazelExtension: GrazelExtension, + private val gradleDependencyToBazelDependency: GradleDependencyToBazelDependency ) : KotlinUnitTestDataExtractor { private val kotlinExtension: KotlinExtension get() = grazelExtension.rules.kotlin @@ -67,12 +69,19 @@ internal class DefaultKotlinUnitTestDataExtractor @Inject constructor( val deps: List = buildList { addAll( - projectDependencyGraphs.directProjectDependencies( + projectDependencyGraphs.directDependencies( project, - ConfigurationScope.TEST + BuildGraphType(ConfigurationScope.TEST) + ).map { dependent -> + gradleDependencyToBazelDependency.map(project, dependent) + } + ) + addAll( + dependenciesDataSource.collectMavenDeps( + project, + BuildGraphType(ConfigurationScope.TEST) ) ) - addAll(dependenciesDataSource.collectMavenDeps(project, ConfigurationScope.TEST)) addAll(project.kotlinParcelizeDeps()) if (projectDependency.toString() != associate.toString()) { add(projectDependency) diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeDependencyGraphs.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeDependencyGraphs.kt index caa80f71..61114a7a 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeDependencyGraphs.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeDependencyGraphs.kt @@ -1,6 +1,6 @@ package com.grab.grazel.fake -import com.grab.grazel.gradle.ConfigurationScope +import com.grab.grazel.gradle.dependencies.BuildGraphType import com.grab.grazel.gradle.dependencies.DependencyGraphs import org.gradle.api.Project @@ -9,16 +9,16 @@ internal class FakeDependencyGraphs( private val dependenciesSubGraph: Set = emptySet(), private val nodes: Set = emptySet() ) : DependencyGraphs { - override fun nodes(vararg scopes: ConfigurationScope): Set = nodes + override fun nodes(vararg buildGraphType: BuildGraphType): Set = nodes override fun dependenciesSubGraph( project: Project, - scopes: Array + vararg buildGraphTypes: BuildGraphType ): Set = dependenciesSubGraph override fun directDependencies( project: Project, - scopes: Array + buildGraphTypes: BuildGraphType? ): Set = directDeps } \ No newline at end of file diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultAndroidVariantDataSourceTest.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultAndroidVariantDataSourceTest.kt index 6c82437d..7158f92a 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultAndroidVariantDataSourceTest.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultAndroidVariantDataSourceTest.kt @@ -17,6 +17,7 @@ package com.grab.grazel.gradle import com.android.build.gradle.api.BaseVariant +import com.android.builder.model.BuildType import com.android.builder.model.ProductFlavor import com.grab.grazel.GrazelExtension import com.grab.grazel.GrazelPluginTest @@ -82,8 +83,11 @@ class DefaultAndroidVariantDataSourceTest : GrazelPluginTest() { } } -private class FakeAndroidVariantsExtractor : AndroidVariantsExtractor { - override fun getVariants(project: Project): Set = setOf( +class FakeAndroidVariantsExtractor : AndroidVariantsExtractor { + override fun getVariants( + project: Project, + configurationScope: ConfigurationScope? + ): Set = setOf( FakeVariant(DEBUG_FLAVOR1, FLAVOR1), FakeVariant(DEBUG_FLAVOR2, FLAVOR2), FakeVariant(RELEASE_FLAVOR1, FLAVOR1), @@ -93,6 +97,10 @@ private class FakeAndroidVariantsExtractor : AndroidVariantsExtractor { override fun getFlavors(project: Project): Set = listOf(FLAVOR1, FLAVOR2).map { FakeProductFlavor(it) }.toSet() + override fun getBuildTypes(project: Project): Set { + return getVariants(project).map { it.buildType }.toSet() + } + override fun getUnitTestVariants(project: Project): Set = emptySet() override fun getTestVariants(project: Project): Set = emptySet() diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultDependenciesDataSourceTest.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultDependenciesDataSourceTest.kt index ffda4578..1e438ad7 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultDependenciesDataSourceTest.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultDependenciesDataSourceTest.kt @@ -69,6 +69,7 @@ class DefaultDependenciesDataSourceTest : GrazelPluginTest() { private lateinit var repositoryDataSource: RepositoryDataSource private lateinit var fakeVariantDataSource: FakeAndroidVariantDataSource private lateinit var configurationDataSource: DefaultConfigurationDataSource + private lateinit var androidVariantsExtractor: AndroidVariantsExtractor @Before fun setUp() { @@ -81,6 +82,7 @@ class DefaultDependenciesDataSourceTest : GrazelPluginTest() { fakeVariantDataSource = FakeAndroidVariantDataSource() configurationDataSource = DefaultConfigurationDataSource(fakeVariantDataSource) repositoryDataSource = DefaultRepositoryDataSource(rootProject) + androidVariantsExtractor = FakeAndroidVariantsExtractor() dependenciesDataSource = DefaultDependenciesDataSource( rootProject = rootProject, @@ -88,7 +90,8 @@ class DefaultDependenciesDataSourceTest : GrazelPluginTest() { artifactsConfig = ArtifactsConfig(ignoredList = listOf(KOTLIN_STDLIB)), repositoryDataSource = repositoryDataSource, dependencyResolutionService = DefaultDependencyResolutionService.register(rootProject), - grazelExtension = GrazelExtension(rootProject) + grazelExtension = GrazelExtension(rootProject), + androidVariantsExtractor = androidVariantsExtractor ) } @@ -217,7 +220,8 @@ class DefaultDependenciesDataSourceTest : GrazelPluginTest() { artifactsConfig = ArtifactsConfig(ignoredList = listOf(DAGGER.split(":%s").first())), repositoryDataSource = repositoryDataSource, dependencyResolutionService = DefaultDependencyResolutionService.register(rootProject), - grazelExtension = GrazelExtension(rootProject) + grazelExtension = GrazelExtension(rootProject), + androidVariantsExtractor = androidVariantsExtractor ) assertTrue( "hasIgnoredArtifacts returns true when project contains any ignored artifacts", @@ -246,7 +250,8 @@ class DefaultDependenciesDataSourceTest : GrazelPluginTest() { artifactsConfig = ArtifactsConfig(excludedList = listOf(excludedDagger)), repositoryDataSource = repositoryDataSource, dependencyResolutionService = DefaultDependencyResolutionService.register(rootProject), - grazelExtension = GrazelExtension(rootProject) + grazelExtension = GrazelExtension(rootProject), + androidVariantsExtractor = androidVariantsExtractor ) val resolvedArtifacts = dependenciesDataSource .resolvedArtifactsFor(listOf(rootProject, subProject)) @@ -285,7 +290,8 @@ class DefaultDependenciesDataSourceTest : GrazelPluginTest() { artifactsConfig = ArtifactsConfig(excludedList = listOf()), repositoryDataSource = repositoryDataSource, dependencyResolutionService = DefaultDependencyResolutionService.register(rootProject), - grazelExtension = GrazelExtension(rootProject) + grazelExtension = GrazelExtension(rootProject), + androidVariantsExtractor = DefaultAndroidVariantsExtractor() ) val dependencyArtifactMap = dependenciesDataSource.dependencyArtifactMap( rootProject, diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/dependencies/BuildGraphTypeKtTest.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/dependencies/BuildGraphTypeKtTest.kt new file mode 100644 index 00000000..9ca4b6f4 --- /dev/null +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/dependencies/BuildGraphTypeKtTest.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2022 Grabtaxi Holdings PTE LTD (GRAB) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.grab.grazel.gradle.dependencies + +import org.junit.Assert.* +import org.junit.Test + +class BuildGraphTypeKtTest{ + + @Test + fun test(){ + assertEquals("-app-gps-debug","appGpsDebug".variantNameSuffix()) + assertEquals("-app-gps-debug","AppGpsDebug".variantNameSuffix()) + } + +} \ No newline at end of file diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/dependencies/DefaultDependencyGraphsTest.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/dependencies/DefaultDependencyGraphsTest.kt index f94ab34f..67ee79cb 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/dependencies/DefaultDependencyGraphsTest.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/dependencies/DefaultDependencyGraphsTest.kt @@ -19,8 +19,10 @@ class DefaultDependencyGraphsTest { private val projectE = FakeProject("E") private val dependenciesGraphs = DefaultDependencyGraphs( - testGraph = buildTestGraphs(), - buildGraph = buildBuildGraphs() + buildGraphs = mapOf( + BuildGraphType(ConfigurationScope.BUILD) to buildBuildGraphs(), + BuildGraphType(ConfigurationScope.TEST) to buildTestGraphs() + ) ) @Test @@ -36,11 +38,14 @@ class DefaultDependencyGraphsTest { fun nodesShouldReturnTheCorrectItemsBaseOnScopes() { val buildNodes = setOf(projectA, projectB, projectC) val testNodes = setOf(projectA, projectB, projectC, projectD, projectE) - assertEquals(buildNodes, dependenciesGraphs.nodes(ConfigurationScope.BUILD)) - assertEquals(testNodes, dependenciesGraphs.nodes(ConfigurationScope.TEST)) + assertEquals(buildNodes, dependenciesGraphs.nodes(BuildGraphType(ConfigurationScope.BUILD))) + assertEquals(testNodes, dependenciesGraphs.nodes(BuildGraphType(ConfigurationScope.TEST))) assertEquals( testNodes + buildNodes, - dependenciesGraphs.nodes(ConfigurationScope.TEST, ConfigurationScope.BUILD) + dependenciesGraphs.nodes( + BuildGraphType(ConfigurationScope.TEST), + BuildGraphType(ConfigurationScope.BUILD) + ) ) } @@ -49,20 +54,7 @@ class DefaultDependencyGraphsTest { val directDepsFromAWithBuildScope = setOf(projectB, projectC) assertEquals( directDepsFromAWithBuildScope, - dependenciesGraphs.directDependencies(projectA, ConfigurationScope.BUILD) - ) - } - - @Test - fun directDependenciesShouldReturnDirectDepsFromBuildAndTestScope() { - val directDepsFromAWithBuildAndTestScope = setOf(projectB, projectC, projectE) - assertEquals( - directDepsFromAWithBuildAndTestScope, - dependenciesGraphs.directDependencies( - projectA, - ConfigurationScope.BUILD, - ConfigurationScope.TEST - ) + dependenciesGraphs.directDependencies(projectA, BuildGraphType(ConfigurationScope.BUILD)) ) } @@ -80,7 +72,10 @@ class DefaultDependencyGraphsTest { val expectDeps = setOf(projectB, projectC) assertEquals( expectDeps, - dependenciesGraphs.dependenciesSubGraph(projectB, ConfigurationScope.BUILD) + dependenciesGraphs.dependenciesSubGraph( + projectB, + BuildGraphType(ConfigurationScope.BUILD) + ) ) } @@ -91,8 +86,8 @@ class DefaultDependencyGraphsTest { expectDeps, dependenciesGraphs.dependenciesSubGraph( projectB, - ConfigurationScope.BUILD, - ConfigurationScope.TEST + BuildGraphType(ConfigurationScope.BUILD), + BuildGraphType(ConfigurationScope.TEST) ) ) } diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/DaggerWorkspaceRuleTest.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/DaggerWorkspaceRuleTest.kt index 09679c28..029d7641 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/DaggerWorkspaceRuleTest.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/DaggerWorkspaceRuleTest.kt @@ -1,5 +1,6 @@ package com.grab.grazel.migrate +import com.android.build.gradle.LibraryExtension import com.google.common.truth.Truth import com.grab.grazel.GrazelExtension import com.grab.grazel.bazel.starlark.asString @@ -8,6 +9,7 @@ import com.grab.grazel.di.DaggerGrazelComponent import com.grab.grazel.gradle.ANDROID_LIBRARY_PLUGIN import com.grab.grazel.gradle.KOTLIN_ANDROID_PLUGIN import com.grab.grazel.migrate.internal.WorkspaceBuilder +import com.grab.grazel.util.doEvaluate import org.gradle.api.Project import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.dependencies @@ -34,6 +36,11 @@ class DaggerWorkspaceRuleTest { apply(ANDROID_LIBRARY_PLUGIN) apply(KOTLIN_ANDROID_PLUGIN) } + extensions.configure { + defaultConfig { + compileSdkVersion(30) + } + } repositories { mavenCentral() google() @@ -49,6 +56,8 @@ class DaggerWorkspaceRuleTest { subProject.dependencies { add("implementation", "com.google.dagger:dagger:$daggerTag") } + subProject.doEvaluate() + rootProject.configure { rules { dagger { diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/KotlinTargetsTest.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/KotlinTargetsTest.kt index c7258533..3dcef644 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/KotlinTargetsTest.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/KotlinTargetsTest.kt @@ -115,7 +115,7 @@ class KotlinTargetsTest { val generatedStatements = projectBazelFileBuilder.build().asString() Truth.assertThat(generatedStatements).apply { contains("kt_db_android_library") - contains("""name = "android-library"""") + contains("""name = "android-library-debug"""") contains(""""src/main/res/activity_main.xml",""") contains("""custom_package = "com.example.androidlibrary"""") contains("""manifest = "src/main/AndroidManifest.xml"""") diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultAndroidUnitTestDataExtractorTest.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultAndroidUnitTestDataExtractorTest.kt index a693cfd8..5e533461 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultAndroidUnitTestDataExtractorTest.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultAndroidUnitTestDataExtractorTest.kt @@ -21,15 +21,21 @@ import com.google.common.truth.Truth import com.grab.grazel.GrazelExtension import com.grab.grazel.GrazelPluginTest import com.grab.grazel.buildProject +import com.grab.grazel.fake.DEBUG_FLAVOR1 +import com.grab.grazel.fake.FLAVOR1 import com.grab.grazel.fake.FakeDependencyGraphs +import com.grab.grazel.fake.FakeVariant import com.grab.grazel.gradle.ANDROID_LIBRARY_PLUGIN +import com.grab.grazel.gradle.AndroidVariantsExtractor import com.grab.grazel.gradle.DefaultAndroidVariantDataSource import com.grab.grazel.gradle.DefaultConfigurationDataSource import com.grab.grazel.gradle.DefaultRepositoryDataSource +import com.grab.grazel.gradle.FakeAndroidVariantsExtractor import com.grab.grazel.gradle.KOTLIN_ANDROID_PLUGIN import com.grab.grazel.gradle.dependencies.ArtifactsConfig import com.grab.grazel.gradle.dependencies.DefaultDependenciesDataSource import com.grab.grazel.gradle.dependencies.DefaultDependencyResolutionService +import com.grab.grazel.gradle.dependencies.GradleDependencyToBazelDependency import com.grab.grazel.util.doEvaluate import org.gradle.api.Project import org.gradle.kotlin.dsl.configure @@ -47,6 +53,9 @@ class DefaultAndroidUnitTestDataExtractorTest : GrazelPluginTest() { private lateinit var subProjectDir: File private lateinit var defaultAndroidUnitTestDataExtractor: DefaultAndroidUnitTestDataExtractor + private lateinit var androidVariantsExtractor: FakeAndroidVariantsExtractor + private lateinit var gradleDependencyToBazelDependency: GradleDependencyToBazelDependency + private val fakeVariant = FakeVariant(DEBUG_FLAVOR1, FLAVOR1) @get:Rule val temporaryFolder = TemporaryFolder() @@ -71,7 +80,9 @@ class DefaultAndroidUnitTestDataExtractorTest : GrazelPluginTest() { } } } - + androidVariantsExtractor = FakeAndroidVariantsExtractor() + gradleDependencyToBazelDependency = + GradleDependencyToBazelDependency(androidVariantsExtractor) File(subProjectDir, "src/main/AndroidManifest.xml").apply { parentFile.mkdirs() createNewFile() @@ -95,6 +106,7 @@ class DefaultAndroidUnitTestDataExtractorTest : GrazelPluginTest() { repositoryDataSource = repositoryDataSource, dependencyResolutionService = DefaultDependencyResolutionService.register(rootProject), grazelExtension = GrazelExtension(rootProject), + androidVariantsExtractor = androidVariantsExtractor ) val dependencyGraphs = FakeDependencyGraphs() @@ -105,7 +117,8 @@ class DefaultAndroidUnitTestDataExtractorTest : GrazelPluginTest() { variantDataSource = variantDataSource, dependencyGraphsProvider = { dependencyGraphs }, androidManifestParser = androidManifestParser, - grazelExtension = GrazelExtension(rootProject) + grazelExtension = GrazelExtension(rootProject), + gradleDependencyToBazelDependency = gradleDependencyToBazelDependency ) } @@ -117,7 +130,8 @@ class DefaultAndroidUnitTestDataExtractorTest : GrazelPluginTest() { } subProject.doEvaluate() - val androidUnitTestData = defaultAndroidUnitTestDataExtractor.extract(subProject) + val androidUnitTestData = + defaultAndroidUnitTestDataExtractor.extract(subProject, fakeVariant) Truth.assertThat(androidUnitTestData.resources).apply { contains("src/test/resources/test.json") } @@ -136,7 +150,8 @@ class DefaultAndroidUnitTestDataExtractorTest : GrazelPluginTest() { } subProject.doEvaluate() - val androidUnitTestData = defaultAndroidUnitTestDataExtractor.extract(subProject) + val androidUnitTestData = + defaultAndroidUnitTestDataExtractor.extract(subProject, fakeVariant) Truth.assertThat(androidUnitTestData.resources).apply { contains("src/test/resources/**") } @@ -155,7 +170,10 @@ class DefaultAndroidUnitTestDataExtractorTest : GrazelPluginTest() { } subProject.doEvaluate() - val androidUnitTestData = defaultAndroidUnitTestDataExtractor.extract(subProject) + val androidUnitTestData = defaultAndroidUnitTestDataExtractor.extract( + subProject, + fakeVariant + ) Truth.assertThat(androidUnitTestData.additionalSrcSets).apply { containsExactlyElementsIn(additionalTestSourceSets) diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultManifestValuesBuilderTest.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultManifestValuesBuilderTest.kt index cefc9664..dc49df0b 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultManifestValuesBuilderTest.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultManifestValuesBuilderTest.kt @@ -24,7 +24,10 @@ import com.grab.grazel.GrazelExtension import com.grab.grazel.GrazelExtension.Companion.GRAZEL_EXTENSION import com.grab.grazel.GrazelPluginTest import com.grab.grazel.buildProject +import com.grab.grazel.fake.DEBUG_FLAVOR1 +import com.grab.grazel.fake.FLAVOR1 import com.grab.grazel.fake.FakeDependencyGraphs +import com.grab.grazel.fake.FakeVariant import com.grab.grazel.gradle.ANDROID_APPLICATION_PLUGIN import com.grab.grazel.gradle.ANDROID_LIBRARY_PLUGIN import com.grab.grazel.gradle.AndroidVariantDataSource @@ -43,6 +46,7 @@ class DefaultManifestValuesBuilderTest : GrazelPluginTest() { private lateinit var androidBinary: Project private lateinit var androidLibrary: Project private lateinit var defaultManifestValuesBuilder: DefaultManifestValuesBuilder + private val fakeVariant = FakeVariant(DEBUG_FLAVOR1, FLAVOR1) @Before fun setUp() { @@ -100,6 +104,7 @@ class DefaultManifestValuesBuilderTest : GrazelPluginTest() { val defaultConfig = androidBinary.the().defaultConfig val androidBinaryManifestValues = defaultManifestValuesBuilder.build( androidBinary, + fakeVariant, defaultConfig, "test.packageName" ) diff --git a/sample-android-flavor/BUILD.bazel b/sample-android-flavor/BUILD.bazel index a1500b01..a08efd71 100644 --- a/sample-android-flavor/BUILD.bazel +++ b/sample-android-flavor/BUILD.bazel @@ -1,14 +1,14 @@ load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") build_config( - name = "sample-android-flavor-build-config", + name = "sample-android-flavor-flavor1-debug-build-config", package_name = "com.grab.grazel.android.flavor", ) load("@grab_bazel_common//tools/databinding:databinding.bzl", "kt_db_android_library") kt_db_android_library( - name = "sample-android-flavor", + name = "sample-android-flavor-flavor1-debug", srcs = glob([ "src/main/java/com/grab/grazel/android/flavor/**/*.kt", "src/flavor1/java/com/grab/grazel/android/flavor/HelloFlavorMessage.kt", @@ -24,9 +24,120 @@ kt_db_android_library( "//visibility:public", ], deps = [ - ":sample-android-flavor-build-config", + ":sample-android-flavor-flavor1-debug-build-config", "//:parcelize", - "//sample-lib-flavor1", + "//sample-library-flavor1", + "@maven//:androidx_appcompat_appcompat", + "@maven//:androidx_constraintlayout_constraintlayout", + "@maven//:androidx_constraintlayout_constraintlayout_core", + "@maven//:androidx_core_core", + "@maven//:org_jacoco_org_jacoco_ant", + ], +) + +load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") + +build_config( + name = "sample-android-flavor-flavor2-debug-build-config", + package_name = "com.grab.grazel.android.flavor", +) + +load("@grab_bazel_common//tools/databinding:databinding.bzl", "kt_db_android_library") + +kt_db_android_library( + name = "sample-android-flavor-flavor2-debug", + srcs = glob([ + "src/main/java/com/grab/grazel/android/flavor/**/*.kt", + "src/flavor2/java/com/grab/grazel/android/flavor/HelloFlavorMessage.kt", + ]), + custom_package = "com.grab.grazel.android.flavor", + manifest = "src/main/AndroidManifest.xml", + resource_files = glob([ + "src/main/res/**", + ]) + glob([ + "src/flavor2/res/values/strings.xml", + ]), + visibility = [ + "//visibility:public", + ], + deps = [ + ":sample-android-flavor-flavor2-debug-build-config", + "//:parcelize", + "//sample-library-flavor2", + "@maven//:androidx_appcompat_appcompat", + "@maven//:androidx_constraintlayout_constraintlayout", + "@maven//:androidx_constraintlayout_constraintlayout_core", + "@maven//:androidx_core_core", + "@maven//:org_jacoco_org_jacoco_ant", + ], +) + +load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") + +build_config( + name = "sample-android-flavor-flavor1-release-build-config", + package_name = "com.grab.grazel.android.flavor", +) + +load("@grab_bazel_common//tools/databinding:databinding.bzl", "kt_db_android_library") + +kt_db_android_library( + name = "sample-android-flavor-flavor1-release", + srcs = glob([ + "src/main/java/com/grab/grazel/android/flavor/**/*.kt", + "src/flavor1/java/com/grab/grazel/android/flavor/HelloFlavorMessage.kt", + ]), + custom_package = "com.grab.grazel.android.flavor", + manifest = "src/main/AndroidManifest.xml", + resource_files = glob([ + "src/main/res/**", + ]) + glob([ + "src/flavor1/res/values/strings.xml", + ]), + visibility = [ + "//visibility:public", + ], + deps = [ + ":sample-android-flavor-flavor1-release-build-config", + "//:parcelize", + "//sample-library-flavor1", + "@maven//:androidx_appcompat_appcompat", + "@maven//:androidx_constraintlayout_constraintlayout", + "@maven//:androidx_constraintlayout_constraintlayout_core", + "@maven//:androidx_core_core", + "@maven//:org_jacoco_org_jacoco_ant", + ], +) + +load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") + +build_config( + name = "sample-android-flavor-flavor2-release-build-config", + package_name = "com.grab.grazel.android.flavor", +) + +load("@grab_bazel_common//tools/databinding:databinding.bzl", "kt_db_android_library") + +kt_db_android_library( + name = "sample-android-flavor-flavor2-release", + srcs = glob([ + "src/main/java/com/grab/grazel/android/flavor/**/*.kt", + "src/flavor2/java/com/grab/grazel/android/flavor/HelloFlavorMessage.kt", + ]), + custom_package = "com.grab.grazel.android.flavor", + manifest = "src/main/AndroidManifest.xml", + resource_files = glob([ + "src/main/res/**", + ]) + glob([ + "src/flavor2/res/values/strings.xml", + ]), + visibility = [ + "//visibility:public", + ], + deps = [ + ":sample-android-flavor-flavor2-release-build-config", + "//:parcelize", + "//sample-library-flavor2", "@maven//:androidx_appcompat_appcompat", "@maven//:androidx_constraintlayout_constraintlayout", "@maven//:androidx_constraintlayout_constraintlayout_core", diff --git a/sample-android-flavor/build.gradle b/sample-android-flavor/build.gradle index 906907bc..c5adda9a 100644 --- a/sample-android-flavor/build.gradle +++ b/sample-android-flavor/build.gradle @@ -47,8 +47,8 @@ android { } dependencies { - flavor1Implementation project(path: ":sample-lib-flavor1") - flavor2Implementation project(path: ":sample-lib-flavor2") + flavor1Implementation project(path: ':sample-library-flavor1') + flavor2Implementation project(path: ":sample-library-flavor2") implementation "androidx.appcompat:appcompat:1.3.1" implementation "androidx.core:core:1.5.0" diff --git a/sample-android-lib/BUILD.bazel b/sample-android-lib/BUILD.bazel deleted file mode 100644 index 28059425..00000000 --- a/sample-android-lib/BUILD.bazel +++ /dev/null @@ -1,49 +0,0 @@ -load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") - -build_config( - name = "sample-android-lib-build-config", - package_name = "com.grab.grazel.android.sample.lib", -) - -load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library") - -kt_android_library( - name = "sample-android-lib", - srcs = glob([ - "src/main/java/com/grab/grazel/android/sample/SampleViewModel.kt", - ]), - custom_package = "com.grab.grazel.android.sample.lib", - manifest = "src/main/AndroidManifest.xml", - visibility = [ - "//visibility:public", - ], - deps = [ - ":sample-android-lib-build-config", - "//:parcelize", - "@maven//:org_jacoco_org_jacoco_ant", - ], -) - -load("@grab_bazel_common//tools/test:test.bzl", "grab_android_local_test") - -grab_android_local_test( - name = "sample-android-lib-test", - srcs = glob([ - "src/test/java/com/grab/grazel/android/sample/SampleViewModelTest.kt", - ]), - associates = [ - "//sample-android-lib:sample-android-lib_kt", - ], - custom_package = "com.grab.grazel.android.sample.lib", - resources = glob([ - "src/test/resources/**", - ]), - visibility = [ - "//visibility:public", - ], - deps = [ - "//:parcelize", - "//sample-android-lib", - "@maven//:junit_junit", - ], -) diff --git a/sample-android-library/BUILD.bazel b/sample-android-library/BUILD.bazel new file mode 100644 index 00000000..0275cf6d --- /dev/null +++ b/sample-android-library/BUILD.bazel @@ -0,0 +1,99 @@ +load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") + +build_config( + name = "sample-android-library-debug-build-config", + package_name = "com.grab.grazel.android.sample.lib", +) + +load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library") + +kt_android_library( + name = "sample-android-library-debug", + srcs = glob([ + "src/main/java/com/grab/grazel/android/sample/SampleViewModel.kt", + ]), + custom_package = "com.grab.grazel.android.sample.lib", + manifest = "src/main/AndroidManifest.xml", + visibility = [ + "//visibility:public", + ], + deps = [ + ":sample-android-library-debug-build-config", + "//:parcelize", + "@maven//:org_jacoco_org_jacoco_ant", + ], +) + +load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") + +build_config( + name = "sample-android-library-release-build-config", + package_name = "com.grab.grazel.android.sample.lib", +) + +load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library") + +kt_android_library( + name = "sample-android-library-release", + srcs = glob([ + "src/main/java/com/grab/grazel/android/sample/SampleViewModel.kt", + ]), + custom_package = "com.grab.grazel.android.sample.lib", + manifest = "src/main/AndroidManifest.xml", + visibility = [ + "//visibility:public", + ], + deps = [ + ":sample-android-library-release-build-config", + "//:parcelize", + "@maven//:org_jacoco_org_jacoco_ant", + ], +) + +load("@grab_bazel_common//tools/test:test.bzl", "grab_android_local_test") + +grab_android_local_test( + name = "sample-android-library-test-debug-unit-test", + srcs = glob([ + "src/test/java/com/grab/grazel/android/sample/SampleViewModelTest.kt", + ]), + associates = [ + "//sample-android-library:sample-android-library-debug_kt", + ], + custom_package = "com.grab.grazel.android.sample.lib", + resources = glob([ + "src/test/resources/**", + ]), + visibility = [ + "//visibility:public", + ], + deps = [ + "//:parcelize", + "//sample-android-library:sample-android-library-debug", + "@maven//:junit_junit", + ], +) + +load("@grab_bazel_common//tools/test:test.bzl", "grab_android_local_test") + +grab_android_local_test( + name = "sample-android-library-test-release-unit-test", + srcs = glob([ + "src/test/java/com/grab/grazel/android/sample/SampleViewModelTest.kt", + ]), + associates = [ + "//sample-android-library:sample-android-library-release_kt", + ], + custom_package = "com.grab.grazel.android.sample.lib", + resources = glob([ + "src/test/resources/**", + ]), + visibility = [ + "//visibility:public", + ], + deps = [ + "//:parcelize", + "//sample-android-library:sample-android-library-release", + "@maven//:junit_junit", + ], +) diff --git a/sample-android-lib/build.gradle b/sample-android-library/build.gradle similarity index 100% rename from sample-android-lib/build.gradle rename to sample-android-library/build.gradle diff --git a/sample-android-lib/src/main/AndroidManifest.xml b/sample-android-library/src/main/AndroidManifest.xml similarity index 100% rename from sample-android-lib/src/main/AndroidManifest.xml rename to sample-android-library/src/main/AndroidManifest.xml diff --git a/sample-android-lib/src/main/java/com/grab/grazel/android/sample/SampleViewModel.kt b/sample-android-library/src/main/java/com/grab/grazel/android/sample/SampleViewModel.kt similarity index 100% rename from sample-android-lib/src/main/java/com/grab/grazel/android/sample/SampleViewModel.kt rename to sample-android-library/src/main/java/com/grab/grazel/android/sample/SampleViewModel.kt diff --git a/sample-android-lib/src/test/java/com/grab/grazel/android/sample/SampleViewModelTest.kt b/sample-android-library/src/test/java/com/grab/grazel/android/sample/SampleViewModelTest.kt similarity index 100% rename from sample-android-lib/src/test/java/com/grab/grazel/android/sample/SampleViewModelTest.kt rename to sample-android-library/src/test/java/com/grab/grazel/android/sample/SampleViewModelTest.kt diff --git a/sample-android-lib/src/test/resources/mock-response.json b/sample-android-library/src/test/resources/mock-response.json similarity index 100% rename from sample-android-lib/src/test/resources/mock-response.json rename to sample-android-library/src/test/resources/mock-response.json diff --git a/sample-android-lib/src/test/resources/test.json b/sample-android-library/src/test/resources/test.json similarity index 100% rename from sample-android-lib/src/test/resources/test.json rename to sample-android-library/src/test/resources/test.json diff --git a/sample-android/BUILD.bazel b/sample-android/BUILD.bazel index 77e35421..b8336d1a 100644 --- a/sample-android/BUILD.bazel +++ b/sample-android/BUILD.bazel @@ -1,7 +1,215 @@ +load("@tools_android//tools/googleservices:defs.bzl", "google_services_xml") + +GOOGLE_SERVICES_XML = google_services_xml( + package_name = "com.grab.grazel.android.sample", + google_services_json = "google-services.json", +) + +load("@tools_android//tools/crashlytics:defs.bzl", "crashlytics_android_library") + +crashlytics_android_library( + name = "crashlytics_lib", + package_name = "com.grab.grazel.android.sample", + build_id = "042cb4d8-56f8-41a0-916a-9da28e94d1ba", + resource_files = GOOGLE_SERVICES_XML, +) + +load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") + +android_binary( + name = "sample-android-flavor2-debug", + assets = glob([ + "src/main/assets/assert-file.png", + ]), + assets_dir = "src/main/assets", + crunch_png = False, + custom_package = "com.grab.grazel.android.sample", + debug_key = "//buildsystem:debug-keystore", + dex_shards = 5, + enable_data_binding = True, + incremental_dexing = True, + manifest = "src/debug/AndroidManifest.xml", + manifest_values = { + "versionCode": "1", + "versionName": "1.0", + "minSdkVersion": "16", + "targetSdkVersion": "29", + "applicationId": "com.grab.grazel.android.sample", + "orientation": "portrait", + "libraryManifestHolder": "value", + }, + multidex = "native", + resource_files = glob([ + "src/main/res/**", + ]) + custom_res( + dir_name = "res-debug", + resource_files = glob([ + "src/main/res-debug/values/strings.xml", + ]), + target = "sample-android-flavor2-debug", + ) + GOOGLE_SERVICES_XML, + visibility = [ + "//visibility:public", + ], + deps = [ + ":crashlytics_lib", + ":sample-android_lib-flavor2-debug", + "@maven//:androidx_annotation_annotation", + "@maven//:androidx_databinding_databinding_adapters", + "@maven//:androidx_databinding_databinding_common", + "@maven//:androidx_databinding_databinding_runtime", + "@maven//:androidx_databinding_viewbinding", + ], +) + +load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") + +android_binary( + name = "sample-android-flavor1-debug", + assets = glob([ + "src/main/assets/assert-file.png", + ]), + assets_dir = "src/main/assets", + crunch_png = False, + custom_package = "com.grab.grazel.android.sample", + debug_key = "//buildsystem:debug-keystore", + dex_shards = 5, + enable_data_binding = True, + incremental_dexing = True, + manifest = "src/debug/AndroidManifest.xml", + manifest_values = { + "versionCode": "1", + "versionName": "1.0", + "minSdkVersion": "16", + "targetSdkVersion": "29", + "applicationId": "com.grab.grazel.android.sample", + "orientation": "portrait", + "libraryManifestHolder": "value", + }, + multidex = "native", + resource_files = glob([ + "src/main/res/**", + ]) + custom_res( + dir_name = "res-debug", + resource_files = glob([ + "src/main/res-debug/values/strings.xml", + ]), + target = "sample-android-flavor1-debug", + ) + GOOGLE_SERVICES_XML, + visibility = [ + "//visibility:public", + ], + deps = [ + ":crashlytics_lib", + ":sample-android_lib-flavor1-debug", + "@maven//:androidx_annotation_annotation", + "@maven//:androidx_databinding_databinding_adapters", + "@maven//:androidx_databinding_databinding_common", + "@maven//:androidx_databinding_databinding_runtime", + "@maven//:androidx_databinding_viewbinding", + ], +) + +load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") + +android_binary( + name = "sample-android-flavor2-release", + assets = glob([ + "src/main/assets/assert-file.png", + ]), + assets_dir = "src/main/assets", + crunch_png = False, + custom_package = "com.grab.grazel.android.sample", + debug_key = "//buildsystem:debug-keystore", + dex_shards = 5, + enable_data_binding = True, + incremental_dexing = True, + manifest = "src/main/AndroidManifest.xml", + manifest_values = { + "versionCode": "1", + "versionName": "1.0", + "minSdkVersion": "16", + "targetSdkVersion": "29", + "applicationId": "com.grab.grazel.android.sample", + "orientation": "portrait", + "libraryManifestHolder": "value", + }, + multidex = "native", + resource_files = glob([ + "src/main/res/**", + ]) + custom_res( + dir_name = "res-release", + resource_files = glob([ + "src/main/res-release/values/strings.xml", + ]), + target = "sample-android-flavor2-release", + ) + GOOGLE_SERVICES_XML, + visibility = [ + "//visibility:public", + ], + deps = [ + ":crashlytics_lib", + ":sample-android_lib-flavor2-release", + "@maven//:androidx_annotation_annotation", + "@maven//:androidx_databinding_databinding_adapters", + "@maven//:androidx_databinding_databinding_common", + "@maven//:androidx_databinding_databinding_runtime", + "@maven//:androidx_databinding_viewbinding", + ], +) + +load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") + +android_binary( + name = "sample-android-flavor1-release", + assets = glob([ + "src/main/assets/assert-file.png", + ]), + assets_dir = "src/main/assets", + crunch_png = False, + custom_package = "com.grab.grazel.android.sample", + debug_key = "//buildsystem:debug-keystore", + dex_shards = 5, + enable_data_binding = True, + incremental_dexing = True, + manifest = "src/main/AndroidManifest.xml", + manifest_values = { + "versionCode": "1", + "versionName": "1.0", + "minSdkVersion": "16", + "targetSdkVersion": "29", + "applicationId": "com.grab.grazel.android.sample", + "orientation": "portrait", + "libraryManifestHolder": "value", + }, + multidex = "native", + resource_files = glob([ + "src/main/res/**", + ]) + custom_res( + dir_name = "res-release", + resource_files = glob([ + "src/main/res-release/values/strings.xml", + ]), + target = "sample-android-flavor1-release", + ) + GOOGLE_SERVICES_XML, + visibility = [ + "//visibility:public", + ], + deps = [ + ":crashlytics_lib", + ":sample-android_lib-flavor1-release", + "@maven//:androidx_annotation_annotation", + "@maven//:androidx_databinding_databinding_adapters", + "@maven//:androidx_databinding_databinding_common", + "@maven//:androidx_databinding_databinding_runtime", + "@maven//:androidx_databinding_viewbinding", + ], +) + load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") build_config( - name = "sample-android_lib-build-config", + name = "sample-android_lib-flavor2-debug-build-config", package_name = "com.grab.grazel.android.sample", booleans = { "SOME_BOOLEAN": "false", @@ -24,7 +232,7 @@ load("@grab_bazel_common//tools/res_value:res_value.bzl", "res_value") load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library") kt_android_library( - name = "sample-android_lib", + name = "sample-android_lib-flavor2-debug", srcs = glob([ "src/main/java/com/grab/grazel/android/sample/MainActivity.kt", ]), @@ -41,9 +249,9 @@ kt_android_library( resource_files = glob([ "src/main/res-debug/values/strings.xml", ]), - target = "sample-android_lib", + target = "sample-android_lib-flavor2-debug", ) + res_value( - name = "sample-android_lib-res-value", + name = "sample-android_lib-flavor2-debug-res-value", strings = { "generated_value": "important-key", }, @@ -52,78 +260,212 @@ kt_android_library( "//visibility:public", ], deps = [ - ":sample-android_lib-build-config", + ":sample-android_lib-flavor2-debug-build-config", "//:dagger", "//:parcelize", - "//sample-android-flavor", - "//sample-android-lib", - "//sample-kotlin-lib", + "//sample-android-flavor:sample-android-flavor-flavor2-debug", + "//sample-android-library:sample-android-library-debug", + "//sample-kotlin-library", "@maven//:androidx_appcompat_appcompat", "@maven//:androidx_constraintlayout_constraintlayout", "@maven//:org_jacoco_org_jacoco_ant", ], ) -load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") -load("@tools_android//tools/googleservices:defs.bzl", "google_services_xml") +load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") -GOOGLE_SERVICES_XML = google_services_xml( +build_config( + name = "sample-android_lib-flavor1-debug-build-config", package_name = "com.grab.grazel.android.sample", - google_services_json = "google-services.json", + booleans = { + "SOME_BOOLEAN": "false", + }, + ints = { + "SOME_INT": 0, + "VERSION_CODE": 1, + }, + longs = { + "SOME_LONG": 0, + }, + strings = { + "SOME_STRING": "Something", + "VERSION_NAME": "1.0", + }, ) -load("@tools_android//tools/crashlytics:defs.bzl", "crashlytics_android_library") +load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") +load("@grab_bazel_common//tools/res_value:res_value.bzl", "res_value") +load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library") -crashlytics_android_library( - name = "crashlytics_lib", +kt_android_library( + name = "sample-android_lib-flavor1-debug", + srcs = glob([ + "src/main/java/com/grab/grazel/android/sample/MainActivity.kt", + ]), + assets = glob([ + "src/main/assets/assert-file.png", + ]), + assets_dir = "src/main/assets", + custom_package = "com.grab.grazel.android.sample", + manifest = "src/debug/AndroidManifest.xml", + resource_files = glob([ + "src/main/res/**", + ]) + custom_res( + dir_name = "res-debug", + resource_files = glob([ + "src/main/res-debug/values/strings.xml", + ]), + target = "sample-android_lib-flavor1-debug", + ) + res_value( + name = "sample-android_lib-flavor1-debug-res-value", + strings = { + "generated_value": "important-key", + }, + ), + visibility = [ + "//visibility:public", + ], + deps = [ + ":sample-android_lib-flavor1-debug-build-config", + "//:dagger", + "//:parcelize", + "//sample-android-flavor:sample-android-flavor-flavor1-debug", + "//sample-android-library:sample-android-library-debug", + "//sample-kotlin-library", + "@maven//:androidx_appcompat_appcompat", + "@maven//:androidx_constraintlayout_constraintlayout", + "@maven//:org_jacoco_org_jacoco_ant", + ], +) + +load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") + +build_config( + name = "sample-android_lib-flavor2-release-build-config", package_name = "com.grab.grazel.android.sample", - build_id = "042cb4d8-56f8-41a0-916a-9da28e94d1ba", - resource_files = GOOGLE_SERVICES_XML, + booleans = { + "SOME_BOOLEAN": "false", + }, + ints = { + "SOME_INT": 0, + "VERSION_CODE": 1, + }, + longs = { + "SOME_LONG": 0, + }, + strings = { + "SOME_STRING": "Something", + "VERSION_NAME": "1.0", + }, ) -android_binary( - name = "sample-android", +load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") +load("@grab_bazel_common//tools/res_value:res_value.bzl", "res_value") +load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library") + +kt_android_library( + name = "sample-android_lib-flavor2-release", + srcs = glob([ + "src/main/java/com/grab/grazel/android/sample/MainActivity.kt", + ]), assets = glob([ "src/main/assets/assert-file.png", ]), assets_dir = "src/main/assets", - crunch_png = False, custom_package = "com.grab.grazel.android.sample", - debug_key = "//buildsystem:debug-keystore", - dex_shards = 5, - enable_data_binding = True, - incremental_dexing = True, - manifest = "src/debug/AndroidManifest.xml", - manifest_values = { - "versionCode": "1", - "versionName": "1.0", - "minSdkVersion": "16", - "targetSdkVersion": "29", - "applicationId": "com.grab.grazel.android.sample", - "orientation": "portrait", - "libraryManifestHolder": "value", + manifest = "src/main/AndroidManifest.xml", + resource_files = glob([ + "src/main/res/**", + ]) + custom_res( + dir_name = "res-release", + resource_files = glob([ + "src/main/res-release/values/strings.xml", + ]), + target = "sample-android_lib-flavor2-release", + ) + res_value( + name = "sample-android_lib-flavor2-release-res-value", + strings = { + "generated_value": "important-key", + }, + ), + visibility = [ + "//visibility:public", + ], + deps = [ + ":sample-android_lib-flavor2-release-build-config", + "//:dagger", + "//:parcelize", + "//sample-android-flavor:sample-android-flavor-flavor2-release", + "//sample-android-library:sample-android-library-release", + "//sample-kotlin-library", + "@maven//:androidx_appcompat_appcompat", + "@maven//:androidx_constraintlayout_constraintlayout", + "@maven//:org_jacoco_org_jacoco_ant", + ], +) + +load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") + +build_config( + name = "sample-android_lib-flavor1-release-build-config", + package_name = "com.grab.grazel.android.sample", + booleans = { + "SOME_BOOLEAN": "false", }, - multidex = "native", + ints = { + "SOME_INT": 0, + "VERSION_CODE": 1, + }, + longs = { + "SOME_LONG": 0, + }, + strings = { + "SOME_STRING": "Something", + "VERSION_NAME": "1.0", + }, +) + +load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") +load("@grab_bazel_common//tools/res_value:res_value.bzl", "res_value") +load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library") + +kt_android_library( + name = "sample-android_lib-flavor1-release", + srcs = glob([ + "src/main/java/com/grab/grazel/android/sample/MainActivity.kt", + ]), + assets = glob([ + "src/main/assets/assert-file.png", + ]), + assets_dir = "src/main/assets", + custom_package = "com.grab.grazel.android.sample", + manifest = "src/main/AndroidManifest.xml", resource_files = glob([ "src/main/res/**", ]) + custom_res( - dir_name = "res-debug", + dir_name = "res-release", resource_files = glob([ - "src/main/res-debug/values/strings.xml", + "src/main/res-release/values/strings.xml", ]), - target = "sample-android", - ) + GOOGLE_SERVICES_XML, + target = "sample-android_lib-flavor1-release", + ) + res_value( + name = "sample-android_lib-flavor1-release-res-value", + strings = { + "generated_value": "important-key", + }, + ), visibility = [ "//visibility:public", ], deps = [ - ":crashlytics_lib", - ":sample-android_lib", - ":sample-android_lib-build-config", - "@maven//:androidx_annotation_annotation", - "@maven//:androidx_databinding_databinding_adapters", - "@maven//:androidx_databinding_databinding_common", - "@maven//:androidx_databinding_databinding_runtime", - "@maven//:androidx_databinding_viewbinding", + ":sample-android_lib-flavor1-release-build-config", + "//:dagger", + "//:parcelize", + "//sample-android-flavor:sample-android-flavor-flavor1-release", + "//sample-android-library:sample-android-library-release", + "//sample-kotlin-library", + "@maven//:androidx_appcompat_appcompat", + "@maven//:androidx_constraintlayout_constraintlayout", + "@maven//:org_jacoco_org_jacoco_ant", ], ) diff --git a/sample-android/build.gradle b/sample-android/build.gradle index 892c3ef8..0f04cb25 100644 --- a/sample-android/build.gradle +++ b/sample-android/build.gradle @@ -81,8 +81,8 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation project(path: ":sample-kotlin-lib") - implementation project(path: ":sample-android-lib") + implementation project(path: ':sample-kotlin-library') + implementation project(path: ':sample-android-library') implementation project(path: ":sample-android-flavor") implementation "androidx.appcompat:appcompat:1.3.1" diff --git a/sample-kotlin-lib/.gitignore b/sample-kotlin-library/.gitignore similarity index 100% rename from sample-kotlin-lib/.gitignore rename to sample-kotlin-library/.gitignore diff --git a/sample-kotlin-lib/BUILD.bazel b/sample-kotlin-library/BUILD.bazel similarity index 80% rename from sample-kotlin-lib/BUILD.bazel rename to sample-kotlin-library/BUILD.bazel index 36126738..576bdd21 100644 --- a/sample-kotlin-lib/BUILD.bazel +++ b/sample-kotlin-library/BUILD.bazel @@ -1,7 +1,7 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") kt_jvm_library( - name = "sample-kotlin-lib", + name = "sample-kotlin-library", srcs = glob([ "src/main/java/com/grab/grazel/sample/HelloWorld.kt", ]), @@ -13,12 +13,12 @@ kt_jvm_library( load("@grab_bazel_common//tools/test:test.bzl", "grab_kt_jvm_test") grab_kt_jvm_test( - name = "sample-kotlin-lib-test", + name = "sample-kotlin-library-test", srcs = glob([ "src/test/java/com/grab/grazel/sample/TestClass1.kt", ]), associates = [ - "//sample-kotlin-lib", + "//sample-kotlin-library:sample-kotlin-library", ], visibility = [ "//visibility:public", diff --git a/sample-kotlin-lib/build.gradle b/sample-kotlin-library/build.gradle similarity index 100% rename from sample-kotlin-lib/build.gradle rename to sample-kotlin-library/build.gradle diff --git a/sample-kotlin-lib/src/main/java/com/grab/grazel/sample/HelloWorld.kt b/sample-kotlin-library/src/main/java/com/grab/grazel/sample/HelloWorld.kt similarity index 100% rename from sample-kotlin-lib/src/main/java/com/grab/grazel/sample/HelloWorld.kt rename to sample-kotlin-library/src/main/java/com/grab/grazel/sample/HelloWorld.kt diff --git a/sample-kotlin-lib/src/test/java/com/grab/grazel/sample/TestClass1.kt b/sample-kotlin-library/src/test/java/com/grab/grazel/sample/TestClass1.kt similarity index 100% rename from sample-kotlin-lib/src/test/java/com/grab/grazel/sample/TestClass1.kt rename to sample-kotlin-library/src/test/java/com/grab/grazel/sample/TestClass1.kt diff --git a/sample-lib-flavor1/.gitignore b/sample-library-flavor1/.gitignore similarity index 100% rename from sample-lib-flavor1/.gitignore rename to sample-library-flavor1/.gitignore diff --git a/sample-lib-flavor1/BUILD.bazel b/sample-library-flavor1/BUILD.bazel similarity index 80% rename from sample-lib-flavor1/BUILD.bazel rename to sample-library-flavor1/BUILD.bazel index e8602b41..152ae42e 100644 --- a/sample-lib-flavor1/BUILD.bazel +++ b/sample-library-flavor1/BUILD.bazel @@ -1,7 +1,7 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") kt_jvm_library( - name = "sample-lib-flavor1", + name = "sample-library-flavor1", srcs = glob([ "src/main/java/com/grab/grazel/android/flavor/ModuleName.kt", ]), @@ -13,12 +13,12 @@ kt_jvm_library( load("@grab_bazel_common//tools/test:test.bzl", "grab_kt_jvm_test") grab_kt_jvm_test( - name = "sample-lib-flavor1-test", + name = "sample-library-flavor1-test", srcs = glob([ "src/test/java/com/grab/grazel/flavor1/ModuleNameTest.kt", ]), associates = [ - "//sample-lib-flavor1", + "//sample-library-flavor1:sample-library-flavor1", ], visibility = [ "//visibility:public", diff --git a/sample-lib-flavor1/build.gradle b/sample-library-flavor1/build.gradle similarity index 100% rename from sample-lib-flavor1/build.gradle rename to sample-library-flavor1/build.gradle diff --git a/sample-lib-flavor1/src/main/java/com/grab/grazel/android/flavor/ModuleName.kt b/sample-library-flavor1/src/main/java/com/grab/grazel/android/flavor/ModuleName.kt similarity index 100% rename from sample-lib-flavor1/src/main/java/com/grab/grazel/android/flavor/ModuleName.kt rename to sample-library-flavor1/src/main/java/com/grab/grazel/android/flavor/ModuleName.kt diff --git a/sample-lib-flavor1/src/test/java/com/grab/grazel/flavor1/ModuleNameTest.kt b/sample-library-flavor1/src/test/java/com/grab/grazel/flavor1/ModuleNameTest.kt similarity index 100% rename from sample-lib-flavor1/src/test/java/com/grab/grazel/flavor1/ModuleNameTest.kt rename to sample-library-flavor1/src/test/java/com/grab/grazel/flavor1/ModuleNameTest.kt diff --git a/sample-lib-flavor2/.gitignore b/sample-library-flavor2/.gitignore similarity index 100% rename from sample-lib-flavor2/.gitignore rename to sample-library-flavor2/.gitignore diff --git a/sample-lib-flavor2/BUILD.bazel b/sample-library-flavor2/BUILD.bazel similarity index 80% rename from sample-lib-flavor2/BUILD.bazel rename to sample-library-flavor2/BUILD.bazel index 99c7af19..18e26768 100644 --- a/sample-lib-flavor2/BUILD.bazel +++ b/sample-library-flavor2/BUILD.bazel @@ -1,7 +1,7 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") kt_jvm_library( - name = "sample-lib-flavor2", + name = "sample-library-flavor2", srcs = glob([ "src/main/java/com/grab/grazel/android/flavor/ModuleName.kt", ]), @@ -13,12 +13,12 @@ kt_jvm_library( load("@grab_bazel_common//tools/test:test.bzl", "grab_kt_jvm_test") grab_kt_jvm_test( - name = "sample-lib-flavor2-test", + name = "sample-library-flavor2-test", srcs = glob([ "src/test/java/com/grab/grazel/flavor2/ModuleNameTest.kt", ]), associates = [ - "//sample-lib-flavor2", + "//sample-library-flavor2:sample-library-flavor2", ], visibility = [ "//visibility:public", diff --git a/sample-lib-flavor2/build.gradle b/sample-library-flavor2/build.gradle similarity index 100% rename from sample-lib-flavor2/build.gradle rename to sample-library-flavor2/build.gradle diff --git a/sample-lib-flavor2/src/main/java/com/grab/grazel/android/flavor/ModuleName.kt b/sample-library-flavor2/src/main/java/com/grab/grazel/android/flavor/ModuleName.kt similarity index 100% rename from sample-lib-flavor2/src/main/java/com/grab/grazel/android/flavor/ModuleName.kt rename to sample-library-flavor2/src/main/java/com/grab/grazel/android/flavor/ModuleName.kt diff --git a/sample-lib-flavor2/src/test/java/com/grab/grazel/flavor2/ModuleNameTest.kt b/sample-library-flavor2/src/test/java/com/grab/grazel/flavor2/ModuleNameTest.kt similarity index 100% rename from sample-lib-flavor2/src/test/java/com/grab/grazel/flavor2/ModuleNameTest.kt rename to sample-library-flavor2/src/test/java/com/grab/grazel/flavor2/ModuleNameTest.kt diff --git a/settings.gradle b/settings.gradle index 22ea983b..f7d7dc59 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,11 +17,11 @@ rootProject.name = "grazel" include(":sample-android") -include(":sample-android-lib") +include(':sample-android-library') include(":sample-android-flavor") -include(":sample-lib-flavor1") -include(":sample-lib-flavor2") -include(":sample-kotlin-lib") +include(':sample-library-flavor1') +include(":sample-library-flavor2") +include(':sample-kotlin-library') includeBuild("grazel-gradle-plugin") { From 7e14576fbaae4347816629ce8217081c69c47321 Mon Sep 17 00:00:00 2001 From: "mohammad.khaleghi" Date: Wed, 14 Sep 2022 17:22:17 +0800 Subject: [PATCH 2/2] fix variant filter --- build.gradle | 6 +- .../com/grab/grazel/gradle/BuildVariant.kt | 54 +-- .../dependencies/DependenciesGraphsBuilder.kt | 13 +- .../builder/AndroidBinaryTargetBuilder.kt | 126 +++---- .../builder/AndroidLibTargetBuilder.kt | 31 +- .../builder/KtAndroidLibTargetBuilder.kt | 56 +-- .../migrate/builder/KtLibTargetBuilder.kt | 13 +- .../grab/grazel/fake/FakeDependencyGraphs.kt | 2 +- .../com/grab/grazel/fake/FakeProductFlavor.kt | 8 + .../com/grab/grazel/fake/FakeVariant.kt | 7 +- .../DefaultAndroidVariantDataSourceTest.kt | 3 +- ...DefaultAndroidUnitTestDataExtractorTest.kt | 28 +- sample-android-flavor/BUILD.bazel | 111 ------ sample-android-library/BUILD.bazel | 50 --- sample-android/BUILD.bazel | 342 ------------------ 15 files changed, 192 insertions(+), 658 deletions(-) diff --git a/build.gradle b/build.gradle index 6f78f1b9..1c496179 100644 --- a/build.gradle +++ b/build.gradle @@ -85,9 +85,9 @@ grazel { multiDexEnabled = true incrementalDexing = true variantFilter { variant -> -// if (variant.name != "flavor1Debug" && variant.name != "debug" && variant.name != "debugUnitTest") { -// variant.setIgnore(true) -// } + if (variant.name != "flavor1Debug" && variant.name != "debug" && variant.name != "debugUnitTest") { + variant.setIgnore(true) + } } features { dataBinding = true diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/BuildVariant.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/BuildVariant.kt index 9c031ea2..02364b94 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/BuildVariant.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/BuildVariant.kt @@ -52,6 +52,14 @@ internal interface AndroidVariantDataSource { * @return The list of variants that can be migrated. */ fun getMigratableVariants(project: Project): List + + /** + * return all variants minus the ones that declared in filtered variants + */ + fun getMigratableVariants( + project: Project, + configurationScope: ConfigurationScope? + ): Set } internal class DefaultAndroidVariantDataSource( @@ -59,6 +67,23 @@ internal class DefaultAndroidVariantDataSource( override val variantFilter: Action? = null ) : AndroidVariantDataSource { + override fun getMigratableVariants( + project: Project, + configurationScope: ConfigurationScope? + ): Set { + return when (configurationScope) { + ConfigurationScope.TEST -> { + androidVariantsExtractor.getUnitTestVariants(project) + } + ConfigurationScope.ANDROID_TEST -> { + androidVariantsExtractor.getTestVariants(project) + } + else -> { + androidVariantsExtractor.getVariants(project) + } + }.filterNot(::ignoredVariantFilter).toSet() + } + override fun getIgnoredFlavors(project: Project): List { val supportFlavors = getMigratableVariants(project).flatMap(BaseVariant::getProductFlavors) return androidVariantsExtractor.getFlavors(project) @@ -87,11 +112,7 @@ internal class DefaultAndroidVariantDataSource( internal interface AndroidVariantsExtractor { fun getUnitTestVariants(project: Project): Set fun getTestVariants(project: Project): Set - fun getVariants( - project: Project, - configurationScope: ConfigurationScope? = null - ): Set - + fun getVariants(project: Project): Set fun getFlavors(project: Project): Set fun getBuildTypes(project: Project): Set } @@ -102,24 +123,11 @@ internal class DefaultAndroidVariantsExtractor @Inject constructor() : AndroidVa private val Project.isAndroidAppOrDynFeature get() = project.isAndroidApplication || project.isAndroidDynamicFeature - override fun getVariants( - project: Project, - configurationScope: ConfigurationScope? - ): Set { - return when (configurationScope) { - ConfigurationScope.TEST -> { - getUnitTestVariants(project) - } - ConfigurationScope.ANDROID_TEST -> { - getTestVariants(project) - } - else -> { - when { - project.isAndroidAppOrDynFeature -> project.the().applicationVariants - project.isAndroidLibrary -> project.the().libraryVariants - else -> emptySet() - } - } + override fun getVariants(project: Project): Set { + return when { + project.isAndroidAppOrDynFeature -> project.the().applicationVariants + project.isAndroidLibrary -> project.the().libraryVariants + else -> emptySet() } } diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependenciesGraphsBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependenciesGraphsBuilder.kt index 847c0f77..5d4d70a0 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependenciesGraphsBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/gradle/dependencies/DependenciesGraphsBuilder.kt @@ -21,7 +21,7 @@ import com.google.common.graph.MutableValueGraph import com.google.common.graph.ValueGraphBuilder import com.grab.grazel.di.qualifiers.RootProject import com.grab.grazel.extension.TestExtension -import com.grab.grazel.gradle.AndroidVariantsExtractor +import com.grab.grazel.gradle.AndroidVariantDataSource import com.grab.grazel.gradle.ConfigurationDataSource import com.grab.grazel.gradle.ConfigurationScope import com.grab.grazel.gradle.isAndroid @@ -33,7 +33,7 @@ internal class DependenciesGraphsBuilder @Inject constructor( @param:RootProject private val rootProject: Project, private val dependenciesDataSource: DependenciesDataSource, private val configurationDataSource: ConfigurationDataSource, - private val androidVariantsExtractor: AndroidVariantsExtractor, + private val androidVariantDataSource: AndroidVariantDataSource, private val testExtension: TestExtension ) { @@ -55,7 +55,10 @@ internal class DependenciesGraphsBuilder @Inject constructor( addEdges(sourceProject, configurationScope, buildGraphs) dependenciesDataSource.projectDependencies(sourceProject, configurationScope) .forEach { (configuration, projectDependency) -> - androidVariantsExtractor.getVariants(sourceProject, configurationScope) + androidVariantDataSource.getMigratableVariants( + sourceProject, + configurationScope + ) .forEach { variant -> if (configurationDataSource.isThisConfigurationBelongsToThisVariants( variant, @@ -90,7 +93,7 @@ internal class DependenciesGraphsBuilder @Inject constructor( ) { dependenciesDataSource.projectDependencies(project, configurationScope) .forEach { (configuration, projectDependency) -> - androidVariantsExtractor.getVariants(project, configurationScope) + androidVariantDataSource.getMigratableVariants(project, configurationScope) .forEach { variant -> if (variant.compileConfiguration.hierarchy.contains(configuration)) { graph.putEdgeValue( @@ -110,7 +113,7 @@ internal class DependenciesGraphsBuilder @Inject constructor( buildGraphs: MutableMap> ) { if (sourceProject.isAndroid) { - androidVariantsExtractor.getVariants(sourceProject, configurationScope) + androidVariantDataSource.getMigratableVariants(sourceProject, configurationScope) .forEach { variant -> buildGraphs.addNode(BuildGraphType(configurationScope, variant), sourceProject) } diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidBinaryTargetBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidBinaryTargetBuilder.kt index 1a190204..cac0e770 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidBinaryTargetBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidBinaryTargetBuilder.kt @@ -16,7 +16,8 @@ package com.grab.grazel.migrate.builder -import com.grab.grazel.gradle.AndroidVariantsExtractor +import com.grab.grazel.gradle.AndroidVariantDataSource +import com.grab.grazel.gradle.ConfigurationScope import com.grab.grazel.gradle.dependencies.variantNameSuffix import com.grab.grazel.gradle.isAndroidApplication import com.grab.grazel.gradle.isKotlin @@ -60,7 +61,7 @@ internal interface AndroidBinaryTargetBuilderModule { internal class AndroidBinaryTargetBuilder @Inject constructor( private val androidLibDataExtractor: AndroidLibraryDataExtractor, private val androidBinDataExtractor: AndroidBinaryDataExtractor, - private val androidVariantsExtractor: AndroidVariantsExtractor + private val androidVariantDataSource: AndroidVariantDataSource ) : TargetBuilder { override fun build(project: Project): List { @@ -73,45 +74,47 @@ internal class AndroidBinaryTargetBuilder @Inject constructor( intermediateTargets: List ): List { - var targets = androidVariantsExtractor.getVariants(project) - .flatMap { variant -> - var androidLibData = androidLibDataExtractor.extract(project, variant) - val deps = if (project.isKotlin) { - // For kotlin project, don't duplicate Maven dependencies - intermediateTargets.filter { it.name.endsWith(variant.name.variantNameSuffix()) } - .map { it.toBazelDependency() } - } else { - intermediateTargets.filter { it.name.endsWith(variant.name.variantNameSuffix()) } - .map { it.toBazelDependency() } + androidLibData.deps - } + var targets = + androidVariantDataSource.getMigratableVariants(project, ConfigurationScope.BUILD) + .flatMap { variant -> + var androidLibData = androidLibDataExtractor.extract(project, variant) + val deps = if (project.isKotlin) { + // For kotlin project, don't duplicate Maven dependencies + intermediateTargets.filter { it.name.endsWith(variant.name.variantNameSuffix()) } + .map { it.toBazelDependency() } + } else { + intermediateTargets.filter { it.name.endsWith(variant.name.variantNameSuffix()) } + .map { it.toBazelDependency() } + androidLibData.deps + } - androidLibData = androidLibData.copy(deps = deps) - val binaryData = androidBinDataExtractor.extract(project, variant, androidLibData) - - listOf( - AndroidBinaryTarget( - name = "${binaryData.name}${variant.name.variantNameSuffix()}", - deps = androidLibData.deps + binaryData.deps, - srcs = androidLibData.srcs, - multidex = binaryData.multidex, - debugKey = binaryData.debugKey, - dexShards = binaryData.dexShards, - incrementalDexing = binaryData.incrementalDexing, - enableDataBinding = binaryData.hasDatabinding, - packageName = androidLibData.packageName, - manifest = androidLibData.manifestFile, - manifestValues = binaryData.manifestValues, - res = androidLibData.res, - resValues = androidLibData.resValues, - customResourceSets = androidLibData.extraRes, - assetsGlob = androidLibData.assets, - assetsDir = androidLibData.assetsDir, - buildId = binaryData.buildId, - googleServicesJson = binaryData.googleServicesJson, - hasCrashlytics = binaryData.hasCrashlytics + androidLibData = androidLibData.copy(deps = deps) + val binaryData = + androidBinDataExtractor.extract(project, variant, androidLibData) + + listOf( + AndroidBinaryTarget( + name = "${binaryData.name}${variant.name.variantNameSuffix()}", + deps = androidLibData.deps + binaryData.deps, + srcs = androidLibData.srcs, + multidex = binaryData.multidex, + debugKey = binaryData.debugKey, + dexShards = binaryData.dexShards, + incrementalDexing = binaryData.incrementalDexing, + enableDataBinding = binaryData.hasDatabinding, + packageName = androidLibData.packageName, + manifest = androidLibData.manifestFile, + manifestValues = binaryData.manifestValues, + res = androidLibData.res, + resValues = androidLibData.resValues, + customResourceSets = androidLibData.extraRes, + assetsGlob = androidLibData.assets, + assetsDir = androidLibData.assetsDir, + buildId = binaryData.buildId, + googleServicesJson = binaryData.googleServicesJson, + hasCrashlytics = binaryData.hasCrashlytics + ) ) - ) - } + intermediateTargets + } + intermediateTargets targets = addCrashlyticsTarget(targets) @@ -149,30 +152,31 @@ internal class AndroidBinaryTargetBuilder @Inject constructor( private fun buildKtAndroidTargets(project: Project): List { return buildList { - androidVariantsExtractor.getVariants(project).forEach { variant -> - val androidProjectData = androidLibDataExtractor.extract( - project = project, - sourceSetType = SourceSetType.JAVA_KOTLIN, - variant = variant - ).copy(name = "${project.name}_lib", hasDatabinding = false) - var deps = androidProjectData.deps - - with(androidProjectData) { - toBuildConfigTarget(variant.name.variantNameSuffix()).also { - deps += it.toBazelDependency() - add(it) + androidVariantDataSource.getMigratableVariants(project, ConfigurationScope.BUILD) + .forEach { variant -> + val androidProjectData = androidLibDataExtractor.extract( + project = project, + sourceSetType = SourceSetType.JAVA_KOTLIN, + variant = variant + ).copy(name = "${project.name}_lib", hasDatabinding = false) + var deps = androidProjectData.deps + + with(androidProjectData) { + toBuildConfigTarget(variant.name.variantNameSuffix()).also { + deps += it.toBazelDependency() + add(it) + } } - } - androidProjectData - .copy( - name = "${androidProjectData.name}${variant.name.variantNameSuffix()}", - deps = deps, - tags = emptyList() // Don't generate classpath reduction tags for final binary target - ) - .toKtLibraryTarget() - ?.also { add(it) } - } + androidProjectData + .copy( + name = "${androidProjectData.name}${variant.name.variantNameSuffix()}", + deps = deps, + tags = emptyList() // Don't generate classpath reduction tags for final binary target + ) + .toKtLibraryTarget() + ?.also { add(it) } + } } } diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidLibTargetBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidLibTargetBuilder.kt index 480487be..2d71a699 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidLibTargetBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/AndroidLibTargetBuilder.kt @@ -17,7 +17,8 @@ package com.grab.grazel.migrate.builder import com.grab.grazel.extension.TestExtension -import com.grab.grazel.gradle.AndroidVariantsExtractor +import com.grab.grazel.gradle.AndroidVariantDataSource +import com.grab.grazel.gradle.ConfigurationScope import com.grab.grazel.gradle.isAndroid import com.grab.grazel.gradle.isAndroidApplication import com.grab.grazel.gradle.isKotlin @@ -47,21 +48,29 @@ internal class AndroidLibTargetBuilder @Inject constructor( private val projectDataExtractor: AndroidLibraryDataExtractor, private val unitTestDataExtractor: AndroidUnitTestDataExtractor, private val testExtension: TestExtension, - private val androidVariantsExtractor: AndroidVariantsExtractor + private val androidVariantDataSource: AndroidVariantDataSource ) : TargetBuilder { override fun build(project: Project): List { - return androidVariantsExtractor.getVariants(project).flatMap { variant -> - if (testExtension.enableTestMigration) { - listOf( - projectDataExtractor.extract(project, variant).toAndroidLibTarget(), - unitTestDataExtractor.extract(project, variant).toUnitTestTarget() - ) - } else { - listOf(projectDataExtractor.extract(project, variant).toAndroidLibTarget()) + return androidVariantDataSource.getMigratableVariants( + project, + ConfigurationScope.BUILD + ).map { variant -> + projectDataExtractor.extract(project, variant).toAndroidLibTarget() + } + unitTestsTargets(project) + } + + private fun unitTestsTargets(project: Project) = + if (testExtension.enableTestMigration) { + androidVariantDataSource.getMigratableVariants( + project, + ConfigurationScope.TEST + ).map { variant -> + unitTestDataExtractor.extract(project, variant).toUnitTestTarget() } + } else { + emptyList() } - } override fun canHandle(project: Project): Boolean = with(project) { isAndroid && !isKotlin && !isAndroidApplication diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtAndroidLibTargetBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtAndroidLibTargetBuilder.kt index 6cad7e26..a621345a 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtAndroidLibTargetBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtAndroidLibTargetBuilder.kt @@ -19,7 +19,8 @@ package com.grab.grazel.migrate.builder import com.grab.grazel.bazel.rules.KotlinProjectType import com.grab.grazel.bazel.rules.Visibility import com.grab.grazel.extension.TestExtension -import com.grab.grazel.gradle.AndroidVariantsExtractor +import com.grab.grazel.gradle.AndroidVariantDataSource +import com.grab.grazel.gradle.ConfigurationScope import com.grab.grazel.gradle.dependencies.variantNameSuffix import com.grab.grazel.gradle.isAndroid import com.grab.grazel.gradle.isAndroidApplication @@ -67,41 +68,42 @@ internal interface KtAndroidLibTargetBuilderModule { internal class KtAndroidLibTargetBuilder @Inject constructor( private val projectDataExtractor: AndroidLibraryDataExtractor, private val unitTestDataExtractor: AndroidUnitTestDataExtractor, - private val androidVariantsExtractor: AndroidVariantsExtractor, + private val androidVariantDataSource: AndroidVariantDataSource, private val testExtension: TestExtension ) : TargetBuilder { override fun build(project: Project): List { return mutableListOf().apply { - androidVariantsExtractor.getVariants(project).forEach { variant -> - val projectData = projectDataExtractor.extract( - project, - sourceSetType = SourceSetType.JAVA_KOTLIN, - variant = variant - ) - var deps = projectData.deps - with(projectData) { - toAarResTarget(variant.name.variantNameSuffix())?.also { add(it) } - toBuildConfigTarget(variant.name.variantNameSuffix()).also { - deps += it.toBazelDependency() - add(it) + androidVariantDataSource.getMigratableVariants(project, ConfigurationScope.BUILD) + .forEach { variant -> + val projectData = projectDataExtractor.extract( + project, + sourceSetType = SourceSetType.JAVA_KOTLIN, + variant = variant + ) + var deps = projectData.deps + with(projectData) { + toAarResTarget(variant.name.variantNameSuffix())?.also { add(it) } + toBuildConfigTarget(variant.name.variantNameSuffix()).also { + deps += it.toBazelDependency() + add(it) + } } - } - projectData - .copy(name = projectData.name + variant.name.variantNameSuffix(), deps = deps) - .toKtLibraryTarget() - ?.also { add(it) } + projectData + .copy( + name = projectData.name + variant.name.variantNameSuffix(), + deps = deps + ) + .toKtLibraryTarget() + ?.also { add(it) } - } - if (testExtension.enableTestMigration) { - androidVariantsExtractor.getUnitTestVariants(project).forEach { variant -> - add( - unitTestDataExtractor - .extract(project, variant) - .toUnitTestTarget() - ) } + if (testExtension.enableTestMigration) { + androidVariantDataSource.getMigratableVariants(project, ConfigurationScope.TEST) + .forEach { variant -> + add(unitTestDataExtractor.extract(project, variant).toUnitTestTarget()) + } } } } diff --git a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtLibTargetBuilder.kt b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtLibTargetBuilder.kt index 5340a31b..b9c4973c 100644 --- a/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtLibTargetBuilder.kt +++ b/grazel-gradle-plugin/src/main/kotlin/com/grab/grazel/migrate/builder/KtLibTargetBuilder.kt @@ -18,7 +18,6 @@ package com.grab.grazel.migrate.builder import com.grab.grazel.extension.KotlinExtension import com.grab.grazel.extension.TestExtension -import com.grab.grazel.gradle.AndroidVariantsExtractor import com.grab.grazel.gradle.isAndroid import com.grab.grazel.gradle.isKotlin import com.grab.grazel.migrate.BazelTarget @@ -34,7 +33,6 @@ import dagger.Binds import dagger.Module import dagger.multibindings.IntoSet import org.gradle.api.Project -import org.gradle.api.internal.BuildType import javax.inject.Inject import javax.inject.Singleton @@ -59,17 +57,16 @@ internal class KtLibTargetBuilder @Inject constructor( private val kotlinExtension: KotlinExtension, private val testExtension: TestExtension ) : TargetBuilder { + override fun build(project: Project): List { val projectData = projectDataExtractor.extract(project) + val ktLibTargets = projectData.toKtLibraryTarget(kotlinExtension.enabledTransitiveReduction) return if (testExtension.enableTestMigration) { - val unitTestData = kotlinUnitTestDataExtractor.extract(project) - listOf( - projectData.toKtLibraryTarget(kotlinExtension.enabledTransitiveReduction), - unitTestData.toUnitTestTarget() - ) + val unitTestsTargets = kotlinUnitTestDataExtractor.extract(project).toUnitTestTarget() + listOf(ktLibTargets, unitTestsTargets) } else { - listOf(projectData.toKtLibraryTarget(kotlinExtension.enabledTransitiveReduction)) + listOf(ktLibTargets) } } diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeDependencyGraphs.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeDependencyGraphs.kt index 61114a7a..19a55335 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeDependencyGraphs.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeDependencyGraphs.kt @@ -19,6 +19,6 @@ internal class FakeDependencyGraphs( override fun directDependencies( project: Project, - buildGraphTypes: BuildGraphType? + buildGraphTypes: BuildGraphType ): Set = directDeps } \ No newline at end of file diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeProductFlavor.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeProductFlavor.kt index d3d3745f..3b29fd1d 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeProductFlavor.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeProductFlavor.kt @@ -23,6 +23,7 @@ import com.android.builder.model.ProductFlavor import com.android.builder.model.VectorDrawablesOptions import com.grab.grazel.extension.VariantFilter import com.grab.grazel.gradle.AndroidVariantDataSource +import com.grab.grazel.gradle.ConfigurationScope import org.gradle.api.Action import org.gradle.api.Project import java.io.File @@ -41,6 +42,13 @@ class FakeAndroidVariantDataSource( override fun getMigratableVariants(project: Project): List { return emptyList() } + + override fun getMigratableVariants( + project: Project, + configurationScope: ConfigurationScope? + ): Set { + return emptySet() + } } class FakeProductFlavor(private val name: String) : ProductFlavor { diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeVariant.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeVariant.kt index 049cb409..478821c2 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeVariant.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/fake/FakeVariant.kt @@ -52,7 +52,8 @@ internal const val RELEASE_FLAVOR2 = "releaseFlavor2" class FakeVariant( private val name: String, - private val flavor: String? = null + private val flavor: String? = null, + private val sourceSets: List = emptyList() ) : BaseVariant { override fun getProductFlavors(): MutableList = if (flavor != null) mutableListOf(FakeProductFlavor(flavor)) @@ -88,7 +89,7 @@ class FakeVariant( } override fun getSourceSets(): MutableList { - TODO("Not yet implemented") + return sourceSets.toMutableList() } override fun getJavaCompileOptions(): JavaCompileOptions { @@ -314,6 +315,6 @@ class FakeBuildType : BuildType { get() = TODO("Not yet implemented") override fun getName(): String { - TODO("Not yet implemented") + return "debug" } } \ No newline at end of file diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultAndroidVariantDataSourceTest.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultAndroidVariantDataSourceTest.kt index 7158f92a..d9291786 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultAndroidVariantDataSourceTest.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/gradle/DefaultAndroidVariantDataSourceTest.kt @@ -85,8 +85,7 @@ class DefaultAndroidVariantDataSourceTest : GrazelPluginTest() { class FakeAndroidVariantsExtractor : AndroidVariantsExtractor { override fun getVariants( - project: Project, - configurationScope: ConfigurationScope? + project: Project ): Set = setOf( FakeVariant(DEBUG_FLAVOR1, FLAVOR1), FakeVariant(DEBUG_FLAVOR2, FLAVOR2), diff --git a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultAndroidUnitTestDataExtractorTest.kt b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultAndroidUnitTestDataExtractorTest.kt index 5e533461..2742b566 100644 --- a/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultAndroidUnitTestDataExtractorTest.kt +++ b/grazel-gradle-plugin/src/test/kotlin/com/grab/grazel/migrate/android/DefaultAndroidUnitTestDataExtractorTest.kt @@ -21,12 +21,8 @@ import com.google.common.truth.Truth import com.grab.grazel.GrazelExtension import com.grab.grazel.GrazelPluginTest import com.grab.grazel.buildProject -import com.grab.grazel.fake.DEBUG_FLAVOR1 -import com.grab.grazel.fake.FLAVOR1 import com.grab.grazel.fake.FakeDependencyGraphs -import com.grab.grazel.fake.FakeVariant import com.grab.grazel.gradle.ANDROID_LIBRARY_PLUGIN -import com.grab.grazel.gradle.AndroidVariantsExtractor import com.grab.grazel.gradle.DefaultAndroidVariantDataSource import com.grab.grazel.gradle.DefaultConfigurationDataSource import com.grab.grazel.gradle.DefaultRepositoryDataSource @@ -39,6 +35,7 @@ import com.grab.grazel.gradle.dependencies.GradleDependencyToBazelDependency import com.grab.grazel.util.doEvaluate import org.gradle.api.Project import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.the import org.junit.Before import org.junit.Rule import org.junit.Test @@ -55,7 +52,6 @@ class DefaultAndroidUnitTestDataExtractorTest : GrazelPluginTest() { private lateinit var defaultAndroidUnitTestDataExtractor: DefaultAndroidUnitTestDataExtractor private lateinit var androidVariantsExtractor: FakeAndroidVariantsExtractor private lateinit var gradleDependencyToBazelDependency: GradleDependencyToBazelDependency - private val fakeVariant = FakeVariant(DEBUG_FLAVOR1, FLAVOR1) @get:Rule val temporaryFolder = TemporaryFolder() @@ -130,8 +126,11 @@ class DefaultAndroidUnitTestDataExtractorTest : GrazelPluginTest() { } subProject.doEvaluate() - val androidUnitTestData = - defaultAndroidUnitTestDataExtractor.extract(subProject, fakeVariant) + + val androidUnitTestData = defaultAndroidUnitTestDataExtractor.extract( + subProject, + debugUnitTestVariant(subProject) + ) Truth.assertThat(androidUnitTestData.resources).apply { contains("src/test/resources/test.json") } @@ -150,8 +149,10 @@ class DefaultAndroidUnitTestDataExtractorTest : GrazelPluginTest() { } subProject.doEvaluate() - val androidUnitTestData = - defaultAndroidUnitTestDataExtractor.extract(subProject, fakeVariant) + val androidUnitTestData = defaultAndroidUnitTestDataExtractor.extract( + subProject, + debugUnitTestVariant(subProject) + ) Truth.assertThat(androidUnitTestData.resources).apply { contains("src/test/resources/**") } @@ -170,14 +171,19 @@ class DefaultAndroidUnitTestDataExtractorTest : GrazelPluginTest() { } subProject.doEvaluate() + val androidUnitTestData = defaultAndroidUnitTestDataExtractor.extract( subProject, - fakeVariant + debugUnitTestVariant(subProject) ) - Truth.assertThat(androidUnitTestData.additionalSrcSets).apply { containsExactlyElementsIn(additionalTestSourceSets) containsNoneIn(defaultTestSourceSets) } } + + private fun debugUnitTestVariant(project: Project) = + project.project.the().unitTestVariants.first { + it.name == "debugUnitTest" + } } diff --git a/sample-android-flavor/BUILD.bazel b/sample-android-flavor/BUILD.bazel index a08efd71..babb5744 100644 --- a/sample-android-flavor/BUILD.bazel +++ b/sample-android-flavor/BUILD.bazel @@ -34,114 +34,3 @@ kt_db_android_library( "@maven//:org_jacoco_org_jacoco_ant", ], ) - -load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") - -build_config( - name = "sample-android-flavor-flavor2-debug-build-config", - package_name = "com.grab.grazel.android.flavor", -) - -load("@grab_bazel_common//tools/databinding:databinding.bzl", "kt_db_android_library") - -kt_db_android_library( - name = "sample-android-flavor-flavor2-debug", - srcs = glob([ - "src/main/java/com/grab/grazel/android/flavor/**/*.kt", - "src/flavor2/java/com/grab/grazel/android/flavor/HelloFlavorMessage.kt", - ]), - custom_package = "com.grab.grazel.android.flavor", - manifest = "src/main/AndroidManifest.xml", - resource_files = glob([ - "src/main/res/**", - ]) + glob([ - "src/flavor2/res/values/strings.xml", - ]), - visibility = [ - "//visibility:public", - ], - deps = [ - ":sample-android-flavor-flavor2-debug-build-config", - "//:parcelize", - "//sample-library-flavor2", - "@maven//:androidx_appcompat_appcompat", - "@maven//:androidx_constraintlayout_constraintlayout", - "@maven//:androidx_constraintlayout_constraintlayout_core", - "@maven//:androidx_core_core", - "@maven//:org_jacoco_org_jacoco_ant", - ], -) - -load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") - -build_config( - name = "sample-android-flavor-flavor1-release-build-config", - package_name = "com.grab.grazel.android.flavor", -) - -load("@grab_bazel_common//tools/databinding:databinding.bzl", "kt_db_android_library") - -kt_db_android_library( - name = "sample-android-flavor-flavor1-release", - srcs = glob([ - "src/main/java/com/grab/grazel/android/flavor/**/*.kt", - "src/flavor1/java/com/grab/grazel/android/flavor/HelloFlavorMessage.kt", - ]), - custom_package = "com.grab.grazel.android.flavor", - manifest = "src/main/AndroidManifest.xml", - resource_files = glob([ - "src/main/res/**", - ]) + glob([ - "src/flavor1/res/values/strings.xml", - ]), - visibility = [ - "//visibility:public", - ], - deps = [ - ":sample-android-flavor-flavor1-release-build-config", - "//:parcelize", - "//sample-library-flavor1", - "@maven//:androidx_appcompat_appcompat", - "@maven//:androidx_constraintlayout_constraintlayout", - "@maven//:androidx_constraintlayout_constraintlayout_core", - "@maven//:androidx_core_core", - "@maven//:org_jacoco_org_jacoco_ant", - ], -) - -load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") - -build_config( - name = "sample-android-flavor-flavor2-release-build-config", - package_name = "com.grab.grazel.android.flavor", -) - -load("@grab_bazel_common//tools/databinding:databinding.bzl", "kt_db_android_library") - -kt_db_android_library( - name = "sample-android-flavor-flavor2-release", - srcs = glob([ - "src/main/java/com/grab/grazel/android/flavor/**/*.kt", - "src/flavor2/java/com/grab/grazel/android/flavor/HelloFlavorMessage.kt", - ]), - custom_package = "com.grab.grazel.android.flavor", - manifest = "src/main/AndroidManifest.xml", - resource_files = glob([ - "src/main/res/**", - ]) + glob([ - "src/flavor2/res/values/strings.xml", - ]), - visibility = [ - "//visibility:public", - ], - deps = [ - ":sample-android-flavor-flavor2-release-build-config", - "//:parcelize", - "//sample-library-flavor2", - "@maven//:androidx_appcompat_appcompat", - "@maven//:androidx_constraintlayout_constraintlayout", - "@maven//:androidx_constraintlayout_constraintlayout_core", - "@maven//:androidx_core_core", - "@maven//:org_jacoco_org_jacoco_ant", - ], -) diff --git a/sample-android-library/BUILD.bazel b/sample-android-library/BUILD.bazel index 0275cf6d..43acf287 100644 --- a/sample-android-library/BUILD.bazel +++ b/sample-android-library/BUILD.bazel @@ -24,32 +24,6 @@ kt_android_library( ], ) -load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") - -build_config( - name = "sample-android-library-release-build-config", - package_name = "com.grab.grazel.android.sample.lib", -) - -load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library") - -kt_android_library( - name = "sample-android-library-release", - srcs = glob([ - "src/main/java/com/grab/grazel/android/sample/SampleViewModel.kt", - ]), - custom_package = "com.grab.grazel.android.sample.lib", - manifest = "src/main/AndroidManifest.xml", - visibility = [ - "//visibility:public", - ], - deps = [ - ":sample-android-library-release-build-config", - "//:parcelize", - "@maven//:org_jacoco_org_jacoco_ant", - ], -) - load("@grab_bazel_common//tools/test:test.bzl", "grab_android_local_test") grab_android_local_test( @@ -73,27 +47,3 @@ grab_android_local_test( "@maven//:junit_junit", ], ) - -load("@grab_bazel_common//tools/test:test.bzl", "grab_android_local_test") - -grab_android_local_test( - name = "sample-android-library-test-release-unit-test", - srcs = glob([ - "src/test/java/com/grab/grazel/android/sample/SampleViewModelTest.kt", - ]), - associates = [ - "//sample-android-library:sample-android-library-release_kt", - ], - custom_package = "com.grab.grazel.android.sample.lib", - resources = glob([ - "src/test/resources/**", - ]), - visibility = [ - "//visibility:public", - ], - deps = [ - "//:parcelize", - "//sample-android-library:sample-android-library-release", - "@maven//:junit_junit", - ], -) diff --git a/sample-android/BUILD.bazel b/sample-android/BUILD.bazel index b8336d1a..a612e4d6 100644 --- a/sample-android/BUILD.bazel +++ b/sample-android/BUILD.bazel @@ -16,54 +16,6 @@ crashlytics_android_library( load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") -android_binary( - name = "sample-android-flavor2-debug", - assets = glob([ - "src/main/assets/assert-file.png", - ]), - assets_dir = "src/main/assets", - crunch_png = False, - custom_package = "com.grab.grazel.android.sample", - debug_key = "//buildsystem:debug-keystore", - dex_shards = 5, - enable_data_binding = True, - incremental_dexing = True, - manifest = "src/debug/AndroidManifest.xml", - manifest_values = { - "versionCode": "1", - "versionName": "1.0", - "minSdkVersion": "16", - "targetSdkVersion": "29", - "applicationId": "com.grab.grazel.android.sample", - "orientation": "portrait", - "libraryManifestHolder": "value", - }, - multidex = "native", - resource_files = glob([ - "src/main/res/**", - ]) + custom_res( - dir_name = "res-debug", - resource_files = glob([ - "src/main/res-debug/values/strings.xml", - ]), - target = "sample-android-flavor2-debug", - ) + GOOGLE_SERVICES_XML, - visibility = [ - "//visibility:public", - ], - deps = [ - ":crashlytics_lib", - ":sample-android_lib-flavor2-debug", - "@maven//:androidx_annotation_annotation", - "@maven//:androidx_databinding_databinding_adapters", - "@maven//:androidx_databinding_databinding_common", - "@maven//:androidx_databinding_databinding_runtime", - "@maven//:androidx_databinding_viewbinding", - ], -) - -load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") - android_binary( name = "sample-android-flavor1-debug", assets = glob([ @@ -110,168 +62,6 @@ android_binary( ], ) -load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") - -android_binary( - name = "sample-android-flavor2-release", - assets = glob([ - "src/main/assets/assert-file.png", - ]), - assets_dir = "src/main/assets", - crunch_png = False, - custom_package = "com.grab.grazel.android.sample", - debug_key = "//buildsystem:debug-keystore", - dex_shards = 5, - enable_data_binding = True, - incremental_dexing = True, - manifest = "src/main/AndroidManifest.xml", - manifest_values = { - "versionCode": "1", - "versionName": "1.0", - "minSdkVersion": "16", - "targetSdkVersion": "29", - "applicationId": "com.grab.grazel.android.sample", - "orientation": "portrait", - "libraryManifestHolder": "value", - }, - multidex = "native", - resource_files = glob([ - "src/main/res/**", - ]) + custom_res( - dir_name = "res-release", - resource_files = glob([ - "src/main/res-release/values/strings.xml", - ]), - target = "sample-android-flavor2-release", - ) + GOOGLE_SERVICES_XML, - visibility = [ - "//visibility:public", - ], - deps = [ - ":crashlytics_lib", - ":sample-android_lib-flavor2-release", - "@maven//:androidx_annotation_annotation", - "@maven//:androidx_databinding_databinding_adapters", - "@maven//:androidx_databinding_databinding_common", - "@maven//:androidx_databinding_databinding_runtime", - "@maven//:androidx_databinding_viewbinding", - ], -) - -load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") - -android_binary( - name = "sample-android-flavor1-release", - assets = glob([ - "src/main/assets/assert-file.png", - ]), - assets_dir = "src/main/assets", - crunch_png = False, - custom_package = "com.grab.grazel.android.sample", - debug_key = "//buildsystem:debug-keystore", - dex_shards = 5, - enable_data_binding = True, - incremental_dexing = True, - manifest = "src/main/AndroidManifest.xml", - manifest_values = { - "versionCode": "1", - "versionName": "1.0", - "minSdkVersion": "16", - "targetSdkVersion": "29", - "applicationId": "com.grab.grazel.android.sample", - "orientation": "portrait", - "libraryManifestHolder": "value", - }, - multidex = "native", - resource_files = glob([ - "src/main/res/**", - ]) + custom_res( - dir_name = "res-release", - resource_files = glob([ - "src/main/res-release/values/strings.xml", - ]), - target = "sample-android-flavor1-release", - ) + GOOGLE_SERVICES_XML, - visibility = [ - "//visibility:public", - ], - deps = [ - ":crashlytics_lib", - ":sample-android_lib-flavor1-release", - "@maven//:androidx_annotation_annotation", - "@maven//:androidx_databinding_databinding_adapters", - "@maven//:androidx_databinding_databinding_common", - "@maven//:androidx_databinding_databinding_runtime", - "@maven//:androidx_databinding_viewbinding", - ], -) - -load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") - -build_config( - name = "sample-android_lib-flavor2-debug-build-config", - package_name = "com.grab.grazel.android.sample", - booleans = { - "SOME_BOOLEAN": "false", - }, - ints = { - "SOME_INT": 0, - "VERSION_CODE": 1, - }, - longs = { - "SOME_LONG": 0, - }, - strings = { - "SOME_STRING": "Something", - "VERSION_NAME": "1.0", - }, -) - -load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") -load("@grab_bazel_common//tools/res_value:res_value.bzl", "res_value") -load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library") - -kt_android_library( - name = "sample-android_lib-flavor2-debug", - srcs = glob([ - "src/main/java/com/grab/grazel/android/sample/MainActivity.kt", - ]), - assets = glob([ - "src/main/assets/assert-file.png", - ]), - assets_dir = "src/main/assets", - custom_package = "com.grab.grazel.android.sample", - manifest = "src/debug/AndroidManifest.xml", - resource_files = glob([ - "src/main/res/**", - ]) + custom_res( - dir_name = "res-debug", - resource_files = glob([ - "src/main/res-debug/values/strings.xml", - ]), - target = "sample-android_lib-flavor2-debug", - ) + res_value( - name = "sample-android_lib-flavor2-debug-res-value", - strings = { - "generated_value": "important-key", - }, - ), - visibility = [ - "//visibility:public", - ], - deps = [ - ":sample-android_lib-flavor2-debug-build-config", - "//:dagger", - "//:parcelize", - "//sample-android-flavor:sample-android-flavor-flavor2-debug", - "//sample-android-library:sample-android-library-debug", - "//sample-kotlin-library", - "@maven//:androidx_appcompat_appcompat", - "@maven//:androidx_constraintlayout_constraintlayout", - "@maven//:org_jacoco_org_jacoco_ant", - ], -) - load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") build_config( @@ -337,135 +127,3 @@ kt_android_library( "@maven//:org_jacoco_org_jacoco_ant", ], ) - -load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") - -build_config( - name = "sample-android_lib-flavor2-release-build-config", - package_name = "com.grab.grazel.android.sample", - booleans = { - "SOME_BOOLEAN": "false", - }, - ints = { - "SOME_INT": 0, - "VERSION_CODE": 1, - }, - longs = { - "SOME_LONG": 0, - }, - strings = { - "SOME_STRING": "Something", - "VERSION_NAME": "1.0", - }, -) - -load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") -load("@grab_bazel_common//tools/res_value:res_value.bzl", "res_value") -load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library") - -kt_android_library( - name = "sample-android_lib-flavor2-release", - srcs = glob([ - "src/main/java/com/grab/grazel/android/sample/MainActivity.kt", - ]), - assets = glob([ - "src/main/assets/assert-file.png", - ]), - assets_dir = "src/main/assets", - custom_package = "com.grab.grazel.android.sample", - manifest = "src/main/AndroidManifest.xml", - resource_files = glob([ - "src/main/res/**", - ]) + custom_res( - dir_name = "res-release", - resource_files = glob([ - "src/main/res-release/values/strings.xml", - ]), - target = "sample-android_lib-flavor2-release", - ) + res_value( - name = "sample-android_lib-flavor2-release-res-value", - strings = { - "generated_value": "important-key", - }, - ), - visibility = [ - "//visibility:public", - ], - deps = [ - ":sample-android_lib-flavor2-release-build-config", - "//:dagger", - "//:parcelize", - "//sample-android-flavor:sample-android-flavor-flavor2-release", - "//sample-android-library:sample-android-library-release", - "//sample-kotlin-library", - "@maven//:androidx_appcompat_appcompat", - "@maven//:androidx_constraintlayout_constraintlayout", - "@maven//:org_jacoco_org_jacoco_ant", - ], -) - -load("@grab_bazel_common//tools/build_config:build_config.bzl", "build_config") - -build_config( - name = "sample-android_lib-flavor1-release-build-config", - package_name = "com.grab.grazel.android.sample", - booleans = { - "SOME_BOOLEAN": "false", - }, - ints = { - "SOME_INT": 0, - "VERSION_CODE": 1, - }, - longs = { - "SOME_LONG": 0, - }, - strings = { - "SOME_STRING": "Something", - "VERSION_NAME": "1.0", - }, -) - -load("@grab_bazel_common//tools/custom_res:custom_res.bzl", "custom_res") -load("@grab_bazel_common//tools/res_value:res_value.bzl", "res_value") -load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library") - -kt_android_library( - name = "sample-android_lib-flavor1-release", - srcs = glob([ - "src/main/java/com/grab/grazel/android/sample/MainActivity.kt", - ]), - assets = glob([ - "src/main/assets/assert-file.png", - ]), - assets_dir = "src/main/assets", - custom_package = "com.grab.grazel.android.sample", - manifest = "src/main/AndroidManifest.xml", - resource_files = glob([ - "src/main/res/**", - ]) + custom_res( - dir_name = "res-release", - resource_files = glob([ - "src/main/res-release/values/strings.xml", - ]), - target = "sample-android_lib-flavor1-release", - ) + res_value( - name = "sample-android_lib-flavor1-release-res-value", - strings = { - "generated_value": "important-key", - }, - ), - visibility = [ - "//visibility:public", - ], - deps = [ - ":sample-android_lib-flavor1-release-build-config", - "//:dagger", - "//:parcelize", - "//sample-android-flavor:sample-android-flavor-flavor1-release", - "//sample-android-library:sample-android-library-release", - "//sample-kotlin-library", - "@maven//:androidx_appcompat_appcompat", - "@maven//:androidx_constraintlayout_constraintlayout", - "@maven//:org_jacoco_org_jacoco_ant", - ], -)