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: emit a clearer error message when building with -tags=ignore #46751

Open
marksalpeter opened this issue Jun 15, 2021 · 5 comments
Open

cmd/go: emit a clearer error message when building with -tags=ignore #46751

marksalpeter opened this issue Jun 15, 2021 · 5 comments

Comments

@marksalpeter
Copy link

@marksalpeter marksalpeter commented Jun 15, 2021

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

$ go version 
go version go1.16.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/temporaryadmin/Library/Caches/go-build"
GOENV="/Users/temporaryadmin/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/temporaryadmin/go/pkg/mod"
GONOPROXY="github.com/deliveryhero/pipeline"
GONOSUMDB="github.com/deliveryhero/pipeline"
GOOS="darwin"
GOPATH="/Users/temporaryadmin/go"
GOPRIVATE="github.com/deliveryhero/pipeline"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/temporaryadmin/go/src/github.com/deliveryhero/dh-vt-ncr-click-service/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wj/mzsjw5sj3r9f9y3dwph2bwz00000gp/T/go-build3374550061=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Add a //+build ignore build flag to the top of a test file
  2. Run go test -v --tags=ignore ../.

What did you expect to see?

My test output

What did you see instead?

go test -v --tags=ignore ../. Output
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/parser
	imports io/fs
	imports time
	imports net/http
	imports context: import cycle not allowed
/usr/local/go/src/crypto/tls/key_agreement.go:9:2: found packages md5 (example_test.go) and main (gen.go) in /usr/local/go/src/crypto/md5
/usr/local/go/src/net/http/client.go:14:2: found packages tls (alert.go) and main (generate_cert.go) in /usr/local/go/src/crypto/tls
/usr/local/go/src/crypto/tls/cipher_suites.go:16:2: found packages x509 (cert_pool.go) and main (root_ios_gen.go) in /usr/local/go/src/crypto/x509
../../../../pkg/mod/golang.org/x/text@v0.3.6/internal/gen/code.go:9:2: found packages gob (codec_test.go) and main (decgen.go) in /usr/local/go/src/encoding/gob
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports bytes
	imports errors: import cycle not allowed
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/parser
	imports io/fs
	imports time
	imports encoding/xml
	imports strconv
	imports flag: import cycle not allowed
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports fmt: import cycle not allowed
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/ast: import cycle not allowed
/usr/local/go/src/go/build/build.go:12:2: found packages doc (comment.go) and main (headscan.go) in /usr/local/go/src/go/doc
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/format: import cycle not allowed
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/parser
	imports go/scanner: import cycle not allowed
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/parser
	imports go/token: import cycle not allowed
../../../../pkg/mod/golang.org/x/text@v0.3.6/secure/precis/options.go:8:2: found packages cases (cases.go) and main (gen.go) in /Users/temporaryadmin/go/pkg/mod/golang.org/x/text@v0.3.6/cases
../../../../pkg/mod/golang.org/x/text@v0.3.6/unicode/rangetable/gen.go:20:2: found packages collate (collate.go) and main (maketables.go) in /Users/temporaryadmin/go/pkg/mod/golang.org/x/text@v0.3.6/collate
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports github.com/googleapis/gax-go/v2
	imports google.golang.org/grpc
	imports google.golang.org/grpc/internal/transport
	imports golang.org/x/net/http2
	imports golang.org/x/net/http/httpguts
	imports golang.org/x/net/idna
	imports golang.org/x/text/secure/bidirule
	imports golang.org/x/text/unicode/bidi
	imports golang.org/x/text/internal/gen
	imports golang.org/x/text/unicode/cldr
	imports golang.org/x/text/internal/gen: import cycle not allowed
../../../../pkg/mod/golang.org/x/text@v0.3.6/language/coverage.go:11:2: found packages language (common.go) and main (gen.go) in /Users/temporaryadmin/go/pkg/mod/golang.org/x/text@v0.3.6/internal/language
../../../../pkg/mod/golang.org/x/text@v0.3.6/language/language.go:16:2: found packages compact (compact.go) and main (gen.go) in /Users/temporaryadmin/go/pkg/mod/golang.org/x/text@v0.3.6/internal/language/compact
../../../../pkg/mod/golang.org/x/text@v0.3.6/internal/colltab/colltab.go:12:2: found packages language (coverage.go) and main (gen.go) in /Users/temporaryadmin/go/pkg/mod/golang.org/x/text@v0.3.6/language
../../../../pkg/mod/github.com/jackc/pgconn@v1.8.0/auth_scram.go:26:2: found packages precis (benchmark_test.go) and main (gen.go) in /Users/temporaryadmin/go/pkg/mod/golang.org/x/text@v0.3.6/secure/precis
../../../../pkg/mod/golang.org/x/text@v0.3.6/secure/bidirule/bidirule.go:16:2: found packages bidi (bidi.go) and main (gen.go) in /Users/temporaryadmin/go/pkg/mod/golang.org/x/text@v0.3.6/unicode/bidi
../../../../pkg/mod/golang.org/x/text@v0.3.6/internal/gen/gen.go:39:2: found packages cldr (base.go) and main (makexml.go) in /Users/temporaryadmin/go/pkg/mod/golang.org/x/text@v0.3.6/unicode/cldr
../../../../pkg/mod/golang.org/x/text@v0.3.6/internal/colltab/table.go:10:2: found packages norm (composition.go) and main (maketables.go) in /Users/temporaryadmin/go/pkg/mod/golang.org/x/text@v0.3.6/unicode/norm
../../../../pkg/mod/golang.org/x/text@v0.3.6/secure/precis/gen.go:23:2: import "golang.org/x/text/unicode/rangetable" is a program, not an importable package
../../../../pkg/mod/golang.org/x/text@v0.3.6/secure/precis/profile.go:17:2: found packages width (common_test.go) and main (gen.go) in /Users/temporaryadmin/go/pkg/mod/golang.org/x/text@v0.3.6/width
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/parser
	imports io/fs
	imports time
	imports net/http
	imports crypto/tls
	imports crypto/md5
	imports text/template
	imports internal/fmtsort: import cycle not allowed
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports internal/reflectlite: import cycle not allowed
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/parser
	imports io/fs
	imports time
	imports encoding/xml
	imports strconv
	imports log
	imports os
	imports io/fs: import cycle not allowed
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/parser
	imports io/fs
	imports time
	imports encoding/xml
	imports strconv
	imports log
	imports os
	imports internal/poll
	imports syscall
	imports log: import cycle not allowed
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/parser
	imports io/fs
	imports time
	imports encoding/xml
	imports strconv
	imports math: import cycle not allowed
/usr/local/go/src/math/fma.go:7:8: found packages bits (bits.go) and main (make_examples.go) in /usr/local/go/src/math/bits
/usr/local/go/src/math/big/int.go:12:2: found packages rand (example_test.go) and main (gen_cooked.go) in /usr/local/go/src/math/rand
/usr/local/go/src/time/genzabbrs.go:22:2: found packages http (alpn_test.go) and main (triv.go) in /usr/local/go/src/net/http
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/parser
	imports io/fs
	imports time
	imports encoding/xml
	imports strconv
	imports log
	imports os
	imports internal/poll
	imports syscall
	imports os: import cycle not allowed
/usr/local/go/src/net/http/triv.go:18:2: found packages exec (bench_test.go) and main (read3.go) in /usr/local/go/src/os/exec
package github.com/deliveryhero/dh-vt-ncr-click-service/internal/click
	imports cloud.google.com/go/pubsub
	imports cloud.google.com/go/iam
	imports context
	imports errors
	imports internal/reflectlite
	imports runtime
	imports flag
	imports fmt
	imports internal/fmtsort
	imports reflect
	imports math
	imports math/bits
	imports go/format
	imports go/ast
	imports go/scanner
	imports go/token
	imports sort
	imports go/parser
	imports io/fs
	imports time
	imports encoding/xml
	imports reflect: import cycle not allowed
/usr/local/go/src/internal/reflectlite/value.go:9:2: found packages runtime (alg.go) and main (mkduff.go) in /usr/local/go/src/runtime
/usr/local/go/src/runtime/internal/math/math.go:7:8: found packages sys (arch.go) and main (gengoos.go) in /usr/local/go/src/runtime/internal/sys
/usr/local/go/src/go/token/position.go:9:2: found packages sort (example_interface_test.go) and main (genzfunc.go) in /usr/local/go/src/sort
/usr/local/go/src/encoding/xml/marshal.go:14:2: found packages strconv (atob.go) and main (makeisprint.go) in /usr/local/go/src/strconv
/usr/local/go/src/internal/poll/errno_unix.go:9:8: found packages syscall (bpf_darwin.go) and main (mkasm.go) in /usr/local/go/src/syscall
/usr/local/go/src/io/fs/fs.go:12:2: found packages time (example_test.go) and main (genzabbrs.go) in /usr/local/go/src/time
@davecheney
Copy link
Contributor

@davecheney davecheney commented Jun 15, 2021

ignore is t a reserved word, but it’s used in lots of example files as a “don’t build this, period” marker. I’m not sure what to do here other than saying “don’t use ignore as the name of a build tag”

@tmthrgd
Copy link
Contributor

@tmthrgd tmthrgd commented Jun 15, 2021

ignore is t a reserved word, but it’s used in lots of example files as a “don’t build this, period” marker. I’m not sure what to do here other than saying “don’t use ignore as the name of a build tag”

Perhaps the go command should explicitly error out if you pass -tags=ignore? That's certainly less confusing.

@mvdan
Copy link
Member

@mvdan mvdan commented Jun 15, 2021

Worth noting that the ignore build tag is already treated in a special way by Go tools, such as go mod tidy ignoring it.

It seems reasonable to me to have -tags=ignore error with a helpful message; all use cases of // +build ignore I've seen involve running the file directly to ignore build constraints, like go run ignored.go. And the standard library breaks with that build tag, anyway.

cc @bcmills @matloob @jayconrod

@mvdan mvdan changed the title Ignore build flag causes cyclical dependency errors in the standard library cmd/go: -tags=ignore makes the standard library fail to build Jun 15, 2021
@marksalpeter
Copy link
Author

@marksalpeter marksalpeter commented Jun 15, 2021

I like the error message idea @mvdan. Also, @tmthrgd do you have a reference to any docs that mention this? I was looking but I couldn't find this information.

@bcmills
Copy link
Member

@bcmills bcmills commented Jun 15, 2021

@mvdan, I think we should continue to allow go list -tags=ignored to list these files, since that works in a lot of cases today (especially with the -e flag). I agree that we could improve the error message from commands that actually build dependencies, though.

@bcmills bcmills changed the title cmd/go: -tags=ignore makes the standard library fail to build cmd/go: emit a clearer error message when building with -tags=ignore Jun 15, 2021
@bcmills bcmills added this to the Backlog milestone Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants