-
Notifications
You must be signed in to change notification settings - Fork 17.3k
/
build_buildvcs_auto.txt
87 lines (61 loc) · 2.32 KB
/
build_buildvcs_auto.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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() {}