Rebuild only if proto changed.
This commit is contained in:
+14
-4
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClass
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.jet.descriptors.serialization.BitEncoding
|
||||
import org.jetbrains.jet.utils.intellij.*
|
||||
import java.util.Arrays
|
||||
|
||||
public class IncrementalCache(baseDir: File) {
|
||||
class object {
|
||||
@@ -72,17 +73,26 @@ public class IncrementalCache(baseDir: File) {
|
||||
})
|
||||
}
|
||||
|
||||
public fun saveFileToCache(moduleId: String, file: File) {
|
||||
public fun saveFileToCache(moduleId: String, file: File): Boolean {
|
||||
val classNameAndHeader = VirtualFileKotlinClass.readClassNameAndHeader(file.readBytes())
|
||||
if (classNameAndHeader == null) return
|
||||
if (classNameAndHeader == null) return false
|
||||
|
||||
val (className, header) = classNameAndHeader
|
||||
if (header.kind == KotlinClassHeader.Kind.PACKAGE_FACADE) {
|
||||
putPackageData(moduleId, className.getFqNameForClassNameWithoutDollars().parent(), BitEncoding.decodeBytes(header.annotationData!!))
|
||||
val fqName = className.getFqNameForClassNameWithoutDollars().parent()
|
||||
val data = BitEncoding.decodeBytes(header.annotationData!!)
|
||||
val oldData = getPackageData(moduleId, fqName)
|
||||
if (Arrays.equals(data, oldData)) {
|
||||
return false
|
||||
}
|
||||
putPackageData(moduleId, fqName, data)
|
||||
return true
|
||||
}
|
||||
// TODO Check class signatures, too!
|
||||
return false
|
||||
}
|
||||
|
||||
public fun putPackageData(moduleId: String, fqName: FqName, data: ByteArray) {
|
||||
private fun putPackageData(moduleId: String, fqName: FqName, data: ByteArray) {
|
||||
packageFacadeData.put(PackageFacadeId(moduleId, fqName), data)
|
||||
}
|
||||
|
||||
|
||||
@@ -198,6 +198,8 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
IncrementalCache cache = new IncrementalCache(KotlinBuilderModuleScriptGenerator.getIncrementalCacheDir(context));
|
||||
|
||||
try {
|
||||
boolean significantChanges = false;
|
||||
|
||||
for (SimpleOutputItem outputItem : outputItemCollector.getOutputs()) {
|
||||
BuildTarget<?> target = null;
|
||||
Collection<File> sourceFiles = outputItem.getSourceFiles();
|
||||
@@ -215,7 +217,9 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
File outputFile = outputItem.getOutputFile();
|
||||
|
||||
if (IncrementalCompilation.ENABLED) {
|
||||
cache.saveFileToCache(target.getId(), outputFile);
|
||||
if (cache.saveFileToCache(target.getId(), outputFile)) {
|
||||
significantChanges = true;
|
||||
}
|
||||
}
|
||||
|
||||
outputConsumer.registerOutputFile(target, outputFile, paths(sourceFiles));
|
||||
@@ -223,18 +227,21 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
|
||||
if (IncrementalCompilation.ENABLED) {
|
||||
// TODO should mark dependencies as dirty, as well
|
||||
FSOperations.markDirty(context, chunk, new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(@NotNull File file) {
|
||||
return !allCompiledFiles.contains(file);
|
||||
}
|
||||
});
|
||||
if (significantChanges) {
|
||||
FSOperations.markDirty(context, chunk, new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(@NotNull File file) {
|
||||
return !allCompiledFiles.contains(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
return ExitCode.ADDITIONAL_PASS_REQUIRED;
|
||||
}
|
||||
else {
|
||||
return ExitCode.OK;
|
||||
}
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
cache.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +108,14 @@ public class IncrementalJpsTest : JpsBuildTestCase() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testReturnTypeChanged() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testTopLevelFunctionSameSignature() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
private class MyLogger(val rootPath: String) : ProjectBuilderLoggerBase() {
|
||||
private val logBuf = StringBuilder()
|
||||
public val log: String
|
||||
|
||||
@@ -3,10 +3,4 @@ out/production/module/test/Foo.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/Foo.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/test/Bar.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/Bar.kt
|
||||
End of files
|
||||
End of files
|
||||
@@ -0,0 +1,14 @@
|
||||
Cleaning output files:
|
||||
out/production/module/test/TestPackage-fun-*.class
|
||||
out/production/module/test/TestPackage.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/fun.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/test/TestPackage-usage-*.class
|
||||
out/production/module/test/TestPackage.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/usage.kt
|
||||
End of files
|
||||
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
fun foo() {
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
fun foo(): String = ":)"
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun usage() {
|
||||
foo()
|
||||
}
|
||||
@@ -4,10 +4,4 @@ out/production/module/test/Foo.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/Foo.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/test/Bar.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/Bar.kt
|
||||
End of files
|
||||
@@ -0,0 +1,7 @@
|
||||
Cleaning output files:
|
||||
out/production/module/test/TestPackage-fun-*.class
|
||||
out/production/module/test/TestPackage.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/fun.kt
|
||||
End of files
|
||||
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
fun foo() {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun foo() {
|
||||
println("body is changed, but it doesn't matter, we won't rebuild dependencies")
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun usage() {
|
||||
foo()
|
||||
}
|
||||
@@ -4,11 +4,4 @@ out/production/module/test/TestPackage.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/a.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/test/TestPackage-b-*.class
|
||||
out/production/module/test/TestPackage.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/b.kt
|
||||
End of files
|
||||
End of files
|
||||
Reference in New Issue
Block a user