You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
# Regression test for https://go.dev/issue/51748: by default, 'go build' should
2
+
# not attempt to stamp VCS information when the VCS tool is not present.
3
+
4
+
[short] skip
5
+
[!exec:git] skip
6
+
7
+
cd sub
8
+
exec git init .
9
+
exec git add sub.go
10
+
exec git commit -m 'initial state'
11
+
cd ..
12
+
13
+
exec git init
14
+
exec git submodule add ./sub
15
+
exec git add go.mod example.go
16
+
exec git commit -m 'initial state'
17
+
18
+
19
+
# Control case: with a git binary in $PATH,
20
+
# 'go build' on a package in the same git repo
21
+
# succeeds and stamps VCS metadata by default.
22
+
23
+
go build -o example.exe .
24
+
go version -m example.exe
25
+
stdout '^\tbuild\tvcs=git$'
26
+
stdout '^\tbuild\tvcs.modified=false$'
27
+
28
+
29
+
# Building a binary from a different (nested) VCS repo should not stamp VCS
30
+
# info. It should be an error if VCS stamps are requested explicitly with
31
+
# '-buildvcs' (since we know the VCS metadata exists), but not an error
32
+
# with '-buildvcs=auto'.
33
+
34
+
go build -o sub.exe ./sub
35
+
go version -m sub.exe
36
+
! stdout '^\tbuild\tvcs'
37
+
38
+
! go build -buildvcs -o sub.exe ./sub
39
+
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'
40
+
41
+
cd ./sub
42
+
go build -o sub.exe .
43
+
go version -m sub.exe
44
+
! stdout '^\tbuild\tvcs'
45
+
46
+
! go build -buildvcs -o sub.exe .
47
+
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'
48
+
cd ..
49
+
50
+
51
+
# After removing 'git' from $PATH, 'go build -buildvcs' should fail...
52
+
53
+
env PATH=
54
+
env path=
55
+
! go build -buildvcs -o example.exe .
56
+
stderr 'go: missing Git command\. See https://golang\.org/s/gogetcmd$'
57
+
58
+
# ...but by default we should omit VCS metadata when the tool is missing.
59
+
60
+
go build -o example.exe .
61
+
go version -m example.exe
62
+
! stdout '^\tbuild\tvcs'
63
+
64
+
# The default behavior can be explicitly set with '-buildvcs=auto'.
65
+
66
+
go build -buildvcs=auto -o example.exe .
67
+
go version -m example.exe
68
+
! stdout '^\tbuild\tvcs'
69
+
70
+
# Other flag values should be rejected with a useful error message.
71
+
72
+
! go build -buildvcs=hg -o example.exe .
73
+
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'
0 commit comments