-
-
Notifications
You must be signed in to change notification settings - Fork 341
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
Fix serialization using standalone kotlinx compiler #2690
Conversation
I'm assuming this works on GitHub actions too, but it doesn't run as it only goes on master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works correctly on my Ubuntu machine, so it should also work fine on GitHub actions.
It works fine without a change, too, though 😅
How is the linked issue triggered for you? When you run this from the command line?
kotlinc -script -Xplugin=/snap/kotlin/current/lib/kotlinx-serialization-compiler-plugin.jar .github/generate-quest-list.main.kts
Cool.
Indeed. Well nearly the same as that:
Like so (using kotlin-compiler-1.4.31.zip):
Is this some weird path/include thing as I'm just running it from the zip? |
Hmm, not sure. Can we completely avoid the compiler plugin by calling the Then calling the script would be much easier: - kotlinc -script -Xplugin=/path/to/kotlinx-serialization-compiler-plugin.jar .github/generate-quest-list.main.kts
+ kotlinc -script .github/generate-quest-list.main.kts |
I recently encountered a similar error when trying to build StreetComplete. For me it was about the system Java version (openjdk 11.0.10), which did not match the version Android was expecting. I fixed it by pointing gradle to Android Studio's version of Java (openjdk version "1.8.0_242-release") instead. I added this arg when calling gradle (your path will be different): |
Based on this diff:
That fails for me with:
They definitely won't match, is Kotlin not standalone (it's all a bit new to me), but I'm not using Gradle at all, just running that script directly. |
The serializer for a class marked with |
So I think you're saying that @FloEdelmann 's suggestion in #2690 (comment) won't work @westnordost ? |
No, I don't know. I just stated how the kotlinx-serialization library works. I'd like to leave the rest for @FloEdelmann as I don't have an overview of this code involved here and also never tried to execute it myself. |
@peternewman I still don't get why the change would be necessary. The unchanged code works fine on the Ubuntu-based GitHub Actions runner. The changed code also works fine when running from the command line, but when editing the file inside Android Studio, it's complaining about two issues: Are you sure that it's not a missing configuration on your machine? |
Interestingly, both versions seem to work fine with or without the
|
Hmm, does it provide any suggestions for how to fix it? So does it actually not run from within Android Studio in that state?
No, and admittedly trying to replicate the same fault on the Ubuntu runner, I can't manage to, even when making it as similar as possible to my machine (i.e. no configuration (apart from what the runner has built in, just checking out the code and downloading and extracting the zip):
Are you sure it's actually recompiling? During some of this testing, I've grown increasingly suspicious that it's secretly caching some stuff somehow/somewhere, e.g. it sometimes seems to arbitrarily break or work for no discernible reason. Doing the following on a clean checkout, to revert my change seems to consistently break it, regardless of the paths and locations of the compiler and plugin: I'm sort of out of ideas for how to troubleshoot it at my end and confused how this fix works for me but isn't required on the runner etc. See also Kotlin/kotlinx.serialization#1125 |
Edit @FloEdelmann . I've found a far simpler fix, which makes just as much sense in that I've swapped the order of the classes so it's not used before it's been defined, which seems reasonable and fixes my issue. Is this acceptable to you (and I guess more importantly does it not break stuff for you)? |
It now throws an error for me, while on the master branch, it works fine 🙁
|
That's odd, as it works fine on multiple action runners: 😕 |
Are you both taking into account that kotlinx-serialization once on build creates the serializer-classes for classes annotated with I don't know exactly how you start the script and how the GitHub actions work, I just want to point out that if you want to reproduce a problem with running the script, you should make sure that the build cache is cleared before each new run. |
I wasn't aware, but that confirms my theory:
Having a look, there is some stuff in
The workflow just runs these commands: StreetComplete/.github/workflows/generate-quest-list.yml Lines 16 to 17 in 6e857b2
Unless you do some config to make them do otherwise, they spin up a clean image, check out the code from git and then run the command, i.e. it's a clean slate with no previous cached data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, clearing the ~/.cache/main.kts.compiled.cache/
directory does the trick!
Then this looks fine :)
I like that it's just a simple line swap.
Thanks for the merge @westnordost .
Glad to hear it @FloEdelmann
I have to admit that clearing my cache also fixed both of them (original and this) for me (I suspect I didn't have the plugin probably in the path, or possibly used the wrong one when I first ran it, so it cached a failed build). Although it still seems sense to not use them before we define them anyway. |
Based on fix from Kotlin/kotlinx.serialization#1105