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

KSP errors are not included in the message output #69

Closed
ansman opened this issue Sep 28, 2020 · 5 comments · Fixed by #95
Closed

KSP errors are not included in the message output #69

ansman opened this issue Sep 28, 2020 · 5 comments · Fixed by #95

Comments

@ansman
Copy link
Contributor

ansman commented Sep 28, 2020

I'm trying to use errors printed by KSP in my test but it seems that any KSP logs are not included. I see them in the test logs but not in KotlinCompilation.Result.messages.

@evant
Copy link
Contributor

evant commented Sep 28, 2020

It's because the stderror stream isn't captured. Was able to work around this by capturing the stderr stream myself. https://github.com/evant/kotlin-inject/blob/main/compiler-tests/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt#L31

@ZacSweers
Copy link
Contributor

I've got a slightly different hack via just copying the sources (leftover from when I needed a newer version compatible with the new package names): https://github.com/ZacSweers/MoshiX/blob/main/ksp-test-util/src/main/kotlin/com/tschuchort/compiletesting/symbolProcessors.kt#L94-L98

@tschuchortdev do you have an implementation in mind for this TODO item in Ksp.kt?

https://github.com/tschuchortdev/kotlin-compile-testing/blob/master/ksp/src/main/kotlin/com/tschuchort/compiletesting/Ksp.kt#L121

If so I'd be happy to take a look at a PR!

@tschuchortdev
Copy link
Owner

tschuchortdev commented Sep 29, 2020

@ZacSweers I don't have a specific implementation in mind. The whole KSP implementation is kind of hacky, because kotlin-compile-testing is not very composable right now, so you might not find a "clean" way to access the KotlinCompilation.messageOutputStream. Currently my plan is to gather complaints/use cases for now and then rewrite it (in December maybe) to be more composable when I have a better grasp of the requirements. Since this will break API compatibility I don't want to rush it and have to rewrite again in the future.

You can try one of the following approaches:

  • Maybe you can get the compiler's message collector from MockProject or CompilerConfiguration inside ComponentRegistrar.registerProjectComponents. Usually all ComponentRegistrars should use the same MessageCollector that is given to K2JVMCompiler by the user, right? So there must be some way for a ComponentRegistrar to access the configured MessageCollector. I don't think they can receive it through the constructor because ComponentRegistrars are often instantiated by a service locator. You can also look at the source code of KSP to see where they get it from.

  • Somehow access the KotlinCompilation.messageOutputStream in a hacky way and replace it with something like TeeOutputStream.

  • Just add a parameter where the user can set the OutputStream to be used for KSP. This has the disadvantage that the messages still won't be recorded in the Result class.

@yigit
Copy link
Contributor

yigit commented Nov 10, 2020

Btw, this might be just related to google/ksp#122.
KSP right now does not report errors to the compilation pipeline so once it is fixed, this issue "might" go away.

@tschuchortdev
Copy link
Owner

@yigit Originally it was simply the case that the KSP-related code had no access to the Outputstream where all the compiler messages are saved. Now that the KSP implementation has changed, deeper changes in KCT will be required to adapt and this issue should get fixed as well.

ZacSweers referenced this issue in ZacSweers/kotlin-compile-testing Dec 24, 2020
Resolves #69. This is based on an implementation I've been using in my projects, and also works around internal access across modules via lesser-known suppression mechanism until kotlin finally finishes implementing friend-paths support in their gradle/IDE tooling.
ZacSweers referenced this issue in ZacSweers/kotlin-compile-testing Dec 24, 2020
Resolves #69. This is based on an implementation I've been using in my projects, and also works around internal access across modules via lesser-known suppression mechanism until kotlin finally finishes implementing friend-paths support in their gradle/IDE tooling.
tschuchortdev added a commit that referenced this issue Dec 26, 2020
* Report KSP logs in compilations

Resolves #69. This is based on an implementation I've been using in my projects, and also works around internal access across modules via lesser-known suppression mechanism until kotlin finally finishes implementing friend-paths support in their gradle/IDE tooling.

* Add tests

* Remove unnecessary copy of MessageCollectorBasedKSPLogger

Co-authored-by: Thilo Schuchort <[email protected]>
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Jan 3, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Jan 4, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Jan 28, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 2, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 3, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 3, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 3, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 4, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 4, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 8, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 8, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 8, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 8, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 10, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 21, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 23, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 24, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 24, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 24, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 24, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Feb 24, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Mar 2, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Mar 2, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Mar 16, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Mar 16, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Mar 22, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Mar 30, 2021
alexvanyo added a commit to livefront/sealed-enum that referenced this issue Apr 20, 2021
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 a pull request may close this issue.

5 participants