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/fmt: tries to download dependencies #31976

Closed
jsha opened this issue May 10, 2019 · 2 comments
Closed

cmd/fmt: tries to download dependencies #31976

jsha opened this issue May 10, 2019 · 2 comments

Comments

@jsha
Copy link

jsha commented May 10, 2019

go version go1.12 linux/amd64

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jsha/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jsha/gopkg"
GOPROXY=""
GORACE=""
GOROOT="/home/jsha/go1.12"
GOTMPDIR=""
GOTOOLDIR="/home/jsha/go1.12/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build307902328=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Create a tiny package using modules:

foo.go

package main

import _ "golang.org/x/crypto/sha3"

func main() {
}

go.mod

module foo

go 1.12

require golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529 // indirect

Clear the module cache:

$ sudo rm -r $GOPATH/pkg/mod/

# Alternately, a less invasive option:
$ sudo rm -r $GOPATH/pkg/mod/cache/download/golang.org/x/crypto/ $GOPATH/pkg/mod/golang.org/x/crypto@v0.0.0-20190510104115-cbcb75029529/

Disconnect from the Internet.

Run go fmt:

$ go fmt foo.go
go: golang.org/x/crypto@v0.0.0-20190510104115-cbcb75029529: unrecognized import path "golang.org/x/crypto" (https fetch: Get https://golang.org/x/crypto?go-get=1: dial tcp: lookup golang.org on [::1]:53: read udp [::1]:46842->[::1]:53: read: connection refused)
go: error loading module requirements

What did you expect to see?

A successful run of go fmt.

What did you see instead?

An error message.

It appears that go fmt attempts to download all module dependencies if they aren't present. However, as far as I can tell, there is no reason for go fmt to do this, since it doesn't process dependencies at all; it just changes the formatting of a single file (or a group of files).

At a minimum, go fmt should obey GOFLAGS=-mod=readonly, but I think even when that's not present, it shouldn't attempt to download dependencies.

This came up in practice on the Boulder project, where we vendor our dependencies and run tests inside a container that does not have Internet access. One of those tests is a check for correct formatting with go fmt.

@mvdan
Copy link
Member

mvdan commented May 11, 2019

Duplicate of #30577?

@andybons
Copy link
Member

Duplicate of #27841

@andybons andybons marked this as a duplicate of #27841 May 13, 2019
@golang golang locked and limited conversation to collaborators May 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants