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: running go generate with go tool with _same_ GOROOT fails #43369

Closed
Dentrax opened this issue Dec 24, 2020 · 9 comments
Closed

cmd/go: running go generate with go tool with _same_ GOROOT fails #43369

Dentrax opened this issue Dec 24, 2020 · 9 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@Dentrax
Copy link

Dentrax commented Dec 24, 2020

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

$ go version
go version go1.15.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes, commit: b116404

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/furkan/Library/Caches/go-build"
GOENV="/Users/furkan/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/furkan/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/furkan/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/Cellar/go/1.15.5/libexec"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nq/vxjjn3311fg4q263qsxrghpcpzgp66/T/go-build556373901=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Clone the fresh Go repo ($ pwd #/Users/furkan.turkal/go/src/goroot)
  2. $ cd src/cmd/compile/internal/gc
  3. Edit syntax.go to add a new AST node type OFOOBAR
  4. Run $ go generate

What did you expect to see?

Expected op_string.go to be updated with the new node type.

$ go generate syntax.go

No errors, but the generated op_string.go does not have the new node type.

What did you see instead?

Expected the new node type to appear in op_string.go after running $ go generate

Ref: #32724
CC: @bcmills @ianlancetaylor

@Dentrax
Copy link
Author

Dentrax commented Dec 24, 2020

A workaround? to fix this problem is:

$ pwd # /Users/furkan/go/src/goroot
$ cd ./src
$ ./make.bash
$ ../bin/go generate -v . # this usage not works at all
$ ../bin/go generate ./cmd/compile/internal/gc/syntax.go # this works well

@mengzhuo
Copy link
Contributor

mengzhuo commented Dec 25, 2020

go generate without filename will using go list which depends on GOROOT.
You can overwrite GOROOT to your Go source path than generate

GOROOT=$HOME/goroot ../bin/go generate

CC @matloob

@gopherbot
Copy link

Change https://golang.org/cl/280252 mentions this issue: cmd/compile: add explicit file name in stringer generation

@gopherbot
Copy link

Change https://golang.org/cl/280572 mentions this issue: [dev.regabi] cmd/compile: add explicit file name in stringer types

gopherbot pushed a commit that referenced this issue Dec 28, 2020
The stringer using `go list` for the type detection, which depends on
GOROOT. Unfortunally by changing GOROOT to develop path will raise
version mismatch with internal packages.

Update #43369

Change-Id: Id81334ea5f1ecdbfa81eb2d162944d65664ce727
Reviewed-on: https://go-review.googlesource.com/c/go/+/280572
Trust: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
@gopherbot
Copy link

Change https://golang.org/cl/280635 mentions this issue: [dev.regabi] cmd/compile: cleanup //go:generate directives

gopherbot pushed a commit that referenced this issue Dec 29, 2020
During recent refactoring, we moved mkbuiltin.go to package typecheck,
but accidentally duplicated its //go:generate directive into a bunch
of other files/directories. This CL cleans up the unnecessary
duplicates.

Also, update all of the stringer invocations to use an explicit file
name, and regenerate their files.

Updates #43369.

Change-Id: I4e493c1fff103d742de0a839d7a3375659270b50
Reviewed-on: https://go-review.googlesource.com/c/go/+/280635
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Meng Zhuo <mzh@golangcn.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 30, 2020
@dmitshur dmitshur added this to the Backlog milestone Dec 30, 2020
@dmitshur dmitshur added the GoCommand cmd/go label Dec 30, 2020
@dmitshur
Copy link
Contributor

I see you mentioned #32724, but how is this issue different from that one? I see the title is different, but the steps in "What did you do?" seem to be the same.

Also, what does which go print?

@dmitshur
Copy link
Contributor

Could it be that you're running into #42563 and /Users/furkan/go/src/goroot/bin isn't in your $PATH?

@jayconrod jayconrod added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 5, 2021
@Dentrax
Copy link
Author

Dentrax commented Jan 7, 2021

which go prints /usr/local/bin/go, in go env i see: GOROOT="/usr/local/Cellar/go/1.15.5/libexec" and GOPATH="/Users/furkan/go"

PATH=:/Users/furkan/go/bin:/usr/local/go/bin:

I tried with /Users/furkan/go/src/goroot/bin/go generate and nothing changed. I do not know exactly what part I missed. @dmitshur

@jayconrod
Copy link
Contributor

If go env GOROOT is showing a different directory than the development GOROOT directory you're running in, then this is a duplicate of #32724. I'll close this issue.

Some things that might be going wrong:

  • Your PATH shouldn't start or end with :.
  • Your PATH should include $GOROOT/bin. In this case, that sounds like /Users/furkan/go/src/goroot/bin.
  • Don't put GOROOT inside GOPATH. Put it somewhere else like /Users/furkan/goroot.

@golang golang locked and limited conversation to collaborators Jan 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants