Skip to content

Commit

Permalink
KT-43489: KGP - Avoid storing build history mapping in a property
Browse files Browse the repository at this point in the history
If tasks are created eagerly, it is possible for this
mapping to be initalized too early. This causes incremental
compilation to fail, as it will contain mappings only for
projects that have been evaluated thus far.

Fixes KT-43489
  • Loading branch information
gavra0 authored and nav-nav committed Nov 23, 2020
1 parent 2c28e65 commit ccc272c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,44 @@ class IncrementalCompilationJvmMultiProjectIT : BaseIncrementalCompilationMultiP
assertCompiledKotlinSources(relativePaths)
}
}

/** Regression test for KT-43489. Make sure build history mapping is not initialized too early. */
@Test
fun testBuildHistoryMappingLazilyComputedWithWorkers() {
val project = defaultProject()
project.setupWorkingDir()
project.projectDir.resolve("app/build.gradle").appendText(
"""
// added to force eager configuration
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
""".trimIndent()
)
val options = defaultBuildOptions().copy(parallelTasksInProject = true)
project.build(options = options, params = arrayOf("build")) {
assertSuccessful()
}

val aKt = project.projectDir.getFileByName("A.kt")
aKt.writeText(
"""
package bar
open class A {
fun a() {}
fun newA() {}
}
"""
)

project.build(options = options, params = arrayOf("build")) {
assertSuccessful()
val affectedSources = project.projectDir.getFilesByNames("A.kt", "B.kt", "AA.kt", "AAA.kt", "BB.kt")
val relativePaths = project.relativize(affectedSources)
assertCompiledKotlinSources(relativePaths)
}
}
}

abstract class BaseIncrementalCompilationMultiProjectIT : BaseGradleIT() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo

private val kotlinLogger by lazy { GradleKotlinLogger(logger) }

/** Keep lazy to avoid computing before all projects are evaluated. */
@get:Internal
internal val compilerRunner by lazy { compilerRunner() }

Expand Down Expand Up @@ -593,10 +594,7 @@ internal open class KotlinCompileWithWorkers @Inject constructor(
private val workerExecutor: WorkerExecutor
) : KotlinCompile() {

@get:Internal
val compilerRunnerValue = GradleCompilerRunnerWithWorkers(GradleCompileTaskProvider(this), workerExecutor)

override fun compilerRunner() = compilerRunnerValue
override fun compilerRunner() = GradleCompilerRunnerWithWorkers(GradleCompileTaskProvider(this), workerExecutor)
}

@CacheableTask
Expand Down

0 comments on commit ccc272c

Please sign in to comment.