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
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.