[BT] Introduce JVM compilation API

This commit is contained in:
Alexander.Likhachev
2023-05-15 23:21:03 +02:00
committed by Space Team
parent 2412693ef0
commit 5993e4bce4
12 changed files with 600 additions and 7 deletions
@@ -6,9 +6,25 @@
package org.jetbrains.kotlin.buildtools.internal
import org.jetbrains.kotlin.buildtools.api.CompilationService
import org.jetbrains.kotlin.buildtools.api.CompilerExecutionStrategyConfiguration
import org.jetbrains.kotlin.buildtools.api.jvm.*
import java.io.File
internal class CompilationServiceImpl : CompilationService {
override fun compile() {
override fun calculateClasspathSnapshot(classpathEntry: File): ClasspathEntrySnapshot {
TODO("Calculating classpath snapshots via the Build Tools API is not yet implemented: KT-57565")
}
override fun makeCompilerExecutionStrategyConfiguration() = CompilerExecutionStrategyConfigurationImpl()
override fun makeJvmCompilationConfiguration() = JvmCompilationConfigurationImpl()
override fun compileJvm(
strategyConfig: CompilerExecutionStrategyConfiguration,
compilationConfig: JvmCompilationConfiguration,
sources: List<File>,
arguments: List<String>
) {
println("I'm simulating compilation, nothing more yet")
}
}
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2023 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.
*/
package org.jetbrains.kotlin.buildtools.internal
import org.jetbrains.kotlin.buildtools.api.CompilerExecutionStrategyConfiguration
import java.io.File
class CompilerExecutionStrategyConfigurationImpl : CompilerExecutionStrategyConfiguration {
override fun useInProcessStrategy(): CompilerExecutionStrategyConfiguration {
return this
}
override fun useDaemonStrategy(sessionDir: File, jvmArguments: List<String>): CompilerExecutionStrategyConfiguration {
TODO("Daemon strategy is not yet supported in the Build Tools API")
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 2010-2023 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.
*/
package org.jetbrains.kotlin.buildtools.internal
import org.jetbrains.kotlin.buildtools.api.KotlinLogger
internal object DefaultKotlinLogger : KotlinLogger {
override val isDebugEnabled: Boolean
get() = TODO("Default KotlinLogger is not yet implemented in the Build Tools API")
override fun error(msg: String, throwable: Throwable?) {
TODO("Default KotlinLogger is not yet implemented in the Build Tools API")
}
override fun warn(msg: String) {
TODO("Default KotlinLogger is not yet implemented in the Build Tools API")
}
override fun info(msg: String) {
TODO("Default KotlinLogger is not yet implemented in the Build Tools API")
}
override fun debug(msg: String) {
TODO("Default KotlinLogger is not yet implemented in the Build Tools API")
}
override fun lifecycle(msg: String) {
TODO("Default KotlinLogger is not yet implemented in the Build Tools API")
}
}
@@ -0,0 +1,104 @@
/*
* Copyright 2010-2023 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.
*/
package org.jetbrains.kotlin.buildtools.internal
import org.jetbrains.kotlin.buildtools.api.KotlinLogger
import org.jetbrains.kotlin.buildtools.api.SourcesChanges
import org.jetbrains.kotlin.buildtools.api.jvm.*
import java.io.File
internal class JvmCompilationConfigurationImpl(
override var kotlinScriptFilenameExtensions: Set<String> = emptySet(),
override var logger: KotlinLogger = DefaultKotlinLogger,
) : JvmCompilationConfiguration {
override fun useLogger(logger: KotlinLogger): JvmCompilationConfiguration {
this.logger = logger
return this
}
override fun useKotlinScriptFilenameExtensions(kotlinScriptExtensions: Collection<String>): JvmCompilationConfiguration {
this.kotlinScriptFilenameExtensions = kotlinScriptExtensions.toSet()
return this
}
override fun makeClasspathSnapshotBasedIncrementalCompilationConfiguration() = ClasspathSnapshotBasedIncrementalJvmCompilationConfigurationImpl()
override fun <P : IncrementalCompilationApproachParameters> useIncrementalCompilation(
workingDirectory: File,
sourcesChanges: SourcesChanges,
approachParameters: P,
options: IncrementalJvmCompilationConfiguration<P>,
) = TODO("Incremental compilation is not yet supported to run via the Build Tools API")
}
internal abstract class JvmIncrementalCompilationConfigurationImpl<P : IncrementalCompilationApproachParameters>(
override var preciseJavaTrackingEnabled: Boolean = true,
override var preciseCompilationResultsBackupEnabled: Boolean = false,
override var incrementalCompilationCachesKeptInMemory: Boolean = false,
override var projectDir: File? = null,
override var forcedNonIncrementalMode: Boolean = false,
) : IncrementalJvmCompilationConfiguration<P> {
override fun useProjectDir(projectDir: File): IncrementalJvmCompilationConfiguration<P> {
this.projectDir = projectDir
return this
}
override fun usePreciseJavaTracking(value: Boolean): IncrementalJvmCompilationConfiguration<P> {
preciseJavaTrackingEnabled = value
return this
}
override fun usePreciseCompilationResultsBackup(value: Boolean): IncrementalJvmCompilationConfiguration<P> {
preciseCompilationResultsBackupEnabled = value
return this
}
override fun keepIncrementalCompilationCachesInMemory(value: Boolean): IncrementalJvmCompilationConfiguration<P> {
incrementalCompilationCachesKeptInMemory = value
return this
}
override fun forceNonIncrementalMode(value: Boolean): IncrementalJvmCompilationConfiguration<P> {
forcedNonIncrementalMode = value
return this
}
}
internal class ClasspathSnapshotBasedIncrementalJvmCompilationConfigurationImpl(
override var assuredNoClasspathSnapshotsChanges: Boolean = false,
) :
JvmIncrementalCompilationConfigurationImpl<ClasspathSnapshotBasedIncrementalCompilationApproachParameters>(),
ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration {
override fun useProjectDir(projectDir: File): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration {
super.useProjectDir(projectDir)
return this
}
override fun usePreciseJavaTracking(value: Boolean): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration {
super.usePreciseJavaTracking(value)
return this
}
override fun usePreciseCompilationResultsBackup(value: Boolean): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration {
super.usePreciseCompilationResultsBackup(value)
return this
}
override fun keepIncrementalCompilationCachesInMemory(value: Boolean): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration {
super.keepIncrementalCompilationCachesInMemory(value)
return this
}
override fun forceNonIncrementalMode(value: Boolean): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration {
super.forceNonIncrementalMode(value)
return this
}
override fun assureNoClasspathSnapshotsChanges(value: Boolean): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration {
assuredNoClasspathSnapshotsChanges = value
return this
}
}