Documentation
¶
Overview ¶
Package goworkspace builds the synthetic go.work Kivgraph uses to load every registered Go module in a single go/packages universe.
The file is written outside every repository, under the configured state directory. Kivgraph never writes a go.work inside an indexed repository.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoModules = errors.New("no registered repository declares a Go module")
ErrNoModules reports that no registered repository declares a Go module.
var ErrRepositoryTarget = errors.New("synthetic go.work path is inside a registered repository")
ErrRepositoryTarget reports a synthetic workspace path inside a repository.
Functions ¶
func LanguageVersion ¶
func LanguageVersion() string
LanguageVersion is the `major.minor` language version this build can type check, derived from the toolchain that compiled it.
func PackagePatternsForModule ¶ added in v0.8.0
PackagePatternsForModule answers which import paths one module contributes, which is what a load has to name explicitly: a "./..." pattern silently skips a package whose files the build configuration all excludes, so it never reports the exclusion. Exported so an audit lists exactly what a pass would load instead of deriving a second answer.
Types ¶
type Conflict ¶
type Conflict struct {
Kind ConflictKind
Subject string
Repositories []string
Details []string
}
Conflict is a fact deliberately excluded because it cannot be decided.
type ConflictKind ¶
type ConflictKind string
ConflictKind classifies a fact excluded from the synthetic workspace.
const ( // AmbiguousModule marks one module path declared by several repositories. AmbiguousModule ConflictKind = "AMBIGUOUS_MODULE_PROVIDER" // ReplaceConflict marks one replaced path with incompatible targets. ReplaceConflict ConflictKind = "MODULE_REPLACE_CONFLICT" )
type Module ¶
type Module struct {
Repository string
ModulePath string
RootPath string
ManifestPath string
GoVersion string
// PackagePatterns are the discovered package paths passed to go/packages.
PackagePatterns []string
// Reaches are the module paths this module requires or replaces. Only
// the ones a registered repository provides matter, and they decide
// which modules must share a workspace.
Reaches []string
// WorkspaceMembers are the module paths bound together by a go.work of
// the indexed repository that lists this module, this one included.
// That file is a fact of the repository, so its grouping is preserved
// and its members always load through a workspace.
WorkspaceMembers []string
}
Module is one Go module included in the synthetic workspace.
type Options ¶
type Options struct {
// GoVersion overrides the version derived from the module manifests.
GoVersion string
// MaximumGoVersion is the highest language version the caller can type
// check. Empty means the version of the toolchain that built this
// binary, which is the only honest default: go/types is linked in, so
// the workspace must never select a toolchain whose sources it cannot
// read. Loading a newer module would fail deep inside the standard
// library instead of naming the repository that requires it.
MaximumGoVersion string
}
Options tunes how the plan is built.
type Plan ¶
type Plan struct {
GoVersion string
Modules []Module
Replaces []Replacement
Conflicts []Conflict
// Unsupported are the modules above the language version this build can
// type-check. They are not in Modules: the workspace claims the highest
// version of its members, and one above the cap would make the go command
// select a toolchain whose standard library go/types cannot read, so every
// load of every repository would fail on a file nobody registered.
Unsupported []UnsupportedModule
}
Plan is the deterministic content of one synthetic workspace.
func BuildPlan ¶
func BuildPlan(ctx context.Context, repositories []workspace.Repository, options Options) (Plan, error)
BuildPlan discovers every Go module of the registered repositories and composes the workspace content without writing anything.
Ambiguous module paths and incompatible replacements are excluded and reported: go itself rejects a workspace with two directories providing the same module, and a replacement Kivgraph cannot decide must never be guessed.
func (Plan) Partition ¶
Partition splits the plan into the independent workspaces it really needs.
A go.work resolves one build list for every module it uses, so unrelated repositories end up sharing a minimum version selection: a dependency bumped in one of them changes the versions selected for all the others, and a version no repository downloaded on its own breaks every load at once. Two modules only need the same workspace when one can reach the other: a requirement or a replacement naming a registered module, or a go.work of the indexed repository that already binds them together. Everything else is loaded exactly as its own toolchain would load it.
The returned plans are ordered by their first module path, and a plan with a single module that reaches nothing keeps its own manifest as the only truth: callers load it in module mode, with no workspace at all.
type Replacement ¶
Replacement is a replace directive promoted to the synthetic workspace.
type Result ¶
Result reports what a write did.
func Write ¶
func Write(ctx context.Context, path string, plan Plan, repositories []workspace.Repository) (Result, error)
Write renders the plan and installs it atomically at path.
The path is rejected when it falls inside any registered repository, so a misconfiguration cannot make Kivgraph write a go.work into indexed code.
type UnsupportedModule ¶ added in v0.10.3
type UnsupportedModule struct {
Repository string
ModulePath string
ManifestPath string
GoVersion string
// Supported is the major.minor language version this build can type-check.
Supported string
}
UnsupportedModule is a registered module written for a newer Go language version than this build can type-check. It is left out of the workspace and reported, never loaded.
func (UnsupportedModule) Detail ¶ added in v0.10.3
func (module UnsupportedModule) Detail() string
Detail says what the module needs and what this build offers, in the words an index report and a doctor line both use.