Skip to content

Commit

Permalink
Incremental: remove outputs recursively
Browse files Browse the repository at this point in the history
outputs of removed outputs should be removed as well, instead of
being recovered from cache.
  • Loading branch information
ting-yuan committed Oct 5, 2023
1 parent fbeec1f commit 99e23a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class IncrementalContext(
sealedMap.remove(it)
}

sourceToOutputsMap.remove(removedOutputsKey)
sourceToOutputsMap.removeRecursively(removedOutputsKey)
}

private fun updateLookupCache(dirtyFiles: Collection<File>) {
Expand Down Expand Up @@ -417,23 +417,32 @@ class IncrementalContext(
return ksFiles.filter { it.relativeFile in dirtyFiles }
}

// Loop detection isn't needed because of overwritten checks in CodeGeneratorImpl
private fun FileToFilesMap.removeRecursively(src: File) {
get(src)?.forEach { out ->
removeRecursively(out)
}
remove(src)
}

private fun updateSourceToOutputs(
dirtyFiles: Collection<File>,
outputs: Set<File>,
sourceToOutputs: Map<File, Set<File>>,
removedOutputs: List<File>,
) {
// Prune deleted sources in source-to-outputs map.
val visiting = mutableMapOf<File, Boolean>()
removed.forEach {
sourceToOutputsMap.remove(it)
sourceToOutputsMap.removeRecursively(it)
}

dirtyFiles.filterNot { sourceToOutputs.containsKey(it) }.forEach {
sourceToOutputsMap.remove(it)
sourceToOutputsMap.removeRecursively(it)
}

removedOutputs.forEach {
sourceToOutputsMap.remove(it)
sourceToOutputsMap.removeRecursively(it)
}
sourceToOutputsMap[removedOutputsKey] = removedOutputs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class IncrementalMultiChainIT(useK2: Boolean) {
Assert.assertTrue(result.output.contains("validating K1Impl.kt"))
Assert.assertTrue(result.output.contains("validating AllImpls.kt"))
Assert.assertTrue(result.output.contains("[K1Impl]"))
Assert.assertFalse(
File(project.root, "workload/build/generated/ksp/main/kotlin/K2ImplInfo.kt").exists()
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ class Aggregator : SymbolProcessor {
}
codeGenerator.associate(impls.map { it.containingFile!! }.toList(), "", "AllImpls")
}

impls.forEach { decl ->
decl as KSClassDeclaration
val file = decl.containingFile!!
val baseName = decl.simpleName.asString()
val fileName = baseName + "Info"
OutputStreamWriter(
codeGenerator.createNewFile(
Dependencies(false, file),
"", fileName
)
).use {
it.write("// dummy file")
}
}
return emptyList()
}
}
Expand Down

0 comments on commit 99e23a8

Please sign in to comment.