Skip to content

Commit

Permalink
UPDATE_KOTLIN_VERSION: 1.9.0-dev-6976
Browse files Browse the repository at this point in the history
(cherry picked from commit 78ecbfd)
  • Loading branch information
neetopia committed May 23, 2023
1 parent a95bbee commit c9d60b6
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 60 deletions.
11 changes: 11 additions & 0 deletions compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ val intellijVersion: String by project
val kotlinBaseVersion: String by project

val libsForTesting by configurations.creating
val libsForTestingCommon by configurations.creating

tasks.withType<KotlinCompile> {
compilerOptions.freeCompilerArgs.add("-Xjvm-default=all-compatibility")
Expand Down Expand Up @@ -66,6 +67,7 @@ dependencies {
libsForTesting(kotlin("stdlib", kotlinBaseVersion))
libsForTesting(kotlin("test", kotlinBaseVersion))
libsForTesting(kotlin("script-runtime", kotlinBaseVersion))
libsForTestingCommon(kotlin("stdlib-common", kotlinBaseVersion))
}

tasks.register<Copy>("CopyLibsForTesting") {
Expand All @@ -75,6 +77,13 @@ tasks.register<Copy>("CopyLibsForTesting") {
rename("(.+)-$escaped\\.jar", "$1.jar")
}

tasks.register<Copy>("CopyLibsForTestingCommon") {
from(configurations.get("libsForTestingCommon"))
into("dist/common")
val escaped = Regex.escape(kotlinBaseVersion)
rename("(.+)-$escaped\\.jar", "$1.jar")
}

fun Project.javaPluginConvention(): JavaPluginConvention = the()
val JavaPluginConvention.testSourceSet: SourceSet
get() = sourceSets.getByName("test")
Expand All @@ -83,6 +92,7 @@ val Project.testSourceSet: SourceSet

tasks.test {
dependsOn("CopyLibsForTesting")
dependsOn("CopyLibsForTestingCommon")
maxHeapSize = "2g"

useJUnitPlatform()
Expand Down Expand Up @@ -114,6 +124,7 @@ repositories {
}

val dokkaJavadocJar by tasks.register<Jar>("dokkaJavadocJar") {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
from(project(":common-util").tasks.dokkaJavadoc.flatMap { it.outputDirectory })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class KSAnnotationJavaImpl private constructor(val psi: PsiAnnotation) : KSAnnot
is PsiJavaFile -> KSFileJavaImpl.getCached(parentPsi)
is PsiClass -> KSClassDeclarationJavaImpl.getCached(parentPsi)
is PsiMethod -> KSFunctionDeclarationJavaImpl.getCached(parentPsi)
is PsiParameter -> KSValueParameterJavaImpl.getCached(parentPsi)
is PsiParameter -> KSValueParameterJavaImpl.getCached(parentPsi, this)
is PsiTypeParameter -> KSTypeParameterJavaImpl.getCached(parentPsi)
is PsiType ->
if (parentPsi.parent is PsiClassType) KSTypeArgumentJavaImpl.getCached(parentPsi, this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class KSFunctionDeclarationJavaImpl private constructor(val psi: PsiMethod) :
}

override val parameters: List<KSValueParameter> by lazy {
psi.parameterList.parameters.map { KSValueParameterJavaImpl.getCached(it) }
psi.parameterList.parameters.map { KSValueParameterJavaImpl.getCached(it, this) }
}

override val parentDeclaration: KSDeclaration? by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,28 @@

package com.google.devtools.ksp.symbol.impl.java

import com.google.devtools.ksp.IdKeyPair
import com.google.devtools.ksp.KSObjectCache
import com.google.devtools.ksp.processing.impl.KSNameImpl
import com.google.devtools.ksp.symbol.*
import com.google.devtools.ksp.symbol.impl.getInstanceForCurrentRound
import com.google.devtools.ksp.symbol.impl.toLocation
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiParameter

class KSValueParameterJavaImpl private constructor(val psi: PsiParameter) : KSValueParameter {
companion object : KSObjectCache<PsiParameter, KSValueParameterJavaImpl>() {
fun getCached(psi: PsiParameter) = cache.getOrPut(psi) { KSValueParameterJavaImpl(psi) }
class KSValueParameterJavaImpl private constructor(val psi: PsiParameter, override val parent: KSNode) :
KSValueParameter {
companion object : KSObjectCache<IdKeyPair<PsiParameter, KSNode>, KSValueParameterJavaImpl>() {
fun getCached(psi: PsiParameter, parent: KSNode): KSValueParameterJavaImpl {
val curParent = getInstanceForCurrentRound(parent) as KSNode
return cache.getOrPut(IdKeyPair(psi, curParent)) { KSValueParameterJavaImpl(psi, curParent) }
}
}

override val origin = Origin.JAVA

override val location: Location by lazy {
psi.toLocation()
}
override val parent: KSNode? by lazy {
var parentPsi = psi.parent
while (true) {
when (parentPsi) {
null, is PsiMethod, is PsiAnnotation -> break
else -> parentPsi = parentPsi.parent
}
}
when (parentPsi) {
is PsiMethod -> KSFunctionDeclarationJavaImpl.getCached(parentPsi)
is PsiAnnotation -> KSAnnotationJavaImpl.getCached(parentPsi)
else -> null
}
}

override val annotations: Sequence<KSAnnotation> by lazy {
psi.annotations.asSequence().map { KSAnnotationJavaImpl.getCached(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fun PsiElement.findParentAnnotated(): KSAnnotated? {
var parent = when (this) {
// Unfortunately, LightMethod doesn't implement parent.
is LightMethod -> this.containingClass
is PsiMethod -> this.containingClass
else -> this.parent
}

Expand Down Expand Up @@ -261,7 +262,7 @@ internal fun getInstanceForCurrentRound(node: KSNode): KSNode? {
is KSTypeParameterJavaImpl -> KSTypeParameterJavaImpl.getCached(node.psi)
is KSTypeReferenceJavaImpl ->
KSTypeReferenceJavaImpl.getCached(node.psi, (node.parent as? KSAnnotated)?.getInstanceForCurrentRound())
is KSValueParameterJavaImpl -> KSValueParameterJavaImpl.getCached(node.psi)
is KSValueParameterJavaImpl -> KSValueParameterJavaImpl.getCached(node.psi, node.parent)
is KSPropertyGetterSyntheticImpl -> KSPropertyGetterSyntheticImpl.getCached(node.ksPropertyDeclaration)
is KSPropertySetterSyntheticImpl -> KSPropertySetterSyntheticImpl.getCached(node.ksPropertyDeclaration)
is KSValueParameterSyntheticImpl ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationInfo
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
import org.jetbrains.kotlin.gradle.plugin.mpp.enabledOnCurrentHost
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompileTool
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon
Expand Down Expand Up @@ -173,7 +174,6 @@ abstract class KspTaskJvm @Inject constructor(
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_PARAMETER_TYPE")
fun `callCompilerAsync$kotlin_gradle_plugin_common`(
args: K2JVMCompilerArguments,
kotlinSources: Set<File>,
inputChanges: InputChanges,
taskOutputsBackup: TaskOutputsBackup?
) {
Expand All @@ -182,7 +182,7 @@ abstract class KspTaskJvm @Inject constructor(
it(changedFiles)
}
args.addPluginOptions(extraOptions)
super.callCompilerAsync(args, kotlinSources, inputChanges, taskOutputsBackup)
super.callCompilerAsync(args, inputChanges, taskOutputsBackup)
}

override fun skipCondition(): Boolean = sources.isEmpty && javaSources.isEmpty
Expand Down Expand Up @@ -212,7 +212,6 @@ abstract class KspTaskJS @Inject constructor(
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_PARAMETER_TYPE")
fun `callCompilerAsync$kotlin_gradle_plugin_common`(
args: K2JSCompilerArguments,
kotlinSources: Set<File>,
inputChanges: InputChanges,
taskOutputsBackup: TaskOutputsBackup?
) {
Expand All @@ -221,7 +220,7 @@ abstract class KspTaskJS @Inject constructor(
it(changedFiles)
}
args.addPluginOptions(extraOptions)
super.callCompilerAsync(args, kotlinSources, inputChanges, taskOutputsBackup)
super.callCompilerAsync(args, inputChanges, taskOutputsBackup)
}
}

Expand All @@ -241,7 +240,6 @@ abstract class KspTaskMetadata @Inject constructor(
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "EXPOSED_PARAMETER_TYPE")
fun `callCompilerAsync$kotlin_gradle_plugin_common`(
args: K2MetadataCompilerArguments,
kotlinSources: Set<File>,
inputChanges: InputChanges,
taskOutputsBackup: TaskOutputsBackup?
) {
Expand All @@ -250,7 +248,7 @@ abstract class KspTaskMetadata @Inject constructor(
it(changedFiles)
}
args.addPluginOptions(extraOptions)
super.callCompilerAsync(args, kotlinSources, inputChanges, taskOutputsBackup)
super.callCompilerAsync(args, inputChanges, taskOutputsBackup)
}
}

Expand Down Expand Up @@ -281,3 +279,7 @@ internal fun File.isParentOf(childCandidate: File): Boolean {

return childCandidatePath.startsWith(parentPath)
}

internal fun disableRunViaBuildToolsApi(kspTask: AbstractKotlinCompileTool<*>) {
kspTask.runViaBuildToolsApi.value(false).disallowChanges()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.devtools.ksp.gradle

import com.google.devtools.ksp.gradle.model.builder.KspModelBuilder
Expand Down Expand Up @@ -315,6 +314,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool

fun configureAsAbstractKotlinCompileTool(kspTask: AbstractKotlinCompileTool<*>) {
kspTask.destinationDirectory.set(kspOutputDir)
disableRunViaBuildToolsApi(kspTask)
kspTask.outputs.dirs(
kotlinOutputDir,
javaOutputDir,
Expand Down Expand Up @@ -427,13 +427,12 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
configureLanguageVersion(kspTask)
if (kspTask.classpathSnapshotProperties.useClasspathSnapshot.get() == false) {
kspTask.compilerOptions.moduleName.convention(
kotlinCompileTask.moduleName.map { "$it-ksp" }
kotlinCompileTask.compilerOptions.moduleName.map { "$it-ksp" }
)
} else {
kspTask.compilerOptions.moduleName.convention(kotlinCompileTask.moduleName)
kspTask.compilerOptions.moduleName.convention(kotlinCompileTask.compilerOptions.moduleName)
}

kspTask.moduleName.value(kotlinCompileTask.moduleName.get())
kspTask.destination.value(kspOutputDir)

val isIntermoduleIncremental =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ class SourceSetConfigurationsTest {
androidNativeX64(name = "bar") { }
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xuse-deprecated-legacy-compiler"
}
""".trimIndent()
)
testRule.appModule.addMultiplatformSource("commonMain", "Foo.kt", "class Foo")
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copied from kotlinc
org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx2200m -Dfile.encoding=UTF-8

kotlinBaseVersion=1.9.0-dev-4392
kotlinBaseVersion=1.9.0-dev-6976
agpBaseVersion=7.0.0
intellijVersion=203.8084.24
intellijVersion=213.7172.25
junitVersion=4.12
googleTruthVersion=1.1
compilerTestEnabled=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assert
import org.junit.Assume
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import java.io.File
Expand Down Expand Up @@ -215,6 +216,7 @@ class KMPImplementedIT {
}
}

@Ignore
@Test
fun testNonEmbeddableArtifact() {
Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.gradle.testkit.runner.GradleRunner
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.junit.Assert
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import java.io.ByteArrayOutputStream
Expand All @@ -14,7 +13,6 @@ import java.net.URLClassLoader

data class CompileResult(val exitCode: ExitCode, val output: String)

@Ignore
class KSPCmdLineOptionsIT {
@Rule
@JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PlaygroundIT {
fun testConfigurationOfConfiguration() {
// FIXME: `clean` fails to delete files on windows.
Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true))
val gradleRunner = GradleRunner.create().withProjectDir(project.root).withGradleVersion("8.0-rc-5")
val gradleRunner = GradleRunner.create().withProjectDir(project.root).withGradleVersion("8.0")
gradleRunner.withArguments(":workload:dependencies", "--info").build().let {
Assert.assertTrue(
it.output.lines().filter { it.startsWith("The configuration :workload:ksp") }.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@ kotlin {
val commonMain by getting
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xuse-deprecated-legacy-compiler"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@ dependencies {
add("kspJs", project(":test-processor"))
add("kspJsTest", project(":test-processor"))
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xuse-deprecated-legacy-compiler"
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ kotlin {
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xuse-deprecated-legacy-compiler"
}

dependencies {
add("kspCommonMainMetadata", project(":test-processor"))
add("kspJvm", project(":test-processor"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ kotlin {
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xuse-deprecated-legacy-compiler"
}

ksp {
arg("option1", "value1")
arg("option2", "value2")
Expand Down
10 changes: 10 additions & 0 deletions kotlin-analysis-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ val intellijVersion: String by project
val junitVersion: String by project
val kotlinBaseVersion: String by project
val libsForTesting by configurations.creating
val libsForTestingCommon by configurations.creating

plugins {
kotlin("jvm")
Expand Down Expand Up @@ -65,6 +66,7 @@ dependencies {
libsForTesting(kotlin("stdlib", kotlinBaseVersion))
libsForTesting(kotlin("test", kotlinBaseVersion))
libsForTesting(kotlin("script-runtime", kotlinBaseVersion))
libsForTestingCommon(kotlin("stdlib-common", kotlinBaseVersion))
}

tasks.register<Copy>("CopyLibsForTesting") {
Expand All @@ -74,6 +76,13 @@ tasks.register<Copy>("CopyLibsForTesting") {
rename("(.+)-$escaped\\.jar", "$1.jar")
}

tasks.register<Copy>("CopyLibsForTestingCommon") {
from(configurations.get("libsForTestingCommon"))
into("dist/common")
val escaped = Regex.escape(kotlinBaseVersion)
rename("(.+)-$escaped\\.jar", "$1.jar")
}

sourceSets.main {
java.srcDirs("src/main/kotlin")
}
Expand All @@ -86,6 +95,7 @@ val Project.testSourceSet: SourceSet

tasks.test {
dependsOn("CopyLibsForTesting")
dependsOn("CopyLibsForTestingCommon")
maxHeapSize = "2g"

useJUnitPlatform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import com.google.devtools.ksp.impl.CommandLineKSPLogger
import com.google.devtools.ksp.impl.KotlinSymbolProcessing
import com.google.devtools.ksp.processor.AbstractTestProcessor
import com.google.devtools.ksp.testutils.AbstractKSPTest
import com.intellij.openapi.extensions.ExtensionPoint
import org.jetbrains.kotlin.analysis.api.resolve.extensions.KtResolveExtensionProvider
import org.jetbrains.kotlin.analysis.api.standalone.buildStandaloneAnalysisAPISession
import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.LLFirSessionConfigurator
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoots
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
Expand Down Expand Up @@ -145,7 +146,14 @@ abstract class AbstractKSPAATest : AbstractKSPTest(FrontendKinds.FIR) {
}.build()
val analysisSession = buildStandaloneAnalysisAPISession(withPsiDeclarationFromBinaryModuleProvider = true) {
buildKtModuleProviderByCompilerConfiguration(compilerConfiguration)
LLFirSessionConfigurator.registerExtensionPoint(project)
project.extensionArea.apply {
registerExtensionPoint(
KtResolveExtensionProvider.EP_NAME.name,
KtResolveExtensionProvider::class.java.name,
ExtensionPoint.Kind.INTERFACE,
false
)
}
}
val ksp = KotlinSymbolProcessing(
compilerConfiguration,
Expand Down
Loading

0 comments on commit c9d60b6

Please sign in to comment.