buildinfo

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package buildinfo reports what build this binary is, for `idea version`, the daemon's /api/v1/version endpoint and `idea doctor`.

Before this existed the only answer was a hardcoded const in the daemon, so every install said "0.1.0" and a bug report could not name a build.

Three build paths produce three different amounts of information, and the stamp says which one it got rather than inventing the rest:

  • `make build` / a release build: -ldflags -X sets Version and Commit.
  • `go install ./cmd/idea` from a checkout: nothing is stamped, but the Go toolchain records vcs.revision and vcs.modified, so the commit is known and a dirty tree is reported as such.
  • `go install <module>@<version>` from the proxy: the module version is known (debug.BuildInfo.Main.Version); there is no VCS data at all, because the proxy serves an extracted zip with no .git. That absence is what distinguishes this path — Main.Version is also set for a local build, to a pseudo-version naming a release that does not exist.

An explicit -ldflags stamp wins over the toolchain's, and not only because it is more specific: building inside a git worktree, the toolchain reports the *main* checkout's HEAD rather than the worktree's, so `make build` (which takes the commit from `git rev-parse` in the working directory) is the one that names the commit you actually built.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SameBuild added in v0.4.0

func SameBuild(a, b Info) bool

SameBuild reports whether two stamps name the same binary.

The commit decides whenever both know one, because the version strings do not survive the build paths above: `make build` off a tag leaves Version empty while `go install` reports `dev`, so identical source produces two different version strings. Commit is also the only thing that separates one `dev` from another, which is the case this exists for -- a daemon left running across an upgrade is executing a different commit under the same word.

Both are normalised to seven characters first: `make build` stamps `git rev-parse --short` and the toolchain records the full 40-character revision, so a raw comparison would report a mismatch on every make-build-then-go-build pair.

Version is the fallback for proxy installs, which carry no VCS data at all.

Modified is deliberately ignored. Two builds from the same commit with different uncommitted edits are indistinguishable here, so "I edited it, rebuilt, and forgot to restart the daemon" is not caught -- catching it would mean warning on every dirty build, which is every build during development.

Types

type Info

type Info struct {
	// Version is a release version ("v0.1.0"), a module version from the proxy,
	// or "dev" when neither is known.
	Version string `json:"version"`
	// Commit is the VCS revision when it is known, "" otherwise.
	Commit string `json:"commit,omitempty"`
	// Modified reports a build made from a dirty working tree.
	Modified bool `json:"modified,omitempty"`
}

Info describes the running build.

func Get

func Get() Info

Get resolves the build stamp, preferring what was set explicitly over what the toolchain inferred.

func (Info) String

func (i Info) String() string

String renders the stamp for a human: "v0.1.0 (abc1234)", "dev (abc1234, dirty)".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL