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

cmd/go: two possible canonical states when go.sum is empty, the file may or may not exist #36236

Open
stephanwesten opened this issue Dec 20, 2019 · 4 comments

Comments

@stephanwesten
Copy link

@stephanwesten stephanwesten commented Dec 20, 2019

What version of Go are you using (go version)?

go version go1.13.5 darwin/amd64

Does this issue reproduce with the latest release?

using latest

What operating system and processor architecture are you using (go env)?

macOS Catalina
GOHOSTARCH="amd64"
GOHOSTOS="darwin"

What did you do?

  • Created simple hello world application without dependencies consisting of main.go and a go.mod file containing:
module github.com/stephanwesten/hellojob

go 1.13
  • Executed go build and noticed that no go.sum was generated (unexpected)

  • added a dummy dependency to go.mod, re-ran go build and a go.sum was generated.

  • removed dependency from go.mod, so it is back to original above, and re-ran go build and go mod tidy

  • go.sum was still there.

What did you expect to see?

(Note that this is the first time for me using go modules so my formulation might not be 100% accurate)
Either go.sum is removed or it should have been generated with the first go.build. This would give symmetric behaviour.

I would prefer that go.sum is always generated. The reason why this was a problem for me is that I used a Dockerfile template that assumed a go.sum file to be there.

What did you see instead?

see above

BTW I entered 'go bug' to file this issue and I got a github error. Perhaps temporary problem?

@dmitshur dmitshur changed the title Asymmetric go.sum generation cmd/go: two possible canonical states when go.sum is empty, the file may or may or may not exist Dec 20, 2019
@dmitshur

This comment has been minimized.

Copy link
Member

@dmitshur dmitshur commented Dec 20, 2019

Thanks for reporting.

We should check if this asymmetry has been discussed in the past and if any decision was made. If not, that can be done in this issue.

/cc @bcmills @jayconrod @matloob as cmd/go owners.

BTW I entered 'go bug' to file this issue and I got a github error. Perhaps temporary problem?

What was the error text? If you can still reproduce the issue, please file a separate issue for that so we can investigate. I tried running go bug just now and did not get an error.

@dmitshur dmitshur added this to the Backlog milestone Dec 20, 2019
@dmitshur dmitshur added the GoCommand label Dec 20, 2019
@dmitshur dmitshur changed the title cmd/go: two possible canonical states when go.sum is empty, the file may or may or may not exist cmd/go: two possible canonical states when go.sum is empty, the file may or may not exist Dec 20, 2019
@OneOfOne

This comment has been minimized.

Copy link
Contributor

@OneOfOne OneOfOne commented Dec 20, 2019

schrodinger's go.sum.

sorry, I'll see myself out now

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Jan 6, 2020

I don't think we should delete the go.sum file entirely when it becomes empty: leaving an empty file makes it more obvious that the edit is intentional (rather than accidental).

I'm ambivalent about creating the go.sum file unconditionally. If the module really doesn't have any dependencies, then we really don't need to create that file, and some folks may find it annoying for the go command to implicitly create an empty file that they don't need.

For the specific use-case of a Dockerfile template, you can always touch go.sum at some point prior to the build.

@stephanwesten

This comment has been minimized.

Copy link
Author

@stephanwesten stephanwesten commented Jan 7, 2020

Imo go build should create the go.sum file always if there is mod file since this gives the most consistent behavior. I see go.sum as some internal housekeeping, its content is not relevant to the user, but its presence does impact the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.