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: go list all breaks in //go:build-only repos #49198

Closed
rsc opened this issue Oct 28, 2021 · 5 comments
Closed

cmd/go: go list all breaks in //go:build-only repos #49198

rsc opened this issue Oct 28, 2021 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Oct 28, 2021

cmd/go has its own //go:build evaluator, which is needed for
patterns like 'all'. The code is a modified copy of some unexported
routines from the go/build package. It doesn't know about //go:build.

This means that //go:build-only repos will not work with 'go list all'
under certain conditions.

Specifically:

% cat testdata/script/list_all_gobuild.txt
# go list all should work with //go:build-only modules
env GOOS=darwin
go list all
env GOOS=linux
go list all

-- go.mod --
module m

-- p/p.go --
package p

-- p/p_test.go --
//go:build linux

package p

import "m/q"

-- q/q_linux.go --
package q

-- r/r.go --
package r

-- r/r_test.go --
// +build linux

package r

import "m/s"

-- s/s_linux.go --
package s

% go test -run=Script/list_all_gobuild
go test proxy running at GOPROXY=http://127.0.0.1:55164/mod
--- FAIL: TestScript (0.01s)
    --- FAIL: TestScript/list_all_gobuild (0.04s)
        script_test.go:257: 
            # go list all should work with //go:build-only modules (0.016s)
            > env GOOS=darwin
            > go list all
            [stderr]
            package m/q: build constraints exclude all Go files in $WORK/gopath/src/q
            [exit status 1]
            FAIL: testdata/script/list_all_gobuild.txt:3: unexpected command failure
            
FAIL
exit status 1
FAIL	cmd/go	1.562s
% 

Note that r and s are fine, just not p and q.

This will need to be backported to Go 1.17.
Go 1.16 did not support //go:build lines, so it doesn't need the backport.

@rsc rsc added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Oct 28, 2021
@rsc rsc added this to the Go1.18 milestone Oct 28, 2021
@rsc rsc self-assigned this Oct 28, 2021
@rsc
Copy link
Contributor Author

rsc commented Oct 28, 2021

@gopherbot please backport 1.17

@gopherbot
Copy link

Change https://golang.org/cl/359355 mentions this issue: cmd/go: update for //go:build lines

@gopherbot
Copy link

Backport issue(s) opened: #49199 (for 1.17).

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

@gopherbot
Copy link

Change https://golang.org/cl/359404 mentions this issue: cmd/go: update for //go:build lines

@gopherbot
Copy link

Change https://golang.org/cl/359404 mentions this issue: [release-branch.go1.17] cmd/go: update for //go:build lines

gopherbot pushed a commit that referenced this issue Oct 28, 2021
cmd/go has its own //go:build evaluator, which is needed for
patterns like 'all'. The code is a modified copy of some unexported
routines from the go/build package. Update it by copying those
again and re-modifying them. The modifications are primarily the new
func eval and also ignoring errors.

This CL will need to be backported to Go 1.17, or else Go 1.17
will break when faced with certain //go:build-only repos during
'go list all' or 'go mod tidy'.

For #41184.
Fixes #49198.

Change-Id: Ie0fe3caa8d49004935ecd76d7977f767fe50e317
Reviewed-on: https://go-review.googlesource.com/c/go/+/359355
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/359404
@rsc rsc removed their assignment Jun 23, 2022
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

2 participants