]> Cypherpunks repositories - gostls13.git/commit
cmd/go: stamp VCS revision and uncommitted status into binaries
authorJay Conrod <jayconrod@google.com>
Fri, 1 Oct 2021 18:21:49 +0000 (11:21 -0700)
committerJay Conrod <jayconrod@google.com>
Thu, 14 Oct 2021 18:44:37 +0000 (18:44 +0000)
commita37bebc042672d20837ea348d45e39740568cb77
tree7300330476aff1cac6a5f644116e080efde51639
parenta8c5a994d62cc920c134426f7eae892b013ee32d
cmd/go: stamp VCS revision and uncommitted status into binaries

When the go command builds a binary, it will now stamp the current
revision from the local Git or Mercurial repository, and it will also
stamp whether there are uncommitted edited or untracked files. Only
Git and Mercurial are supported for now.

If no repository is found containing the current working directory
(where the go command was started), or if either the main package
directory or the containing module's root directory is outside the
repository, no VCS information will be stamped. If the VCS tool is
missing or returns an error, that error is reported on the main
package (hinting that -buildvcs may be disabled).

This change introduces the -buildvcs flag, which is enabled by
default. When disabled, VCS information won't be stamped when it would
be otherwise.

Stamped information may be read using 'go version -m file' or
debug.ReadBuildInfo.

For #37475

Change-Id: I4e7d3159e1c270d85869ad99f10502e546e7582d
Reviewed-on: https://go-review.googlesource.com/c/go/+/353930
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
14 files changed:
api/next.txt
src/cmd/go/alldocs.go
src/cmd/go/internal/cfg/cfg.go
src/cmd/go/internal/get/get.go
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/vcs/vcs.go
src/cmd/go/internal/vcs/vcs_test.go
src/cmd/go/internal/work/build.go
src/cmd/go/script_test.go
src/cmd/go/testdata/script/version_buildvcs_git.txt [new file with mode: 0644]
src/cmd/go/testdata/script/version_buildvcs_hg.txt [new file with mode: 0644]
src/cmd/go/testdata/script/version_buildvcs_nested.txt [new file with mode: 0644]
src/cmd/internal/str/path.go
src/runtime/debug/mod.go