Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: 2.0.3-release
ref: 2.0.4-release

- name: merge commits from main to release branch
run: |
Expand All @@ -40,7 +40,7 @@ jobs:
VERSION_BUMPS=$(git log $MERGE_BASE..origin/main --pretty=%H --grep UPDATE_KOTLIN_VERSION)
TO_PICK=$(grep -Fxv -f <(echo "$PICKED"; echo "$VERSION_BUMPS"; echo "$DONT_PICK") <(echo "$CANDIDATES") | awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }')
echo Picking $TO_PICK
if [ -n "$TO_PICK" ]; then git cherry-pick -x $TO_PICK; fi
if [ -n "$TO_PICK" ]; then git cherry-pick -x --allow-empty $TO_PICK; fi

- name: Setup Java 17
uses: actions/[email protected]
Expand Down
762 changes: 0 additions & 762 deletions api/api.base

This file was deleted.

3 changes: 2 additions & 1 deletion compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.google.devtools.ksp.RelativizingInternalPathProvider
import com.google.devtools.ksp.RelativizingPathProvider

evaluationDependsOn(":common-util")
Expand Down Expand Up @@ -116,5 +117,5 @@ tasks.test.configure {
.asFile
.apply { if (!exists()) mkdirs() }
jvmArgumentProviders.add(RelativizingPathProvider("idea.home.path", ideaHomeDir))
jvmArgumentProviders.add(RelativizingPathProvider("java.io.tmpdir", temporaryDir))
jvmArgumentProviders.add(RelativizingInternalPathProvider("java.io.tmpdir", temporaryDir))
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ object AndroidPluginIntegration {
}

fun getCompilationSourceSets(kotlinCompilation: KotlinJvmAndroidCompilation): List<String> {
return kotlinCompilation.androidVariant
.sourceSets
.map { it.name }
return kotlinCompilation.androidVariant?.sourceSets?.map { it.name } ?: emptyList()
}

/**
Expand All @@ -81,36 +79,33 @@ object AndroidPluginIntegration {
val kaptProvider: TaskProvider<Task>? =
project.locateTask(kotlinCompilation.compileTaskProvider.kaptTaskName)

val useLegacyApi = project.useLegacyVariantApi()
if (useLegacyApi) {
val sources = kotlinCompilation.androidVariant.getSourceFolders(SourceKind.JAVA)
kspTaskProvider.configure { task ->
// this is workaround for KAPT generator that prevents circular dependency
val filteredSources = Callable {
val destinationProperty = (kaptProvider?.get() as? KaptTask)?.destinationDir
val dir = destinationProperty?.get()?.asFile
sources.filter { dir?.isParentOf(it.dir) != true }
}
when (task) {
is KspTaskJvm -> { task.source(filteredSources) }
is KspAATask -> { task.kspConfig.javaSourceRoots.from(filteredSources) }
else -> Unit
}
val androidVariant = kotlinCompilation.androidVariant
if (androidVariant == null) {
throw RuntimeException(
"KSP is not compatible with Android Gradle Plugin's built-in Kotlin. " +
"Please disable by adding android.builtInKotlin=false to gradle.properties " +
"and apply kotlin(\"android\") plugin"
)
}
val sources = androidVariant.getSourceFolders(SourceKind.JAVA)

kspTaskProvider.configure { task ->
// this is workaround for KAPT generator that prevents circular dependency
val filteredSources = Callable {
val destinationProperty = (kaptProvider?.get() as? KaptTask)?.destinationDir
val dir = destinationProperty?.get()?.asFile
sources.filter { dir?.isParentOf(it.dir) != true }
}
} else {
kspTaskProvider.configure { task ->
val sources = androidComponent?.sources?.java?.static
// this is workaround for KAPT generator that prevents circular dependency
val filteredSources = Callable {
val destinationProperty = (kaptProvider?.get() as? KaptTask)?.destinationDir
val dir = destinationProperty?.get()?.asFile
sources?.map { it.filter { dir?.isParentOf(it.asFile) != true } }
when (task) {
is KspTaskJvm -> {
task.source(filteredSources)
}
when (task) {
is KspTaskJvm -> { task.source(filteredSources) }
is KspAATask -> { task.kspConfig.javaSourceRoots.from(filteredSources) }
else -> Unit

is KspAATask -> {
task.kspConfig.javaSourceRoots.from(filteredSources)
}

else -> Unit
}
}
}
Expand All @@ -135,14 +130,14 @@ object AndroidPluginIntegration {
classOutputDir: Provider<Directory>,
resourcesOutputDir: Provider<Directory>,
androidComponent: Component?,
useKsp2: Boolean,
) {
if (androidComponent != null && kspTaskProvider.isKspAATask() &&
project.canUseAddGeneratedSourceDirectoriesApi()
) {
if (androidComponent != null && useKsp2 && project.canUseAddGeneratedSourceDirectoriesApi()) {
androidComponent.sources.java?.addGeneratedSourceDirectory(
taskProvider = kspTaskProvider,
wiredWith = { task -> (task as KspAATask).kspConfig.javaOutputDir }
)

androidComponent.sources.java?.addGeneratedSourceDirectory(
taskProvider = kspTaskProvider,
wiredWith = { task -> (task as KspAATask).kspConfig.kotlinOutputDir }
Expand Down Expand Up @@ -180,18 +175,16 @@ object AndroidPluginIntegration {
kspKotlinOutput.include("**/*.kt")
kspClassOutput.include("**/*.class")

kotlinCompilation.androidVariant.addJavaSourceFoldersToModel(kspKotlinOutput.dir)
kotlinCompilation.androidVariant.registerExternalAptJavaOutput(kspJavaOutput)
kotlinCompilation.androidVariant.registerPostJavacGeneratedBytecode(resourcesOutput)
kotlinCompilation.androidVariant?.addJavaSourceFoldersToModel(kspKotlinOutput.dir)
kotlinCompilation.androidVariant?.registerExternalAptJavaOutput(kspJavaOutput)
kotlinCompilation.androidVariant?.registerPostJavacGeneratedBytecode(resourcesOutput)
if (project.isAgpBuiltInKotlinUsed().not()) {
// This API leads to circular dependency with AGP + Built in kotlin
kotlinCompilation.androidVariant.registerPreJavacGeneratedBytecode(kspClassOutput)
kotlinCompilation.androidVariant?.registerPreJavacGeneratedBytecode(kspClassOutput)
}
}
}

fun TaskProvider<*>.isKspAATask(): Boolean = map { it is KspAATask }.getOrElse(false)

fun syncSourceSets(
project: Project,
kotlinCompilation: KotlinJvmAndroidCompilation,
Expand All @@ -200,7 +193,8 @@ object AndroidPluginIntegration {
kotlinOutputDir: Provider<Directory>,
classOutputDir: Provider<Directory>,
resourcesOutputDir: Provider<Directory>,
androidComponent: Component?
androidComponent: Component?,
useKsp2: Boolean,
) {
// Order is important here as we update task with AGP generated sources and
// then update AGP with source that KSP will generate.
Expand All @@ -215,7 +209,8 @@ object AndroidPluginIntegration {
kotlinOutputDir,
classOutputDir,
resourcesOutputDir,
androidComponent
androidComponent,
useKsp2
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskProvider
import org.gradle.process.CommandLineArgumentProvider
import org.gradle.process.ExecOperations
import org.gradle.work.Incremental
import org.gradle.work.InputChanges
import org.gradle.work.NormalizeLineEndings
Expand Down Expand Up @@ -308,13 +307,11 @@ abstract class KspTaskNative @Inject internal constructor(
compilation: KotlinCompilationInfo,
objectFactory: ObjectFactory,
providerFactory: ProviderFactory,
execOperations: ExecOperations
) : KotlinNativeCompile(
compilation,
objectFactory.newInstance(KotlinNativeCompilerOptionsDefault::class.java),
objectFactory,
providerFactory,
execOperations
),
KspTask

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.google.devtools.ksp.gradle

import com.google.devtools.ksp.gradle.AndroidPluginIntegration.canUseAddGeneratedSourceDirectoriesApi
import com.google.devtools.ksp.impl.KotlinSymbolProcessing
import com.google.devtools.ksp.processing.ExitCode
import com.google.devtools.ksp.processing.KSPCommonConfig
Expand Down Expand Up @@ -207,13 +206,9 @@ abstract class KspAATask @Inject constructor(
}
cfg.sourceRoots.from(filtered)
cfg.javaSourceRoots.from(filtered)
if (kotlinCompilation.platformType != KotlinPlatformType.androidJvm &&
project.canUseAddGeneratedSourceDirectoriesApi()
) {
kspAATask.dependsOn(
sourceSet.kotlin.nonSelfDeps(kspTaskName).filter { it.name !in filteredTasks }
)
}
kspAATask.dependsOn(
sourceSet.kotlin.nonSelfDeps(kspTaskName).filter { it.name !in filteredTasks }
)
}
if (kotlinCompilation is KotlinCommonCompilation) {
cfg.commonSourceRoots.from(kotlinCompilation.defaultSourceSet.kotlin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
classOutputDir = classOutputDir,
resourcesOutputDir = resourceOutputDir,
androidComponent = component,
useKsp2 = useKSP2
)
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copied from kotlinc
org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx4096m -Dfile.encoding=UTF-8

kotlinBaseVersion=2.2.20-dev-5774
kotlinBaseVersion=2.2.20
agpBaseVersion=8.13.0-rc01
intellijVersion=241.19416.19
junitVersion=4.13.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class AGP900IT(useKSP2: Boolean) {
fun testRunsKSP() {
val gradleRunner = GradleRunner.create().withProjectDir(project.root).withGradleVersion("9.0.0")

File(project.root, "gradle.properties").appendText("\nagpVersion=9.0.0-alpha03")
File(project.root, "gradle.properties").appendText("\nagpVersion=9.0.0-alpha05")
File(project.root, "gradle.properties").appendText("\nandroid.builtInKotlin=false")
File(project.root, "gradle.properties").appendText("\nandroid.newDsl=false")

gradleRunner.withArguments(":workload:compileDebugKotlin").build().let { result ->
Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":workload:kspDebugKotlin")?.outcome)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,23 @@ class AndroidBuiltInKotlinIT {
assert("w: [ksp] [workload_release] Mangled name for internalFun: internalFun\$workload_release" in outputs)
}
}

@Test
fun testPlaygroundAndroidWithBuiltInKotlinAGP90() {
val gradleRunner = GradleRunner.create().withProjectDir(project.root).withGradleVersion("9.0.0")

File(project.root, "gradle.properties").appendText("\nagpVersion=9.0.0-alpha05")

gradleRunner.withArguments(
"clean", "build", "minifyReleaseWithR8", "--configuration-cache", "--info", "--stacktrace"
).buildAndFail().let { result ->
Assert.assertTrue(
result.output.contains(
"KSP is not compatible with Android Gradle Plugin's built-in Kotlin. " +
"Please disable by adding android.builtInKotlin=false to gradle.properties " +
"and apply kotlin(\"android\") plugin"
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.google.devtools.ksp.test

import org.gradle.testkit.runner.GradleRunner
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized::class)
class AndroidDataBindingIT(useKSP2: Boolean) {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("android-data-binding", useKSP2 = useKSP2)

@Test
fun testPlaygroundAndroid() {
val gradleRunner = GradleRunner.create().withProjectDir(project.root)

// Disabling configuration cache. See https://github.com/google/ksp/issues/299 for details
gradleRunner.withArguments(
"clean",
":app:assemble",
"--configuration-cache-problems=warn",
"--info",
"--stacktrace"
)
.build().let { result ->
val output = result.output.lines()
val kspTask = output.filter {
it.contains(":app:kspDebugKotlin")
}
Assert.assertTrue(kspTask.isNotEmpty())
}
}

companion object {
@JvmStatic
@Parameterized.Parameters(name = "KSP2={0}")
fun params() = listOf(arrayOf(true), arrayOf(false))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.junit.runners.Parameterized
class AndroidViewBindingIT(useKSP2: Boolean) {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("android-view-binding", "playground", useKSP2)
val project: TemporaryTestProject = TemporaryTestProject("android-view-binding", useKSP2 = useKSP2)

@Test
fun testPlaygroundAndroid() {
Expand All @@ -20,7 +20,7 @@ class AndroidViewBindingIT(useKSP2: Boolean) {
// Disabling configuration cache. See https://github.com/google/ksp/issues/299 for details
gradleRunner.withArguments(
"clean",
":app:testDebugUnitTest",
":app:assemble",
"--configuration-cache-problems=warn",
"--info",
"--stacktrace"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@ class GeneratedSrcsIncIT(useKSP2: Boolean) {
val gradleRunner = GradleRunner.create().withProjectDir(project.root)

val expected = listOf(
"w: [ksp] 1: [File: Bar.kt, File: Baz.kt]",
"w: [ksp] 2: [File: Foo.kt]",
"w: [ksp] 1: [File: A.kt, File: Bar.kt, File: Baz.kt, File: MyJavaClass.java, File: MyKotlinClass.kt]",
"w: [ksp] 2: [File: Foo.kt, File: MyJavaClassBuilder.kt, File: MyKotlinClassBuilder.kt]",
"w: [ksp] 3: [File: FooBar.kt, File: FooBaz.kt]"
)

gradleRunner.withArguments("assemble").build().let { result ->
val outputs = result.output.lines().filter { it.startsWith("w: [ksp]") }
val outputs = result.output.lines().filter { it.startsWith("w: [ksp]") }.distinct()
Assert.assertEquals(expected, outputs)
}

val expected2 = listOf(
"w: [ksp] 1: [File: Bar.kt, File: Baz.kt, File: MyJavaClass.java, File: MyKotlinClass.kt]",
"w: [ksp] 2: [File: Foo.kt, File: MyJavaClassBuilder.kt, File: MyKotlinClassBuilder.kt]",
"w: [ksp] 3: [File: FooBar.kt, File: FooBaz.kt]"
)

File(project.root, "workload/src/main/kotlin/com/example/Baz.kt").appendText(System.lineSeparator())
gradleRunner.withArguments("assemble").build().let { result ->
val outputs = result.output.lines().filter { it.startsWith("w: [ksp]") }
Assert.assertEquals(expected, outputs)
val outputs = result.output.lines().filter { it.startsWith("w: [ksp]") }.distinct()
Assert.assertEquals(expected2, outputs)
}
}

Expand Down
Loading