Skip to content

Add support for source generators in Bloop #1774

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 4 commits into from
Aug 25, 2022

Conversation

Duhemm
Copy link
Collaborator

@Duhemm Duhemm commented Aug 4, 2022

This commit changes the Bloop project definition to add a new field,
sourceGenerators, which can be used to define source generators.

Source generators are parts of the build that are run when Bloop gathers
the sources of a project (either when queried via BSP or when
compiling).

Source generators are configured with globs matching input files, an
output directory, and a program to run. When the inputs or known outputs
of a source generator change, the source generator is automatically
re-run. When there are no changes, the result of a source generator is
cached.

The command to execute to run a source generator will be built from the
configured argv, followed by the output directory and the input files.

@Duhemm Duhemm force-pushed the source-generators branch from 946790c to 90d0c71 Compare August 4, 2022 13:30
@oyvindberg
Copy link
Contributor

Hey this is exciting! Can you see a path forward to having a source generator being a class file in another bloop project in the same build? that's something I really want

@Duhemm
Copy link
Collaborator Author

Duhemm commented Aug 4, 2022

Hey this is exciting! Can you see a path forward to having a source generator being a class file in another bloop project in the same build? that's something I really want

Interesting, I hadn't thought of this. I think that this should work for bloop compile in the current implementation, but not when querying the sources in BSP. Actually I guess your source generator could run bloop run my-source-generator -- output-directory input1 input2 ... 🤔

@Duhemm Duhemm force-pushed the source-generators branch 2 times, most recently from 23ad797 to 232c1f6 Compare August 5, 2022 08:53
@tgodzik
Copy link
Contributor

tgodzik commented Aug 10, 2022

@Duhemm This looks great! Is it ready to review?

@Duhemm Duhemm force-pushed the source-generators branch from 232c1f6 to 75e38c6 Compare August 17, 2022 14:23
@Duhemm
Copy link
Collaborator Author

Duhemm commented Aug 17, 2022

Thanks @tgodzik ! I think it is ready for review. There was an issue where the source generators would not be re-run when their inputs changed in watch mode, that I unfortunately couldn't figure out before going on vacation. It's fixed now!

@tgodzik
Copy link
Contributor

tgodzik commented Aug 17, 2022

Thanks @tgodzik ! I think it is ready for review. There was an issue where the source generators would not be re-run when their inputs changed in watch mode, that I unfortunately couldn't figure out before going on vacation. It's fixed now!

Ok cool, I am just going on some very short vacations so I will take a look on Monday.

We also merged the update to Monix 3 just right now, so that caused some conflicts unfortunately 😓

But now we should be able to update to Scala 2.13 on the plus side.

@Duhemm Duhemm force-pushed the source-generators branch from 75e38c6 to 2791fbc Compare August 17, 2022 15:13
Duhemm added 3 commits August 17, 2022 17:19
This commit changes the Bloop project definition to add a new field,
`sourceGenerators`, which can be used to define source generators.

Source generators are parts of the build that are run when Bloop gathers
the sources of a project (either when queried via BSP or when
compiling).

Source generators are configured with globs matching input files, an
output directory, and a program to run. When the inputs or known outputs
of a source generator change, the source generator is automatically
re-run. When there are no changes, the result of a source generator is
cached.

The command to execute to run a source generator will be built from the
configured `argv`, followed by the output directory and the input files.
Previously, Bloop would use types from `scala.sys.process` to run the
source generators. This commit migrates over to using Bloop's `Forker`.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Previously, Bloop would not work correctly when watching for changed,
and the inputs of source generators were changed.
@Duhemm Duhemm force-pushed the source-generators branch from 2791fbc to 7f6e50f Compare August 17, 2022 15:22
@Duhemm
Copy link
Collaborator Author

Duhemm commented Aug 17, 2022

Thanks for the heads up. I rebased and fixed the conflicts.

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

Looks good! I left a couple of comments, but this seems like a really good approach.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@Duhemm
Copy link
Collaborator Author

Duhemm commented Aug 25, 2022

I think the test failure is unrelated to this change:

[error] Failed: Total 346, Failed 1, Errors 0, Passed 345
[error] Failed tests:
[error] 	bloop.bsp.LocalBspIntellijClientSpec

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

The error is unrelated, LGTM 🎉

@Duhemm
Copy link
Collaborator Author

Duhemm commented Aug 25, 2022

Nice, thank you! There's no rush in merging, but in case you were waiting for me to do it, I don't have write permissions to this repository anymore 😄

@tgodzik
Copy link
Contributor

tgodzik commented Aug 25, 2022

Nice, thank you! There's no rush in merging, but in case you were waiting for me to do it, I don't have write permissions to this repository anymore smile

Ach, ok. I can add you back to the repo if you want?

@tgodzik tgodzik merged commit c51f8d9 into scalacenter:main Aug 25, 2022
@Duhemm Duhemm deleted the source-generators branch August 25, 2022 09:51
@Duhemm
Copy link
Collaborator Author

Duhemm commented Aug 25, 2022

Yes, please, if you don't mind. I can't promise anything, but I'd be happy to help maintain the project.

@tgodzik
Copy link
Contributor

tgodzik commented Aug 25, 2022

Added!

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.

None yet

3 participants