Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPDATE_KOTLIN_VERSION: 2.0.0-Beta3 #1686

Merged
merged 10 commits into from
Jan 18, 2024
8 changes: 6 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ subprojects {
}

tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
sourceCompatibility = JavaVersion.VERSION_11.toString()
targetCompatibility = JavaVersion.VERSION_11.toString()
javaCompiler.set(
javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(17))
Expand All @@ -121,4 +121,8 @@ subprojects {
}
)
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions.freeCompilerArgs.add("-Xskip-prerelease-check")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ package com.google.devtools.ksp.symbol.impl.binary
import com.google.devtools.ksp.memoized
import com.google.devtools.ksp.processing.impl.KSNameImpl
import com.google.devtools.ksp.symbol.*
import org.jetbrains.kotlin.backend.common.serialization.findPackage
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.findPackage
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.parents
Expand All @@ -50,7 +50,7 @@ abstract class KSDeclarationDescriptorImpl(private val descriptor: DeclarationDe
is ClassDescriptor -> KSClassDeclarationDescriptorImpl.getCached(containingDescriptor)
is FunctionDescriptor -> KSFunctionDeclarationDescriptorImpl.getCached(containingDescriptor)
else -> null
} as KSDeclaration?
}
}

override val parent: KSNode? by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.gradle.process.CommandLineArgumentProvider
import org.gradle.process.ExecOperations
import org.gradle.work.InputChanges
import org.gradle.workers.WorkerExecutor
import org.jetbrains.kotlin.buildtools.api.SourcesChanges
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
Expand Down Expand Up @@ -67,7 +68,6 @@ import org.jetbrains.kotlin.gradle.tasks.TaskOutputsBackup
import org.jetbrains.kotlin.gradle.tasks.configuration.BaseKotlin2JsCompileConfig
import org.jetbrains.kotlin.gradle.tasks.configuration.KotlinCompileCommonConfig
import org.jetbrains.kotlin.gradle.tasks.configuration.KotlinCompileConfig
import org.jetbrains.kotlin.incremental.ChangedFiles
import org.jetbrains.kotlin.konan.target.HostManager
import java.io.File
import java.nio.file.Paths
Expand Down Expand Up @@ -186,7 +186,7 @@ interface KspTask : Task {
val commandLineArgumentProviders: ListProperty<CommandLineArgumentProvider>

@get:Internal
val incrementalChangesTransformers: ListProperty<(ChangedFiles) -> List<SubpluginOption>>
val incrementalChangesTransformers: ListProperty<(SourcesChanges) -> List<SubpluginOption>>
}

@CacheableTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
import org.gradle.util.GradleVersion
import org.gradle.work.ChangeType
import org.gradle.work.InputChanges
import org.jetbrains.kotlin.buildtools.api.SourcesChanges
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.internal.kapt.incremental.CLASS_STRUCTURE_ARTIFACT_TYPE
Expand All @@ -56,7 +57,6 @@ import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.tasks.*
import org.jetbrains.kotlin.incremental.ChangedFiles
import org.jetbrains.kotlin.incremental.isJavaFile
import org.jetbrains.kotlin.incremental.isKotlinFile
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
Expand Down Expand Up @@ -661,15 +661,16 @@ internal fun getClassStructureFiles(
// Reuse Kapt's infrastructure to compute affected names in classpath.
// This is adapted from KaptTask.findClasspathChanges.
internal fun findClasspathChanges(
changes: ChangedFiles,
changes: SourcesChanges,
cacheDir: File,
allDataFiles: Set<File>,
libs: List<File>,
processorCP: List<File>,
): KaptClasspathChanges {
cacheDir.mkdirs()

val changedFiles = (changes as? ChangedFiles.Known)?.let { it.modified + it.removed }?.toSet() ?: allDataFiles
val changedFiles =
(changes as? SourcesChanges.Known)?.let { it.modifiedFiles + it.removedFiles }?.toSet() ?: allDataFiles

val loadedPrevious = ClasspathSnapshot.ClasspathSnapshotFactory.loadFrom(cacheDir)
val previousAndCurrentDataFiles = lazy { loadedPrevious.getAllDataFiles() + allDataFiles }
Expand Down Expand Up @@ -698,7 +699,7 @@ internal fun findClasspathChanges(
)

val classpathChanges = currentSnapshot.diff(previousSnapshot, changedFiles)
if (classpathChanges is KaptClasspathChanges.Unknown || changes is ChangedFiles.Unknown) {
if (classpathChanges is KaptClasspathChanges.Unknown || changes is SourcesChanges.Unknown) {
cacheDir.deleteRecursively()
cacheDir.mkdirs()
}
Expand All @@ -707,11 +708,11 @@ internal fun findClasspathChanges(
return classpathChanges
}

internal fun ChangedFiles.hasNonSourceChange(): Boolean {
if (this !is ChangedFiles.Known)
internal fun SourcesChanges.hasNonSourceChange(): Boolean {
if (this !is SourcesChanges.Known)
return true

return !(this.modified + this.removed).all {
return !(this.modifiedFiles + this.removedFiles).all {
it.isKotlinFile(listOf("kt")) || it.isJavaFile()
}
}
Expand All @@ -726,13 +727,13 @@ fun KaptClasspathChanges.toSubpluginOptions(): List<SubpluginOption> {
}
}

fun ChangedFiles.toSubpluginOptions(): List<SubpluginOption> {
return if (this is ChangedFiles.Known) {
fun SourcesChanges.toSubpluginOptions(): List<SubpluginOption> {
return if (this is SourcesChanges.Known) {
val options = mutableListOf<SubpluginOption>()
this.modified.filter { it.isKotlinFile(listOf("kt")) || it.isJavaFile() }.ifNotEmpty {
this.modifiedFiles.filter { it.isKotlinFile(listOf("kt")) || it.isJavaFile() }.ifNotEmpty {
options += SubpluginOption("knownModified", map { it.path }.joinToString(File.pathSeparator))
}
this.removed.filter { it.isKotlinFile(listOf("kt")) || it.isJavaFile() }.ifNotEmpty {
this.removedFiles.filter { it.isKotlinFile(listOf("kt")) || it.isJavaFile() }.ifNotEmpty {
options += SubpluginOption("knownRemoved", map { it.path }.joinToString(File.pathSeparator))
}
options
Expand All @@ -749,7 +750,7 @@ internal fun createIncrementalChangesTransformer(
classpathStructure: Provider<FileCollection>,
libraries: Provider<FileCollection>,
processorCP: Provider<FileCollection>,
): (ChangedFiles) -> List<SubpluginOption> = { changedFiles ->
): (SourcesChanges) -> List<SubpluginOption> = { changedFiles ->
val options = mutableListOf<SubpluginOption>()
val apClasspath = processorCP.get().files.toList()
if (isKspIncremental) {
Expand Down Expand Up @@ -790,7 +791,7 @@ internal fun getCPChanges(
): List<String> {
val apClasspath = processorCP.files.toList()
val changedFiles = if (!inputChanges.isIncremental) {
ChangedFiles.Unknown()
SourcesChanges.Unknown
} else {
incrementalProps.fold(mutableListOf<File>() to mutableListOf<File>()) { (modified, removed), prop ->
inputChanges.getFileChanges(prop).forEach {
Expand All @@ -802,7 +803,7 @@ internal fun getCPChanges(
}
modified to removed
}.run {
ChangedFiles.Known(first, second)
SourcesChanges.Known(first, second)
}
}
val classpathChanges = findClasspathChanges(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class SourceSetConfigurationsTest {
val baseVariant = (this as com.android.build.gradle.internal.api.BaseVariantImpl)
val variantData = baseVariant::class.java.getMethod("getVariantData").invoke(baseVariant)
as com.android.build.gradle.internal.variant.BaseVariantData
variantData.extraGeneratedSourceFolders.forEach {
variantData.extraGeneratedSourceFoldersOnlyInModel.forEach {
println("SRC:" + it.relativeTo(buildDir).path)
}
variantData.allPreJavacGeneratedBytecode.forEach {
Expand Down Expand Up @@ -238,21 +238,6 @@ class SourceSetConfigurationsTest {
it.path.contains("ksp")
}
).containsExactly(
SourceFolder(
"debug", "SRC:generated/ksp/debug/java"
),
SourceFolder(
"release", "SRC:generated/ksp/release/java"
),
SourceFolder(
"debugAndroidTest", "SRC:generated/ksp/debugAndroidTest/java"
),
SourceFolder(
"debugUnitTest", "SRC:generated/ksp/debugUnitTest/java"
),
SourceFolder(
"releaseUnitTest", "SRC:generated/ksp/releaseUnitTest/java"
),
SourceFolder(
"debug", "SRC:generated/ksp/debug/kotlin"
),
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copied from kotlinc
org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx2200m -Dfile.encoding=UTF-8

kotlinBaseVersion=1.9.22
agpBaseVersion=7.0.0
kotlinBaseVersion=2.0.0-Beta3
agpBaseVersion=7.2.0
intellijVersion=213.7172.25
junitVersion=4.13.1
junit5Version=5.8.2
junitPlatformVersion=1.8.2
googleTruthVersion=1.1

aaKotlinBaseVersion=2.0.0-dev-7674
aaKotlinBaseVersion=2.0.0-dev-12830
aaIntellijVersion=213.7172.25
aaGuavaVersion=29.0-jre
aaAsmVersion=9.0
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class KSPCmdLineOptionsIT(val useKSP2: Boolean) {
}.maxByOrNull { it.lastModified() }!!
val compilerArgs = mutableListOf(
"-no-stdlib",
"-language-version", "1.9",
"-Xplugin=${kspPluginJar.absolutePath}",
"-Xplugin=${kspApiJar.absolutePath}",
"-P", "plugin:$kspPluginId:apclasspath=${processorJar.absolutePath}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.google.devtools.ksp.test
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assert
import org.junit.Assume
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -18,6 +19,7 @@ class MultiplatformIT(useKSP2: Boolean) {

@Test
fun testJVM() {
Assume.assumeFalse(System.getProperty("os.name").startsWith("mac", ignoreCase = true))
val gradleRunner = GradleRunner.create().withProjectDir(project.root)

val resultCleanBuild =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ class PlaygroundIT(val useKSP2: Boolean) {
Assert.assertTrue(jarFile.getEntry("hello/HELLO.class").size > 0)
Assert.assertTrue(jarFile.getEntry("com/example/AClassBuilder.class").size > 0)
}
Assert.assertTrue(result.output.contains("w: Language version 2.0 is experimental"))
project.restore(buildFile.path)
}

Expand Down Expand Up @@ -263,7 +262,6 @@ class PlaygroundIT(val useKSP2: Boolean) {
Assert.assertTrue(jarFile.getEntry("hello/HELLO.class").size > 0)
Assert.assertTrue(jarFile.getEntry("com/example/AClassBuilder.class").size > 0)
}
Assert.assertTrue(result.output.contains("w: Language version 2.0 is experimental"))
project.restore(buildFile.path)
project.restore(gradleProperties.path)
}
Expand All @@ -283,7 +281,10 @@ class PlaygroundIT(val useKSP2: Boolean) {
gradleRunner.buildAndCheck("clean", "build") { result ->
Assert.assertTrue(result.output.contains("language version: 1.5"))
Assert.assertTrue(result.output.contains("api version: 1.5"))
Assert.assertTrue(result.output.contains("compiler version: $kotlinVersion"))
if (!useKSP2) {
// In case KSP 1 and KSP 2 uses different compiler versions, ignore this test for KSP 2 for now.
Assert.assertTrue(result.output.contains("compiler version: $kotlinVersion"))
}
}
project.restore(buildFile.path)
}
Expand All @@ -299,12 +300,12 @@ class PlaygroundIT(val useKSP2: Boolean) {
gradleRunner.withArguments("build").buildAndFail().let {
Assert.assertEquals(TaskOutcome.SUCCESS, it.task(":workload:kspKotlin")?.outcome)
Assert.assertEquals(TaskOutcome.FAILED, it.task(":workload:compileKotlin")?.outcome)
Assert.assertTrue("Unresolved reference: AClassBuilder" in it.output)
Assert.assertTrue("Unresolved reference 'AClassBuilder'" in it.output)
}
gradleRunner.withArguments("build").buildAndFail().let {
Assert.assertEquals(TaskOutcome.UP_TO_DATE, it.task(":workload:kspKotlin")?.outcome)
Assert.assertEquals(TaskOutcome.FAILED, it.task(":workload:compileKotlin")?.outcome)
Assert.assertTrue("Unresolved reference: AClassBuilder" in it.output)
Assert.assertTrue("Unresolved reference 'AClassBuilder'" in it.output)
}

project.restore("workload/build.gradle.kts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,26 @@ import org.jetbrains.kotlin.analysis.api.session.KtAnalysisSessionProvider
import org.jetbrains.kotlin.analysis.api.standalone.KotlinStaticPackagePartProviderFactory
import org.jetbrains.kotlin.analysis.api.standalone.StandaloneAnalysisAPISession
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.FirStandaloneServiceRegistrar
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtStaticProjectStructureProvider
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.LLFirStandaloneLibrarySymbolProviderFactory
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.StandaloneProjectFactory
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getFirResolveSession
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.services.FirSealedClassInheritorsProcessorFactory
import org.jetbrains.kotlin.analysis.low.level.api.fir.project.structure.LLFirLibrarySymbolProviderFactory
import org.jetbrains.kotlin.analysis.project.structure.KtBinaryModule
import org.jetbrains.kotlin.analysis.project.structure.KtModule
import org.jetbrains.kotlin.analysis.project.structure.allDirectDependencies
import org.jetbrains.kotlin.analysis.project.structure.builder.KtModuleBuilder
import org.jetbrains.kotlin.analysis.project.structure.builder.KtModuleProviderBuilder
import org.jetbrains.kotlin.analysis.project.structure.builder.buildKtSdkModule
import org.jetbrains.kotlin.analysis.project.structure.impl.KtModuleProviderImpl
import org.jetbrains.kotlin.analysis.project.structure.impl.getSourceFilePaths
import org.jetbrains.kotlin.analysis.providers.*
import org.jetbrains.kotlin.analysis.providers.impl.*
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoots
import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCliJavaFileManagerImpl
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreApplicationEnvironmentMode
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreProjectEnvironment
import org.jetbrains.kotlin.cli.jvm.compiler.computeDefaultRootModules
import org.jetbrains.kotlin.cli.jvm.compiler.createSourceFilesFromSourceRoots
Expand Down Expand Up @@ -159,9 +162,7 @@ class KotlinSymbolProcessing(
val kotlinCoreProjectEnvironment: KotlinCoreProjectEnvironment =
StandaloneProjectFactory.createProjectEnvironment(
projectDisposable,
applicationDisposable,
false,
classLoader = MockProject::class.java.classLoader
KotlinCoreApplicationEnvironmentMode.Production
)

val application: Application = kotlinCoreProjectEnvironment.environment.application
Expand Down Expand Up @@ -238,7 +239,7 @@ class KotlinSymbolProcessing(
}.build()

// register services and build session
val ktModuleProviderImpl = projectStructureProvider as KtModuleProviderImpl
val ktModuleProviderImpl = projectStructureProvider as KtStaticProjectStructureProvider
val modules = ktModuleProviderImpl.allKtModules
val allSourceFiles = ktModuleProviderImpl.allSourceFiles
StandaloneProjectFactory.registerServicesForProjectEnvironment(
Expand All @@ -263,7 +264,8 @@ class KotlinSymbolProcessing(
KotlinPsiDeclarationProviderFactory::class.java,
KotlinStaticPsiDeclarationProviderFactory(
this,
ktModuleProviderImpl.binaryModules,
ktModuleProviderImpl.allKtModules.flatMap { it.allDirectDependencies() }
.filterIsInstance<KtBinaryModule>(),
kotlinCoreProjectEnvironment.environment.jarFileSystem as CoreJarFileSystem
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import org.jetbrains.kotlin.psi.KtScript
import org.jetbrains.kotlin.psi.KtTypeAlias

class IncrementalKotlinDeclarationProvider(var del: KotlinDeclarationProvider) : KotlinDeclarationProvider() {
override fun computePackageSetWithTopLevelCallableDeclarations(): Set<String>? {
return del.computePackageSetWithTopLevelCallableDeclarations()
}
override val hasSpecificCallablePackageNamesComputation: Boolean
get() = del.hasSpecificCallablePackageNamesComputation
override val hasSpecificClassifierPackageNamesComputation: Boolean
get() = del.hasSpecificClassifierPackageNamesComputation

override fun findFilesForFacade(facadeFqName: FqName): Collection<KtFile> {
return del.findFilesForFacade(facadeFqName)
Expand Down
Loading