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

Use GoModuleInfo for both ManifestWriter and GoModGenerator #410

Merged
merged 1 commit into from
Jan 27, 2023

Conversation

syall
Copy link
Contributor

@syall syall commented Jan 27, 2023

Issue #, if available:

Related to changes in #405


Description of changes:

Currently, ManifestWriter and GoModGenerator use different
ways to calculate non-standard library dependencies and
the go directive (minimum go version), which could produce
inconsistencies.

This commit updates both writers to use the same source of
information (GoModuleInfo) for writing generated.json
and go.mod.


Testing:

All tests were done in smithy-go-codegen-test:

Test Case goDirective in smithy-build.json goDirective in generated.json goDirective in go.mod
goDirective < default 1.12 IllegalArgumentException IllegalArgumentException
goDirective == default 1.15 1.15 1.15
goDirective > default 1.18 1.18 1.18
goDirective is undefined undefined 1.15 1.15

The IllegalArgumentException thrown when goDirective < default is:

Projection source failed: java.lang.IllegalArgumentException: `goDirective` must be greater than or equal to the default go directive (1.15): 1.12
software.amazon.smithy.go.codegen.GoModuleInfo.calculateMinimumGoDirective(GoModuleInfo.java:63)
...

No codegen diff was produced when testing aws-sdk-go-v2 code generation (make generate).


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@syall syall requested review from a team as code owners January 27, 2023 03:00
Currently, `ManifestWriter` and `GoModGenerator` use different
ways to calculate non-standard library dependencies and
the go directive (minimum go version), which could produce
inconsistencies.

This commit updates both writers to use the same source of
information (`GoModuleInfo`) for writing `generated.json`
and `go.mod`.
@syall syall force-pushed the fix-go-mod-generation branch from dcd8f9b to a897e6d Compare January 27, 2023 03:31
CodegenUtils.runCommand(
String.format("go mod edit -require=%s@%s", dependency.getKey(), dependency.getValue()),
manifest.getBaseDir());
}

CodegenUtils.runCommand(
String.format("go mod edit -go=%s", settings.getGoDirective()),
String.format("go mod edit -go=%s", goModuleInfo.getGoDirective()),
manifest.getBaseDir());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not directly related to the changes in the PR, but should we run go mod tidy to generate a go.sum file?

In the GitHub Go Modules FAQ, the guidance is to check in the corresponding go.sum file produced by go mod tidy into version control.

@syall syall merged commit 81d0ec8 into aws:main Jan 27, 2023
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.

2 participants