Skip to content

Cleanup old sources between compilations #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2024

Conversation

ansman
Copy link

@ansman ansman commented Jul 20, 2024

This is required since KSP accepts a list of source directories while Kotlin accepts a list of source files. This means that if you compile multiple times, removing a source file between, KSP will still process the removed files.

This is required since KSP accepts a list of source directories while Kotlin accepts a list of source files. This means that if you compile multiple times, removing a source file between, KSP will still process the removed files.
@@ -9,7 +9,7 @@ import org.intellij.lang.annotations.Language
* A source file for the [KotlinCompilation]
*/
abstract class SourceFile {
internal abstract fun writeIfNeeded(dir: File): File
internal abstract fun writeTo(dir: File): File
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured that renaming this makes sense since it will always write the contents now. Can revert though.

@@ -50,12 +50,13 @@ abstract class SourceFile {
/**
* Compile an existing source file
*/
@Deprecated("This will not work reliably with KSP, use `new` instead")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since KSP2 accepts source directories KCT can't allow arbitrary files now.

@@ -117,6 +117,12 @@ var KotlinCompilation.kspLoggingLevels: Set<CompilerMessageSeverity>
tool.loggingLevels = value
}

@ExperimentalCompilerApi
val JvmCompilationResult.sourcesGeneratedBySymbolProcessor: Sequence<File>
get() = outputDirectory.parentFile.resolve("ksp/sources")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not thrilled about this solution but other solutions require exposing the compilation which doesn't seem ideal.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the round matter here? KSP does output files by round in some circumstances

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you have a result all rounds should be over, so this should include all files. But perhaps I misunderstand your question?

@@ -117,6 +117,12 @@ var KotlinCompilation.kspLoggingLevels: Set<CompilerMessageSeverity>
tool.loggingLevels = value
}

@ExperimentalCompilerApi
val JvmCompilationResult.sourcesGeneratedBySymbolProcessor: Sequence<File>
get() = outputDirectory.parentFile.resolve("ksp/sources")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the round matter here? KSP does output files by round in some circumstances

@ZacSweers ZacSweers merged commit 4fefab3 into ZacSweers:main Jul 20, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants