Skip to content
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

Feature request: Room KSP support #238

Closed
PhilGlass opened this issue Feb 8, 2022 · 17 comments
Closed

Feature request: Room KSP support #238

PhilGlass opened this issue Feb 8, 2022 · 17 comments

Comments

@PhilGlass
Copy link

KSP has been stable for a while now, and is supported by Room since 2.3.0-beta02.

The schema generation behaviour is the same as the kapt version, so it suffers from the same cache miss issues.

@PhilGlass PhilGlass changed the title Feature request: KSP support Feature request: Room KSP support Feb 8, 2022
@runningcode
Copy link
Contributor

Thanks for the request Phil.
Can you share the cache miss that you are seeing when using KSP with Room and the android-cache-fix plugin applied? This will help us understand how to fix it.

@PhilGlass
Copy link
Author

PhilGlass commented Feb 8, 2022

I could put together a standalone repro, but I think the issues are exactly the same as they are for the kapt version - schemaLocation is passed as an absolute path and is used as both an input and output directory.

@runningcode
Copy link
Contributor

That helps for now. Thanks.

@runningcode
Copy link
Contributor

@PhilGlass do you know if there is an issue tracking the KSP cache miss on Google's side?

@PhilGlass
Copy link
Author

I don't know of a KSP specific one - I guess the existing issue applies? In that you can't really fix this using only kapt/KSP APIs, you need a Gradle plugin.

@runningcode
Copy link
Contributor

Can you please add a comment in that one or file a new one? :)
We're often in discussions about this issue with Google but it's really helpful to have the community pressure to fix this since they don't understand the importance or impact of this issue.

@runningcode
Copy link
Contributor

runningcode commented Feb 16, 2022

This is currently not possible since KSP does not expose a way to pass CommandLineArgumentProviders to the extension.
https://github.com/google/ksp/blob/main/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspExtension.kt

google/ksp#847

@PhilGlass
Copy link
Author

KspTask exposes its ListProperty<SubpluginOption> as public API, so I think it is possible - I used that to work around this internally for now. Might be worth waiting for the CommandLineArgumentProvider to land & release though!

One thing to note is that, like kapt, KSP tasks wipe any declared output directories when they run non-incrementally (this behaviour is inherited from AbstractKotlinCompile).

@runningcode
Copy link
Contributor

runningcode commented Mar 7, 2022

Thanks for following up on this @PhilGlass . Unfortunately, ListProperty<SubpluginOption> is neither an input nor an output. That means that changes to the input, or clearing the output directory would not cause the task to re-run leading to an incorrect build.

On the second note thanks for sharing, that is why the workaround that google has explained here is simply not sufficient. Please comment and let Google know that their workaround is not sufficient. I have already shared my thoughts with them on this workaround via other channels but I would like to hear the community say it as well.

The Android Cache Fix plugin has a workaround for the task outputs being cleared .

@PhilGlass
Copy link
Author

PhilGlass commented Mar 7, 2022

Thanks for following up on this @PhilGlass . Unfortunately, ListProperty is neither an input nor an output. That means that changes to the input, or clearing the output directory would not cause the task to re-run leading to an incorrect build.

It's definitely not a workaround on its own - but it is a mechanism you can use to pass arguments to KSP without them becoming a task input (using InternalSubpluginOption or one of the other SubpluginOption subclasses that are treated specially - see my comment on your KSP PR). Then you can use the other workarounds implemented by this plugin to fix the myriad of other problems!

On the second note thanks for sharing, that is why the workaround that google has explained here is simply not sufficient. Please comment and let Google know that their workaround is not sufficient. I have already shared my thoughts with them on this workaround via other channels but I would like to hear the community say it as well.

Done. As I mentioned in that comment, Auto migrations are another spanner in the works. Now the schemas directory is both an input and output of the kapt/KSP tasks, because past versions of the schema are required to generate the auto migrations. So if the schema directory changes, Room should re-run... but Room also writes the current schemas into that directory, effectively invalidating its own inputs for the next build. 😭

@runningcode
Copy link
Contributor

runningcode commented Mar 7, 2022

Thanks for commenting there! Makes sense that the Subplugin options are a workaround. I'll take care of resolving your comments in the PR soon.
If you can still edit your comment, it would be good to explain that their workarounds for KAPT do not fully solve the issue as well for the same reasons you mention.

And yes the RoomSchemaWorkaround does also take care of the pre-existing schemas.

@PhilGlass
Copy link
Author

I can't edit it any more - but it already mentions kapt briefly.

And yes the RoomSchemaWorkaround does also take care of the pre-existing schemas.

Sort of. It copies the contents of the version controlled schemas directory to the temporary directories passed as room.schemaLocation - but that version controlled directory isn't tracked as a task input (or output). So if something in it changes kapt/KSP won't re-run, which can produce incorrect results for auto migrations (e.g if you delete an old schema that's required to generate an auto migration Room should fail, but it won't unless some other change forces it to rerun).

@runningcode
Copy link
Contributor

Thanks for that edge case. It's a good point that we don't cover that, we didn't think it was so common. Is that a common thing to delete old schema?

@PhilGlass
Copy link
Author

PhilGlass commented Mar 7, 2022

I don't think so - I haven't seen this fail in practice. Just another thing that came to mind when I was thinking about all the things that are wrong with the way room.schemaLocation is designed. 😅

@bishiboosh
Copy link

Seeing as the PR has been merged in KSP, is there any news on this topic ?

@runningcode
Copy link
Contributor

runningcode commented May 2, 2022

Unfortunately, this is still blocked by this. KSP requires variant support in order for this workaround to work otherwise we will have overlapping outputs and the caching will still be disabled.

@cdsap
Copy link
Member

cdsap commented Feb 28, 2023

@PhilGlass @PhilGlass we have published version 2.7.0 with support for ksp in the RoomWorkaround

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

No branches or pull requests

4 participants