Documentation
¶
Overview ¶
Package toolcache is the one machine-wide directory every tool forge installs for itself lives in: the gate's pinned linters and scanners (internal/cigate), forge lint's golangci-lint build (internal/cli/lint), and the codegen plugins and air that `forge generate` and `forge env up` pin (internal/cli). Every worktree of every project on the machine shares it.
Layout ¶
$FORGE_TOOLS_CACHE (default <UserCacheDir>/forge/tools)/
<kind>/ gate, golangci-lint, pinned
<key>/ one ENTRY: a tool at one version (+toolchain)
<binary>
.build-<key>-*/ an install in progress
An entry's key names everything that decides its bytes (tool, version and, where it matters, the Go toolchain), so an entry is never rewritten for a different version: a bump is a new key beside the old one, and a checkout still on the old pin keeps working.
Concurrency ¶
An install builds into a private staging directory and is published by one rename, so no reader ever execs a half-written binary (a `go version -m` of one failed the pin with "installed binary reports unknown": TestE2EFixtureCorpusKalshiShaped). There is no lock: two processes that miss the same key at once both build it — the second build is mostly Go build cache hits — and the one that loses the rename uses the winner's entry.
Nothing here evicts. An entry is a few binaries per pinned version; the machine's disk steward, not forge, decides what a full disk gives up.
Index ¶
Constants ¶
const ( // KindGate holds `forge ci gate`'s pinned tools (internal/cigate). KindGate = "gate" // KindGolangci holds forge lint's own golangci-lint builds. KindGolangci = "golangci-lint" // KindPinned holds go.mod-pinned codegen plugins and the dev loop's air. KindPinned = "pinned" )
The kinds of entry forge installs. Each is a directory under the root.
const EnvRoot = "FORGE_TOOLS_CACHE"
EnvRoot relocates the whole tool cache: a read-only home directory, a CI runner that caches one directory, or a test that must not touch the developer's real cache.
Variables ¶
This section is empty.
Functions ¶
func Ensure ¶
func Ensure(ctx context.Context, kindDir, key string, ready func(dir string) bool, build func(ctx context.Context, stage string) error) (string, error)
Ensure resolves the entry <kindDir>/<key>, installing it when ready reports it unusable, and returns its directory.
ready(dir) answers whether the entry at dir is usable as is (the binary exists and reports the pinned version). build(ctx, stage) installs the entry's files into stage, an empty directory that becomes the entry when build succeeds. Ensure does not re-check ready after its own build: a caller that wants its own message for a build that produced the wrong thing verifies the returned directory itself.
Types ¶
This section is empty.