Fixes after review
This commit is contained in:
+5
-1
@@ -1,8 +1,12 @@
|
|||||||
package org.jetbrains.kotlin.gradle.tasks
|
package org.jetbrains.kotlin.gradle.tasks
|
||||||
|
|
||||||
import org.jetbrains.kotlin.incremental.LookupSymbol
|
import org.jetbrains.kotlin.incremental.LookupSymbol
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
|
||||||
internal sealed class ChangesEither {
|
internal sealed class ChangesEither {
|
||||||
internal class Known(val lookupSymbols: Set<LookupSymbol>) : ChangesEither()
|
internal class Known(
|
||||||
|
val lookupSymbols: Collection<LookupSymbol> = emptyList(),
|
||||||
|
val fqNames: Collection<FqName> = emptyList()
|
||||||
|
) : ChangesEither()
|
||||||
internal class Unknown : ChangesEither()
|
internal class Unknown : ChangesEither()
|
||||||
}
|
}
|
||||||
+15
-10
@@ -293,20 +293,20 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
symbols
|
symbols
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getClasspathChanges(modifiedClasspath: List<File>): DirtyData? {
|
fun getClasspathChanges(modifiedClasspath: List<File>): ChangesEither {
|
||||||
if (modifiedClasspath.isEmpty()) {
|
if (modifiedClasspath.isEmpty()) {
|
||||||
logger.kotlinDebug { "No classpath changes" }
|
logger.kotlinDebug { "No classpath changes" }
|
||||||
return DirtyData()
|
return ChangesEither.Known()
|
||||||
}
|
}
|
||||||
if (artifactDifferenceRegistry == null) {
|
if (artifactDifferenceRegistry == null) {
|
||||||
logger.kotlinDebug { "No artifact history provider" }
|
logger.kotlinDebug { "No artifact history provider" }
|
||||||
return null
|
return ChangesEither.Unknown()
|
||||||
}
|
}
|
||||||
|
|
||||||
val lastBuildTS = lastBuildInfo?.startTS
|
val lastBuildTS = lastBuildInfo?.startTS
|
||||||
if (lastBuildTS == null) {
|
if (lastBuildTS == null) {
|
||||||
logger.kotlinDebug { "Could not determine last build timestamp" }
|
logger.kotlinDebug { "Could not determine last build timestamp" }
|
||||||
return null
|
return ChangesEither.Unknown()
|
||||||
}
|
}
|
||||||
|
|
||||||
val symbols = HashSet<LookupSymbol>()
|
val symbols = HashSet<LookupSymbol>()
|
||||||
@@ -315,13 +315,13 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
val diffs = artifactDifferenceRegistry!![file]
|
val diffs = artifactDifferenceRegistry!![file]
|
||||||
if (diffs == null) {
|
if (diffs == null) {
|
||||||
logger.kotlinDebug { "Could not get changes for file: $file" }
|
logger.kotlinDebug { "Could not get changes for file: $file" }
|
||||||
return null
|
return ChangesEither.Unknown()
|
||||||
}
|
}
|
||||||
|
|
||||||
val (beforeLastBuild, afterLastBuild) = diffs.partition { it.buildTS < lastBuildTS }
|
val (beforeLastBuild, afterLastBuild) = diffs.partition { it.buildTS < lastBuildTS }
|
||||||
if (beforeLastBuild.isEmpty()) {
|
if (beforeLastBuild.isEmpty()) {
|
||||||
logger.kotlinDebug { "No known build preceding timestamp $lastBuildTS for file $file" }
|
logger.kotlinDebug { "No known build preceding timestamp $lastBuildTS for file $file" }
|
||||||
return null
|
return ChangesEither.Unknown()
|
||||||
}
|
}
|
||||||
|
|
||||||
afterLastBuild.forEach {
|
afterLastBuild.forEach {
|
||||||
@@ -330,7 +330,7 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return DirtyData(symbols, fqNames)
|
return ChangesEither.Known(symbols, fqNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun calculateSourcesToCompile(): Pair<Set<File>, Boolean> {
|
fun calculateSourcesToCompile(): Pair<Set<File>, Boolean> {
|
||||||
@@ -354,12 +354,17 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
|
|
||||||
val modifiedClasspathEntries = modified.filter { it in classpath }
|
val modifiedClasspathEntries = modified.filter { it in classpath }
|
||||||
val classpathChanges = getClasspathChanges(modifiedClasspathEntries)
|
val classpathChanges = getClasspathChanges(modifiedClasspathEntries)
|
||||||
?: return rebuild("could not get changes from modified classpath entries: ${filesToString(modifiedClasspathEntries)}")
|
if (classpathChanges is ChangesEither.Unknown) {
|
||||||
|
return rebuild("could not get changes from modified classpath entries: ${filesToString(modifiedClasspathEntries)}")
|
||||||
|
}
|
||||||
|
if (classpathChanges !is ChangesEither.Known) {
|
||||||
|
throw AssertionError("Unknown implementation of ChangesEither: ${classpathChanges.javaClass}")
|
||||||
|
}
|
||||||
|
|
||||||
val dirtyFiles = modified.filter { it.isKotlinFile() }.toMutableSet()
|
val dirtyFiles = modified.filter { it.isKotlinFile() }.toMutableSet()
|
||||||
val lookupSymbols = HashSet<LookupSymbol>()
|
val lookupSymbols = HashSet<LookupSymbol>()
|
||||||
lookupSymbols.addAll(dirtyJavaLookupSymbols.value)
|
lookupSymbols.addAll(dirtyJavaLookupSymbols.value)
|
||||||
lookupSymbols.addAll(classpathChanges.dirtyLookupSymbols)
|
lookupSymbols.addAll(classpathChanges.lookupSymbols)
|
||||||
|
|
||||||
if (lookupSymbols.any()) {
|
if (lookupSymbols.any()) {
|
||||||
val dirtyFilesFromLookups = mapLookupSymbolsToFiles(lookupStorage, lookupSymbols, logAction, ::projectRelativePath)
|
val dirtyFilesFromLookups = mapLookupSymbolsToFiles(lookupStorage, lookupSymbols, logAction, ::projectRelativePath)
|
||||||
@@ -367,7 +372,7 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val allCaches = targets.map(::getIncrementalCache)
|
val allCaches = targets.map(::getIncrementalCache)
|
||||||
val dirtyClassesFqNames = classpathChanges.dirtyClassesFqNames.flatMap { withSubtypes(it, allCaches) }
|
val dirtyClassesFqNames = classpathChanges.fqNames.flatMap { withSubtypes(it, allCaches) }
|
||||||
if (dirtyClassesFqNames.any()) {
|
if (dirtyClassesFqNames.any()) {
|
||||||
val dirtyFilesFromFqNames = mapClassesFqNamesToFiles(allCaches, dirtyClassesFqNames, logAction, ::projectRelativePath)
|
val dirtyFilesFromFqNames = mapClassesFqNamesToFiles(allCaches, dirtyClassesFqNames, logAction, ::projectRelativePath)
|
||||||
dirtyFiles.addAll(dirtyFilesFromFqNames)
|
dirtyFiles.addAll(dirtyFilesFromFqNames)
|
||||||
|
|||||||
+4
-1
@@ -89,7 +89,10 @@ class KotlinGradleBuildServices private constructor(gradle: Gradle): BuildAdapte
|
|||||||
|
|
||||||
override fun buildFinished(result: BuildResult) {
|
override fun buildFinished(result: BuildResult) {
|
||||||
val gradle = result.gradle!!
|
val gradle = result.gradle!!
|
||||||
val kotlinCompilerCalled = gradle.rootProject.allprojects.flatMap { it.tasks }.any { it is AbstractKotlinCompile<*> && it.compilerCalled }
|
val kotlinCompilerCalled = gradle.rootProject
|
||||||
|
.allprojects
|
||||||
|
.flatMap { it.tasks }
|
||||||
|
.any { it is AbstractKotlinCompile<*> && it.compilerCalled }
|
||||||
|
|
||||||
if (kotlinCompilerCalled) {
|
if (kotlinCompilerCalled) {
|
||||||
log.kotlinDebug("Cleanup after kotlin")
|
log.kotlinDebug("Cleanup after kotlin")
|
||||||
|
|||||||
+3
-3
@@ -42,7 +42,7 @@ internal class ArtifactDifferenceRegistryImpl(
|
|||||||
value.sortedBy { it.buildTS }.joinToString(separator = ",\n\t") { diff ->
|
value.sortedBy { it.buildTS }.joinToString(separator = ",\n\t") { diff ->
|
||||||
"{ " +
|
"{ " +
|
||||||
"timestamp: ${diff.buildTS}, " +
|
"timestamp: ${diff.buildTS}, " +
|
||||||
"lookup symbols: [${diff.dirtyData.dirtyLookupSymbols.dumpLookupSymbols()}], " +
|
"lookup symbols: [${diff.dirtyData.dirtyLookupSymbols.dumpLookupSymbols()}], " +
|
||||||
"fq names: [${diff.dirtyData.dirtyClassesFqNames.dumpFqNames()}]"
|
"fq names: [${diff.dirtyData.dirtyClassesFqNames.dumpFqNames()}]"
|
||||||
"}"
|
"}"
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ private object ArtifactDifferenceCollectionExternalizer : DataExternalizer<Colle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <T> DataInput.readCollectionTo(col: MutableCollection<T>, readT: DataInput.()->T): Collection<T> {
|
private inline fun <T> DataInput.readCollectionTo(col: MutableCollection<T>, readT: DataInput.() -> T): Collection<T> {
|
||||||
val size = readInt()
|
val size = readInt()
|
||||||
|
|
||||||
repeat(size) {
|
repeat(size) {
|
||||||
@@ -96,7 +96,7 @@ private inline fun <T> DataInput.readCollectionTo(col: MutableCollection<T>, rea
|
|||||||
return col
|
return col
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <T> DataOutput.writeCollection(col: Collection<T>, writeT: DataOutput.(T)->Unit) {
|
private inline fun <T> DataOutput.writeCollection(col: Collection<T>, writeT: DataOutput.(T) -> Unit) {
|
||||||
writeInt(col.size)
|
writeInt(col.size)
|
||||||
col.forEach { writeT(it) }
|
col.forEach { writeT(it) }
|
||||||
}
|
}
|
||||||
-4
@@ -52,8 +52,4 @@ internal class BuildCacheStorage(workingDir: File) : BasicMapsOwner() {
|
|||||||
super.close()
|
super.close()
|
||||||
version.saveIfNeeded()
|
version.saveIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun flush(memoryCachesOnly: Boolean) {
|
|
||||||
super.flush(memoryCachesOnly)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+2
-1
@@ -10,6 +10,7 @@ import org.junit.AfterClass
|
|||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.regex.Pattern
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
private val SYSTEM_LINE_SEPARATOR = System.getProperty("line.separator")
|
private val SYSTEM_LINE_SEPARATOR = System.getProperty("line.separator")
|
||||||
@@ -162,7 +163,7 @@ abstract class BaseGradleIT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun CompiledProject.assertSubstringCount(substring: String, expectedCount: Int) {
|
fun CompiledProject.assertSubstringCount(substring: String, expectedCount: Int) {
|
||||||
val actualCount = substring.toRegex().findAll(output).count()
|
val actualCount = Pattern.quote(substring).toRegex().findAll(output).count()
|
||||||
assertEquals(expectedCount, actualCount, "Number of occurrences in output for substring '$substring'")
|
assertEquals(expectedCount, actualCount, "Number of occurrences in output for substring '$substring'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user