Skip to content

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

@apparentlymart

Description

@apparentlymart

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildAuto-pinning

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions