Skip to content

Commit 1e541b1

Browse files
committed
[Bugfix] Incremental compilation via constructor parameter change.
1 parent a2a3ada commit 1e541b1

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

compiler/src/main/java/com/squareup/anvil/compiler/codegen/CodeGenerationExtension.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,17 @@ internal class CodeGenerationExtension(
7070

7171
val anvilContext = commandLineOptions.toAnvilContext(anvilModule)
7272

73-
codeGenDir.listFiles()
74-
?.forEach {
75-
check(it.deleteRecursively()) {
76-
"Could not clean file: $it"
73+
if (files.isNotEmpty()) {
74+
codeGenDir.listFiles()
75+
?.forEach {
76+
check(it.deleteRecursively()) {
77+
"Could not clean file: $it"
78+
}
7779
}
78-
}
80+
} else {
81+
// No files to analyze indicates either empty module or incremental compilation. We should
82+
// not clear generated code if there are no changes in the incremental build.
83+
}
7984

8085
val generatedFiles = mutableMapOf<String, GeneratedFile>()
8186

@@ -136,9 +141,12 @@ internal class CodeGenerationExtension(
136141
codeGenerator.flush(codeGenDir, anvilModule).toKtFile()
137142
}
138143

144+
val touchedFiles = mutableListOf<KtFile>().apply { addAll(files) }
139145
var newFiles = nonPrivateCodeGenerators.generateCode(files)
140146

141147
while (newFiles.isNotEmpty()) {
148+
touchedFiles.addAll(newFiles)
149+
142150
// Parse the KtFile for each generated file. Then feed the code generators with the new
143151
// parsed files until no new files are generated.
144152
newFiles = nonPrivateCodeGenerators.generateCode(newFiles)

0 commit comments

Comments
 (0)