Skip to content

Commit

Permalink
cmd/go: add bzr based version stamping for binaries
Browse files Browse the repository at this point in the history
This CL adds support for tagging binaries in a bzr vcs environment.

For: #50603
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Change-Id: I81eb72d9e0e15dbec8778dd06613ca212820a726
Reviewed-on: https://go-review.googlesource.com/c/go/+/627295
Auto-Submit: Sam Thanawalla <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
samthanawalla authored and gopherbot committed Nov 15, 2024
1 parent 400433a commit 5030146
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cmd/go/internal/modfetch/codehost/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ func hgParseStat(rev, out string) (*RevInfo, error) {
func bzrParseStat(rev, out string) (*RevInfo, error) {
var revno int64
var tm time.Time
var tags []string
for _, line := range strings.Split(out, "\n") {
if line == "" || line[0] == ' ' || line[0] == '\t' {
// End of header, start of commit message.
Expand Down Expand Up @@ -594,6 +595,8 @@ func bzrParseStat(rev, out string) (*RevInfo, error) {
return nil, vcsErrorf("unexpected timestamp from bzr log: %q", line)
}
tm = t.UTC()
case "tags":
tags = strings.Split(val, ", ")
}
}
if revno == 0 || tm.IsZero() {
Expand All @@ -605,6 +608,7 @@ func bzrParseStat(rev, out string) (*RevInfo, error) {
Short: fmt.Sprintf("%012d", revno),
Time: tm,
Version: rev,
Tags: tags,
}
return info, nil
}
Expand Down
18 changes: 18 additions & 0 deletions src/cmd/go/testdata/script/version_buildvcs_bzr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exec bzr whoami 'J.R. Gopher <[email protected]>'
go install
go version -m $GOBIN/a$GOEXE
! stdout bzrrevision
stdout '^\tmod\texample.com/a\t\(devel\)'
rm $GOBIN/a$GOEXE

# If there is a repository, but it can't be used for some reason,
Expand Down Expand Up @@ -52,6 +53,23 @@ stdout '^\tbuild\tvcs=bzr$'
stdout '^\tbuild\tvcs.revision='
stdout '^\tbuild\tvcs.time='
stdout '^\tbuild\tvcs.modified=false$'
stdout '^\tmod\texample.com/a\tv0.0.0-\d+-\d+\t+'
rm $GOBIN/a$GOEXE

# Tag is reflected in the version.
cd ..
cp README README2
exec bzr add a README2
exec bzr commit -m 'second commit'
exec bzr tag v1.2.3
cd a
go install
go version -m $GOBIN/a$GOEXE
stdout '^\tbuild\tvcs=bzr$'
stdout '^\tbuild\tvcs.revision='
stdout '^\tbuild\tvcs.time='
stdout '^\tbuild\tvcs.modified=false$'
stdout '^\tmod\texample.com/a\tv1.2.3\t+'
rm $GOBIN/a$GOEXE

# Building an earlier commit should still build clean.
Expand Down

0 comments on commit 5030146

Please sign in to comment.