Skip to content

Commit

Permalink
Only clear the output dir the first round
Browse files Browse the repository at this point in the history
Hopeefully resolves square#693
  • Loading branch information
ZacSweers committed Jun 20, 2023
1 parent 4ebc2d2 commit 22b1e67
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal class CodeGenerationExtension(
) : AnalysisHandlerExtension {

private var didRecompile = false
private var compilationRound = 0

private val codeGenerators = codeGenerators
.onEach {
Expand Down Expand Up @@ -59,6 +60,7 @@ internal class CodeGenerationExtension(
bindingTrace: BindingTrace,
files: Collection<KtFile>
): AnalysisResult? {
compilationRound++
if (didRecompile) return null
didRecompile = true

Expand All @@ -70,12 +72,16 @@ internal class CodeGenerationExtension(

val anvilContext = commandLineOptions.toAnvilContext(anvilModule)

codeGenDir.listFiles()
?.forEach {
check(it.deleteRecursively()) {
"Could not clean file: $it"
if (compilationRound == 1) {
// Only clear the output directory the first round
// https://github.com/square/anvil/issues/693#issuecomment-1585545532
codeGenDir.listFiles()
?.forEach {
check(it.deleteRecursively()) {
"Could not clean file: $it"
}
}
}
}

val generatedFiles = mutableMapOf<String, GeneratedFile>()

Expand Down

0 comments on commit 22b1e67

Please sign in to comment.