Skip to content

Commit 1ae67bf

Browse files
committed
Rebuild if processing options changed
1 parent 7569b95 commit 1ae67bf

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

compiler-plugin/src/main/kotlin/com/google/devtools/ksp/Incremental.kt

+27
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,34 @@ class IncrementalContext(
336336
logFile.appendText("\nDirty / All: $percentage%\n\n")
337337
}
338338

339+
private val processingOptionsFile = File(options.cachesDir, "processing.options")
340+
private val processingOptionsString: String by lazy {
341+
StringBuilder().apply {
342+
options.processingOptions.toSortedMap().forEach {
343+
append("${it.key}: ${it.value}\n")
344+
}
345+
}.toString()
346+
}
347+
348+
private val isProcessingOptionsChanged: Boolean by lazy {
349+
if (processingOptionsFile.exists() && processingOptionsFile.isFile) {
350+
val fileContents = processingOptionsFile.readText()
351+
processingOptionsString == fileContents
352+
} else {
353+
true
354+
}
355+
}
356+
339357
// Beware: no side-effects here; Caches should only be touched in updateCaches.
340358
fun calcDirtyFiles(): Collection<KSFile> {
341359
if (!isIncremental) {
342360
cleanIncrementalCache()
343361
return ksFiles
344362
}
345363

364+
if (isProcessingOptionsChanged)
365+
rebuild = true
366+
346367
if (!rebuild) {
347368
val dirtyFilesByDeps = calcDirtySetByDeps()
348369

@@ -415,10 +436,16 @@ class IncrementalContext(
415436
}
416437
}
417438

439+
fun updateProcessingOptions() {
440+
if (isProcessingOptionsChanged)
441+
processingOptionsFile.writeText(processingOptionsString)
442+
}
443+
418444
// TODO: Don't do anything if processing failed.
419445
private fun updateCaches(dirtyFiles: Collection<File>, outputs: Set<File>, sourceToOutputs: Map<File, Set<File>>) {
420446
updateSourceToOutputs(dirtyFiles, outputs, sourceToOutputs)
421447
updateLookupCache(dirtyFiles)
448+
updateProcessingOptions()
422449

423450
// Update symbolsMap
424451
if (!rebuild) {

0 commit comments

Comments
 (0)