Skip to content

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

Closed
@rsc

Description

@rsc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions