From 3a8d7c083999bca901c7591f1ac3987554b80766 Mon Sep 17 00:00:00 2001 From: "Alexander.Likhachev" Date: Fri, 17 Mar 2023 13:57:54 +0100 Subject: [PATCH] [Build] Add build-tools-api and build-tools-impl modules #KT-57396 In Progress --- .space/CODEOWNERS | 1 + compiler/build-tools/README.md | 3 +++ compiler/build-tools/build-tools-api/README.md | 9 +++++++++ .../build-tools/build-tools-api/build.gradle.kts | 14 ++++++++++++++ .../kotlin/buildtools/api/CompilationService.kt | 14 ++++++++++++++ .../build-tools/build-tools-impl/build.gradle.kts | 13 +++++++++++++ .../buildtools/internal/CompilationServiceImpl.kt | 14 ++++++++++++++ ...brains.kotlin.buildtools.api.CompilationService | 1 + gradle/verification-metadata.xml | 2 ++ settings.gradle | 3 +++ 10 files changed, 74 insertions(+) create mode 100644 compiler/build-tools/README.md create mode 100644 compiler/build-tools/build-tools-api/README.md create mode 100644 compiler/build-tools/build-tools-api/build.gradle.kts create mode 100644 compiler/build-tools/build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationService.kt create mode 100644 compiler/build-tools/build-tools-impl/build.gradle.kts create mode 100644 compiler/build-tools/build-tools-impl/src/main/kotlin/org/jetbrains/kotlin/buildtools/internal/CompilationServiceImpl.kt create mode 100644 compiler/build-tools/build-tools-impl/src/main/resources/META-INF/services/org.jetbrains.kotlin.buildtools.api.CompilationService diff --git a/.space/CODEOWNERS b/.space/CODEOWNERS index e1d14540755..65dc5cf1b37 100644 --- a/.space/CODEOWNERS +++ b/.space/CODEOWNERS @@ -47,6 +47,7 @@ /compiler/backend/ "Kotlin JVM" /compiler/backend.common.jvm/ "Kotlin JVM" /compiler/backend-common/ "Kotlin JVM" "Kotlin JS" "Kotlin Native" "Kotlin Wasm" +/compiler/build-tools/ "Kotlin Build Tools" /compiler/builtins-serializer/ "Kotlin Compiler Core" /compiler/cli/ "Kotlin Compiler Core" /compiler/cli/cli-js/ "Kotlin JS" "Kotlin Wasm" diff --git a/compiler/build-tools/README.md b/compiler/build-tools/README.md new file mode 100644 index 00000000000..d9b1c97570b --- /dev/null +++ b/compiler/build-tools/README.md @@ -0,0 +1,3 @@ +## Build Tools + +Please refer to the [Build Tools API readme](./build-tools-api/README.md). \ No newline at end of file diff --git a/compiler/build-tools/build-tools-api/README.md b/compiler/build-tools/build-tools-api/README.md new file mode 100644 index 00000000000..dc1954a4181 --- /dev/null +++ b/compiler/build-tools/build-tools-api/README.md @@ -0,0 +1,9 @@ +## Build Tools API + +This module contains public interfaces for Kotlin build tools. +Using APIs from this module should be the preferred way to work with Kotlin compiler when integrating Kotlin builds into different build systems. +The Kotlin stdlib of at least Kotlin 1.4 is expected to be a dependency of a consumer of the API. + +The default implementation of the API is located in the [build-tools-impl](../build-tools-impl) directory. +Interfaces implementation are expected to be loaded using the [ServiceLoader](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html). +The purpose of such a segregation is to allow using this API with different Kotlin compiler versions. \ No newline at end of file diff --git a/compiler/build-tools/build-tools-api/build.gradle.kts b/compiler/build-tools/build-tools-api/build.gradle.kts new file mode 100644 index 00000000000..8988966394a --- /dev/null +++ b/compiler/build-tools/build-tools-api/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + kotlin("jvm") + id("jps-compatible") +} + +configureKotlinCompileTasksGradleCompatibility() + +dependencies { + compileOnly(kotlinStdlib()) +} + +publish() + +standardPublicJars() \ No newline at end of file diff --git a/compiler/build-tools/build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationService.kt b/compiler/build-tools/build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationService.kt new file mode 100644 index 00000000000..ed6da9c9fa3 --- /dev/null +++ b/compiler/build-tools/build-tools-api/src/main/kotlin/org/jetbrains/kotlin/buildtools/api/CompilationService.kt @@ -0,0 +1,14 @@ +/* + * 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 + +/** + * 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 + */ +interface CompilationService { + fun compile() +} \ No newline at end of file diff --git a/compiler/build-tools/build-tools-impl/build.gradle.kts b/compiler/build-tools/build-tools-impl/build.gradle.kts new file mode 100644 index 00000000000..115ef62ac92 --- /dev/null +++ b/compiler/build-tools/build-tools-impl/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + kotlin("jvm") + id("jps-compatible") +} + +dependencies { + api(project(":compiler:build-tools:build-tools-api")) + implementation(kotlinStdlib()) +} + +publish() + +standardPublicJars() \ No newline at end of file diff --git a/compiler/build-tools/build-tools-impl/src/main/kotlin/org/jetbrains/kotlin/buildtools/internal/CompilationServiceImpl.kt b/compiler/build-tools/build-tools-impl/src/main/kotlin/org/jetbrains/kotlin/buildtools/internal/CompilationServiceImpl.kt new file mode 100644 index 00000000000..fc2ba32c439 --- /dev/null +++ b/compiler/build-tools/build-tools-impl/src/main/kotlin/org/jetbrains/kotlin/buildtools/internal/CompilationServiceImpl.kt @@ -0,0 +1,14 @@ +/* + * 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.CompilationService + +internal class CompilationServiceImpl : CompilationService { + override fun compile() { + println("I'm simulating compilation, nothing more yet") + } +} \ No newline at end of file diff --git a/compiler/build-tools/build-tools-impl/src/main/resources/META-INF/services/org.jetbrains.kotlin.buildtools.api.CompilationService b/compiler/build-tools/build-tools-impl/src/main/resources/META-INF/services/org.jetbrains.kotlin.buildtools.api.CompilationService new file mode 100644 index 00000000000..015ff5725db --- /dev/null +++ b/compiler/build-tools/build-tools-impl/src/main/resources/META-INF/services/org.jetbrains.kotlin.buildtools.api.CompilationService @@ -0,0 +1 @@ +org.jetbrains.kotlin.buildtools.internal.CompilationServiceImpl \ No newline at end of file diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index a62eb3905d4..445035c7784 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -12,6 +12,8 @@ + + diff --git a/settings.gradle b/settings.gradle index ae32a0779c2..99302773ffb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -378,6 +378,9 @@ if (!buildProperties.inJpsBuildIdeaSync) { ":prepare:ide-plugin-dependencies:kotlin-compiler-fir-for-ide" } +include ":compiler:build-tools:build-tools-api", + ":compiler:build-tools:build-tools-impl" + void intellij(String imlPath) { File imlFile = new File("${rootDir}/intellij/community/plugins/kotlin/${imlPath}") imlFile = imlFile.exists() ? imlFile : new File("${rootDir}/intellij/plugins/kotlin/${imlPath}")