-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: allow '-buildvcs=auto' and treat it as the default
When we added VCS stamping in the Go 1.18 release, we defaulted to -buildvcs=true, on the theory that most folks will actually want VCS information stamped. We also made -buildvcs=true error out if a VCS directory is found and no VCS tool is available, on the theory that a user who builds with '-buildvcs=true' will be very surprised if the VCS metadata is silently missing. However, that causes a problem for CI environments that don't have the appropriate VCS tool installed. (And we know that's a common situation because we're in that situation ourselves — see #46693!) The new '-buildvcs=auto' setting provides a middle ground: it stamps VCS information by default when the tool is present (and reports explicit errors if the tool errors out), but omits the metadata when the tool isn't present at all. Fixes #51748. Updates #51999. Change-Id: Iebc955c2af0abca9b7517f62ca48b1d944eb2df4 Reviewed-on: https://go-review.googlesource.com/c/go/+/398855 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
- Loading branch information
Showing
8 changed files
with
159 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Regression test for https://go.dev/issue/51748: by default, 'go build' should | ||
# not attempt to stamp VCS information when the VCS tool is not present. | ||
|
||
[short] skip | ||
[!exec:git] skip | ||
|
||
cd sub | ||
exec git init . | ||
exec git add sub.go | ||
exec git commit -m 'initial state' | ||
cd .. | ||
|
||
exec git init | ||
exec git submodule add ./sub | ||
exec git add go.mod example.go | ||
exec git commit -m 'initial state' | ||
|
||
|
||
# Control case: with a git binary in $PATH, | ||
# 'go build' on a package in the same git repo | ||
# succeeds and stamps VCS metadata by default. | ||
|
||
go build -o example.exe . | ||
go version -m example.exe | ||
stdout '^\tbuild\tvcs=git$' | ||
stdout '^\tbuild\tvcs.modified=false$' | ||
|
||
|
||
# Building a binary from a different (nested) VCS repo should not stamp VCS | ||
# info. It should be an error if VCS stamps are requested explicitly with | ||
# '-buildvcs' (since we know the VCS metadata exists), but not an error | ||
# with '-buildvcs=auto'. | ||
|
||
go build -o sub.exe ./sub | ||
go version -m sub.exe | ||
! stdout '^\tbuild\tvcs' | ||
|
||
! go build -buildvcs -o sub.exe ./sub | ||
stderr '\Aerror obtaining VCS status: main package is in repository ".*" but current directory is in repository ".*"\n\tUse -buildvcs=false to disable VCS stamping.\n\z' | ||
|
||
cd ./sub | ||
go build -o sub.exe . | ||
go version -m sub.exe | ||
! stdout '^\tbuild\tvcs' | ||
|
||
! go build -buildvcs -o sub.exe . | ||
stderr '\Aerror obtaining VCS status: main module is in repository ".*" but current directory is in repository ".*"\n\tUse -buildvcs=false to disable VCS stamping.\n\z' | ||
cd .. | ||
|
||
|
||
# After removing 'git' from $PATH, 'go build -buildvcs' should fail... | ||
|
||
env PATH= | ||
env path= | ||
! go build -buildvcs -o example.exe . | ||
stderr 'go: missing Git command\. See https://golang\.org/s/gogetcmd$' | ||
|
||
# ...but by default we should omit VCS metadata when the tool is missing. | ||
|
||
go build -o example.exe . | ||
go version -m example.exe | ||
! stdout '^\tbuild\tvcs' | ||
|
||
# The default behavior can be explicitly set with '-buildvcs=auto'. | ||
|
||
go build -buildvcs=auto -o example.exe . | ||
go version -m example.exe | ||
! stdout '^\tbuild\tvcs' | ||
|
||
# Other flag values should be rejected with a useful error message. | ||
|
||
! go build -buildvcs=hg -o example.exe . | ||
stderr '\Ainvalid boolean value "hg" for -buildvcs: value is neither ''auto'' nor a valid bool\nusage: go build .*\nRun ''go help build'' for details.\n\z' | ||
|
||
|
||
-- go.mod -- | ||
module example | ||
|
||
go 1.18 | ||
-- example.go -- | ||
package main | ||
|
||
func main() {} | ||
-- sub/sub.go -- | ||
package main | ||
|
||
func main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters