Skip to content

cmd/go: errors from tool invocations shouldn't suggest unavailable build flags #75507

@tjgurwara99

Description

@tjgurwara99

Go version

go version go1.25.1 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/<username>/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/<username>/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/0b/1jh1hs217r3fg9vmm2v13z8w0000gn/T/go-build1418714177=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/<username>/<owner>/<repo>/tools/go.mod'
GOMODCACHE='/Users/<username>/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/<username>/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/<username>/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.1.darwin-arm64'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/<username>/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/<username>/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.1.darwin-arm64/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.25.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

With any vendored project (with the vendor directory inside the repo), create a new submodule, say tools in a subdirectory ./tools.

Initialise the mod to not pollute the dependencies on the main project like so:

go mod init github.com/<owner>/<repo>/tools

add some tools. In this case I used golangci-lint

go mod edit -tool github.com/golangci/golangci-lint/cmd/golangci-lint

given this, I run the following:

go tool -modfile ./tools/go.mod golangci-lint run ./...

What did you see happen?

It returns an error:

go: inconsistent vendoring in <dir>:
  ... // all the dependencies

        To ignore the vendor directory, use -mod=readonly or -mod=mod.
        To sync the vendor directory, run:
                go mod vendor

Given this error message, it may seem like the -mod=readonly should work but we get the following when using both -mod=readonly or -mod=mod.

flag provided but not defined: -mod
usage: go tool [-n] command [args...]
Run 'go help tool' for details.

which is misleading. Looking at the

What did you expect to see?

It should either not have the error message indicating -mod=readonly -mod=mod could solve the issue or we should be allowed to use all the build flags that we do with go build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions