Revert "Add command line arguments to the 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: I58832b3cdf7d325bf10ef205f2476142124d943b
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index b89e5f8..317f5c4 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -1,15 +1,6 @@
[Builtin Hooks]
gofmt = true
bpfmt = true
-ktfmt = true
[Hook Scripts]
do_not_use_DO_NOT_MERGE = ${REPO_ROOT}/build/soong/scripts/check_do_not_merge.sh ${PREUPLOAD_COMMIT}
-
-ktlint_hook = ${REPO_ROOT}/prebuilts/ktlint/ktlint.py --no-verify-format -f ${PREUPLOAD_FILES}
-
-[Builtin Hooks Options]
-ktfmt = --kotlinlang-style --include-dirs=cmd/kotlinc_incremental
-
-[Tool Paths]
-ktfmt = ${REPO_ROOT}/external/ktfmt/ktfmt.sh
\ No newline at end of file
diff --git a/cmd/kotlinc_incremental/Android.bp b/cmd/kotlinc_incremental/Android.bp
index 9811cc1..7816553 100644
--- a/cmd/kotlinc_incremental/Android.bp
+++ b/cmd/kotlinc_incremental/Android.bp
@@ -57,9 +57,6 @@
srcs: [
"tests/src/com/**/*.kt",
],
- data: [
- "tests/resources/test_build.xml",
- ],
static_libs: [
"kotlin-incremental-client-lib",
"junit",
diff --git a/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Argument.kt b/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Argument.kt
deleted file mode 100644
index d59cd99..0000000
--- a/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Argument.kt
+++ /dev/null
@@ -1,395 +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 java.io.File
-import javax.xml.parsers.SAXParserFactory
-
-abstract class Argument<T> {
- abstract val argumentName: String
- abstract val helpText: String
- abstract val default: T?
-
- var error: String? = null
- protected set
-
- abstract fun matches(arg: String): Boolean
-
- abstract fun parse(arg: String, position: Iterator<String>, opts: Options)
-
- abstract fun setOption(option: T, opts: Options)
-
- fun setupDefault(opts: Options) {
- if (default != null) {
- setOption(default!!, opts)
- }
- }
-}
-
-abstract class NoArgument : Argument<Boolean>() {
- override val default = null
-
- override fun matches(arg: String) = arg == "-$argumentName"
-
- override fun parse(arg: String, position: Iterator<String>, opts: Options) {
- setOption(true, opts)
- }
-}
-
-abstract class SingleArgument<T> : Argument<T>() {
-
- override fun matches(arg: String) = arg.startsWith("-$argumentName=")
-
- override fun parse(arg: String, position: Iterator<String>, opts: Options) {
- val splits = arg.split("=", limit = 2)
- if (splits.size != 2 || splits[1].isEmpty()) {
- error = "Required argument not supplied for $argumentName"
- return
- }
- val value = stringToType(splits[1])
- setOption(value, opts)
- }
-
- abstract fun stringToType(arg: String): T
-}
-
-abstract class StringArgument : SingleArgument<String>() {
- override fun stringToType(arg: String): String {
- return arg
- }
-}
-
-class SourcesArgument : Argument<String>() {
- override val default = null
- override val argumentName = "-"
- override val helpText =
- """
- Everything after this is treated as a source file.
- """.trimIndent()
-
- override fun matches(arg: String) = arg == "--"
-
- override fun parse(arg: String, position: Iterator<String>, opts: Options) {
- position.forEachRemaining { setOption(it, opts) }
- }
-
- override fun setOption(option: String, opts: Options) {
- opts.addSource(option)
- }
-}
-
-class BuildFileArgument : StringArgument() {
- override val default = null
-
- override val argumentName = "build-file"
- override val helpText =
- """
- Build file containing sources and classpaths to be consumed by kotlinc. See
- -Xbuild-file on kotlinc.
- """
- .trimIndent()
-
- override fun setOption(option: String, opts: Options) {
- opts.buildFileLocation = option
- parseBuildFile(opts.buildFile!!, opts)
- }
-
- private fun parseBuildFile(buildFile: File, opts: Options) {
- val parser = BuildFileParser()
- val spf = SAXParserFactory.newInstance()
- val saxParser = spf.newSAXParser()
- val xmlReader = saxParser.xmlReader
- xmlReader.contentHandler = parser
- xmlReader.parse(buildFile.absolutePath)
-
- opts.buildFileModuleName = parser.moduleName
- opts.buildFileClassPaths = parser.classpaths
- opts.buildFileSources = parser.sources
- opts.buildFileJavaSources = parser.javaSources
- if (parser.outputDirName != null) {
- opts.outputDirName = parser.outputDirName!!
- }
- }
-}
-
-class XBuildFileArgument : StringArgument() {
- override val default = null
-
- override val argumentName = "Xbuild-file"
- override val helpText = """
- Deprecated: use -build-file
- """.trimIndent()
-
- override fun setOption(option: String, opts: Options) {
- error = "Can not parser -Xbuild-file. Please use -build-file."
- }
-}
-
-class HelpArgument : NoArgument() {
- override val argumentName = "h"
-
- override val helpText = """
- Outputs this help text.
- """.trimIndent()
-
- override fun setOption(option: Boolean, opts: Options) {}
-}
-
-abstract class WritableDirectoryArgument : StringArgument() {
- override fun setOption(option: String, opts: Options) {
- val e = isValidDirectoryForWriting(option)
- if (e != null) {
- error = "Invalid $argumentName option specified: $e"
- } else {
- setDirectory(File(option), opts)
- }
- }
-
- abstract fun setDirectory(dir: File, opts: Options)
-}
-
-abstract class SubdirectoryArgument : StringArgument() {
- override fun setOption(option: String, opts: Options) {
- if (option.isBlank()) {
- error = "Invalid $argumentName option specified: Must be non-empty string."
- } else if (option.contains("..")) {
- error = "Invalid $argumentName option specified: No path traversal allowed."
- } else {
- setSubDirectory(option, opts)
- }
- }
-
- abstract fun setSubDirectory(dir: String, opts: Options)
-}
-
-class LogDirArgument : WritableDirectoryArgument() {
- override val argumentName = "log-dir"
- override val helpText = """
- Directory to write log output to.
- """.trimIndent()
- override val default = null
-
- override fun setDirectory(dir: File, opts: Options) {
- opts.logDir = dir
- }
-}
-
-class RunFilesArgument : WritableDirectoryArgument() {
- override val argumentName = "run-files-path"
- override val helpText =
- """
- Local directory to place lock files and other process-specific
- metadata.
- """
- .trimIndent()
- override val default = "/tmp"
-
- override fun setDirectory(dir: File, opts: Options) {
- opts.runFiles = dir
- }
-}
-
-class RootDirArgument : WritableDirectoryArgument() {
- override val argumentName = "root-dir"
- override val helpText =
- """
- Base directory for the Kotlin daemon's artifacts.
- Other directories - working-dir, output-dir, and build-dir - are all relative
- to this directory.
- This option is REQUIRED.
- """
- .trimIndent()
- override val default = null
-
- override fun setDirectory(dir: File, opts: Options) {
- opts.rootDir = dir
- }
-}
-
-class WorkingDirArgument : SubdirectoryArgument() {
- override val argumentName = "working-dir"
- override val helpText =
- """
- Stores intermediate steps used specifically for incremental compilation.
- Must be maintained between compilation invocations to see
- incremental speed benefits.
- Relative to root-dir.
- """
- .trimIndent()
- override val default = "work"
-
- override fun setSubDirectory(dir: String, opts: Options) {
- opts.workingDirName = dir
- }
-}
-
-class OutputDirArgument : SubdirectoryArgument() {
- override val argumentName = "output-dir"
- override val helpText =
- """
- Where to output compiler results.
- Relative to root-dir.
- """
- .trimIndent()
- override val default = "output"
-
- override fun setSubDirectory(dir: String, opts: Options) {
- opts.outputDirName = dir
- }
-}
-
-class BuildDirArgument : SubdirectoryArgument() {
- override val argumentName = "build-dir"
- override val helpText =
- """
- TODO: figure out what this is. Notes say:
- "buildDir is the parent of destDir and workingDir"
- """
- .trimIndent()
- override val default = "build"
-
- override fun setSubDirectory(dir: String, opts: Options) {
- opts.buildDirName = dir
- }
-}
-
-class BuildHistoryFileArgument : StringArgument() {
- override val argumentName = "build-history"
- override val helpText =
- """
- Location of the build-history file used for incremental compilation.
- """
- .trimIndent()
- override val default = "build-history"
-
- override fun setOption(option: String, opts: Options) {
- opts.buildHistoryFileName = option
- }
-}
-
-class ClassPathArgument : StringArgument() {
- override val argumentName = "classpath"
- override val helpText =
- """
- List of directories and JAR/ZIP archives to search for user class files.
- Colon separated: "foo.jar:bar.jar"
- """
- .trimIndent()
- override val default = null
-
- override fun setOption(option: String, opts: Options) {
- val paths = option.split(":").filter { !it.isBlank() }
- // TODO: validate paths?
- opts.classPath.addAll(paths)
- }
-}
-
-/**
- * Intercepts the -Xplugin argument of kotlinc such that we can prepend them to the front of the
- * classpath.
- *
- * Without this, you can run into a bug where a passed in plugin can cause a plugin implementing the
- * same package+classname to be loaded from a different part of the classpath than is intended.
- */
-class PluginArgument : StringArgument() {
- override val argumentName = "Xplugin"
- override val helpText =
- """
- Compiler plugins passed to kotlin. See the `-Xplugin` argument of kotlinc.
- """
- .trimIndent()
- override val default = null
-
- override fun setOption(option: String, opts: Options) {
- opts.classPath.addFirst(option)
- opts.passThroughArgs.add("-Xplugin=$option")
- }
-}
-
-class JvmArgument : Argument<String>() {
- override val argumentName = "-J<option>"
- override val helpText = """
- Options passed through to the JVM.
- """.trimIndent()
- override val default = null
-
- override fun matches(arg: String) = arg.startsWith("-J")
-
- override fun parse(arg: String, position: Iterator<String>, opts: Options) {
- // Strip off "-J-" so that we're left with just "<option>"
- setOption(arg.substring(3), opts)
- }
-
- override fun setOption(option: String, opts: Options) {
- opts.jvmArgs.add(option)
- }
-}
-
-fun isValidDirectoryForWriting(filePath: String): String? {
- try {
- val file = File(filePath)
- if (file.exists()) {
- if (!file.isDirectory) {
- return "Path exists but is not a directory"
- }
- if (!file.canWrite()) {
- return "Directory exists but is not writable"
- }
- } else if (!file.mkdirs()) {
- return "Unable to create directory"
- }
-
- return null // All checks passed!
- } catch (e: Exception) {
- // Handle exceptions like invalid path characters, no permissions, etc.
- return e.message
- }
-}
-
-fun isValidFilePathForWriting(filePath: String): String? {
- if (filePath.isBlank()) {
- return "Empty log-file path"
- }
-
- try {
- val file = File(filePath)
- val parentDir = file.parentFile ?: return "Invalid parent directory"
-
- if (!parentDir.exists()) {
- if (!parentDir.mkdirs()) {
- return "Unable to create parent directory"
- }
- } else if (!parentDir.isDirectory) {
- return "Parent directory is not a directory"
- } else if (!parentDir.canWrite()) {
- return "Parent directory is not writable"
- }
-
- if (file.exists()) {
- if (file.isDirectory) {
- return "File is a directory"
- } else if (!file.canWrite()) {
- return "File exists but is not writable"
- }
- }
-
- return null // All checks passed!
- } catch (e: Exception) {
- // Handle exceptions like invalid path characters, no permissions, etc.
- return e.message
- }
-}
diff --git a/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/BuildFileParser.kt b/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/BuildFileParser.kt
deleted file mode 100644
index 2e26e43..0000000
--- a/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/BuildFileParser.kt
+++ /dev/null
@@ -1,104 +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.xml.sax.Attributes
-import org.xml.sax.helpers.DefaultHandler
-
-class BuildFileParser : DefaultHandler() {
- val classpaths: List<String>
- get() = _classpaths
-
- val sources: List<String>
- get() = _sources
-
- val javaSources: List<String>
- get() = _javaSources
-
- val moduleName: String?
- get() = _moduleName
-
- val outputDirName: String?
- get() = _outputDirName
-
- private val _classpaths = mutableListOf<String>()
- private val _sources = mutableListOf<String>()
- private val _javaSources = mutableListOf<String>()
- private var _moduleName: String? = null
- private var _outputDirName: String? = null
-
- override fun startElement(
- uri: String?,
- localName: String?,
- qName: String?,
- attributes: Attributes?,
- ) {
- when (qName) {
- "module" -> parseModule(attributes)
- "classpath" -> parseClassPath(attributes)
- "sources" -> parseSources(attributes)
- "javaSourceRoots" -> parseJavaSourceRoots(attributes)
- }
- }
-
- private fun parseClassPath(attributes: Attributes?) {
- if (attributes == null) {
- return
- }
-
- val cp = attributes.getValue("", "path")
- if (cp == null) {
- return
- }
- _classpaths.add(cp)
- }
-
- private fun parseSources(attributes: Attributes?) {
- if (attributes == null) {
- return
- }
-
- val path = attributes.getValue("", "path")
- if (path == null) {
- return
- }
-
- _sources.add(path)
- }
-
- private fun parseJavaSourceRoots(attributes: Attributes?) {
- if (attributes == null) {
- return
- }
-
- val path = attributes.getValue("", "path")
- if (path == null) {
- return
- }
-
- _javaSources.add(path)
- }
-
- private fun parseModule(attributes: Attributes?) {
- if (attributes == null) {
- return
- }
-
- _moduleName = attributes.getValue("", "name")
- _outputDirName = attributes.getValue("", "outputDir")
- }
-}
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 f3be307..4938641 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,100 +16,6 @@
package com.android.kotlin.compiler.client
-import kotlin.system.exitProcess
-
-private val ARGUMENT_PARSERS =
- listOf(
- BuildDirArgument(),
- BuildFileArgument(),
- BuildHistoryFileArgument(),
- ClassPathArgument(),
- HelpArgument(),
- JvmArgument(),
- LogDirArgument(),
- OutputDirArgument(),
- PluginArgument(),
- RunFilesArgument(),
- RootDirArgument(),
- WorkingDirArgument(),
- SourcesArgument(), // must come last
- )
-
fun main(args: Array<String>) {
- val opts = Options()
- ARGUMENT_PARSERS.forEach { it.setupDefault(opts) }
-
- if (!parseArgs(args, opts)) {
- exitProcess(-1)
- }
-
- println("compiling")
-}
-
-fun parseArgs(args: Array<String>, opts: Options): Boolean {
- var hasError = false
- var showHelp = args.isEmpty()
- val iter = args.iterator()
- while (iter.hasNext()) {
- val arg = iter.next()
- for (parser in ARGUMENT_PARSERS) {
- if (parser.matches(arg)) {
- 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()
- }
- break
- }
- }
- }
-
- if (showHelp) {
- showArgumentHelp()
- }
-
- return !hasError
-}
-
-fun showArgumentHelp() {
- var longest = -1
- val padding = 5
-
- println(
- "Usage: kotlin-incremental-client <-root-dir>=<dir> [options] [kotlinc options] " +
- "[-- <source files>]"
- )
- println()
- for (parser in ARGUMENT_PARSERS) {
- if (parser.argumentName.length > longest) {
- longest = parser.argumentName.length
- }
- }
-
- val indent = " ".repeat(longest + padding)
- for (parser in ARGUMENT_PARSERS) {
- print(("-" + parser.argumentName).padEnd(longest + padding))
- var first = true
- parser.helpText.lines().forEach {
- if (first) {
- println(it)
- first = false
- } else {
- println(indent + it)
- }
- }
- if (parser.default != null) {
- print(indent + "[Default: ")
- if (parser.default is String) {
- println("\"${parser.default}\"]")
- } else {
- println("${parser.default}]")
- }
- }
- }
+ println("compiling")
}
diff --git a/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Options.kt b/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Options.kt
deleted file mode 100644
index 5564fb1..0000000
--- a/cmd/kotlinc_incremental/src/com/android/kotlin/compiler/client/Options.kt
+++ /dev/null
@@ -1,187 +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 java.io.File
-
-class Options {
- val classPath = mutableListOf<String>()
- val passThroughArgs = mutableListOf<String>()
- val jvmArgs = mutableListOf<String>()
- val _sources = mutableListOf<String>()
- val sources
- get() = _sources
-
- fun addSource(arg: String) {
- _sources.add(arg)
- }
-
- private var _rootDir: File? = null
- var rootDir: File
- get() {
- return _rootDir ?: throw IllegalStateException("Can not read rootDir before it is set")
- }
- set(value) {
- _rootDir = value
- }
-
- var rootDirLocation: String
- get() {
- return _rootDir?.absolutePath
- ?: throw IllegalStateException("Can not read rootDirLocation before it is set")
- }
- set(value) {
- if (value == "") {
- _rootDir = null
- } else {
- _rootDir = File(value)
- }
- }
-
- var buildDirName: String = "build"
- val buildDir: File
- get() {
- if (_rootDir == null) {
- throw IllegalStateException("Can not read buildDir before rootDir is set")
- }
- if (buildDirName.isEmpty()) {
- throw IllegalStateException("buildDirName may not be empty.")
- }
- return File(rootDir, buildDirName)
- }
-
- var outputDirName: String = "output"
- val outputDir: File
- get() {
- if (_rootDir == null) {
- throw IllegalStateException("Can not read outputDir before rootDir is set")
- }
- if (outputDirName.isEmpty()) {
- throw IllegalStateException("outputDirName may not be empty.")
- }
- return File(rootDir, outputDirName)
- }
-
- var workingDirName: String = "work"
- val workingDir: File
- get() {
- if (_rootDir == null) {
- throw IllegalStateException("Can not read workingDir before rootDir is set")
- }
- if (workingDirName.isEmpty()) {
- throw IllegalStateException("workingDirName may not be empty.")
- }
- return File(rootDir, workingDirName)
- }
-
- var buildHistoryFileName: String = "build-history"
- val buildHistory: File
- get() {
- if (_rootDir == null) {
- throw IllegalStateException("Can not read buildHistory before rootDir is set")
- }
- if (buildHistoryFileName.isEmpty()) {
- throw IllegalStateException("buildHistoryFileName may not be empty.")
- }
- return File(rootDir, buildHistoryFileName)
- }
-
- private var _logDir: File? = null
- var logDir: File
- get() {
- return _logDir ?: throw IllegalStateException("Can not read logDir before it is set")
- }
- set(value) {
- _logDir = value
- }
-
- var logDirLocation: String
- get() {
- return _logDir?.absolutePath
- ?: throw IllegalStateException("Can not read logDirLocation before it is set")
- }
- set(value) {
- if (value == "") {
- _logDir = null
- } else {
- _logDir = File(value)
- }
- }
-
- private var _runFiles: File? = null
- var runFiles: File
- get() {
- return _runFiles
- ?: throw IllegalStateException("Can not read runFiles before it is set")
- }
- set(value) {
- _runFiles = value
- }
-
- var runFilesLocation: String
- get() {
- return _runFiles?.absolutePath
- ?: throw IllegalStateException("Can not read runFilesLocation before it is set")
- }
- set(value) {
- if (value == "") {
- _runFiles = null
- } else {
- _runFiles = File(value)
- }
- }
-
- private var _buildFile: File? = null
- var buildFile: File?
- get() = _buildFile
- set(value) {
- _buildFile = value
- }
-
- var buildFileLocation: String?
- get() {
- return _buildFile?.absolutePath
- ?: throw IllegalStateException("Can not read buildFileLocation before it is set")
- }
- set(value) {
- if (value == "" || value == null) {
- _buildFile = null
- } else {
- _buildFile = File(value)
- }
- }
-
- var buildFileModuleName: String? = null
-
- var buildFileClassPaths: List<String> = emptyList()
-
- var buildFileSources: List<String> = emptyList()
-
- var buildFileJavaSources: List<String> = emptyList()
-
- private var classpathSnapshotDir: String = "cpsnapshot"
- val classpathSnapshot: File
- get() {
- if (_rootDir == null) {
- throw IllegalStateException("Can not read classpathSnapshot before rootDir is set")
- }
- if (classpathSnapshotDir.isEmpty()) {
- throw IllegalStateException("classpathSnapshotDir may not be empty.")
- }
- return File(rootDir, classpathSnapshotDir)
- }
-}
diff --git a/cmd/kotlinc_incremental/tests/resources/test_build.xml b/cmd/kotlinc_incremental/tests/resources/test_build.xml
deleted file mode 100644
index ed443d4..0000000
--- a/cmd/kotlinc_incremental/tests/resources/test_build.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<modules>
- <module name="test_module" type="java-production" outputDir="output">
- <classpath path="a.jar" />
- <classpath path="b.jar" />
- <javaSourceRoots path="c.java" />
- <javaSourceRoots path="d.java" />
- <sources path="e.kt" />
- <sources path="f.kt" />
- </module>
-</modules>
\ No newline at end of file
diff --git a/cmd/kotlinc_incremental/tests/src/com/android/kotlin/compiler/client/ArgumentTest.kt b/cmd/kotlinc_incremental/tests/src/com/android/kotlin/compiler/client/ArgumentTest.kt
deleted file mode 100644
index 947be2c..0000000
--- a/cmd/kotlinc_incremental/tests/src/com/android/kotlin/compiler/client/ArgumentTest.kt
+++ /dev/null
@@ -1,434 +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 com.google.common.truth.Truth.assertThat
-import java.io.File
-import java.nio.file.attribute.PosixFilePermission
-import kotlin.io.path.setPosixFilePermissions
-import org.junit.Assert.assertThrows
-import org.junit.Before
-import org.junit.Rule
-import org.junit.Test
-import org.junit.rules.TemporaryFolder
-
-class ArgumentTest {
-
- private val opts = Options()
-
- @get:Rule val tFolder = TemporaryFolder()
-
- @Before fun setup() {}
-
- @Test
- fun testSourcesArgument_NoAdditional() {
- val dda = SourcesArgument()
- assertThat(dda.matches("--")).isTrue()
- dda.parse("--", emptyList<String>().iterator(), opts)
- assertThat(opts.sources.size).isEqualTo(0)
- }
-
- @Test
- fun testSourcesArgument_OneArgument() {
- val dda = SourcesArgument()
- val arg1 = "foo"
- dda.parse("--", listOf(arg1).iterator(), opts)
- assertThat(opts.sources.size).isEqualTo(1)
- assertThat(opts.sources.get(0)).isEqualTo(arg1)
- }
-
- @Test
- fun testSourcesArgument_MultiArgument() {
- val dda = SourcesArgument()
- // Test a variety of argument formats, even though we treat them all as source.
- val args = listOf("foo", "bar", "-cp", "this:is:a:classpath", "-single", "-with-arg", "arg")
- dda.parse("--", args.iterator(), opts)
- assertThat(opts.sources.size).isEqualTo(args.size)
- assertThat(opts.sources).isEqualTo(args)
- }
-
- @Test
- fun testBuildFileArgument() {
- val bfa = BuildFileArgument()
- val buildFile = File("tests/resources/test_build.xml")
- val arg = "-build-file=" + buildFile.absoluteFile
- bfa.parse(arg, emptyList<String>().iterator(), opts)
- assertThat(opts.buildFileLocation).isEqualTo(buildFile.absolutePath)
- }
-
- @Test
- fun testBuildFileArgument_SetsOptions() {
- val bfa = BuildFileArgument()
- val buildFile = File("tests/resources/test_build.xml")
- val arg = "-build-file=" + buildFile.absoluteFile
- bfa.parse(arg, emptyList<String>().iterator(), opts)
- assertThat(opts.buildFileLocation).isEqualTo(buildFile.absolutePath)
- assertThat(opts.buildFileClassPaths).containsExactly("a.jar", "b.jar")
- assertThat(opts.buildFileJavaSources).containsExactly("c.java", "d.java")
- assertThat(opts.buildFileSources).containsExactly("e.kt", "f.kt")
- assertThat(opts.buildFileModuleName).isEqualTo("test_module")
- assertThat(opts.outputDirName).isEqualTo("output")
- }
-
- @Test
- fun testBuildFileArgument_NoArgument() {
- val bfa = BuildFileArgument()
- val arg = "-build-file="
- bfa.parse(arg, emptyList<String>().iterator(), opts)
- assertThrows(IllegalStateException::class.java, { opts.buildFileLocation })
- assertThat(bfa.error).isNotEmpty()
- }
-
- @Test
- fun testHelpArgument() {
- val ha = HelpArgument()
- assertThat(ha.matches("-h")).isTrue()
- val args = listOf("foo").iterator()
- ha.parse("-h", args, opts)
- assertThat(args.hasNext()).isTrue()
- }
-
- @Test
- fun testLogDirArgument() {
- val lfa = LogDirArgument()
- val logDirLocation = tFolder.root.absolutePath
- val arg = "-log-dir=$logDirLocation"
- assertThat(lfa.matches(arg)).isTrue()
- lfa.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.logDirLocation).isEqualTo(logDirLocation)
- assertThat(lfa.error).isNull()
- }
-
- @Test
- fun testLogDirArgument_NoArgument() {
- val lfa = LogDirArgument()
- val arg = "-log-dir="
- lfa.parse(arg, emptyList<String>().iterator(), opts)
- assertThrows(IllegalStateException::class.java, { opts.logDirLocation })
- assertThat(lfa.error).isNotEmpty()
- }
-
- @Test
- fun testLogDirArgument_NoWritePermissions() {
- val lfa = LogDirArgument()
- val readOnlyDirectory = tFolder.newFolder("read-only")
- // Remove write permissions
- readOnlyDirectory
- .toPath()
- .setPosixFilePermissions(
- setOf(
- PosixFilePermission.OWNER_READ,
- PosixFilePermission.OWNER_EXECUTE,
- PosixFilePermission.GROUP_READ,
- PosixFilePermission.GROUP_EXECUTE,
- PosixFilePermission.OTHERS_READ,
- PosixFilePermission.OTHERS_EXECUTE,
- )
- )
-
- val logDirLocation = readOnlyDirectory.absolutePath
- val arg = "-log-dir=$logDirLocation"
- lfa.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThrows(IllegalStateException::class.java, { opts.logDirLocation })
- assertThat(lfa.error).isNotEmpty()
- }
-
- @Test
- fun testRunFilesArgument() {
- val rfa = RunFilesArgument()
- val runFilesLocation = tFolder.root.absolutePath
- val arg = "-run-files-path=$runFilesLocation"
- assertThat(rfa.matches(arg)).isTrue()
- rfa.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.runFilesLocation).isEqualTo(runFilesLocation)
- assertThat(rfa.error).isNull()
- }
-
- @Test
- fun testRunFilesArgument_NoArgument() {
- val rfa = RunFilesArgument()
- val arg = "-run-files-path="
- rfa.parse(arg, emptyList<String>().iterator(), opts)
- assertThrows(IllegalStateException::class.java, { opts.runFilesLocation })
- assertThat(rfa.error).isNotEmpty()
- }
-
- @Test
- fun testRunFilesArgument_NoWritePermissions() {
- val rfa = RunFilesArgument()
- val readOnlyDirectory = tFolder.newFolder("read-only")
- // Remove write permissions
- readOnlyDirectory
- .toPath()
- .setPosixFilePermissions(
- setOf(
- PosixFilePermission.OWNER_READ,
- PosixFilePermission.OWNER_EXECUTE,
- PosixFilePermission.GROUP_READ,
- PosixFilePermission.GROUP_EXECUTE,
- PosixFilePermission.OTHERS_READ,
- PosixFilePermission.OTHERS_EXECUTE,
- )
- )
-
- val runFilesLocation = readOnlyDirectory.absolutePath
- val arg = "-run-files-path=$runFilesLocation"
-
- rfa.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThrows(IllegalStateException::class.java, { opts.runFilesLocation })
- assertThat(rfa.error).isNotEmpty()
- }
-
- @Test
- fun testBuildHistoryFileArgument() {
- val bfa = BuildHistoryFileArgument()
- val tFile = tFolder.newFile("build")
- val arg = "-build-history=" + tFile.absolutePath
- bfa.parse(arg, emptyList<String>().iterator(), opts)
- assertThat(opts.buildHistoryFileName).isEqualTo(tFile.absolutePath)
- }
-
- @Test
- fun testBuildHistoryFileArgument_NoArgument() {
- val bfa = BuildHistoryFileArgument()
- val arg = "-build-history="
- bfa.parse(arg, emptyList<String>().iterator(), opts)
- assertThat(bfa.error).isNotEmpty()
- }
-
- @Test
- fun testRootDirArgument() {
- val rfa = RootDirArgument()
- val rootDirLocation = tFolder.root.absolutePath
- val arg = "-root-dir=$rootDirLocation"
- assertThat(rfa.matches(arg)).isTrue()
- rfa.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.rootDirLocation).isEqualTo(rootDirLocation)
- assertThat(rfa.error).isNull()
- }
-
- @Test
- fun testRootDirArgument_NoArgument() {
- val rfa = RootDirArgument()
- val arg = "-root-dir="
- rfa.parse(arg, emptyList<String>().iterator(), opts)
- assertThrows(IllegalStateException::class.java, { opts.rootDirLocation })
- assertThat(rfa.error).isNotEmpty()
- }
-
- @Test
- fun testRootDirArgument_NoWritePermissions() {
- val rfa = RootDirArgument()
- val readOnlyDirectory = tFolder.newFolder("read-only")
- // Remove write permissions
- readOnlyDirectory
- .toPath()
- .setPosixFilePermissions(
- setOf(
- PosixFilePermission.OWNER_READ,
- PosixFilePermission.OWNER_EXECUTE,
- PosixFilePermission.GROUP_READ,
- PosixFilePermission.GROUP_EXECUTE,
- PosixFilePermission.OTHERS_READ,
- PosixFilePermission.OTHERS_EXECUTE,
- )
- )
-
- val rootDirLocation = readOnlyDirectory.absolutePath
- val arg = "-root-dir=$rootDirLocation"
-
- rfa.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThrows(IllegalStateException::class.java, { opts.rootDirLocation })
- assertThat(rfa.error).isNotEmpty()
- }
-
- @Test
- fun testWorkingDirArgument() {
- val wda = WorkingDirArgument()
- val arg = "-working-dir=FOOBAR"
- assertThat(wda.matches(arg)).isTrue()
- wda.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.workingDirName).isEqualTo("FOOBAR")
- assertThat(wda.error).isNull()
- }
-
- @Test
- fun testWorkingDirArgument_NoArgument() {
- val wda = WorkingDirArgument()
- val arg = "-working-dir="
- wda.parse(arg, emptyList<String>().iterator(), opts)
- assertThat(wda.error).isNotEmpty()
- }
-
- @Test
- fun testWorkingDirArgument_PathTraversal() {
- val wda = WorkingDirArgument()
- val arg = "-working-dir=../FOOBAR"
- wda.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(wda.error).isNotEmpty()
- }
-
- @Test
- fun testOutputDirArgument() {
- val oda = OutputDirArgument()
- val arg = "-output-dir=FOOBAR"
- assertThat(oda.matches(arg)).isTrue()
- oda.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.outputDirName).isEqualTo("FOOBAR")
- assertThat(oda.error).isNull()
- }
-
- @Test
- fun testOutputDirArgument_NoArgument() {
- val wda = OutputDirArgument()
- val arg = "-output-dir="
- wda.parse(arg, emptyList<String>().iterator(), opts)
- assertThat(wda.error).isNotEmpty()
- }
-
- @Test
- fun testOutputDirArgument_PathTraversal() {
- val wda = OutputDirArgument()
- val arg = "-output-dir=../FOOBAR"
- wda.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(wda.error).isNotEmpty()
- }
-
- @Test
- fun testBuildDirArgument() {
- val oda = BuildDirArgument()
- val arg = "-build-dir=FOOBAR"
- assertThat(oda.matches(arg)).isTrue()
- oda.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.buildDirName).isEqualTo("FOOBAR")
- assertThat(oda.error).isNull()
- }
-
- @Test
- fun testBuildDirArgument_NoArgument() {
- val wda = BuildDirArgument()
- val arg = "-build-dir="
- wda.parse(arg, emptyList<String>().iterator(), opts)
- assertThat(wda.error).isNotEmpty()
- }
-
- @Test
- fun testBuildDirArgument_PathTraversal() {
- val wda = BuildDirArgument()
- val arg = "-build-dir=../FOOBAR"
- wda.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(wda.error).isNotEmpty()
- }
-
- @Test
- fun testClassPathArgument() {
- val cpa = ClassPathArgument()
- val paths = listOf("foo", "bar", "baz")
- val arg = "-classpath=" + paths.joinToString(":")
- assertThat(cpa.matches(arg)).isTrue()
- cpa.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.classPath).isEqualTo(paths)
- }
-
- @Test
- fun testClassPathArgument_NoArgument() {
- val cpa = ClassPathArgument()
- val arg = "-classpath="
- cpa.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.classPath).isEmpty()
- assertThat(cpa.error).isNotEmpty()
- }
-
- @Test
- fun testPluginArgument() {
- val pa = PluginArgument()
- val arg = "-Xplugin=foo"
- assertThat(pa.matches(arg)).isTrue()
- pa.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.classPath).contains("foo")
- assertThat(opts.passThroughArgs).contains("-Xplugin=foo")
- }
-
- @Test
- fun testPluginArgument_NoArgument() {
- val pa = PluginArgument()
- val arg = "-Xplugin="
- pa.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.classPath).isEmpty()
- assertThat(opts.passThroughArgs).isEmpty()
- assertThat(pa.error).isNotEmpty()
- }
-
- @Test
- fun testPluginArgument_FirstInClassPath() {
- val pa = PluginArgument()
- val arg = "-Xplugin=foo"
-
- opts.classPath.addAll(listOf("a", "b", "c"))
- assertThat(opts.classPath.first()).isNotEqualTo("foo")
-
- assertThat(pa.matches(arg)).isTrue()
- pa.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.classPath.first()).isEqualTo("foo")
- assertThat(opts.passThroughArgs).contains("-Xplugin=foo")
- }
-
- @Test
- fun testJvmArgument() {
- val jvma = JvmArgument()
- val arg = "-J-option"
- assertThat(jvma.matches(arg)).isTrue()
- jvma.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.jvmArgs).contains("option")
- }
-
- @Test
- fun testPluginArgument_WithEquals() {
- val jvma = JvmArgument()
- val arg = "-J-option=foo"
- jvma.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.jvmArgs).contains("option=foo")
- }
-
- @Test
- fun testPluginArgument_DoubleDash() {
- val jvma = JvmArgument()
- val arg = "-J--option=foo"
- jvma.parse(arg, emptyList<String>().iterator(), opts)
-
- assertThat(opts.jvmArgs).contains("-option=foo")
- }
-}
diff --git a/cmd/kotlinc_incremental/tests/src/com/android/kotlin/compiler/client/BuildFileParserTest.kt b/cmd/kotlinc_incremental/tests/src/com/android/kotlin/compiler/client/BuildFileParserTest.kt
deleted file mode 100644
index 068bda3..0000000
--- a/cmd/kotlinc_incremental/tests/src/com/android/kotlin/compiler/client/BuildFileParserTest.kt
+++ /dev/null
@@ -1,66 +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 com.google.common.truth.Truth.assertThat
-import java.io.File
-import javax.xml.parsers.SAXParserFactory
-import org.junit.Before
-import org.junit.Test
-import org.xml.sax.XMLReader
-
-class BuildFileParserTest {
- private lateinit var parser: BuildFileParser
- private lateinit var xmlReader: XMLReader
- val buildFile = File("tests/resources/test_build.xml")
-
- @Before
- fun setup() {
- parser = BuildFileParser()
- val spf = SAXParserFactory.newInstance()
- val saxParser = spf.newSAXParser()
- xmlReader = saxParser.xmlReader
- xmlReader.contentHandler = parser
-
- xmlReader.parse(buildFile.absolutePath)
- }
-
- @Test
- fun testParseClasspaths() {
- assertThat(parser.classpaths).containsExactly("a.jar", "b.jar")
- }
-
- @Test
- fun testParseJavaSources() {
- assertThat(parser.javaSources).containsExactly("c.java", "d.java")
- }
-
- @Test
- fun testParseSources() {
- assertThat(parser.sources).containsExactly("e.kt", "f.kt")
- }
-
- @Test
- fun testParserModuleName() {
- assertThat(parser.moduleName).isEqualTo("test_module")
- }
-
- @Test
- fun testParserOutputDirName() {
- assertThat(parser.outputDirName).isEqualTo("output")
- }
-}
diff --git a/cmd/kotlinc_incremental/tests/src/com/android/kotlin/compiler/client/MainTest.kt b/cmd/kotlinc_incremental/tests/src/com/android/kotlin/compiler/client/MainTest.kt
new file mode 100644
index 0000000..3354aa4
--- /dev/null
+++ b/cmd/kotlinc_incremental/tests/src/com/android/kotlin/compiler/client/MainTest.kt
@@ -0,0 +1,27 @@
+/*
+ * 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 com.google.common.truth.Truth.assertThat
+import org.junit.Test
+
+class MainTest {
+ @Test
+ fun testMain() {
+ assertThat(true).isTrue()
+ }
+}
\ No newline at end of file