From 3e5cbf324de8b6f8243e79c28210184b750b855d Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Fri, 20 Nov 2020 11:21:42 +0100 Subject: [PATCH] syncKotlinAndAndroidSourceSets.kt: Cover flavors with tests --- .../AbstractKotlinAndroidGradleTests.kt | 13 +++++- .../lib/build.gradle.kts | 45 ++++++++++++++++++- .../SyncKotlinAndAndroidSourceSetsTest.kt | 41 ++++++++++++++++- .../mpp/syncKotlinAndAndroidSourceSets.kt | 2 +- 4 files changed, 95 insertions(+), 6 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/AbstractKotlinAndroidGradleTests.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/AbstractKotlinAndroidGradleTests.kt index 1e9a92466ee..2973827e45d 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/AbstractKotlinAndroidGradleTests.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/AbstractKotlinAndroidGradleTests.kt @@ -49,9 +49,18 @@ open class KotlinAndroid36GradleIT : KotlinAndroid33GradleIT() { assertContains("JNI sources: [lib/src/androidTestDebug/jni, lib/src/androidAndroidTestDebug/jni]") assertContains("JNI libraries: [lib/src/androidTestDebug/jniLibs, lib/src/androidAndroidTestDebug/jniLibs]") assertContains("Java-style resources: [lib/src/androidTestDebug/resources, lib/src/androidAndroidTestDebug/resources]") + + assertContains("Java sources: [lib/betaSrc/paidBeta/java, lib/src/androidPaidBeta/kotlin, lib/src/paidBeta/kotlin]") + assertContains("Java sources: [lib/betaSrc/paidBetaDebug/java, lib/src/androidPaidBetaDebug/kotlin, lib/src/paidBetaDebug/kotlin]") + assertContains("Java sources: [lib/betaSrc/paidBetaRelease/java, lib/src/androidPaidBetaRelease/kotlin, lib/src/paidBetaRelease/kotlin]") + + assertContains("Java sources: [lib/betaSrc/freeBeta/java, lib/src/androidFreeBeta/kotlin, lib/src/freeBeta/kotlin]") + assertContains("Java sources: [lib/betaSrc/freeBetaDebug/java, lib/src/androidFreeBetaDebug/kotlin, lib/src/freeBetaDebug/kotlin]") + assertContains("Java sources: [lib/betaSrc/freeBetaRelease/java, lib/src/androidFreeBetaRelease/kotlin, lib/src/freeBetaRelease/kotlin]") + } - build("testDebug") { + build("testFreeBetaDebug") { assertFailed() assertContains("CommonTest > fail FAILED") assertContains("TestKotlin > fail FAILED") @@ -886,4 +895,4 @@ fun getSomething() = 10 assertContainsRegex(kotlinJvmTarget18Regex) } } -} \ No newline at end of file +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android-source-sets/lib/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android-source-sets/lib/build.gradle.kts index 1da4a7944ab..fddf5ddbfab 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android-source-sets/lib/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android-source-sets/lib/build.gradle.kts @@ -10,6 +10,47 @@ android { targetSdkVersion(28) testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" } + + flavorDimensions("pricing", "releaseType") + + productFlavors { + create("beta") { + setDimension("releaseType") + } + create("production") { + setDimension("releaseType") + } + create("free") { + setDimension("pricing") + } + create("paid") { + setDimension("pricing") + } + } + + sourceSets { + maybeCreate("beta").apply { + setRoot("betaSrc/beta") + } + maybeCreate("freeBeta").apply { + setRoot("betaSrc/freeBeta") + } + maybeCreate("freeBetaDebug").apply { + setRoot("betaSrc/freeBetaDebug") + } + maybeCreate("freeBetaRelease").apply { + setRoot("betaSrc/freeBetaRelease") + } + maybeCreate("paidBeta").apply { + setRoot("betaSrc/paidBeta") + } + maybeCreate("paidBetaDebug").apply { + setRoot("betaSrc/paidBetaDebug") + } + maybeCreate("paidBetaRelease").apply { + setRoot("betaSrc/paidBetaRelease") + } + } } kotlin { @@ -21,7 +62,7 @@ kotlin { implementation(kotlin("stdlib-common")) } - getByName("commonMain").dependencies { + getByName("commonTest").dependencies { implementation(kotlin("test")) implementation(kotlin("test-annotations-common")) } @@ -35,4 +76,4 @@ kotlin { implementation("com.android.support.test:runner:1.0.2") } } -} \ No newline at end of file +} diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/SyncKotlinAndAndroidSourceSetsTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/SyncKotlinAndAndroidSourceSetsTest.kt index 94b4c1f52fb..3304bfbf5f6 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/SyncKotlinAndAndroidSourceSetsTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/SyncKotlinAndAndroidSourceSetsTest.kt @@ -2,7 +2,7 @@ * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -@file:Suppress("invisible_reference", "invisible_member", "FunctionName") +@file:Suppress("invisible_reference", "invisible_member", "FunctionName", "DuplicatedCode") package org.jetbrains.kotlin.gradle @@ -89,8 +89,47 @@ class SyncKotlinAndAndroidSourceSetsTest { ) } + @Test + fun `two product flavor dimensions`() { + android.flavorDimensions("pricing", "releaseType") + android.productFlavors { + it.create("beta").dimension = "releaseType" + it.create("production").dimension = "releaseType" + it.create("free").dimension = "pricing" + it.create("paid").dimension = "pricing" + } + kotlin.android() + project.evaluate() + + fun assertSourceSetsExist(androidName: String, kotlinName: String) { + val androidSourceSet = assertNotNull(android.sourceSets.findByName(androidName), "Expected Android source set '$androidName'") + val kotlinSourceSet = assertNotNull(kotlin.sourceSets.findByName(kotlinName), "Expected Kotlin source set '$kotlinName'") + assertSame(kotlinSourceSet, androidSourceSet.kotlinSourceSet) + } + + assertSourceSetsExist("freeBetaDebug", "androidFreeBetaDebug") + assertSourceSetsExist("freeBetaRelease", "androidFreeBetaRelease") + + assertSourceSetsExist("freeProductionDebug", "androidFreeProductionDebug") + assertSourceSetsExist("freeProductionRelease", "androidFreeProductionRelease") + + + assertSourceSetsExist("paidBetaDebug", "androidPaidBetaDebug") + assertSourceSetsExist("paidBetaRelease", "androidPaidBetaRelease") + + assertSourceSetsExist("paidProductionDebug", "androidPaidProductionDebug") + assertSourceSetsExist("paidProductionRelease", "androidPaidProductionRelease") + } + @Test fun `all source directories are disjoint in source sets`() { + android.flavorDimensions("pricing", "releaseType") + android.productFlavors { + it.create("beta").dimension = "releaseType" + it.create("production").dimension = "releaseType" + it.create("free").dimension = "pricing" + it.create("paid").dimension = "pricing" + } kotlin.android() project.evaluate() diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/syncKotlinAndAndroidSourceSets.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/syncKotlinAndAndroidSourceSets.kt index 83f228797f5..c1c7ae33777 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/syncKotlinAndAndroidSourceSets.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/syncKotlinAndAndroidSourceSets.kt @@ -105,7 +105,7 @@ private fun syncKotlinAndAndroidResources( androidSourceSet.resources.srcDirs(*kotlinSourceSet.resources.toList().toTypedArray()) if (androidSourceSet.resources.srcDirs.isNotEmpty()) { androidSourceSet.resources.srcDir(kotlinSourceSet.sourceFolderFor(project, "resources")) - kotlinSourceSet.resources.srcDirs(androidSourceSet.resources.srcDirs - kotlinSourceSet.resources.srcDirs) + kotlinSourceSet.resources.srcDirs(androidSourceSet.resources.srcDirs) } if (androidSourceSet.assets.srcDirs.isNotEmpty()) {