Revert "Initial pass at a semi-functional Kotlin Compiler Client."
Revert submission 32464406-b392906864-kotlin-incremental
Reason for revert: Potential cause of b/415313604.
Reverted changes: /q/submissionid:32464406-b392906864-kotlin-incremental
Change-Id: I356ec1d6ef3350b352213b3444a5fe0c94f6ec31
diff --git a/cmd/kotlinc_incremental/Android.bp b/cmd/kotlinc_incremental/Android.bp
index 8b9fd63..9811cc1 100644
--- a/cmd/kotlinc_incremental/Android.bp
+++ b/cmd/kotlinc_incremental/Android.bp
@@ -34,22 +34,9 @@
"src/com/**/*.kt",
],
static_libs: [
- "kotlin-build-tools", // 2.1.10
- "kotlin-compiler-embeddable", // 2.1.10
- "kotlin-compiler-runner", // 2.1.10
+ "kotlin-compiler-embeddable",
+ "kotlin-compiler-runner",
"kotlin-daemon-client",
- "kotlin-daemon-embeddable",
- "kotlinx_coroutines",
- ],
- libs: [
- // Disabled until we use Kotlin's Build-Tools-API
- //"kotlin-build-tools-impl", // Must be dynamically linked in because of the way that
- // build tools tries to cast the class loader to URLClassLoader.
- // If we statically compile this, the cast fails.
- ],
- required: [
- // "kotlin-build-tools-impl",
- // "kotlin-compose-compiler-embeddable",
],
plugins: [],
@@ -63,11 +50,6 @@
name: "kotlin-incremental-client",
manifest: "kotlin-incremental-client.mf",
static_libs: ["kotlin-incremental-client-lib"],
- libs: ["kotlin-build-tools-impl"],
- required: [
- "kotlin-build-tools-impl",
- "kotlin-compose-compiler-embeddable",
- ],
}
java_test_host {
diff --git a/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Logger.kt b/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Logger.kt
deleted file mode 100644
index ba4a679..0000000
--- a/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Logger.kt
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2025 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.kotlin.compiler.client
-
-import org.jetbrains.kotlin.buildtools.api.KotlinLogger
-
-class Logger : KotlinLogger {
- override val isDebugEnabled: Boolean
- get() = true
-
- override fun debug(msg: String) {
- println(msg)
- }
-
- override fun error(msg: String, throwable: Throwable?) {
- println(msg)
- if (throwable != null) {
- println(throwable)
- }
- }
-
- override fun info(msg: String) {
- println(msg)
- }
-
- override fun lifecycle(msg: String) {
- println(msg)
- }
-
- override fun warn(msg: String, throwable: Throwable?) {
- println(msg)
- if (throwable != null) {
- println(throwable)
- }
- }
-}
diff --git a/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Main.kt b/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Main.kt
index 8e16926..f3be307 100644
--- a/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Main.kt
+++ b/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Main.kt
@@ -16,17 +16,7 @@
package com.android.kotlin.compiler.client
-import java.io.File
-import java.net.URLClassLoader
-import java.util.UUID
import kotlin.system.exitProcess
-import org.jetbrains.kotlin.buildtools.api.CompilationService
-import org.jetbrains.kotlin.buildtools.api.ExperimentalBuildToolsApi
-import org.jetbrains.kotlin.buildtools.api.ProjectId
-import org.jetbrains.kotlin.buildtools.api.SourcesChanges
-import org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity
-import org.jetbrains.kotlin.buildtools.api.jvm.ClasspathEntrySnapshot
-import org.jetbrains.kotlin.buildtools.api.jvm.ClasspathSnapshotBasedIncrementalCompilationApproachParameters
private val ARGUMENT_PARSERS =
listOf(
@@ -42,7 +32,6 @@
RunFilesArgument(),
RootDirArgument(),
WorkingDirArgument(),
- XBuildFileArgument(),
SourcesArgument(), // must come last
)
@@ -54,30 +43,23 @@
exitProcess(-1)
}
- if (opts.sources.isEmpty() && (opts.buildFile == null || opts.buildFileSources.isEmpty())) {
- println("No sources or build file specified. Exiting.")
- exitProcess(0)
- }
-
- BTACompilation(opts)
+ println("compiling")
}
fun parseArgs(args: Array<String>, opts: Options): Boolean {
- var matched = false
var hasError = false
var showHelp = args.isEmpty()
val iter = args.iterator()
while (iter.hasNext()) {
val arg = iter.next()
- matched = false
for (parser in ARGUMENT_PARSERS) {
if (parser.matches(arg)) {
- matched = true
if (parser is HelpArgument) {
showHelp = true
}
parser.parse(arg, iter, opts)
if (parser.error != null) {
+ println("The error: " + parser.error)
hasError = true
System.err.println(parser.error)
System.err.println()
@@ -85,9 +67,6 @@
break
}
}
- if (!matched) {
- opts.passThroughArgs.add(arg.substring(0))
- }
}
if (showHelp) {
@@ -134,117 +113,3 @@
}
}
}
-
-fun BTACompilation(opts: Options) {
- val kotlincArgs = mutableListOf<String>()
- if (opts.buildFile != null) {
- if (opts.buildFileModuleName != null) {
- kotlincArgs.add("-module-name")
- kotlincArgs.add(opts.buildFileModuleName!!)
- }
- }
- kotlincArgs.add("-d=${opts.outputDir.absolutePath}")
- kotlincArgs.addAll(opts.passThroughArgs)
- kotlincArgs.addAll(opts.sources)
- kotlincArgs.addAll(opts.buildFileJavaSources)
- doBtaCompilation(
- opts.sources + opts.buildFileSources,
- opts.classPath + opts.buildFileClassPaths,
- opts.workingDir,
- kotlincArgs,
- opts.jvmArgs,
- Logger(),
- )
-}
-
-@OptIn(ExperimentalBuildToolsApi::class)
-fun doBtaCompilation(
- sources: List<String>,
- classPath: List<String>,
- workingDirectory: File,
- args: List<String>,
- jvmArgs: List<String>,
- logger: Logger,
-) {
- val loader =
- URLClassLoader(
- classPath.map { File(it).toURI().toURL() }.toTypedArray() +
- // TODO: don't hardcode this path.
- arrayOf(
- "out/soong/.intermediates/external/kotlinc/kotlin-build-tools-impl/" +
- "linux_glibc_common/local-combined/kotlin-build-tools-impl.jar"
- // TODO: this root path also won't work on other's computers!
- )
- .map { File("/src/android/aosp/$it").toURI().toURL() } +
-
- // Need to include this code's own jar in the classpath.
- arrayOf(Options::class.java.protectionDomain?.codeSource?.location)
- )
-
- val service = CompilationService.loadImplementation(loader)
- val executionConfig = service.makeCompilerExecutionStrategyConfiguration()
- // TODO: investigate using the daemon.
- // Right now, it hangs (https://youtrack.jetbrains.com/issue/KT-75142/)
- // executionConfig.useDaemonStrategy(jvmArgs)
- executionConfig.useInProcessStrategy()
- val compilationConfig = service.makeJvmCompilationConfiguration()
-
- val cpsnapshotParameters =
- getClasspathSnapshotParameters(
- workingDirectory,
- classPath,
- service::calculateClasspathSnapshot,
- )
-
- val sourcesChanges =
- SourcesChanges.Known(
- modifiedFiles = listOf(sources.first()).map { File(it) },
- removedFiles = emptyList(),
- )
- val incJvmCompilationConfig =
- compilationConfig.makeClasspathSnapshotBasedIncrementalCompilationConfiguration()
- incJvmCompilationConfig.assureNoClasspathSnapshotsChanges(true)
- compilationConfig.useIncrementalCompilation(
- workingDirectory,
- sourcesChanges,
- cpsnapshotParameters,
- incJvmCompilationConfig,
- )
- compilationConfig.useLogger(logger)
-
- val pid = ProjectId.ProjectUUID(UUID.randomUUID())
- val mArgs = args.toMutableList()
- mArgs.add("-cp")
- mArgs.add(classPath.joinToString(":"))
- service.compileJvm(pid, executionConfig, compilationConfig, sources.map { File(it) }, mArgs)
-}
-
-@OptIn(ExperimentalBuildToolsApi::class)
-fun getClasspathSnapshotParameters(
- workingDirectory: File,
- classPath: List<String>,
- calculateClasspathSnapshot: (File, ClassSnapshotGranularity) -> ClasspathEntrySnapshot,
-): ClasspathSnapshotBasedIncrementalCompilationApproachParameters {
- val cps = File(workingDirectory.parentFile, "shrunk-classpath-snapshot.bin")
- val cpsFiles =
- classPath.map {
- val cpFile = File(it)
- // TODO: Consider CLASS_LEVEL snapshots of things that change infrequently.
- // CLASS_MEMBER_LEVEL
- // of everything else.
- val snName = cpFile.name.replace(".", "_") + "-snapshot.bin"
- val snf = File(workingDirectory.parentFile, snName)
- // TODO: we need to delete/regenerate the snf if the jar has changed.
- if (!snf.exists()) {
- val sn =
- calculateClasspathSnapshot(cpFile, ClassSnapshotGranularity.CLASS_MEMBER_LEVEL)
- sn.saveSnapshot(snf)
- }
- snf
- }
-
- return ClasspathSnapshotBasedIncrementalCompilationApproachParameters(
- newClasspathSnapshotFiles = cpsFiles,
- shrunkClasspathSnapshot = cps,
- )
-}