[BT] Introduce JVM compilation API
This commit is contained in:
committed by
Space Team
parent
2412693ef0
commit
5993e4bce4
@@ -1,13 +1,21 @@
|
||||
public abstract interface class org/jetbrains/kotlin/buildtools/api/CompilationService {
|
||||
public static final field Companion Lorg/jetbrains/kotlin/buildtools/api/CompilationService$Companion;
|
||||
public abstract fun compile ()V
|
||||
public abstract fun calculateClasspathSnapshot (Ljava/io/File;)Lorg/jetbrains/kotlin/buildtools/api/jvm/ClasspathEntrySnapshot;
|
||||
public abstract fun compileJvm (Lorg/jetbrains/kotlin/buildtools/api/CompilerExecutionStrategyConfiguration;Lorg/jetbrains/kotlin/buildtools/api/jvm/JvmCompilationConfiguration;Ljava/util/List;Ljava/util/List;)V
|
||||
public static fun loadImplementation (Ljava/lang/ClassLoader;)Lorg/jetbrains/kotlin/buildtools/api/CompilationService;
|
||||
public abstract fun makeCompilerExecutionStrategyConfiguration ()Lorg/jetbrains/kotlin/buildtools/api/CompilerExecutionStrategyConfiguration;
|
||||
public abstract fun makeJvmCompilationConfiguration ()Lorg/jetbrains/kotlin/buildtools/api/jvm/JvmCompilationConfiguration;
|
||||
}
|
||||
|
||||
public final class org/jetbrains/kotlin/buildtools/api/CompilationService$Companion {
|
||||
public final fun loadImplementation (Ljava/lang/ClassLoader;)Lorg/jetbrains/kotlin/buildtools/api/CompilationService;
|
||||
}
|
||||
|
||||
public abstract interface class org/jetbrains/kotlin/buildtools/api/CompilerExecutionStrategyConfiguration {
|
||||
public abstract fun useDaemonStrategy (Ljava/io/File;Ljava/util/List;)Lorg/jetbrains/kotlin/buildtools/api/CompilerExecutionStrategyConfiguration;
|
||||
public abstract fun useInProcessStrategy ()Lorg/jetbrains/kotlin/buildtools/api/CompilerExecutionStrategyConfiguration;
|
||||
}
|
||||
|
||||
public abstract interface class org/jetbrains/kotlin/buildtools/api/KotlinLogger {
|
||||
public abstract fun debug (Ljava/lang/String;)V
|
||||
public abstract fun error (Ljava/lang/String;Ljava/lang/Throwable;)V
|
||||
@@ -22,3 +30,71 @@ public final class org/jetbrains/kotlin/buildtools/api/SharedApiClassesClassLoad
|
||||
public static final fun newInstance ()Ljava/lang/ClassLoader;
|
||||
}
|
||||
|
||||
public abstract interface class org/jetbrains/kotlin/buildtools/api/SourcesChanges {
|
||||
}
|
||||
|
||||
public final class org/jetbrains/kotlin/buildtools/api/SourcesChanges$Known : org/jetbrains/kotlin/buildtools/api/SourcesChanges {
|
||||
public fun <init> (Ljava/util/List;Ljava/util/List;)V
|
||||
public final fun getModifiedFiles ()Ljava/util/List;
|
||||
public final fun getRemovedFiles ()Ljava/util/List;
|
||||
}
|
||||
|
||||
public final class org/jetbrains/kotlin/buildtools/api/SourcesChanges$ToBeCalculated : org/jetbrains/kotlin/buildtools/api/SourcesChanges {
|
||||
public static final field INSTANCE Lorg/jetbrains/kotlin/buildtools/api/SourcesChanges$ToBeCalculated;
|
||||
}
|
||||
|
||||
public final class org/jetbrains/kotlin/buildtools/api/SourcesChanges$Unknown : org/jetbrains/kotlin/buildtools/api/SourcesChanges {
|
||||
public static final field INSTANCE Lorg/jetbrains/kotlin/buildtools/api/SourcesChanges$Unknown;
|
||||
}
|
||||
|
||||
public abstract interface class org/jetbrains/kotlin/buildtools/api/jvm/ClassSnapshot {
|
||||
}
|
||||
|
||||
public abstract interface class org/jetbrains/kotlin/buildtools/api/jvm/ClasspathEntrySnapshot {
|
||||
public abstract fun getClassSnapshots ()Ljava/util/LinkedHashMap;
|
||||
public abstract fun saveSnapshot (Ljava/io/File;)V
|
||||
}
|
||||
|
||||
public final class org/jetbrains/kotlin/buildtools/api/jvm/ClasspathSnapshotBasedIncrementalCompilationApproachParameters : org/jetbrains/kotlin/buildtools/api/jvm/IncrementalCompilationApproachParameters {
|
||||
public fun <init> (Ljava/util/List;Ljava/io/File;)V
|
||||
public final fun getNewClasspathSnapshotFiles ()Ljava/util/List;
|
||||
public final fun getShrunkClasspathSnapshot ()Ljava/io/File;
|
||||
}
|
||||
|
||||
public abstract interface class org/jetbrains/kotlin/buildtools/api/jvm/ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration : org/jetbrains/kotlin/buildtools/api/jvm/IncrementalJvmCompilationConfiguration {
|
||||
public abstract fun assureNoClasspathSnapshotsChanges (Z)Lorg/jetbrains/kotlin/buildtools/api/jvm/ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration;
|
||||
public static synthetic fun assureNoClasspathSnapshotsChanges$default (Lorg/jetbrains/kotlin/buildtools/api/jvm/ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration;ZILjava/lang/Object;)Lorg/jetbrains/kotlin/buildtools/api/jvm/ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration;
|
||||
public abstract fun forceNonIncrementalMode (Z)Lorg/jetbrains/kotlin/buildtools/api/jvm/ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration;
|
||||
public abstract fun getAssuredNoClasspathSnapshotsChanges ()Z
|
||||
public abstract fun keepIncrementalCompilationCachesInMemory (Z)Lorg/jetbrains/kotlin/buildtools/api/jvm/ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration;
|
||||
public abstract fun usePreciseCompilationResultsBackup (Z)Lorg/jetbrains/kotlin/buildtools/api/jvm/ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration;
|
||||
public abstract fun usePreciseJavaTracking (Z)Lorg/jetbrains/kotlin/buildtools/api/jvm/ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration;
|
||||
public abstract fun useProjectDir (Ljava/io/File;)Lorg/jetbrains/kotlin/buildtools/api/jvm/ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration;
|
||||
}
|
||||
|
||||
public abstract interface class org/jetbrains/kotlin/buildtools/api/jvm/IncrementalCompilationApproachParameters {
|
||||
}
|
||||
|
||||
public abstract interface class org/jetbrains/kotlin/buildtools/api/jvm/IncrementalJvmCompilationConfiguration {
|
||||
public abstract fun forceNonIncrementalMode (Z)Lorg/jetbrains/kotlin/buildtools/api/jvm/IncrementalJvmCompilationConfiguration;
|
||||
public static synthetic fun forceNonIncrementalMode$default (Lorg/jetbrains/kotlin/buildtools/api/jvm/IncrementalJvmCompilationConfiguration;ZILjava/lang/Object;)Lorg/jetbrains/kotlin/buildtools/api/jvm/IncrementalJvmCompilationConfiguration;
|
||||
public abstract fun getForcedNonIncrementalMode ()Z
|
||||
public abstract fun getIncrementalCompilationCachesKeptInMemory ()Z
|
||||
public abstract fun getPreciseCompilationResultsBackupEnabled ()Z
|
||||
public abstract fun getPreciseJavaTrackingEnabled ()Z
|
||||
public abstract fun getProjectDir ()Ljava/io/File;
|
||||
public abstract fun keepIncrementalCompilationCachesInMemory (Z)Lorg/jetbrains/kotlin/buildtools/api/jvm/IncrementalJvmCompilationConfiguration;
|
||||
public abstract fun usePreciseCompilationResultsBackup (Z)Lorg/jetbrains/kotlin/buildtools/api/jvm/IncrementalJvmCompilationConfiguration;
|
||||
public abstract fun usePreciseJavaTracking (Z)Lorg/jetbrains/kotlin/buildtools/api/jvm/IncrementalJvmCompilationConfiguration;
|
||||
public abstract fun useProjectDir (Ljava/io/File;)Lorg/jetbrains/kotlin/buildtools/api/jvm/IncrementalJvmCompilationConfiguration;
|
||||
}
|
||||
|
||||
public abstract interface class org/jetbrains/kotlin/buildtools/api/jvm/JvmCompilationConfiguration {
|
||||
public abstract fun getKotlinScriptFilenameExtensions ()Ljava/util/Set;
|
||||
public abstract fun getLogger ()Lorg/jetbrains/kotlin/buildtools/api/KotlinLogger;
|
||||
public abstract fun makeClasspathSnapshotBasedIncrementalCompilationConfiguration ()Lorg/jetbrains/kotlin/buildtools/api/jvm/ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration;
|
||||
public fun useIncrementalCompilation (Ljava/io/File;Lorg/jetbrains/kotlin/buildtools/api/SourcesChanges;Lorg/jetbrains/kotlin/buildtools/api/jvm/IncrementalCompilationApproachParameters;Lorg/jetbrains/kotlin/buildtools/api/jvm/IncrementalJvmCompilationConfiguration;)V
|
||||
public abstract fun useKotlinScriptFilenameExtensions (Ljava/util/Collection;)Lorg/jetbrains/kotlin/buildtools/api/jvm/JvmCompilationConfiguration;
|
||||
public abstract fun useLogger (Lorg/jetbrains/kotlin/buildtools/api/KotlinLogger;)Lorg/jetbrains/kotlin/buildtools/api/jvm/JvmCompilationConfiguration;
|
||||
}
|
||||
|
||||
|
||||
+45
-3
@@ -5,12 +5,54 @@
|
||||
|
||||
package org.jetbrains.kotlin.buildtools.api
|
||||
|
||||
import org.jetbrains.kotlin.buildtools.api.jvm.ClasspathEntrySnapshot
|
||||
import org.jetbrains.kotlin.buildtools.api.jvm.JvmCompilationConfiguration
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* A facade for invoking compilation in Kotlin compiler. It allows to use compiler in different modes.
|
||||
* TODO: add a mention where to see the available modes after implementing them
|
||||
* A facade for invoking compilation and related stuff (such as [calculateClasspathSnapshot]) in Kotlin compiler.
|
||||
*
|
||||
* An example of the basic usage is:
|
||||
* ```
|
||||
* val service = CompilationService.loadImplementation(ClassLoader.getSystemClassLoader())
|
||||
* val executionConfig = service.makeCompilerExecutionStrategyConfiguration()
|
||||
* val compilationConfig = service.makeJvmCompilationConfiguration()
|
||||
* service.compileJvm(executionConfig, compilationConfig, listOf(File("src/a.kt")), listOf("-Xexplicit-api=strict"))
|
||||
* ```
|
||||
*
|
||||
* This interface is not intended to be implemented by the API consumers. An instance of [CompilationService] is expected to be obtained from [loadImplementation].
|
||||
*/
|
||||
public interface CompilationService {
|
||||
public fun compile()
|
||||
/**
|
||||
* TODO KT-57565
|
||||
*/
|
||||
public fun calculateClasspathSnapshot(classpathEntry: File): ClasspathEntrySnapshot
|
||||
|
||||
/**
|
||||
* Provides a default [CompilerExecutionStrategyConfiguration] allowing to use it as is or customizing for specific requirements.
|
||||
* Could be used as an overview to default values of the options (as they are implementation-specific).
|
||||
*/
|
||||
public fun makeCompilerExecutionStrategyConfiguration(): CompilerExecutionStrategyConfiguration
|
||||
|
||||
/**
|
||||
* Provides a default [CompilerExecutionStrategyConfiguration] allowing to use it as is or customizing for specific requirements.
|
||||
* Could be used as an overview to default values of the options (as they are implementation-specific).
|
||||
*/
|
||||
public fun makeJvmCompilationConfiguration(): JvmCompilationConfiguration
|
||||
|
||||
/**
|
||||
* Compiles Kotlin code targeting JVM platform and using specified options.
|
||||
* @param strategyConfig an instance of [CompilerExecutionStrategyConfiguration] initially obtained from [makeCompilerExecutionStrategyConfiguration]
|
||||
* @param compilationConfig an instance of [JvmCompilationConfiguration] initially obtained from [makeJvmCompilationConfiguration]
|
||||
* @param sources a list of all sources of the compilation unit
|
||||
* @param arguments a list of Kotlin JVM compiler arguments
|
||||
*/
|
||||
public fun compileJvm(
|
||||
strategyConfig: CompilerExecutionStrategyConfiguration,
|
||||
compilationConfig: JvmCompilationConfiguration,
|
||||
sources: List<File>,
|
||||
arguments: List<String>
|
||||
)
|
||||
|
||||
public companion object {
|
||||
@JvmStatic
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.api
|
||||
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Allows users to customize the compiler execution strategy.
|
||||
*
|
||||
* This interface is not intended to be implemented by the API consumers.
|
||||
*/
|
||||
public interface CompilerExecutionStrategyConfiguration {
|
||||
/**
|
||||
* Marks the compilation to be run inside the same JVM as the caller.
|
||||
* The default strategy.
|
||||
*/
|
||||
public fun useInProcessStrategy(): CompilerExecutionStrategyConfiguration
|
||||
|
||||
/**
|
||||
* Marks the compilation to be run in Kotlin daemon launched as a separate process and shared across similar compilation requests.
|
||||
* See Kotlin daemon documentation here: https://kotlinlang.org/docs/gradle-compilation-and-caches.html#the-kotlin-daemon-and-how-to-use-it-with-gradle
|
||||
* @param sessionDir a directory for storing data related to the daemon work session (should not be shared with other compilations)
|
||||
* @param jvmArguments a list of JVM startup arguments for the daemon
|
||||
*/
|
||||
public fun useDaemonStrategy(
|
||||
sessionDir: File,
|
||||
jvmArguments: List<String>,
|
||||
): CompilerExecutionStrategyConfiguration
|
||||
}
|
||||
+3
@@ -5,6 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.buildtools.api
|
||||
|
||||
/**
|
||||
* A logger object used to log messages from the Build Tools API.
|
||||
*/
|
||||
public interface KotlinLogger {
|
||||
public val isDebugEnabled: Boolean
|
||||
public fun error(msg: String, throwable: Throwable? = null)
|
||||
|
||||
+33
@@ -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.api
|
||||
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* A hierarchy representing source files changes for incremental compilation
|
||||
*/
|
||||
public sealed interface SourcesChanges {
|
||||
/**
|
||||
* A marker object stating that the API consumer cannot calculate changes (either because it's an initial build or for some other reason).
|
||||
* The Build Tools API will not enable its source file changes detector in this mode, expecting the API consumer to provide file changes as [Known] for the consequent builds.
|
||||
*/
|
||||
public object Unknown : SourcesChanges
|
||||
|
||||
/**
|
||||
* A marker object stating that the API consumer is not capable of calculating source file changes.
|
||||
* In this mode, the Build Tools API will enable its source file changes detector and detect changes itself.
|
||||
*/
|
||||
public object ToBeCalculated : SourcesChanges
|
||||
|
||||
/**
|
||||
* A class containing [modifiedFiles] and [removedFiles] calculated from source file changes by the API consumer.
|
||||
*/
|
||||
public class Known(
|
||||
public val modifiedFiles: List<File>,
|
||||
public val removedFiles: List<File>,
|
||||
) : SourcesChanges
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.api.jvm
|
||||
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* TODO add docs KT-57565
|
||||
*
|
||||
* This interface is not intended to be implemented by the API consumers.
|
||||
*/
|
||||
public interface ClasspathEntrySnapshot {
|
||||
public val classSnapshots: LinkedHashMap<String, ClassSnapshot>
|
||||
|
||||
public fun saveSnapshot(path: File)
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO add docs KT-57565
|
||||
*
|
||||
* This interface is not intended to be implemented by the API consumers.
|
||||
*/
|
||||
public interface ClassSnapshot {
|
||||
// ... TODO: KT-57565, it will expose some part of org.jetbrains.kotlin.incremental.classpathDiff.ClassSnapshot hierarchy
|
||||
}
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 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.api.jvm
|
||||
|
||||
import org.jetbrains.kotlin.buildtools.api.KotlinLogger
|
||||
import org.jetbrains.kotlin.buildtools.api.SourcesChanges
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Allows users to customize the compilation process and to observe the configured settings (or the default ones).
|
||||
*
|
||||
* This interface defines a set of properties and methods that allow users to customize the compilation process.
|
||||
* It provides control over various aspects of compilation, such as incremental compilation, logging customization and other.
|
||||
*
|
||||
* This interface is not intended to be implemented by the API consumers.
|
||||
*/
|
||||
public interface JvmCompilationConfiguration {
|
||||
/**
|
||||
* A logger used during the compilation.
|
||||
*
|
||||
* Managed by [useLogger]
|
||||
* Default logger is a logger just printing messages to stdin and stderr.
|
||||
*/
|
||||
public val logger: KotlinLogger
|
||||
|
||||
/**
|
||||
* @see [JvmCompilationConfiguration.logger]
|
||||
*/
|
||||
public fun useLogger(logger: KotlinLogger): JvmCompilationConfiguration
|
||||
|
||||
/**
|
||||
* A set of additional to the `.kt` and `.kts` Kotlin script extensions.
|
||||
*
|
||||
* Managed by [useKotlinScriptFilenameExtensions]
|
||||
* Default value is an empty set.
|
||||
*/
|
||||
public val kotlinScriptFilenameExtensions: Set<String>
|
||||
|
||||
/**
|
||||
* @see [JvmCompilationConfiguration.kotlinScriptFilenameExtensions]
|
||||
*/
|
||||
public fun useKotlinScriptFilenameExtensions(kotlinScriptExtensions: Collection<String>): JvmCompilationConfiguration
|
||||
|
||||
/**
|
||||
* Provides a default [ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration] allowing to use it as is or customizing for specific requirements.
|
||||
* Could be used as an overview to default values of the options (as they are implementation-specific).
|
||||
* @see [useIncrementalCompilation]
|
||||
*/
|
||||
public fun makeClasspathSnapshotBasedIncrementalCompilationConfiguration(): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration
|
||||
|
||||
/**
|
||||
* Configures usage of incremental compilation.
|
||||
* @param workingDirectory a working directory for incremental compilation internal state
|
||||
* @param sourcesChanges an instance of [SourcesChanges]
|
||||
* @param approachParameters an object representing mandatory parameters specific for the selected incremental compilation approach
|
||||
* @param options an object representing optional parameters and handles specific for the selected incremental compilation approach
|
||||
* @see [makeClasspathSnapshotBasedIncrementalCompilationConfiguration]
|
||||
*/
|
||||
public fun <P : IncrementalCompilationApproachParameters> useIncrementalCompilation(
|
||||
workingDirectory: File,
|
||||
sourcesChanges: SourcesChanges,
|
||||
approachParameters: P,
|
||||
options: IncrementalJvmCompilationConfiguration<P>,
|
||||
) {
|
||||
error("This version of the Build Tools API does not support incremental compilation")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to observe and customize general JVM incremental compilation settings.
|
||||
*
|
||||
* This interface is not intended to be implemented by the API consumers.
|
||||
*/
|
||||
public interface IncrementalJvmCompilationConfiguration<P : IncrementalCompilationApproachParameters> {
|
||||
/**
|
||||
* A directory used as a base path for computing relative paths in the incremental compilation caches.
|
||||
*
|
||||
* If is not specified, incremental compilation caches will be non-relocatable
|
||||
*
|
||||
* Managed by [useProjectDir]
|
||||
* Default values is `null`
|
||||
*/
|
||||
public val projectDir: File?
|
||||
|
||||
/**
|
||||
* @see [IncrementalJvmCompilationConfiguration.projectDir]
|
||||
*/
|
||||
public fun useProjectDir(projectDir: File): IncrementalJvmCompilationConfiguration<P>
|
||||
|
||||
/**
|
||||
* An indicator whether incremental compilation will analyze Java files precisely for better changes detection
|
||||
*
|
||||
* Managed by [usePreciseJavaTracking]
|
||||
* Default value is defined by implementation of the API
|
||||
*/
|
||||
public val preciseJavaTrackingEnabled: Boolean
|
||||
|
||||
/**
|
||||
* @see [IncrementalJvmCompilationConfiguration.preciseJavaTrackingEnabled]
|
||||
*/
|
||||
public fun usePreciseJavaTracking(value: Boolean): IncrementalJvmCompilationConfiguration<P>
|
||||
|
||||
/**
|
||||
* An indicator whether incremental compilation should perform file-by-file backup of files and revert them in the case of a failure
|
||||
*
|
||||
* Managed by [usePreciseCompilationResultsBackup]
|
||||
* Default value is defined by implementation of the API
|
||||
*/
|
||||
public val preciseCompilationResultsBackupEnabled: Boolean
|
||||
|
||||
/**
|
||||
* @see [IncrementalJvmCompilationConfiguration.preciseCompilationResultsBackupEnabled]
|
||||
*/
|
||||
public fun usePreciseCompilationResultsBackup(value: Boolean): IncrementalJvmCompilationConfiguration<P>
|
||||
|
||||
/**
|
||||
* Incremental compilation uses the PersistentHashMap of the intellij platform for storing caches.
|
||||
* An indicator whether the changes should remain in memory and not being flushed to the disk until we could mark the compilation as successful.
|
||||
*
|
||||
* Managed by [keepIncrementalCompilationCachesInMemory]
|
||||
* Default value is defined by implementation of the API
|
||||
*/
|
||||
public val incrementalCompilationCachesKeptInMemory: Boolean
|
||||
|
||||
/**
|
||||
* @see [IncrementalJvmCompilationConfiguration.incrementalCompilationCachesKeptInMemory]
|
||||
*/
|
||||
public fun keepIncrementalCompilationCachesInMemory(value: Boolean): IncrementalJvmCompilationConfiguration<P>
|
||||
|
||||
/**
|
||||
* An indicator whether the non-incremental mode of the incremental compiler is forced.
|
||||
* The non-incremental mode of the incremental compiler means that during the non-incremental compilation
|
||||
* the compiler will collect enough information to perform the following builds incrementally.
|
||||
*
|
||||
* Manager by [forceNonIncrementalMode]
|
||||
* By default, the compilation is considered incremental
|
||||
*/
|
||||
public val forcedNonIncrementalMode: Boolean
|
||||
|
||||
/**
|
||||
* @see [forcedNonIncrementalMode]
|
||||
*/
|
||||
public fun forceNonIncrementalMode(value: Boolean = true): IncrementalJvmCompilationConfiguration<P>
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to observe and customize JVM incremental compilation settings specific to the classpath snapshots based approach.
|
||||
*
|
||||
* This interface is not intended to be implemented by the API consumers.
|
||||
*/
|
||||
public interface ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration :
|
||||
IncrementalJvmCompilationConfiguration<ClasspathSnapshotBasedIncrementalCompilationApproachParameters> {
|
||||
/**
|
||||
* An indicator whether classpath snapshots comparing should be avoided.
|
||||
* Could be used if the check is already performed by the API consumer for the sake of optimization
|
||||
*
|
||||
* Managed by [assureNoClasspathSnapshotsChanges]
|
||||
* By default, the incremental compiler will compare the snapshots itself.
|
||||
*/
|
||||
public val assuredNoClasspathSnapshotsChanges: Boolean
|
||||
|
||||
/**
|
||||
* @see [assuredNoClasspathSnapshotsChanges]
|
||||
*/
|
||||
public fun assureNoClasspathSnapshotsChanges(value: Boolean = true): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration
|
||||
|
||||
override fun useProjectDir(projectDir: File): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration
|
||||
|
||||
override fun usePreciseJavaTracking(value: Boolean): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration
|
||||
|
||||
override fun usePreciseCompilationResultsBackup(value: Boolean): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration
|
||||
|
||||
override fun keepIncrementalCompilationCachesInMemory(value: Boolean): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration
|
||||
|
||||
override fun forceNonIncrementalMode(value: Boolean): ClasspathSnapshotBasedIncrementalJvmCompilationConfiguration
|
||||
}
|
||||
|
||||
/**
|
||||
* Mandatory parameters for an incremental compilation approach
|
||||
*/
|
||||
public sealed interface IncrementalCompilationApproachParameters
|
||||
|
||||
/**
|
||||
* Mandatory parameters of the classpath snapshots based incremental compilation approach
|
||||
*/
|
||||
public class ClasspathSnapshotBasedIncrementalCompilationApproachParameters(
|
||||
/**
|
||||
* The classpath snapshots files actual at the moment of compilation
|
||||
*/
|
||||
public val newClasspathSnapshotFiles: List<File>,
|
||||
/**
|
||||
* The shrunk classpath snapshot, a result of the previous compilation. Could point to a non-existent file.
|
||||
* At the successful end of the compilation, the shrunk version of the [newClasspathSnapshotFiles] will be stored at this path.
|
||||
*/
|
||||
public val shrunkClasspathSnapshot: File,
|
||||
) : IncrementalCompilationApproachParameters
|
||||
+17
-1
@@ -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")
|
||||
}
|
||||
}
|
||||
+19
@@ -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")
|
||||
}
|
||||
}
|
||||
+33
@@ -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")
|
||||
}
|
||||
}
|
||||
+104
@@ -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
|
||||
}
|
||||
}
|
||||
+10
-2
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.compilerRunner.GradleKotlinCompilerWorkArguments
|
||||
import org.jetbrains.kotlin.gradle.internal.ClassLoadersCachingBuildService
|
||||
import org.jetbrains.kotlin.gradle.internal.ParentClassLoaderProvider
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
internal abstract class BuildToolsApiCompilationWork : WorkAction<BuildToolsApiCompilationWork.BuildToolsApiCompilationParameters> {
|
||||
internal interface BuildToolsApiCompilationParameters : WorkParameters {
|
||||
@@ -36,7 +35,16 @@ internal abstract class BuildToolsApiCompilationWork : WorkAction<BuildToolsApiC
|
||||
val classLoader = parameters.classLoadersCachingService.get()
|
||||
.getClassLoader(workArguments.compilerFullClasspath, SharedApiClassesClassLoaderProvider)
|
||||
val compilationService = CompilationService.loadImplementation(classLoader)
|
||||
compilationService.compile()
|
||||
val executionConfig = compilationService.makeCompilerExecutionStrategyConfiguration().apply {
|
||||
useInProcessStrategy()
|
||||
}
|
||||
val jvmCompilationConfig = compilationService.makeJvmCompilationConfiguration()
|
||||
compilationService.compileJvm(
|
||||
executionConfig,
|
||||
jvmCompilationConfig,
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user