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

"go generate" doesn't work in a fresh dev environment #18380

Closed
apparentlymart opened this issue Jul 3, 2018 · 6 comments
Closed

"go generate" doesn't work in a fresh dev environment #18380

apparentlymart opened this issue Jul 3, 2018 · 6 comments
Labels
build Auto-pinning

Comments

@apparentlymart
Copy link
Member

As initially discussed in #18344, we currently run go generate as part of the main build process (what make runs) but due to golang/go#10249 a fresh dev environment is not ready to run go generate because packages have not yet been installed so that stringer can see them.

$ make
==> Checking that code complies with gofmt requirements...
go generate ./...
2018/07/03 10:03:50 Generated command/internal_plugin_list.go
stringer: checking package: decoder_spec.go:4:2: could not import github.com/hashicorp/hcl2/hcldec (can't find import: "github.com/hashicorp/terraform/vendor/github.com/hashicorp/hcl2/hcldec")
config/configschema/schema.go:80: running "stringer": exit status 1
stringer: checking package: backend.go:4:2: could not import github.com/hashicorp/hcl2/hcl (can't find import: "github.com/hashicorp/terraform/vendor/github.com/hashicorp/hcl2/hcl")
configs/provisioner.go:139: running "stringer": exit status 1
stringer: checking package: diagnostics.go:7:2: could not import github.com/hashicorp/errwrap (can't find import: "github.com/hashicorp/terraform/vendor/github.com/hashicorp/errwrap")
tfdiags/diagnostic.go:11: running "stringer": exit status 1
Makefile:75: recipe for target 'generate' failed
make: *** [generate] Error 1

Normal Go development practice is for go generate to be a separate step from build, so we might choose to address this by taking the generate step out of the default make target altogether and require developers to run go generate manually if they are changing something that is subject to code generation. I believe most Go developers are accustomed to doing this anyway, but it'll probably be surprising for those who are not familiar with Go development so we may need to add some additional documentation close to the parts of the code that are subject to code generation (enums, etc) as a prompt for future maintainers.

@apparentlymart apparentlymart added the build Auto-pinning label Jul 3, 2018
@apparentlymart
Copy link
Member Author

It seems that we're now seeing this error in Travis-CI too. Possible that it was a regression caused by a recent stringer change. Will investigate further soon.

@apparentlymart
Copy link
Member Author

Further breadcrumbs here suggest that this was indeed a recent regression:

@apparentlymart
Copy link
Member Author

At the moment we're just waiting for some dust to settle on the Go side here, and then we'll see if we need to take any further action in our README and Travis-CI configurations.

Unfortunately that means that for the moment any new PR will get a Travis-CI error, so if this isn't resolved upstream soon then we'll start to investigate workarounds.

@caarlos0
Copy link
Contributor

caarlos0 commented Jul 9, 2018

FWIW, my workaround on goreleaser:

setup:
	rm -rf $$GOPATH/src/golang.org/x/tools
	go get -u golang.org/x/tools/cmd/stringer
	go get -u golang.org/x/tools/cmd/cover
	# TODO: temporary hack for https://github.com/golang/go/issues/21387
	(cd $$GOPATH/src/golang.org/x/tools; git checkout ae8cc594552814363a7aeeb4f2825515a771fa38; go install ./cmd/stringer/... ; go install ./cmd/cover/...)

@apparentlymart
Copy link
Member Author

Over in golang/go#10249 after some discussion the reverting was reverted, so we should now be back to a working state again.

From peeking at a few recent PRs I see that they are no longer failing the Travis-CI run, or at least (in some cases) now failing for more legitimate reasons.

@ghost
Copy link

ghost commented Apr 4, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
build Auto-pinning
Projects
None yet
Development

No branches or pull requests

2 participants