File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
compiler/src/main/java/com/squareup/anvil/compiler/codegen Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff 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)
You can’t perform that action at this time.
0 commit comments