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: TestScript/gotoolchain_issue66175 fails on tip locally #67277

Closed
cherrymui opened this issue May 9, 2024 · 8 comments
Closed

cmd/go: TestScript/gotoolchain_issue66175 fails on tip locally #67277

cherrymui opened this issue May 9, 2024 · 8 comments
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done. Testing An issue that has been verified to require only test changes, not just a test failure.
Milestone

Comments

@cherrymui
Copy link
Member

cherrymui commented May 9, 2024

Go version

tip. go version devel go1.23-9eebdca8a9 Thu May 9 20:33:37 2024 +0000 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/cherryyz/Library/Caches/go-build'
GOENV='/Users/cherryyz/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/cherryyz/gopkg/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/cherryyz/gopkg'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/cherryyz/src/go-tmp'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/cherryyz/src/go-tmp/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='devel go1.23-9eebdca8a9 Thu May 9 20:33:37 2024 +0000'
GODEBUG=''
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/cherryyz/src/go-tmp/src/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/hn/13ch8f612p7_6sr0h3wzf_9r00bkwx/T/go-build3419327835=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Run cmd/go TestScript/gotoolchain_issue66175 locally on my macOS machine.

What did you see happen?

$ go test cmd/go -v -run=TestScript/gotoolchain_issue66175 -count=1
=== RUN   TestScript
vcs-test.golang.org rerouted to http://127.0.0.1:63388
https://vcs-test.golang.org rerouted to https://127.0.0.1:63389
go test proxy running at GOPROXY=http://127.0.0.1:63390/mod
=== RUN   TestScript/gotoolchain_issue66175
=== PAUSE TestScript/gotoolchain_issue66175
=== CONT  TestScript/gotoolchain_issue66175
    script_test.go:135: 2024-05-09T21:31:49Z
    script_test.go:137: $WORK=/var/folders/hn/13ch8f612p7_6sr0h3wzf_9r00bkwx/T/cmd-go-test-595709031/tmpdir3920472925/gotoolchain_issue66175105850138
    script_test.go:159: 
        PATH=/var/folders/hn/13ch8f612p7_6sr0h3wzf_9r00bkwx/T/cmd-go-test-595709031/tmpdir3920472925/testbin:/Users/cherryyz/src/go-tmp/bin:/Users/cherryyz/bin:/usr/local/git/git-google/bin:/usr/local/git/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/cherryyz/gopkg/bin:/Users/cherryyz/src/plan9port/bin:/Users/cherryyz/src/luci/depot_tools
        HOME=/no-home
        CCACHE_DISABLE=1
        GOARCH=amd64
        TESTGO_GOHOSTARCH=amd64
        GOCACHE=/Users/cherryyz/Library/Caches/go-build
        GOCOVERDIR=
        GODEBUG=
        GOEXE=
        GOEXPERIMENT=
        GOOS=darwin
        TESTGO_GOHOSTOS=darwin
        GOPROXY=http://127.0.0.1:63390/mod
        GOPRIVATE=
        GOROOT=/Users/cherryyz/src/go-tmp
        GOTRACEBACK=system
        TESTGO_GOROOT=/Users/cherryyz/src/go-tmp
        TESTGO_EXE=/var/folders/hn/13ch8f612p7_6sr0h3wzf_9r00bkwx/T/cmd-go-test-595709031/tmpdir3920472925/testbin/go
        TESTGO_VCSTEST_HOST=127.0.0.1:63388
        TESTGO_VCSTEST_TLS_HOST=127.0.0.1:63389
        TESTGO_VCSTEST_CERT=/var/folders/hn/13ch8f612p7_6sr0h3wzf_9r00bkwx/T/cmd-go-test-595709031/vcstest1885017284/cert.pem
        TESTGONETWORK=panic
        GOSUMDB=localhost.localdev/sumdb+00000c67+AcTrnkbUA+TU4heY3hkjiSES/DSQniBqIeQ/YppAUtK6
        GONOPROXY=
        GONOSUMDB=
        GOVCS=*:all
        devnull=/dev/null
        goversion=1.23
        CMDGO_TEST_RUN_MAIN=true
        HGRCPATH=
        GOTOOLCHAIN=auto
        newline=
        
        WORK=/var/folders/hn/13ch8f612p7_6sr0h3wzf_9r00bkwx/T/cmd-go-test-595709031/tmpdir3920472925/gotoolchain_issue66175105850138
        TEST_TELEMETRY_DIR=/var/folders/hn/13ch8f612p7_6sr0h3wzf_9r00bkwx/T/cmd-go-test-595709031/tmpdir3920472925/gotoolchain_issue66175105850138/telemetry
        TMPDIR=/var/folders/hn/13ch8f612p7_6sr0h3wzf_9r00bkwx/T/cmd-go-test-595709031/tmpdir3920472925/gotoolchain_issue66175105850138/tmp
        GOPATH=/var/folders/hn/13ch8f612p7_6sr0h3wzf_9r00bkwx/T/cmd-go-test-595709031/tmpdir3920472925/gotoolchain_issue66175105850138/gopath
        PWD=/var/folders/hn/13ch8f612p7_6sr0h3wzf_9r00bkwx/T/cmd-go-test-595709031/tmpdir3920472925/gotoolchain_issue66175105850138/gopath/src
        
        > env TESTGO_VERSION=go1.14
        # check for invalid toolchain in go.mod (0.074s)
        > go mod init m
        [stderr]
        go: creating new go.mod: module m
        > go mod edit -go=1.14 -toolchain=go1.22
        > ! go version
        [stderr]
        go: toolchain go1.22.3 invoked to provide go1.22
        [exit status 1]
        > stderr 'go: invalid toolchain: go1.22 is a language version but not a toolchain version \(go1.22.x\)'
    script_test.go:159: FAIL: testdata/script/gotoolchain_issue66175.txt:7: stderr 'go: invalid toolchain: go1.22 is a language version but not a toolchain version \(go1.22.x\)': no match for `(?m)go: invalid toolchain: go1.22 is a language version but not a toolchain version \(go1.22.x\)` in stderr
--- FAIL: TestScript (0.05s)
    --- FAIL: TestScript/gotoolchain_issue66175 (0.08s)
FAIL
FAIL	cmd/go	0.587s
FAIL

What did you expect to see?

Test passes.

It doesn't seem to fail on the build dashboard. I don't think my machine has weird setup, but that is certainly possible. Let me know if there is anything I can find to help.
Thanks.

cc @matloob @samthanawalla

@cherrymui cherrymui changed the title cmd/go: TestScript/gotoolchain_issue66175 fails cmd/go: TestScript/gotoolchain_issue66175 fails on tip locally May 9, 2024
@cherrymui cherrymui added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 9, 2024
@cherrymui cherrymui added this to the Go1.23 milestone May 9, 2024
@cherrymui
Copy link
Member Author

cherrymui commented May 10, 2024

Oh, it seems that this is because I have a go1.22 binary in my PATH that is actually Go 1.22.3. In my machine I have go1.x binary at a checkout of the 1.x release branch for working on the release branch.

I guess this is not a bug in the go command or the test, but my environment. Is it possible to make the go command not look at my PATH? Or make this test resilient for that? Thanks.

@cherrymui cherrymui closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2024
@cherrymui
Copy link
Member Author

Reopen. It would be good to make the test not depend on things in my PATH. Thanks.

@cherrymui cherrymui reopened this May 10, 2024
@dmitshur
Copy link
Contributor

https://go.dev/doc/toolchain#select includes:

To run a toolchain other than the bundled Go toolchain, the go command searches the process’s executable path ($PATH on Unix and Plan 9, %PATH% on Windows) for a program with the given name (for example, go1.21.3) and runs that program. […]

Trying it with a local go1.22.3 toolchain, that behavior is working as expected:

$ GOTOOLCHAIN=local go version
go version go1.22.3 darwin/arm64
$ which go1.22 go1.22.0
go1.22 not found
go1.22.0 not found

# Check if it would be willing to use a binary that isn't named "go1.22.0"
# when a go1.22.0 toolchain is requested.
$ printf "#\!/bin/sh\necho 'a script named go1.22, notably without .0'" > ~/bin/go1.22 && chmod u+x ~/bin/go1.22
$ GOTOOLCHAIN=go1.22.0+path go version
go: cannot find "go1.22.0" in PATH

$ printf "#\!/bin/sh\necho 'a script named go1.22.0, notably with .0'" > ~/bin/go1.22.0 && chmod u+x ~/bin/go1.22.0
$ GOTOOLCHAIN=go1.22.0+path go version
a script named go1.22.0, notably with .0

The same at tip:

$ GOTOOLCHAIN=local go version
go version devel go1.23-df4f40b9e0 Fri May 10 16:04:54 2024 +0000 darwin/arm64
$ which go1.22 go1.22.0
go1.22 not found
go1.22.0 not found

# Check if it would be willing to use a binary that isn't named "go1.22.0"
# when a go1.22.0 toolchain is requested.
$ printf "#\!/bin/sh\necho 'a script named go1.22, notably without .0'" > ~/bin/go1.22 && chmod u+x ~/bin/go1.22
$ GOTOOLCHAIN=go1.22.0+path go version
go: cannot find "go1.22.0" in PATH

So it seems having a binary named go1.22 (without a trailing .0) in PATH doesn't cause a problem in general, just for this test.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/584258 mentions this issue: cmd/go/testdata/script: clear path in gotoolchain_issue66175

@matloob
Copy link
Contributor

matloob commented May 10, 2024

@gopherbot Please backport to Go 1.21 and Go 1.22.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #67310 (for 1.21), #67311 (for 1.22).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/584935 mentions this issue: [release-branch.go1.21] cmd/go/testdata/script: clear path in gotoolchain_issue66175

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/584955 mentions this issue: [release-branch.go1.22] cmd/go/testdata/script: clear path in gotoolchain_issue66175

@dmitshur dmitshur added Testing An issue that has been verified to require only test changes, not just a test failure. NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 10, 2024
gopherbot pushed a commit that referenced this issue May 13, 2024
…hain_issue66175

The gotoolchain_issue66175 script test would fail if a binary named
go1.21 or go1.22 was present in the system PATH. Clear the path at the
beginning of the test to make it independent of the system path.

For #67277
Fixes #67311

Change-Id: I6d9133aee5b20ab116e07b659e8ecf3eb8add4ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/584258
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
(cherry picked from commit a0a6026)
Reviewed-on: https://go-review.googlesource.com/c/go/+/584955
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
gopherbot pushed a commit that referenced this issue May 13, 2024
…hain_issue66175

The gotoolchain_issue66175 script test would fail if a binary named
go1.21 or go1.22 was present in the system PATH. Clear the path at the
beginning of the test to make it independent of the system path.

For #67277
Fixes #67310

Change-Id: I6d9133aee5b20ab116e07b659e8ecf3eb8add4ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/584258
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
(cherry picked from commit a0a6026)
Reviewed-on: https://go-review.googlesource.com/c/go/+/584935
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done. Testing An issue that has been verified to require only test changes, not just a test failure.
Projects
None yet
Development

No branches or pull requests

4 participants