]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't stamp build or vcs info for GOROOT binaries
authorJay Conrod <jayconrod@google.com>
Thu, 14 Oct 2021 23:47:47 +0000 (16:47 -0700)
committerBryan C. Mills <bcmills@google.com>
Fri, 15 Oct 2021 02:02:50 +0000 (02:02 +0000)
Fixes a test failure in cmd/go TestScript/mod_outside.

make.bash (cmd/dist) builds everything with -gcflags=all= -ldflags=all=
by default. If those no-op flags aren't used, all GOROOT binaries
appear stale.

It's likely safe to omit those flags in cmd/dist if they're
empty. Checking out a new commit in GOROOT would always cause
staleness since the VCS info would change.

For #37475

Change-Id: Ic9aa0f3b7318e05fbb2f7d2c008ad07a4c61952f
Reviewed-on: https://go-review.googlesource.com/c/go/+/356014
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>
src/cmd/go/internal/load/pkg.go

index 716994b3adbe7419107016a81562a4c4ae08552e..58dc242383ca03f9a85c481a8fe20765330aab6e 100644 (file)
@@ -2205,6 +2205,11 @@ func (p *Package) collectDeps() {
 // Note that the GoVersion field is not set here to avoid encoding it twice.
 // It is stored separately in the binary, mostly for historical reasons.
 func (p *Package) setBuildInfo() {
+       // TODO: build and vcs information is not embedded for executables in GOROOT.
+       // cmd/dist uses -gcflags=all= -ldflags=all= by default, which means these
+       // executables always appear stale unless the user sets the same flags.
+       // Perhaps it's safe to omit those flags when GO_GCFLAGS and GO_LDFLAGS
+       // are not set?
        setPkgErrorf := func(format string, args ...interface{}) {
                if p.Error == nil {
                        p.Error = &PackageError{Err: fmt.Errorf(format, args...)}
@@ -2274,7 +2279,7 @@ func (p *Package) setBuildInfo() {
 
        // Add command-line flags relevant to the build.
        // This is informational, not an exhaustive list.
-       if cfg.BuildBuildinfo {
+       if cfg.BuildBuildinfo && !p.Standard {
                appendSetting("compiler", cfg.BuildContext.Compiler)
                if BuildAsmflags.present {
                        appendSetting("asmflags", BuildAsmflags.String())
@@ -2313,7 +2318,7 @@ func (p *Package) setBuildInfo() {
        var repoDir string
        var vcsCmd *vcs.Cmd
        var err error
-       if cfg.BuildBuildvcs && p.Module != nil && p.Module.Version == "" {
+       if cfg.BuildBuildvcs && p.Module != nil && p.Module.Version == "" && !p.Standard {
                repoDir, vcsCmd, err = vcs.FromDir(base.Cwd(), "")
                if err != nil && !errors.Is(err, os.ErrNotExist) {
                        setVCSError(err)