diff options
author | Ivan Gavrilovic <gavra@google.com> | 2021-10-04 19:14:51 +0100 |
---|---|---|
committer | laszio <ting-yuan@users.noreply.github.com> | 2021-10-04 12:59:50 -0700 |
commit | 4d5ebe1a5fd5e2ff9faa0e769949f46b11658b2b (patch) | |
tree | fc3264b23a5f6b6bf85d482c7b092c4668e3e564 | |
parent | 043baf0e67b43ad463434ac118f71bc9a814357a (diff) | |
download | ksp-4d5ebe1a5fd5e2ff9faa0e769949f46b11658b2b.tar.gz |
Add test project with Android library and application
... in order to test incremental Kotlin compilation
if KSP is applied in the library, to address issue #647.
Test: AndroidIncrementalIT
12 files changed, 258 insertions, 0 deletions
diff --git a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt index f14534ab..b273a6ce 100644 --- a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt +++ b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt @@ -419,6 +419,9 @@ abstract class KspTaskJvm : KotlinCompile(KotlinJvmOptionsImpl()), KspTask { kotlinCompile: AbstractKotlinCompile<*>, ) { Configurator<KspTaskJvm>(kotlinCompilation).configure(this) + // Assign moduleName different from kotlin compilation to work around https://github.com/google/ksp/issues/647 + // This will not be necessary once https://youtrack.jetbrains.com/issue/KT-45777 lands + this.moduleName.set(kotlinCompile.moduleName.map { "$it-ksp" }) kotlinCompile as KotlinCompile val providerFactory = kotlinCompile.project.providers compileKotlinArgumentsContributor.set( diff --git a/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/AndroidIncrementalIT.kt b/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/AndroidIncrementalIT.kt new file mode 100644 index 00000000..3bea21d7 --- /dev/null +++ b/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/AndroidIncrementalIT.kt @@ -0,0 +1,61 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * 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.google.devtools.ksp.test + +import com.google.devtools.ksp.test.fixtures.BuildResultFixture +import org.gradle.testkit.runner.GradleRunner +import org.gradle.testkit.runner.TaskOutcome +import org.junit.Assert +import org.junit.Rule +import org.junit.Test + +class AndroidIncrementalIT { + @Rule + @JvmField + val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground") + + @Test + fun testPlaygroundAndroid() { + val gradleRunner = GradleRunner.create().withProjectDir(project.root) + + gradleRunner.withArguments( + "clean", ":application:compileDebugKotlin", "--configuration-cache-problems=warn", "--debug", "--stacktrace" + ).build().let { result -> + Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":workload:compileDebugKotlin")?.outcome) + Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":application:compileDebugKotlin")?.outcome) + } + + project.root.resolve("workload/src/main/java/com/example/A.kt").also { + it.appendText( + """ + + class Unused + """.trimIndent() + ) + } + + gradleRunner.withArguments( + ":application:compileDebugKotlin", "--configuration-cache-problems=warn", "--debug", "--stacktrace" + ).build().let { result -> + Assert.assertEquals( + setOf("workload/src/main/java/com/example/A.kt"), + BuildResultFixture(result).compiledKotlinSources, + ) + } + } +} diff --git a/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/fixtures/BuildResultFixture.kt b/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/fixtures/BuildResultFixture.kt new file mode 100644 index 00000000..cb66ea1b --- /dev/null +++ b/integration-tests/src/test/kotlin/com/google/devtools/ksp/test/fixtures/BuildResultFixture.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * 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.google.devtools.ksp.test.fixtures + +import org.gradle.testkit.runner.BuildResult + +private val compileKotlinSrcs = Regex("\\[KOTLIN\\] compile iteration: ([^\\r\\n]*)") + +class BuildResultFixture(private val result: BuildResult) { + + /** Get all compiled Kotlin sources in the current build. */ + val compiledKotlinSources by lazy { + compileKotlinSrcs.findAll(result.output) + .asIterable() + .flatMap { + it.groups[1]!!.value.split(", ") + }.toSet() + } +} diff --git a/integration-tests/src/test/resources/playground-android-multi/application/build.gradle.kts b/integration-tests/src/test/resources/playground-android-multi/application/build.gradle.kts new file mode 100644 index 00000000..7f328d2c --- /dev/null +++ b/integration-tests/src/test/resources/playground-android-multi/application/build.gradle.kts @@ -0,0 +1,31 @@ +val testRepo: String by project + +plugins { + id("com.android.application") + kotlin("android") +} + +version = "1.0-SNAPSHOT" + +repositories { + maven(testRepo) + mavenCentral() + maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") + jcenter() +} + +dependencies { + implementation(kotlin("stdlib")) + implementation(project(":workload")) +} + +android { + compileSdkVersion(30) + defaultConfig { + applicationId = "org.gradle.kotlin.dsl.samples.androidstudio" + minSdkVersion(30) + targetSdkVersion(30) + versionCode = 1 + versionName = "1.0" + } +} diff --git a/integration-tests/src/test/resources/playground-android-multi/application/src/main/AndroidManifest.xml b/integration-tests/src/test/resources/playground-android-multi/application/src/main/AndroidManifest.xml new file mode 100644 index 00000000..81a4ba30 --- /dev/null +++ b/integration-tests/src/test/resources/playground-android-multi/application/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.myapplication"> +</manifest>
\ No newline at end of file diff --git a/integration-tests/src/test/resources/playground-android-multi/application/src/main/java/com/example/application/Foo.kt b/integration-tests/src/test/resources/playground-android-multi/application/src/main/java/com/example/application/Foo.kt new file mode 100644 index 00000000..4f164e18 --- /dev/null +++ b/integration-tests/src/test/resources/playground-android-multi/application/src/main/java/com/example/application/Foo.kt @@ -0,0 +1,3 @@ +package com.example.application + +class Foo diff --git a/integration-tests/src/test/resources/playground-android-multi/build.gradle.kts b/integration-tests/src/test/resources/playground-android-multi/build.gradle.kts new file mode 100644 index 00000000..b349665d --- /dev/null +++ b/integration-tests/src/test/resources/playground-android-multi/build.gradle.kts @@ -0,0 +1,29 @@ +buildscript { + val testRepo: String by project + + repositories { + maven(testRepo) + mavenCentral() + maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") + jcenter() + google() + } +} + +plugins { + id("com.android.application") apply false + kotlin("android") apply false + id("com.google.devtools.ksp") apply false + id("com.android.library") apply false +} + +allprojects { + val testRepo: String by project + repositories { + maven(testRepo) + mavenCentral() + maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") + jcenter() + google() + } +} diff --git a/integration-tests/src/test/resources/playground-android-multi/gradle.properties b/integration-tests/src/test/resources/playground-android-multi/gradle.properties new file mode 100644 index 00000000..b3c7a033 --- /dev/null +++ b/integration-tests/src/test/resources/playground-android-multi/gradle.properties @@ -0,0 +1 @@ +org.gradle.jvmargs=-Xmx2048M diff --git a/integration-tests/src/test/resources/playground-android-multi/settings.gradle.kts b/integration-tests/src/test/resources/playground-android-multi/settings.gradle.kts new file mode 100644 index 00000000..2daf2ddf --- /dev/null +++ b/integration-tests/src/test/resources/playground-android-multi/settings.gradle.kts @@ -0,0 +1,27 @@ +pluginManagement { + val kotlinVersion: String by settings + val kspVersion: String by settings + val testRepo: String by settings + val agpVersion: String by settings + plugins { + id("com.google.devtools.ksp") version kspVersion apply false + kotlin("jvm") version kotlinVersion apply false + kotlin("android") version kotlinVersion apply false + id("com.android.application") version agpVersion apply false + id("com.android.library") version agpVersion apply false + } + repositories { + maven(testRepo) + gradlePluginPortal() + google() + jcenter() + mavenCentral() + maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") + } +} + +rootProject.name = "playground" + +include(":application") +include(":workload") +include(":test-processor") diff --git a/integration-tests/src/test/resources/playground-android-multi/test-processor/build.gradle.kts b/integration-tests/src/test/resources/playground-android-multi/test-processor/build.gradle.kts new file mode 100644 index 00000000..75c6c7c5 --- /dev/null +++ b/integration-tests/src/test/resources/playground-android-multi/test-processor/build.gradle.kts @@ -0,0 +1,25 @@ +val kspVersion: String by project +val testRepo: String by project + +plugins { + kotlin("jvm") +} + +group = "com.example" +version = "1.0-SNAPSHOT" + +repositories { + maven(testRepo) + mavenCentral() + maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") +} + +dependencies { + implementation(kotlin("stdlib")) + implementation("com.squareup:javapoet:1.12.1") + implementation("com.google.devtools.ksp:symbol-processing-api:$kspVersion") +} + +sourceSets.main { + java.srcDirs("src/main/kotlin") +} diff --git a/integration-tests/src/test/resources/playground-android-multi/workload/build.gradle.kts b/integration-tests/src/test/resources/playground-android-multi/workload/build.gradle.kts new file mode 100644 index 00000000..518ed04e --- /dev/null +++ b/integration-tests/src/test/resources/playground-android-multi/workload/build.gradle.kts @@ -0,0 +1,36 @@ +val testRepo: String by project + +plugins { + // DO NOT CHANGE THE ORDER. + id("com.google.devtools.ksp") + id("com.android.library") + kotlin("android") +} + +version = "1.0-SNAPSHOT" + +repositories { + maven(testRepo) + mavenCentral() + maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") + jcenter() +} + +dependencies { + implementation(kotlin("stdlib")) + implementation(project(":test-processor")) + ksp(project(":test-processor")) +} + +android { + compileSdkVersion(30) + defaultConfig { + minSdkVersion(30) + targetSdkVersion(30) + } +} + +ksp { + arg("option1", "value1") + arg("option2", "value2") +} diff --git a/integration-tests/src/test/resources/playground-android-multi/workload/src/main/AndroidManifest.xml b/integration-tests/src/test/resources/playground-android-multi/workload/src/main/AndroidManifest.xml new file mode 100644 index 00000000..522bce61 --- /dev/null +++ b/integration-tests/src/test/resources/playground-android-multi/workload/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.mylibrary"> +</manifest>
\ No newline at end of file |