-
Notifications
You must be signed in to change notification settings - Fork 245
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
feat(go): run "go build" on generated code #2485
Conversation
To ensure the generated go code is formatted and compiles by executing `go fmt` and `go build` on the output directory. In order to be able to do that within mono-repos (and in the jsii repo itself), we need to be able to resolve local dependencies (same as all other languages). Resolves #2463
- Restore original `go.mod` so the published one does not have the “replace” directives - Only add `replace` if the dependency’s `go.mod` file includes the correct module name.
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.
Code looks good. Wondering if we should exclude 'go build' if the code-only option is set? Formatting would still be wanted so resolving dependencies is still necessary.
Currently both |
The module @scope/jsii-calc-base-of-base is intended to be used as a _transitive_ dependency and not direct. Add a test to ensure this doesn't regress in the future.
The title of this Pull Request does not conform with [Conventional Commits] guidelines. It will need to be adjusted before the PR can be merged. |
The title of this Pull Request does not conform with [Conventional Commits] guidelines. It will need to be adjusted before the PR can be merged. |
go fmt
and go build
after code generation
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
To ensure the generated go code is formatted and compiles by executing
go fmt
and
go build
on the output directory.Similar to other languages, in order to be able to build the go module within mono-repos (and in the jsii repo itself), we need to be able to resolve local dependencies. This is done in the following way:
dist/go
candidates (based on thejsii.outdir
relative to dependency package dirs)outDir
, in case--outdir
is useddist
directory, check if we can find a<goModule>/go.mod
file that contains amodule <moduleName>
directive.replace
directive with a relative path to our owngo.mod
which tellsgo fmt
andgo build
to find the dependency locally.go.mod
file so that the published one will not include thereplace
directives.TESTING: this is primarily tested using the
test:build
target ofjsii-pacmak
which generates & builds the go code for the "calc" fixture (in all pacmak execution variants).NOTE: running
go fmt
on the generated sources turned out to be problematic because sources are generated in parallel by default, and therefore it was not possible to resolve local dependencies at that time (which is required sincego fmt
processesgo.mod
).Resolves #2463
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.