-
Notifications
You must be signed in to change notification settings - Fork 68
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
Facilitate sharing specs across multi-module builds. #432
Conversation
This adds necessary the necessary mechanisms and logic to facilitate sharing smithy specs in multi-module settings. The first important part is the addition of a resource generation mechanism that adds the local smithy files to the output resources, and synthetise smithy files containing only metadata, keeping track of the namespaces that have been generated by smithy4s. Because the metadata in question is an array node, it is monoidal in nature and the values are aggregated when loading models. These values are used to skip code generation in downstream Smithy4s calls, as the downstream modules can trust that the upstream one will have generated the relevant package. Then, the SBT plugin changes to load internal dependency outputs as local jars. This has the effect of pulling the models from upstream modules in the current model assembler, allowing users to depend on the shapes it contains.
modules/codegen-cli/src/smithy4s/codegen/cli/CodegenCommand.scala
Outdated
Show resolved
Hide resolved
modules/codegen-plugin/src/sbt-test/codegen-plugin/multimodule/project/plugins.sbt
Show resolved
Hide resolved
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.
I'm too braindead to read through this today, but might take a peek later
modules/codegen-cli/src/smithy4s/codegen/cli/CodegenCommand.scala
Outdated
Show resolved
Hide resolved
Update nscplugin, sbt-scala-native, ... to 0.4.7
Bump Scala 3 to 3.2.0
This exhaustively captures the codegenArgs as a way to invalidate SBT's cache to retrigger codegen every time something changes. This uses SBT's JsonFormat, converting os-lib's paths into file hashes. In theory, when a local file changes (say, a dependency snapshot), the cache should now be invalidated and trigger a regeneration.
This allows people who experiment with snapshot jars (published locally) to get a better developer experience, by not requiring them to restart SBT between spec changes.
Also tests that no two different bits were responsible for generating the same namespaces.
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.
I pushed a commit to address a doc issue, but otherwise it LGTM
@@ -823,7 +825,7 @@ def genSmithyImpl(config: Configuration) = Def.task { | |||
val outputDir = (config / genSmithyOutput).?.value | |||
.getOrElse((config / sourceManaged).value) | |||
.getAbsolutePath() | |||
val openapiOutputDir = | |||
val resourceOutputDir = | |||
(config / genSmithyOpenapiOutput).?.value |
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.
working on the mill version: should we rename this to genResourcesOutput
?
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.
I can always address this on my mill PR
did my comment make sense to you?
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.
Yeah sure you can go ahead and rename in your PR :)
This adds the necessary mechanisms and logic to facilitate sharing smithy specs in multi-module settings.
The first important part is the addition of a resource generation mechanism that adds the local smithy files to the output resources, and synthesise smithy files containing only metadata, keeping track of the namespaces that have been generated by smithy4s. Because this extends the openapi generation to be able to generate more resources, I've renamed/revamped the arguments in
CodegenArgs
andCodegenCommand
to be more fitting.Because the metadata in question is an array node, it is monoidal in nature and the values are aggregated when loading models. These values are used to skip code generation in downstream Smithy4s calls, as the downstream modules can trust that the upstream one will have generated the relevant package.
Then, the SBT plugin changes to load internal dependency outputs as local jars. This has the effect of pulling the models from upstream modules in the current model assembler, allowing users to depend on the shapes it contains.
resolves #420
resolves #391
TODOS :
[ ] Think about whether some other metadata should be added to track the version of Smithy4s that generated the sources, to try and protect against incompatibilities, as this mechanism could be extended to use Smithy4s in the same style as protobuf, where specs are packaged alongside the generated code.in a subsequent PR