wip
diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/BuildSystemSpecification.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/BuildSystemSpecification.kt
new file mode 100644
index 0000000..2f10fb5
--- /dev/null
+++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/BuildSystemSpecification.kt
@@ -0,0 +1,57 @@
+/*
+ * 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.incremental
+
+import org.jetbrains.kotlin.incremental.ICBuildSystem.*
+
+/**
+ * This is internal API. From incremental compilation's point of view,
+ * build system provides a set of constraints and guarantees.
+ * These guarantees may vary, so it makes sense to account for them
+ * in the general IC algorithm.
+ */
+enum class ICBuildSystem {
+ UNKNOWN,
+ JPS,
+ GRADLE,
+ MAVEN,
+ ANT,
+ BAZEL,
+ CLI,
+}
+
+/**
+ * This is internal API.
+ *
+ * In the future, this might have properties such as `normalizesSourcePaths`,
+ * `tracksChangedFiles`, etc.
+ *
+ * Depending on tool's configuration and version, it might provide different guarantees.
+ * So not all properties would be deducible based on `buildSystem` alone.
+ */
+class BuildSystemSpecification(
+ private val buildSystem: ICBuildSystem
+) {
+ //TODO write IC-friendly code - do we add extensions to separate files? would it help?
+ val methodToEnableICFallback: String?
+ get() = when (buildSystem) {
+ GRADLE -> "Add foo.bar.tmp=true to gradle.properties"
+ MAVEN -> "Add property <kotlin.compiler.incremental.fallback>true</kotlin.compiler.incremental.fallback> to pom.xml"
+ else -> null
+ }?.let {
+ """
+ If you see this message too often, you can enable the automatic fallback to full compilation.
+
+ $it
+
+ Please let us know in KT-???. Based on user feedback, we could enable fallback by default in the stable release.
+ """.trimIndent()
+ }
+
+ companion object {
+ val unknownBuildSystem = BuildSystemSpecification(UNKNOWN)
+ }
+}
diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt
index 79bab32..92d456a 100644
--- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt
+++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt
@@ -75,6 +75,7 @@
protected val withAbiSnapshot: Boolean = false,
private val preciseCompilationResultsBackup: Boolean = false,
private val keepIncrementalCompilationCachesInMemory: Boolean = false,
+ private val enableFallbackToRebuild: Boolean = false,
) {
protected val cacheDirectory = File(workingDir, cacheDirName)
@@ -128,22 +129,25 @@
}
is ICResult.Failed -> {
messageCollector.reportException(result.cause, ExceptionLocation.INCREMENTAL_COMPILATION)
- reporter.warn {
- // The indentation after the first line is intentional (so that this message is distinct from next message)
- """
+ if (enableFallbackToRebuild) {
+ reporter.warn {
+ // The indentation after the first line is intentional (so that this message is distinct from next message)
+ """
|Incremental compilation was attempted but failed:
| ${result.reason.readableString}: ${result.cause.stackTraceToString().removeSuffixIfPresent("\n")}
| Falling back to non-incremental compilation (reason = ${result.reason})
- | To help us fix this issue, please file a bug at https://youtrack.jetbrains.com/issues/KT with the above stack trace.
- | (Be sure to search for the above exception in existing issues first to avoid filing duplicated bugs.)
+ | To help us fix this issue, please file a bug at https://youtrack.jetbrains.com/issues/KT
+ | with the above stack trace and reproduction steps.
""".trimMargin()
- }
- // TODO: Collect the stack trace too
- reporter.addAttribute(result.reason)
+ }
+ reporter.addAttribute(result.reason)
- compileNonIncrementally(
- result.reason, allSourceFiles, args, fileLocations, trackChangedFiles = changedFiles == null, messageCollector
- )
+ compileNonIncrementally(
+ result.reason, allSourceFiles, args, fileLocations, trackChangedFiles = changedFiles == null, messageCollector
+ )
+ } else {
+ ExitCode.COMPILATION_ERROR //TODO look at adding separate Failed states for COMP error and INTERNAL error?
+ }
}
}
}