Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bsdcode opened this issue Apr 19, 2025 · 5 comments · May be fixed by #73446
Open

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

bsdcode opened this issue Apr 19, 2025 · 5 comments · May be fixed by #73446
Assignees
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolProposal Issues describing a requested change to a Go tool or command-line program.

Comments

@bsdcode
Copy link

bsdcode commented Apr 19, 2025

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.

@gabyhelp gabyhelp added the ToolProposal Issues describing a requested change to a Go tool or command-line program. label Apr 19, 2025
@seankhliao
Copy link
Member

do you want to submit a change?
see https://go.dev/doc/contribute

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Apr 19, 2025
bsdcode added a commit to bsdcode/go that referenced this issue Apr 19, 2025
The existing implementation lacks the Status function for retrieving VCS build
information for Subversion. As a consequence, binaries aren't stamped with the
Revision, CommitTime and Uncommitted information from SVN repositories.

This change provides the svnStatus function and retrieves the information by
running svn info and svn status commands.

Fixes golang#73444
bsdcode added a commit to bsdcode/go that referenced this issue Apr 19, 2025
The existing implementation lacks the Status function for retrieving VCS build
information for Subversion. As a consequence, binaries aren't stamped with the
Revision, CommitTime and Uncommitted information from SVN repositories.

This change provides the svnStatus function and retrieves the information by
running svn info and svn status commands.

Fixes golang#73444
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/666875 mentions this issue: cmd/go/internal/vcs: include Subversion VCS build information

@bsdcode
Copy link
Author

bsdcode commented Apr 19, 2025

Thanks, I submitted the change.

@seankhliao
Copy link
Member

@samthanawalla not sure why you said in CL 630195 this needed to be a proposal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolProposal Issues describing a requested change to a Go tool or command-line program.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants