hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
41.63k stars 9.41k forks source link

go-generate doesn't work in go1.11 (stringer, CacheLineSize redeclared in this block) #19310

Closed kb-0 closed 4 years ago

kb-0 commented 5 years ago

Terraform Version

0.11.10

Expected Behavior

Successful compilation of latest Terraform source using Golang 1.11.*.

Actual Behavior

==> Checking that code complies with gofmt requirements...
go generate ./...
go: extracting github.com/hashicorp/consul v0.0.0-20171026175957-610f3c86a089
go: extracting github.com/coreos/etcd v3.3.10+incompatible
go: extracting github.com/hashicorp/hil v0.0.0-20170627220502-fa9f258a9250
go: extracting github.com/hashicorp/go-safetemp v0.0.0-20180326211150-b1a1dbde6fdc
go: extracting github.com/hashicorp/vault v0.0.0-20161029210149-9a60bf2a50e4
go: extracting github.com/gophercloud/gophercloud v0.0.0-20170524130959-3027adb1ce72
go: extracting github.com/hashicorp/go-checkpoint v0.0.0-20171009173528-1545e56e46de
go: extracting github.com/hashicorp/logutils v0.0.0-20150609070431-0dc08b1671f3
go: extracting github.com/hashicorp/hcl2 v0.0.0-20180925175540-3f1c5474d4f7
go: extracting github.com/hashicorp/errwrap v1.0.0
go: extracting github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f
go: extracting github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90
go: extracting github.com/agext/levenshtein v1.2.1
go: extracting github.com/hashicorp/go-retryablehttp v0.0.0-20160930035102-6e85be8fee1d
go: extracting github.com/hashicorp/go-version v0.0.0-20180322230233-23480c066577
go: extracting github.com/hashicorp/go-plugin v0.0.0-20181002195811-1faddcf740b6
go: extracting github.com/hashicorp/go-uuid v1.0.0
go: extracting github.com/hashicorp/go-cleanhttp v0.0.0-20171130225243-06c9ea3a335b
go: extracting github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f
go: extracting github.com/hashicorp/yamux v0.0.0-20160720233140-d1caa6c97c9f
go: extracting github.com/dylanmei/iso8601 v0.1.0
go: extracting github.com/hashicorp/go-tfe v0.2.6
go: extracting github.com/hashicorp/go-slug v0.1.0
go: extracting github.com/gogo/protobuf v0.0.0-20180821102207-98f6aa8b3bcf
go: extracting github.com/coreos/go-semver v0.2.0
2018/11/07 12:24:11 Generated command/internal_plugin_list.go
stringer: checking package: input_variable.go:4:2: could not import fmt (type-checking package "fmt" failed (/usr/local/go/src/fmt/format.go:8:2: could not import strconv (type-checking package "strconv" failed (/usr/local/go/src/strconv/atof.go:13:8: could not import math (type-checking package "math" failed (/usr/local/go/src/math/exp_asm.go:9:8: could not import internal/cpu (type-checking package "internal/cpu" failed (/usr/local/go/src/internal/cpu/cpu_x86.go:9:7: CacheLineSize redeclared in this block))))))))
addrs/resource.go:256: running "stringer": exit status 1
stringer: checking package: backend.go:4:2: could not import github.com/hashicorp/hcl2/hcl (type-checking package "github.com/hashicorp/terraform/vendor/github.com/hashicorp/hcl2/hcl" failed (/home/igor/Projects/github/powerdns_terraform/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hcl2/hcl/diagnostic.go:4:2: could not import fmt (type-checking package "fmt" failed (/usr/local/go/src/fmt/format.go:8:2: could not import strconv (type-checking package "strconv" failed (/usr/local/go/src/strconv/atof.go:13:8: could not import math (type-checking package "math" failed (/usr/local/go/src/math/exp_asm.go:9:8: could not import internal/cpu (type-checking package "internal/cpu" failed (/usr/local/go/src/internal/cpu/cpu_x86.go:9:7: CacheLineSize redeclared in this block))))))))))
configs/provisioner.go:115: running "stringer": exit status 1
stringer: checking package: coerce_value.go:4:2: could not import fmt (type-checking package "fmt" failed (/usr/local/go/src/fmt/format.go:8:2: could not import strconv (type-checking package "strconv" failed (/usr/local/go/src/strconv/atof.go:13:8: could not import math (type-checking package "math" failed (/usr/local/go/src/math/exp_asm.go:9:8: could not import internal/cpu (type-checking package "internal/cpu" failed (/usr/local/go/src/internal/cpu/cpu_x86.go:9:7: CacheLineSize redeclared in this block))))))))
configs/configschema/schema.go:86: running "stringer": exit status 1
stringer: checking package: action_string.go:5:8: could not import strconv (type-checking package "strconv" failed (/usr/local/go/src/strconv/atof.go:13:8: could not import math (type-checking package "math" failed (/usr/local/go/src/math/exp_asm.go:9:8: could not import internal/cpu (type-checking package "internal/cpu" failed (/usr/local/go/src/internal/cpu/cpu_x86.go:9:7: CacheLineSize redeclared in this block))))))
plans/action.go:15: running "stringer": exit status 1
stringer: checking package: eachmode_string.go:5:8: could not import strconv (type-checking package "strconv" failed (/usr/local/go/src/strconv/atof.go:13:8: could not import math (type-checking package "math" failed (/usr/local/go/src/math/exp_asm.go:9:8: could not import internal/cpu (type-checking package "internal/cpu" failed (/usr/local/go/src/internal/cpu/cpu_x86.go:9:7: CacheLineSize redeclared in this block))))))
states/instance_object.go:43: running "stringer": exit status 1
stringer: checking package: context.go:4:2: could not import bytes (type-checking package "bytes" failed (/usr/local/go/src/bytes/buffer.go:11:2: could not import io (type-checking package "io" failed (/usr/local/go/src/io/pipe.go:12:2: could not import sync (type-checking package "sync" failed (/usr/local/go/src/sync/pool.go:9:2: could not import runtime (type-checking package "runtime" failed (/usr/local/go/src/runtime/alg.go:8:2: could not import internal/cpu (type-checking package "internal/cpu" failed (/usr/local/go/src/internal/cpu/cpu_x86.go:9:7: CacheLineSize redeclared in this block))))))))))
terraform/variables.go:78: running "stringer": exit status 1
stringer: checking package: config_traversals.go:4:2: could not import bytes (type-checking package "bytes" failed (/usr/local/go/src/bytes/buffer.go:11:2: could not import io (type-checking package "io" failed (/usr/local/go/src/io/pipe.go:12:2: could not import sync (type-checking package "sync" failed (/usr/local/go/src/sync/pool.go:9:2: could not import runtime (type-checking package "runtime" failed (/usr/local/go/src/runtime/alg.go:8:2: could not import internal/cpu (type-checking package "internal/cpu" failed (/usr/local/go/src/internal/cpu/cpu_x86.go:9:7: CacheLineSize redeclared in this block))))))))))
tfdiags/diagnostic.go:20: running "stringer": exit status 1
Makefile:77: recipe for target 'generate' failed
make: *** [generate] Error 1

Steps to Reproduce

  1. Clone repository onto Ubuntu 18.04 machine
  2. Install Golang as described and set $PATH and $GOPATH accordingly
  3. Proceed with the install steps in the README.md

Additional Context

I have tested this with golang 1.11.1 and 1.11.2 as well as GO111MODULE=on, GO111MODULE=off and GO111MODULE=auto (not explicitly set).

After 3 hours of trial and error I am now at a loss. Does someone have an idea what is going on here?

Dominik-K commented 5 years ago

@kb-0 I think it's because stringer doesn't support Go modules yet (marked Beta). It's used in many source files (search for //go:generate stringer).

Workaround this with

GO111MODULE=on go install .

either in $GOPATH/src/github.com/hashicorp/terraform or outside it. Then

$GOPATH/bin/terraform version

should output Terraform v0.12.0-dev.

apparentlymart commented 5 years ago

At the time this was opened we were in the middle of merging the 0.12 changes which included the switch to Go Modules, and so the build scripts + makefile hadn't yet been updated completely to deal with Go Modules.

Since then we've made various updates that have result in the workflow steps working for us and for running in Travis-CI. Unfortunately as @Dominik-K mentioned there's some complexity here because some tools support Go Modules while others don't, and so we've selectively enabled/disabled modules in various places to get things working. It is likely that further adjustments will be required over time as different parts of the Go ecosystem become modules-aware.

cyberliem commented 5 years ago

I found out that the wasm files that redeclare its functions, which get conflicts with other arc declaration(my arch was x86). I commented out the code in /usr/local/go/src/runtime/sys_wasm.go and /usr/local/go/src/runtime/internal/atomic/atomic_wasm.go, after which my stringer works normally.

My go version was 1.11

hashibot commented 4 years ago

Hello again!

We didn't hear back from you, so I'm going to close this in the hope that a previous response gave you the information you needed. If not, please do feel free to re-open this and leave another comment with the information my human friends requested above. Thanks!

ghost commented 4 years ago

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.