-
Notifications
You must be signed in to change notification settings - Fork 81
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
Implement contribution merging in KSP #1001
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Looks like this pattern of overrides + indirections all work as expected 👍 interface UserComponent {
interface Factory {
fun create(): UserComponent
}
interface Builder {
fun input(input: String): Builder
fun build(): UserComponent
}
}
interface AnvilUserComponent : UserComponent {
interface Factory : UserComponent.Factory {
override fun create(): AnvilUserComponent
}
interface Builder : UserComponent.Builder {
override fun input(input: String): Builder
override fun build(): AnvilUserComponent
}
}
class DaggerAnvilUserComponent : AnvilUserComponent {
companion object {
fun factory(): AnvilUserComponent.Factory {
TODO()
}
fun builder(): AnvilUserComponent.Builder {
TODO()
}
}
}
object DaggerUserComponent {
fun factory(): UserComponent.Factory {
return DaggerAnvilUserComponent.factory()
}
fun builder(): UserComponent.Builder {
return DaggerAnvilUserComponent.builder()
}
} |
This work is continuing in a fork instead. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a second, clean restart on implementing contribution merging in KSP. This would make Anvil compatible with dagger KSP (while also being backward compatible with dagger apt, but more on that later).
How it works
This approach builds on our recent simplifications to how hints are generated. Now that they are just in a single package, we can use public KSP APIs. It does change a little about how Anvil's historically worked. Instead of modifying in-memory class representations directly, this generates an intermediate component interface with the correct annotations (essentially a source file version of what we did in-memory before). This would then get processed by Dagger's KSP processor in a following round.
@Component.Factory
and@Component.Builder
are both covered.Since folks usually have a
DaggerAppComponent
entry point they expect, this also generates a corresponding shim like so, so that theoretically no source changes are needed.Lastly, this is actually backward compatible with dagger apt as well. It would be not ideal to run both, but given that dagger-ksp is quite slow it may be convenient. All that would need to be done would be for Anvil KSP's contribution merging to run before kapt and its sources be inputs into kapt. Kapt wouldn't know any difference.
Open questions
@MergeModules
no longer works in this case. That one exclusively relies on modifying sources and it's not clear how we can handle that here. One idea is we could generate a module in a "known" location, such asAppModule -> MergedAppModule
and just say people need to include it directly.@MergeInterfaces
no longer works.a. Immediately defer the element until the next round (simplest)
b. Generate anyway, but "know" where and what it will generate to and expect those sources to be generated.
TODO