Clean up fall-back logic in IncrementalCompilerRunner

Make it clear that there 3 distinct cases:
   1. Incremental compilation completed with an ExitCode.
   2. Incremental compilation was not possible for some valid reason
      (e.g., for a clean build), and we will perform non-incremental
      compilation.
   3. Incremental compilation failed with an exception.
      In this case, we will:
        - Print a warning with a stack trace
        - Ask the user to file a bug
        - Collect rebuild reason enum for analytics
           + TODO: Collect the stack trace too
        - Fall back to non-incremental compilation

Test: Existing BaseIncrementalCompilationMultiProjectIT.testFailureHandling_UserError,
      Updated BaseIncrementalCompilationMultiProjectIT.testFailureHandling_ToolError

^KT-53015: In progress
This commit is contained in:
Hung Nguyen
2022-06-20 13:41:40 +01:00
committed by Andrey Uskov
parent 57bbc335f4
commit def886cd31
24 changed files with 409 additions and 341 deletions
@@ -18,9 +18,11 @@ enum class BuildAttributeKind : Serializable {
enum class BuildAttribute(val kind: BuildAttributeKind, val readableString: String) : Serializable {
NO_BUILD_HISTORY(BuildAttributeKind.REBUILD_REASON, "Build history file not found"),
NO_ABI_SNAPSHOT(BuildAttributeKind.REBUILD_REASON, "ABI snapshot not found"),
INTERNAL_ERROR(BuildAttributeKind.REBUILD_REASON, "Internal error during preparation of IC round"),
CLASSPATH_SNAPSHOT_NOT_FOUND(BuildAttributeKind.REBUILD_REASON, "Classpath snapshot not found"),
INCREMENTAL_COMPILATION_FAILED(BuildAttributeKind.REBUILD_REASON, "Incremental compilation failed"),
IC_FAILED_TO_GET_CHANGED_FILES(BuildAttributeKind.REBUILD_REASON, "Failed to get changed files"),
IC_FAILED_TO_COMPUTE_FILES_TO_RECOMPILE(BuildAttributeKind.REBUILD_REASON, "Failed to compute files to recompile"),
IC_FAILED_TO_COMPILE_INCREMENTALLY(BuildAttributeKind.REBUILD_REASON, "Failed to compile incrementally"),
IC_FAILED_TO_CLOSE_CACHES(BuildAttributeKind.REBUILD_REASON, "Failed to close caches"),
UNKNOWN_CHANGES_IN_GRADLE_INPUTS(BuildAttributeKind.REBUILD_REASON, "Unknown Gradle changes"),
JAVA_CHANGE_UNTRACKED_FILE_IS_REMOVED(BuildAttributeKind.REBUILD_REASON, "Untracked Java file is removed"),
JAVA_CHANGE_UNEXPECTED_PSI(BuildAttributeKind.REBUILD_REASON, "Java PSI file is expected"),
@@ -29,15 +29,15 @@ fun File.isClassFile(): Boolean =
extension.equals("class", ignoreCase = true)
/**
* Deletes the contents of this directory (not the directory itself) if it exists, or creates the directory if it does not yet exist.
* Deletes the contents of this directory (not the directory itself).
*
* If this is a regular file, this method will throw an exception.
* If the directory does not exist or if this is a regular file, this method will throw an exception.
*/
fun File.cleanDirectoryContents() {
fun File.deleteDirectoryContents() {
when {
isDirectory -> listFiles()!!.forEach { it.deleteRecursivelyOrThrow() }
isFile -> error("File.cleanDirectoryContents does not accept a regular file: $path")
else -> mkdirsOrThrow()
isFile -> error("Expected a directory but found a regular file: $path")
else -> error("Directory does not exist: $path")
}
}
@@ -49,11 +49,12 @@ fun File.deleteRecursivelyOrThrow() {
}
/**
* Creates this directory (if it does not yet exist), throwing an exception if the directiory creation failed or if a regular file already
* exists at this path.
* Creates this directory (if it does not yet exist).
*
* If a regular file already exists at this path, this method will throw an exception.
*/
@Suppress("SpellCheckingInspection")
fun File.mkdirsOrThrow() {
fun File.createDirectory() {
when {
isDirectory -> Unit
isFile -> error("A regular file already exists at this path: $path")