Gradle: compile tests incrementally when main is changed
#KT-17674 fixed
This commit is contained in:
+22
-4
@@ -20,10 +20,7 @@ import org.gradle.api.logging.LogLevel
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.gradle.plugin.CopyClassesToJavaOutputStatus
|
||||
import org.jetbrains.kotlin.gradle.tasks.USING_INCREMENTAL_COMPILATION_MESSAGE
|
||||
import org.jetbrains.kotlin.gradle.util.checkBytecodeContains
|
||||
import org.jetbrains.kotlin.gradle.util.getFileByName
|
||||
import org.jetbrains.kotlin.gradle.util.getFilesByNames
|
||||
import org.jetbrains.kotlin.gradle.util.modify
|
||||
import org.jetbrains.kotlin.gradle.util.*
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.util.zip.ZipFile
|
||||
@@ -490,6 +487,27 @@ class KotlinGradleIT: BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIncrementalTestCompile() {
|
||||
val project = Project("kotlinProject", GRADLE_VERSION)
|
||||
val options = defaultBuildOptions().copy(incremental = true)
|
||||
|
||||
project.build("build", options = options) {
|
||||
assertSuccessful()
|
||||
}
|
||||
|
||||
val joinerKt = project.projectDir.getFileByName("KotlinGreetingJoiner.kt")
|
||||
joinerKt.modify {
|
||||
it.replace("class KotlinGreetingJoiner", "internal class KotlinGreetingJoiner")
|
||||
}
|
||||
|
||||
project.build("build", options = options) {
|
||||
assertSuccessful()
|
||||
val testJoinerKt = project.projectDir.getFileByName("TestKotlinGreetingJoiner.kt")
|
||||
assertCompiledKotlinSources(project.relativize(joinerKt, testJoinerKt))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLanguageVersionApiVersionExplicit() {
|
||||
val project = Project("kotlinProject", "3.3")
|
||||
|
||||
+6
-21
@@ -1,15 +1,13 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.jetbrains.kotlin.gradle.util.allKotlinFiles
|
||||
import org.jetbrains.kotlin.gradle.util.getFileByName
|
||||
import org.jetbrains.kotlin.gradle.util.modify
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
class TestRootAffectedIT : BaseGradleIT() {
|
||||
@Test
|
||||
fun testSourceRootClassIsModifiedIC() {
|
||||
val project = Project("kotlinProject", "2.10")
|
||||
val project = Project("kotlinProject", "4.1")
|
||||
val buildOptions = defaultBuildOptions().copy(incremental = true)
|
||||
|
||||
project.build("build", options = buildOptions) {
|
||||
@@ -26,8 +24,8 @@ class TestRootAffectedIT : BaseGradleIT() {
|
||||
|
||||
project.build("build", options = buildOptions) {
|
||||
assertSuccessful()
|
||||
val expectedToCompile = project.relativize(listOf(kotlinGreetingJoinerFile) + project.allTestKotlinFiles())
|
||||
assertCompiledKotlinSources(expectedToCompile)
|
||||
val testKotlinGreetingJoinerFile = project.projectDir.getFileByName("TestKotlinGreetingJoiner.kt")
|
||||
assertCompiledKotlinSources(project.relativize(kotlinGreetingJoinerFile, testKotlinGreetingJoinerFile))
|
||||
}
|
||||
|
||||
project.build("build", options = buildOptions) {
|
||||
@@ -38,7 +36,8 @@ class TestRootAffectedIT : BaseGradleIT() {
|
||||
|
||||
@Test
|
||||
fun testSourceRootClassIsRemovedIC() {
|
||||
val project = Project("kotlinProject", "2.10")
|
||||
// todo: update Gradle after https://github.com/gradle/gradle/issues/3051 is resolved
|
||||
val project = Project("kotlinProject", "3.0")
|
||||
val buildOptions = defaultBuildOptions().copy(incremental = true)
|
||||
|
||||
project.build("build", options = buildOptions) {
|
||||
@@ -48,12 +47,6 @@ class TestRootAffectedIT : BaseGradleIT() {
|
||||
val dummyFile = project.projectDir.getFileByName("Dummy.kt")
|
||||
dummyFile.delete()
|
||||
|
||||
project.build("build", options = buildOptions) {
|
||||
assertSuccessful()
|
||||
val expectedToCompile = project.relativize(project.allTestKotlinFiles())
|
||||
assertCompiledKotlinSources(expectedToCompile)
|
||||
}
|
||||
|
||||
project.build("build", options = buildOptions) {
|
||||
assertSuccessful()
|
||||
assertCompiledKotlinSources(emptyList())
|
||||
@@ -62,7 +55,7 @@ class TestRootAffectedIT : BaseGradleIT() {
|
||||
|
||||
@Test
|
||||
fun testTestRootClassIsRemovedIC() {
|
||||
val project = Project("kotlinProject", "2.10")
|
||||
val project = Project("kotlinProject", "4.1")
|
||||
val buildOptions = defaultBuildOptions().copy(incremental = true)
|
||||
|
||||
project.build("build", options = buildOptions) {
|
||||
@@ -76,13 +69,5 @@ class TestRootAffectedIT : BaseGradleIT() {
|
||||
assertSuccessful()
|
||||
assertCompiledKotlinSources(emptyList())
|
||||
}
|
||||
|
||||
project.build("build", options = buildOptions) {
|
||||
assertSuccessful()
|
||||
assertCompiledKotlinSources(emptyList())
|
||||
}
|
||||
}
|
||||
|
||||
private fun Project.allTestKotlinFiles(): Iterable<File> =
|
||||
File(projectDir, "src/test").allKotlinFiles()
|
||||
}
|
||||
+3
-1
@@ -36,5 +36,7 @@ internal class GradleIncrementalCompilerEnvironment(
|
||||
compilerArgs: CommonCompilerArguments,
|
||||
val kaptAnnotationsFileUpdater: AnnotationFileUpdater? = null,
|
||||
val artifactDifferenceRegistryProvider: ArtifactDifferenceRegistryProvider? = null,
|
||||
val artifactFile: File? = null
|
||||
val artifactFile: File? = null,
|
||||
val buildHistoryFile: File? = null,
|
||||
val friendBuildHistoryFile: File? = null
|
||||
) : GradleCompilerEnvironment(compilerClasspath, messageCollector, outputItemsCollector, compilerArgs)
|
||||
+3
-1
@@ -255,7 +255,9 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
||||
reportSeverity = reportSeverity(verbose),
|
||||
requestedCompilationResults = arrayOf(CompilationResultCategory.IC_COMPILE_ITERATION.code),
|
||||
compilerMode = CompilerMode.INCREMENTAL_COMPILER,
|
||||
targetPlatform = targetPlatform
|
||||
targetPlatform = targetPlatform,
|
||||
resultDifferenceFile = environment.buildHistoryFile,
|
||||
friendDifferenceFile = environment.friendBuildHistoryFile
|
||||
)
|
||||
val servicesFacade = GradleIncrementalCompilerServicesFacadeImpl(project, environment)
|
||||
val argsArray = ArgumentUtils.convertArgumentsToStringList(environment.compilerArgs).toTypedArray()
|
||||
|
||||
+5
-1
@@ -243,6 +243,7 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
||||
internal open val sourceRootsContainer = FilteringSourceRootsContainer()
|
||||
|
||||
private var kaptAnnotationsFileUpdater: AnnotationFileUpdater? = null
|
||||
val buildHistoryFile: File = File(taskBuildDirectory, "build-history.bin")
|
||||
|
||||
val kaptOptions = KaptOptions()
|
||||
|
||||
@@ -316,10 +317,13 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
||||
!incremental -> GradleCompilerEnvironment(computedCompilerClasspath, messageCollector, outputItemCollector, args)
|
||||
else -> {
|
||||
logger.warn(USING_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
val friendTask = friendTaskName?.let { project.tasks.findByName(it) as? KotlinCompile }
|
||||
GradleIncrementalCompilerEnvironment(computedCompilerClasspath, changedFiles, reporter, taskBuildDirectory,
|
||||
messageCollector, outputItemCollector, args, kaptAnnotationsFileUpdater,
|
||||
artifactDifferenceRegistryProvider,
|
||||
artifactFile)
|
||||
artifactFile = artifactFile,
|
||||
buildHistoryFile = buildHistoryFile,
|
||||
friendBuildHistoryFile = friendTask?.buildHistoryFile)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user