From b3fbe4c484507270a9d4ba85c30f420773a6a923 Mon Sep 17 00:00:00 2001 From: "Alexander.Likhachev" Date: Tue, 27 Jun 2023 16:01:23 +0200 Subject: [PATCH] [BT] Introduce CompilationResult #KT-57398 In Progress --- .../api/kotlin-build-tools-api.api | 11 ++++- .../buildtools/api/CompilationResult.kt | 44 +++++++++++++++++++ .../buildtools/api/CompilationService.kt | 2 +- .../internal/CompilationServiceImpl.kt | 4 +- 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 compiler/build-tools/kotlin-build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationResult.kt diff --git a/compiler/build-tools/kotlin-build-tools-api/api/kotlin-build-tools-api.api b/compiler/build-tools/kotlin-build-tools-api/api/kotlin-build-tools-api.api index f5c4ccbbaf3..7918414b6bc 100644 --- a/compiler/build-tools/kotlin-build-tools-api/api/kotlin-build-tools-api.api +++ b/compiler/build-tools/kotlin-build-tools-api/api/kotlin-build-tools-api.api @@ -1,7 +1,16 @@ +public final class org/jetbrains/kotlin/buildtools/api/CompilationResult : java/lang/Enum { + public static final field COMPILATION_ERROR Lorg/jetbrains/kotlin/buildtools/api/CompilationResult; + public static final field COMPILATION_OOM_ERROR Lorg/jetbrains/kotlin/buildtools/api/CompilationResult; + public static final field COMPILATION_SUCCESS Lorg/jetbrains/kotlin/buildtools/api/CompilationResult; + public static final field COMPILER_INTERNAL_ERROR Lorg/jetbrains/kotlin/buildtools/api/CompilationResult; + public static fun valueOf (Ljava/lang/String;)Lorg/jetbrains/kotlin/buildtools/api/CompilationResult; + public static fun values ()[Lorg/jetbrains/kotlin/buildtools/api/CompilationResult; +} + 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 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 abstract fun compileJvm (Lorg/jetbrains/kotlin/buildtools/api/CompilerExecutionStrategyConfiguration;Lorg/jetbrains/kotlin/buildtools/api/jvm/JvmCompilationConfiguration;Ljava/util/List;Ljava/util/List;)Lorg/jetbrains/kotlin/buildtools/api/CompilationResult; 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; diff --git a/compiler/build-tools/kotlin-build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationResult.kt b/compiler/build-tools/kotlin-build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationResult.kt new file mode 100644 index 00000000000..10495241906 --- /dev/null +++ b/compiler/build-tools/kotlin-build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationResult.kt @@ -0,0 +1,44 @@ +/* + * 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 + +/** + * Represents the result of a compilation process. + * + * This enum is used as the return value of compilation methods to indicate the status of the compilation process. + */ +public enum class CompilationResult { + /** + * Represents a successful compilation state. + */ + COMPILATION_SUCCESS, + + /** + * Represents an error that occurs during compilation of code. + * Usage: + * The object of this class should be used when an error occurs during the compilation of code. It can be used to + * identify and handle such errors during runtime. + */ + COMPILATION_ERROR, + + /** + * Represents a compilation error caused by running out of memory. + * + * This error is thrown when the compilation process has run out of memory and was unable to complete. This can occur when + * the compilation task requires more memory than is available to the operating system or allocated to the process. + * + * This error should be handled by allocating more memory to the process or optimizing the compilation task to require + * less memory. + */ + COMPILATION_OOM_ERROR, + + /** + * Represents an internal error that occurs within the compiler. + * + * This error should be [reported](https://kotl.in/issue) to the compiler developers for investigation and resolution. + */ + COMPILER_INTERNAL_ERROR, +} \ No newline at end of file diff --git a/compiler/build-tools/kotlin-build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationService.kt b/compiler/build-tools/kotlin-build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationService.kt index 0b87b01dc9e..c37c59c6bcb 100644 --- a/compiler/build-tools/kotlin-build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationService.kt +++ b/compiler/build-tools/kotlin-build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationService.kt @@ -53,7 +53,7 @@ public interface CompilationService { compilationConfig: JvmCompilationConfiguration, sources: List, arguments: List - ) + ): CompilationResult @ExperimentalBuildToolsApi public companion object { diff --git a/compiler/build-tools/kotlin-build-tools-impl/src/main/kotlin/org/jetbrains/kotlin/buildtools/internal/CompilationServiceImpl.kt b/compiler/build-tools/kotlin-build-tools-impl/src/main/kotlin/org/jetbrains/kotlin/buildtools/internal/CompilationServiceImpl.kt index bfd58cfe75b..84e23f73da6 100644 --- a/compiler/build-tools/kotlin-build-tools-impl/src/main/kotlin/org/jetbrains/kotlin/buildtools/internal/CompilationServiceImpl.kt +++ b/compiler/build-tools/kotlin-build-tools-impl/src/main/kotlin/org/jetbrains/kotlin/buildtools/internal/CompilationServiceImpl.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.buildtools.internal +import org.jetbrains.kotlin.buildtools.api.CompilationResult import org.jetbrains.kotlin.buildtools.api.CompilationService import org.jetbrains.kotlin.buildtools.api.CompilerExecutionStrategyConfiguration import org.jetbrains.kotlin.buildtools.api.jvm.* @@ -24,7 +25,8 @@ internal class CompilationServiceImpl : CompilationService { compilationConfig: JvmCompilationConfiguration, sources: List, arguments: List - ) { + ): CompilationResult { println("I'm simulating compilation, nothing more yet") + return CompilationResult.COMPILATION_SUCCESS } } \ No newline at end of file