Skip to content

cmd/go: Subversion VCS build information should be included in the build #73444

Closed
@bsdcode

Description

@bsdcode

Go version

go version go1.24.2 freebsd/amd64

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build105780697=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='freebsd'
GOINSECURE=''
GOMOD='/tmp/example/go.mod'
GOMODCACHE='/home/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='freebsd'
GOPATH='/home/user/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go124'
GOSUMDB='sum.golang.org'
GOTELEMETRY='off'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go124/pkg/tool/freebsd_amd64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Consider an example SVN repository containing an example program reading out the VCS build information:

$ svn info
Path: .
Working Copy Root Path: /tmp/example
URL: file:///tmp/svn
Relative URL: ^/
Repository Root: file:///tmp/svn
Repository UUID: 06cb4ac0-f01c-f011-8e60-309c239b96ba
Revision: 5
Node Kind: directory
Schedule: normal
Last Changed Author: user
Last Changed Rev: 5
Last Changed Date: 2025-04-19 12:22:27 +0200 (Sat, 19 Apr 2025)

$ svn list
go.mod
main.go
module example

go 1.24.2
package main

import (
	"fmt"
	"log"
	"runtime/debug"
)

func main() {
	bi, ok := debug.ReadBuildInfo()
	if !ok {
		log.Fatalln("ReadBuildInfo failed")
	}

	for _, s := range bi.Settings {
		switch s.Key {
		case "vcs", "vcs.modified", "vcs.revision", "vcs.time":
			fmt.Printf("%s: %s\n", s.Key, s.Value)
		}
	}
}
$ go build

Executing the resulting binary example should list the SVN related informations.

What did you see happen?

$ ./example

No VCS build information is printed.

What did you expect to see?

Considering the above output of svn info and the specific outputs of

$ svn info --show-item last-changed-revision
5

$ svn info --show-item last-changed-date
2025-04-19T10:22:27.784965Z

$ svn status

I expected to see an output similar to this:

$ ./example
vcs: svn
vcs.revision: 5
vcs.time: 2025-04-19T10:22:27.784965Z
vcs.modified: false

Reading src/cmd/go/internal/vcs/vcs.go reveales that vcsSvn currently doesn't set a Status function to retrieve this information like vcsBzr, vcsFossil, vcsGit and vcsHg do.

A prototype for such a function could be:

func svnStatus(vcsSvn *Cmd, rootDir string) (Status, error) {
        out, err := vcsSvn.runOutputVerboseOnly(rootDir, "info --show-item last-changed-revision")
        if err != nil {
                return Status{}, err
        }
        rev := strings.TrimSpace(string(out))

        out, err = vcsSvn.runOutputVerboseOnly(rootDir, "info --show-item last-changed-date")
        if err != nil {
                return Status{}, err
        }
        commitTime, err := time.Parse(time.RFC3339, strings.TrimSpace(string(out)))
        if err != nil {
                return Status{}, fmt.Errorf("unable to parse output of svn info: %v", err)
        }

        out, err = vcsSvn.runOutputVerboseOnly(rootDir, "status")
        if err != nil {
                return Status{}, err
        }
        uncommitted := len(out) > 0

        return Status{
                Revision:    rev,
                CommitTime:  commitTime,
                Uncommitted: uncommitted,
        }, nil
}

I tested this prototype with my example program and it produced the expected output above.

Metadata

Metadata

Assignees

Labels

GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolProposalIssues describing a requested change to a Go tool or command-line program.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions