package deps¶
Package deps models a factory's dependencies. It reads project.ub, which lists each direct dependency and the lowest version the factory accepts for it, and drives pkg/resolve to fetch them.
Constants¶
CurrentProjectLockVersion is the schema version this package reads and writes. A different version errors on read, since this build cannot guarantee a correct interpretation.
ProjectFileName is the dependency project filename.
ProjectLockFileName is the dependency project-lock filename.
Functions¶
func CheckNoReplacementSentinelInProjectLock¶
func CheckPackageBoundary¶
func CheckReplacementSentinels¶
func EncodeProject¶
EncodeProject renders a parseable project.ub draft.
func EncodeProjectLock¶
EncodeProjectLock serializes projectLock as canonical project-lock.ub source.
func FindProjectDir¶
FindProjectDir walks up from start to the nearest ancestor directory holding a project and returns that directory: the root of the project that governs start. start may be any path inside the project, a directory or a file. It stops at the filesystem root and returns an error wrapping fs.ErrNotExist when no project is found.
func FindProjectMarkerDir¶
func GoReplacementSentinel¶
func HasProjectMarker¶
HasProjectMarker reports whether fsys contains project.ub or go.mod at its root.
func HashUBProject¶
func Highest¶
Highest returns the greatest version in vs by semver order, or "" when vs is empty.
func ImportedPackages¶
ImportedPackages scans every .ub file under root and returns the set of packages named by remote imports. The version on an import is not read here: a package's version floor lives on its owning project in project.ub, not in the import string. Local imports are intra-project and contribute no remote package. Hidden directories (a leading dot, such as .git) are skipped.
func ImportedRepos¶
ImportedRepos is kept for callers that still need the import strings in the older Dependency form.
func IsReplacementSentinel¶
func ProjectContains¶
ProjectContains reports whether project owns pkg. The returned subdir is the package path inside the project, or "." when pkg names the project root.
func ProjectTag¶
ProjectTag returns the git tag for a project version.
func ReplacementPath¶
ReplacementPath returns the local replacement path for dep.
func RequireProject¶
RequireProject checks that dep resolves to a project root at version.
func Resolve¶
Resolve runs minimal version selection over the dependency graph rooted at a project. It selects the highest floor for each dependency, fetches it at that version to read its own requirements, and repeats until the selection stops changing. A dependency whose version is later raised is re-fetched, since a higher version may declare different requirements; the walk terminates at any dependency with no project. The result maps each dependency to its selected version -- project-lock, keyed per imported library, is built separately by the import walk.
func ResolveVersion¶
ResolveVersion turns a `deps get` query into a concrete version of dep, chosen among the repository's tags. An empty query or "latest" picks the highest available version; a full version (vX.Y.Z) is used as-is once confirmed present; a partial version (v1 or v1.2) picks the highest available version under that prefix.
func Verify¶
Verify re-fetches every ub-kind dependency in project-lock at its pinned commit and checks the content hash against the recorded one. A mismatch means the source changed under a pinned commit. Go dependencies are skipped: their integrity rides the generated go.sum, not a content hash here. It returns one message per dependency whose hash no longer matches, in id order.
func Versions¶
Versions returns the dependency's semver tags in increasing order.
func WriteProject¶
WriteProject serializes m as canonical project.ub source and atomically replaces the file at path.
func WriteProjectLock¶
WriteProjectLock serializes projectLock as canonical project-lock.ub source and atomically replaces the file at path.
Types¶
type Dependency¶
Dependency identifies an importable unit by its repository URL and an optional subdirectory within that repository. It is the project's notion of "a dependency"; a resolved version (a git tag) is paired with it elsewhere, not stored on the identity.
func ParseDependency¶
ParseDependency parses a dependency id of the form `repo-url` or `repo-url//subdir`, the same `//` separator imports use but without a trailing `@version`.
func (Dependency) String¶
String renders the dependency back to its id form, the inverse of ParseDependency.
func (Dependency) Tag¶
Tag returns the most specific git tag that names a version of this dependency.
func (Dependency) TagPrefix¶
TagPrefix returns the most specific git tag prefix for this dependency.
type Fetcher¶
Fetcher fetches a dependency's project at a selected version, for the version walk. It returns nil when the dependency declares no project: a leaf with no further dependencies, such as a Go library or a UB library that imports nothing remote.
func NewFetcher¶
NewFetcher returns a Fetcher that reads dependency projects through resolver. It is the production Fetcher behind unobin deps; tests pass a fake resolver.
type PackageOwner¶
PackageOwner records the project that owns a package import.
func MostSpecificProject¶
MostSpecificProject chooses the project with the longest matching subdir.
type Project¶
type Project struct {
UnobinVersion string
Requires map[Dependency]Requirement
Replace map[Dependency]string
}
Project is a parsed dependency project. Requires maps each dependency to the lowest version (a git tag) the factory accepts for it; resolution may select a higher one to satisfy the whole set. The factory's own version is its git tag, not recorded here. Replace maps a dependency's URL to a local path: the resolver reads that dependency from the path instead of fetching it, and the dependency needs no floor or project-lock entry. UnobinVersion, when set, pins the toolchain: only a CLI of exactly that version compiles the project, since the unobin runtime is not a dependency whose version resolution selects.
func ReadProject¶
ReadProject reads and parses project.ub from fsys. A missing file returns an error wrapping fs.ErrNotExist, which callers can detect with errors.Is.
func (*Project) DirectCount¶
func (*Project) DirectRequireVersions¶
func (*Project) IndirectCount¶
func (*Project) RequireVersions¶
func (*Project) SetRequire¶
type ProjectID¶
ProjectID identifies a versioned dependency project.
func ProjectIDFromDependency¶
func ProjectIDsFromDependencies¶
func ProjectIDsFromReplace¶
func (ProjectID) Dependency¶
func (ProjectID) String¶
type ProjectLock¶
ProjectLock is the on-disk schema for the dependency project-lock file. It pins the full resolved set so compiles are reproducible without re-running selection. Deps is keyed by dependency id, a repository URL with an optional `//subdir`, the same form a project `requires:` key uses.
func DecodeProjectLock¶
DecodeProjectLock parses a grammar-first project-lock.ub from bytes.
func NewProjectLock¶
NewProjectLock returns an empty project-lock at the current schema version.
func ProjectLockFromImports¶
func ProjectLockFromImports(
rootFS fs.FS,
selection map[Dependency]string,
resolver resolve.Resolver,
replace map[Dependency]string,
) (*ProjectLock, error)
ProjectLockFromImports builds the project-lock for the project rooted at rootFS. It visits every .ub file under the root -- factory.ub, library files at the root, or libraries in subdirectories -- and visits remote UB library imports too. Each remote library becomes one selected dependency entry, keyed by `repo//subdir`. Local imports are not selected separately because the project visit already sees every file under the root. A library's version is its repository's selected version; a repository the selection does not cover is an error. Go dependencies are recorded by project id. UB dependencies are recorded by project id with a project-root hash. A repository named in replace is read from its local path and never added to the project-lock; a replaced UB library's own remote dependencies are still visited.
func ReadProjectLock¶
ReadProjectLock reads and parses project-lock.ub from fsys. A missing file returns an error wrapping fs.ErrNotExist, which callers can detect with errors.Is.
func (*ProjectLock) RepoVersions¶
RepoVersions maps each selected dependency id to its selected version. Compile feeds this to the import walk so versionless imports resolve at the selected version.
func (*ProjectLock) SortedIDs¶
SortedIDs returns the dependency ids in sorted order.
type ProjectLockDep¶
ProjectLockDep is one resolved dependency. Version is the selected git tag; the floor lives in project.ub and is never copied here. Hash is the source-tree content hash for `ub` dependencies and is omitted for `go`.
type ProjectLockKind¶
ProjectLockKind records how a selected dependency's integrity is guaranteed: a `ub` dependency holds a content hash of its source tree, while a `go` dependency rides the generated module's go.sum and records only a commit.
type RemotePackage¶
RemotePackage identifies a package import below a dependency project.
func RemotePackageFromDependency¶
func (RemotePackage) Dependency¶
func (RemotePackage) String¶
type Replacement¶
Replacement describes the local path selected for a dependency.
func ReplacementFor¶
ReplacementFor returns the local replacement for dep. A repository-level replacement covers imports from subdirectories in that repository. A subdirectory replacement covers that subdirectory and packages below it.
type Requirement¶
Requirement is a root dependency floor declared by project.ub.
type Selection¶
Selection performs minimal version selection incrementally. Add records that some project requires a dependency at a floor version, and Selection keeps the highest floor seen for each dependency -- Go's max-of-minimums. A walker feeds it every requirement across the dependency graph; the highest floor per dependency is the selected version. Floors must be valid semver, which the project reader guarantees.
func NewSelection¶
NewSelection returns an empty Selection.
func (*Selection) Add¶
Add records a required floor for dep and reports whether it raised the selected version: true the first time dep is seen, or when floor is higher than the current selection. A walker uses the result to decide whether it must read dep's project at the new version, since a higher version may declare different requirements.
func (*Selection) Chosen¶
Chosen returns a copy of the selected version for every dependency added so far.
func (*Selection) Version¶
Version returns the selected version for dep, or "" if dep has not been added.