Locate build history when file is outside of root project dir

Support use-cases when the build dir is outside of root project dir.
Many projects set up output dir as <root_project>/../out/<project_name>/build
to be able to clean build dir more easily. This commit adds support
to build history file detection and it tries to find build history
files for artifacts that are:
- under root project dir (a default structure)
- under root project's build dir parent (to support typical custom setup)

Fixes https://youtrack.jetbrains.com/issue/KT-40875

Test: BaseIncrementalCompilationMultiProjectIT
This commit is contained in:
Ivan Gavrilovic
2021-02-01 15:40:29 +00:00
committed by nataliya.valtman
parent 5de34b052f
commit 2fce6a4af9
6 changed files with 48 additions and 7 deletions
@@ -347,5 +347,33 @@ open class A {
assertCompiledKotlinSources(project.relativize(aaKt))
}
}
/** Regression test for KT-40875. */
@Test
fun testMoveFunctionFromLibWithRemappedBuildDirs() {
val project = defaultProject()
project.setupWorkingDir()
project.projectDir.resolve("build.gradle").appendText("""
allprojects {
it.buildDir = new File(rootDir, "../out" + it.path.replace(":", "/") + "/build")
}
""".trimIndent())
project.build("build") {
assertSuccessful()
}
val barUseABKt = project.projectDir.getFileByName("barUseAB.kt")
val barInApp = File(project.projectDir, "app/src/main/kotlin/bar").apply { mkdirs() }
barUseABKt.copyTo(File(barInApp, barUseABKt.name))
barUseABKt.delete()
project.build("build") {
assertSuccessful()
val affectedSources = project.projectDir.getFilesByNames("fooCallUseAB.kt", "barUseAB.kt")
val relativePaths = project.relativize(affectedSources)
assertCompiledKotlinSources(relativePaths)
}
}
}
@@ -257,6 +257,7 @@ internal open class GradleCompilerRunner(protected val taskProvider: GradleCompi
return IncrementalModuleInfo(
projectRoot = gradle.rootProject.projectDir,
rootProjectBuildDir = gradle.rootProject.buildDir,
dirToModule = dirToModule,
nameToModules = nameToModules,
jarToClassListFile = jarToClassListFile,