你正在使用的Go版本是什么( go version
)?
$ go version
go version go1.16.5 darwin/amd64
这个问题在最新版本中是否重现?
是的
你正在使用什么操作系统和处理器架构( go env
)?
go env
输出
$ 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"
你做了什么?
- 在测试文件顶部添加了一个
//+build ignore
构建标志 - 运行
go test -v --tags=ignore ../.
你期望看到什么?
我的测试输出
你看到了什么?
go test -v --tags=ignore ../.
输出
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
5条答案
按热度按时间u0sqgete1#
ignore
是一个保留字,但在许多示例文件中用作“不要构建此项,结束”的标记。我不确定在这里应该怎么做,除了说“不要将ignore用作构建标签的名称”。vktxenjb2#
忽略是一个保留字,但它在许多示例文件中作为“不要构建这个,结束”的标记。我不确定在这里该怎么办,除了说“不要将ignore用作构建标签的名称”。
也许go命令应该明确地在传递
-tags=ignore
时出错?这当然要少一些困惑。w51jfk4q3#
值得注意的是,
ignore
构建标签已经被Go工具以特殊方式处理,例如go mod tidy
忽略它。对我来说,让-tags=ignore
出错并附带有用的信息是合理的;我见过的所有// +build ignore
的使用案例都涉及到直接运行文件来忽略构建约束,例如go run ignored.go
。而且,无论如何,标准库都会因为这个构建标签而中断。cc @bcmills@matloob@jayconrod
voj3qocg4#
我喜欢@mvdan提出的错误信息想法。另外,@tmthrgd,你有没有参考过任何提到这个的文档?我在找,但是找不到这方面的信息。
hlswsv355#
@mvdan,我认为我们应该继续允许
go list -tags=ignored
列出这些文件,因为在今天的很多情况下都能正常工作(尤其是在使用-e
标志的情况下)。不过我同意,我们可以改进那些实际构建依赖关系的命令的错误信息。