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: fmt suggests -buildvcs when it doesn't take build flags #52333

Closed
ocket8888 opened this issue Apr 13, 2022 · 9 comments
Closed

cmd/go: fmt suggests -buildvcs when it doesn't take build flags #52333

ocket8888 opened this issue Apr 13, 2022 · 9 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@ocket8888
Copy link

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

$ go version
go version 1.18 linux/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="/home/ocket8888/.cache/go-build"
GOENV="/home/ocket8888/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ocket8888/pkg/mod"
GONONPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ocket8888"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="REDACTED"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="REDACTED"
GOVCS="*:off"
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
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-build1502895740=/tmp/go-build -gno-record-gcc-switches"

What did you do?

mkdir -p "$GOPATH/src/example.com/m"
cd "$GOPATH/src/example.com/m"
go mod init
cat > main.go <<-EOF
package main
import "fmt"

func main(){
fmt.Println("Hello World!");
}
EOF
mkdir .git
go fmt ./...

What did you expect to see?

package main

import "fmt"

func main() {
    fmt.Println("Hello World!")
}

What did you see instead?

go: missing Git command. See https://golang.org/s/gogetcmd
error obtaining VCS status: exec: "git": executable file not found in $PATH
        Use -buildvcs=false to disable VCS stamping.

Note that this error message is incorrect as neither go nor go fmt accept the -buildvcs flag. Also note that GOVCS is set to *:off.

@mvdan
Copy link
Member

mvdan commented Apr 13, 2022

This will be solved by #51748 in Go 1.18.2, but I agree that it's unexpected that go fmt would do any VCS build stamping at all. It shouldn't be doing any building.

@mvdan mvdan changed the title cmd/gofmt: Requires git to format when .git directory present, cannot be bypassed cmd/go: fmt suggests -buildvcs when it doesn't take build flags Apr 13, 2022
@ocket8888
Copy link
Author

Will the fix be backported? Ultimately that doesn't actually matter to me unless backporting would happen sooner than the 18.2 release. Otherwise I'd just upgrade. But still curious.

@seankhliao
Copy link
Member

Given that 1.18.1 is out, 1.18.2 is the soonest release it can be in. Backport issue is #51798

@ocket8888
Copy link
Author

ocket8888 commented Apr 13, 2022

Well that's about changing build behavior, right? With go fmt I can't explicitly enable or disable vcs stamping - because it shouldn't need to do that at all, no? gofmt itself doesn't do anything like that, just seems like a true bug in the invocation. Because if it does find git then according to the proposal for --buildvcs=auto in #51798, the go fmt run will fail if invocation of git fails for some reason. But go fmt shouldn't depend on git at all, because gofmt doesn't.

@mvdan
Copy link
Member

mvdan commented Apr 13, 2022

Right, this seems like a regression bug. I imagine 1.18.2 will be out sometime over the next week; it's already been four weeks since 1.18 and usually there would have been a bugfix release two weeks ago.

I think keeping this issue open is worthwhile because it's not a dupliate; as already stated, there's presumably no reason for go fmt to stamp VCS information.

@seankhliao
Copy link
Member

I believe it may have been unintentionally fixed in 1.18.1 already by #51723, which restricts when buildvcs is included (eg go run doesn't have it now, #52338).
strace -f go fmt 2>&1 | grep execve doesn't show git being called for 1.18.1, but it does for 1.18

@mvdan
Copy link
Member

mvdan commented Apr 13, 2022

Ah, you're right. 1.18.1 was announced as a security release, so I assumed it only contained security fixes, but it doesn't.

@ocket8888
Copy link
Author

I didn't check 1.18.1 - didn't realize that existed when I wrote the example. I'll check that out and close the issue if it's resolved in the newest release. (or should I leave it open for tracking backport?)

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 14, 2022
@ocket8888
Copy link
Author

1.18.1 doesn't have this problem

@golang golang locked and limited conversation to collaborators Apr 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants