Documentation
¶
Overview ¶
Package renderstage assembles the single-build render module (enhancement 0019 D9): it reads the two committed cue.mod/module.cue resolutions the render inputs carry, promotes them into the render module's dependency list (D13), checks that list for OPM-namespace coverage (the D13 refusal invariant), compares the two committed lists for catalog version skew (D7/D18), stages the generated render module into a directory, and builds it once in a caller-supplied cue.Context (D8).
The directory holds only the generated module: its cue.mod pair and the glue. An on-disk input is referenced in place through its local-module.cue replacement; an overlay-mode input is re-keyed under the directory that replacement names and served to the build through load.Config.Overlay, so no file of it is written.
An input's own cue.mod/local-module.cue (a developer's redirection of a dependency to a directory or another module) is read in either mode (ReadLocalModFile) and, when the caller enables local replacements, promoted into the render module's main-module view under the precedence dependencies get: the platform's replacements whole, the instance's only for paths the platform's list does not name. A replaced path the promoted list lacks is listed with a placeholder version of its major, so the coverage invariant holds; the honoured set is reported as ReplacementRow values on Staged. With local replacements off, an input whose file carries a replacement is refused before anything is written.
It is internal: the kernel's Render entry point owns the public types and the decode of the built value. Nothing here performs registry I/O of its own beyond the one cue/load build; the dependency list is string-level modfile mechanics over the two files the inputs already carry.
Index ¶
- Constants
- func Build(cueCtx *cue.Context, staged *Staged, env []string) (cue.Value, error)
- func ImportPath(qualifiedModule, pkgDir, pkgName string) (string, error)
- func IsOPMPath(path string) bool
- func RenderGlue(in GlueInputs) ([]byte, error)
- func ReplacedVersion(qualifiedPath string) (string, error)
- func VerifyCoverage(written []byte, filename string, inputs map[string]*ModFile) error
- type CoverageError
- type Dep
- type GlueInputs
- type LocalModFile
- type ModFile
- type Promotion
- type ReplacementRow
- type Staged
- type VersionRow
Constants ¶
const LocalModFileName = "cue.mod/local-module.cue"
LocalModFileName is the path, relative to a module root, of the optional main-module dependency view cue/load reads in place of module.cue's deps: the file a developer redirects dependencies with (CUE v0.17.0).
const MinLanguageVersion = "v0.17.0"
MinLanguageVersion is the floor of the render module's declared language.version: v0.17.0 introduced cue.mod/local-module.cue, which carries the directory replacements that bring the inputs into the build.
const ModFileName = "cue.mod/module.cue"
ModFileName is the module file path relative to a module root.
const RenderFileName = "render.cue"
RenderFileName is the generated glue file's name inside the render module.
const RenderModulePath = "render.opmodel.dev/build@v0"
RenderModulePath is the render module's own identity: a reserved, never published module path under a host no registry mapping serves. It never resolves anywhere because the render module is always the main module of the build it is generated for (0019 D9); it is fixed rather than derived per render so generated files are byte-stable across renders of the same inputs.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build evaluates the staged render module exactly once in cueCtx and returns the built value. env is the environment slice cue/load consults (nil for the process environment). The overlay-mode inputs Stage collected are handed to cue/load as load.Config.Overlay, so their replacement directories are served from memory. A load failure (an import that does not resolve, a malformed module file) is returned as an error; an evaluation error on the built value is NOT, because the fail-closed gate is one such error and the kernel reads `diagnostics` beside it.
func ImportPath ¶
ImportPath forms the import path of a package inside a module: the module's root path, the package directory (slash-separated, "" for the root package), the module's major, and the package name as an explicit qualifier when it differs from the last path element.
func IsOPMPath ¶
IsOPMPath reports whether a major-qualified module path lives in the OPM namespace: its host element is opmodel.dev or a subdomain of it. This is the path set the D13 refusal invariant and the D7 skew comparison cover; fixture domains (testing.opmodel.dev) are included deliberately so the invariant is exercised by fixture-backed tests.
func RenderGlue ¶
func RenderGlue(in GlueInputs) ([]byte, error)
RenderGlue renders the glue file for the given inputs. Caller-supplied strings enter as quoted CUE literals, never by raw interpolation.
func ReplacedVersion ¶
ReplacedVersion is the placeholder version the render module lists for an input module it serves from a directory: "vN.0.0" for a path qualified "@vN". cue/load never resolves it (the replacement wins), but module.cue must carry a well-formed version of the entry's own major for the entry, and so its default-major marker, to be accepted.
func VerifyCoverage ¶
VerifyCoverage re-parses the render module's written module.cue and refuses when any OPM-namespace path present in either input's dependency list is absent from it. inputs maps a label ("platform", "instance") to the committed module file it was promoted from. The first uncovered path in lexical order is reported.
Types ¶
type CoverageError ¶
type CoverageError struct {
// Path is the uncovered major-qualified module path.
Path string
// RequiredBy names the input(s) whose module file lists the path.
RequiredBy []string
}
CoverageError is the D13 refusal: the written render module lists no entry for an OPM-namespace path one of the inputs requires, so cue/load would answer that path from the module graph's maximum-version selection instead of from the render module's own roots. It is a kernel defect by definition; no caller can configure it away.
func (*CoverageError) Error ¶
func (e *CoverageError) Error() string
type Dep ¶
type Dep struct {
// Version is the canonical dependency version ("v1.2.3", "v2.0.0-alpha.9").
Version string
// Default marks this major as the default for imports of the path that
// omit a major qualifier.
Default bool
}
Dep is one dependency entry of a parsed module file, with the default-major marker intact: a catalog's `default: true` for a path is honoured by cue/load only while that path is a root dependency (0019 02-design.md, "The render build"), so promotion must carry the marker into the render module.
type GlueInputs ¶
type GlueInputs struct {
// InstancePath is the instance package's import path: the instance
// module's qualified path plus the package directory, with an explicit
// package qualifier when the package name differs from the directory.
InstancePath string
// PlatformPath is the platform package's import path, formed the same way.
PlatformPath string
// RuntimeName is the executing runtime's identity, entering the build as
// a CUE string literal.
RuntimeName string
}
GlueInputs are the generated slots of the render.cue template.
type LocalModFile ¶
type LocalModFile struct {
// Replacements maps each replaced major-qualified path to its target: an
// absolute directory (a relative one is resolved against the input's
// module root, since cue/load resolves it against the main module's root
// and the render module's root is elsewhere), or a module path verbatim.
Replacements map[string]string
// Deps is every entry the local file lists, versions and default markers
// as cue/load reads them against the module file (a version omitted in
// the local file is the module file's). Replacement targets are on
// Replacements, never here.
Deps map[string]Dep
}
LocalModFile is the parsed view of one input's cue.mod/local-module.cue: the dependencies the developer redirected and the entries the file lists. cue/load reads the file only from the main module, so an input's view reaches the render build only by promotion into the render module's own.
func ReadLocalModFile ¶
func ReadLocalModFile(src *module.Source, base *ModFile) (*LocalModFile, error)
ReadLocalModFile reads and parses the cue.mod/local-module.cue of a staged source tree against its parsed module file (base, from ReadModFile), in either mode. An absent file is the normal case and yields a nil view. A relative directory target is resolved against src.Root.
type ModFile ¶
type ModFile struct {
// Module is the qualified module path, major suffix included
// ("testing.opmodel.dev/library-parity@v0").
Module string
// Language is the declared language.version ("v0.17.0").
Language string
// Deps maps major-qualified dependency paths ("opmodel.dev/core@v2") to
// their entries. A dependency may carry no version: cue accepts the
// shape for a path a local replacement serves, and promotion refuses it
// when no promoted replacement covers the path.
Deps map[string]Dep
// contains filtered or unexported fields
}
ModFile is the parsed view of one input's committed cue.mod/module.cue.
func ParseModFile ¶
ParseModFile parses a module.cue in its standard (strict) format: every dependency carries its major in the path and, unless a local replacement serves it, a canonical version. filename is used for error messages only.
type Promotion ¶
type Promotion struct {
// Deps is the promoted dependency list keyed by major-qualified path. It
// includes the two input modules themselves: cue/load resolves an
// unqualified import inside a dependency (a module importing its own
// subpackage, "example.com/mod/identity" from within example.com/mod@v0,
// the ordinary authoring shape) through the MAIN module's default-major
// table, which it reads from cue.mod/module.cue only. A replacement in
// local-module.cue carries no default of its own, so without this entry
// the input's self-imports fail with "cannot find module providing
// package". The entry's version is a placeholder ([ReplacedVersion]):
// the directory replacement serves the module and the version is never
// resolved; the modfile decoder refuses a null version.
Deps map[string]Dep
// Language is the render module's language.version: the maximum of the
// two inputs' declared versions, floored at MinLanguageVersion.
Language string
// Replacements maps each replaced qualified path to its target (the
// local-module.cue replaceWith): each input module's own path to the
// absolute directory cue/load serves it from, plus every promoted
// replacement from the inputs' own local views, an absolute directory
// or a module path.
Replacements map[string]string
// Rows is one row per promoted local replacement, in path order: the
// developer's redirections the render honours, for the kernel to report
// as data. The two input directories are the mechanism, not a row.
Rows []ReplacementRow
}
Promotion is the render module's derived dependency list (0019 D13): the platform module's tidied list adopted whole, the instance module's list unioned in for paths only the instance carries, the platform's entry winning every shared path, and each input module's own path entered as a replace-only, default-marked entry. No tidy-equivalent and no registry consultation computes it; it is string-level mechanics over the two committed files.
func Promote ¶
func Promote(platform, instance *ModFile, platformLocal, instanceLocal *LocalModFile, platformDir, instanceDir string) (*Promotion, error)
Promote derives the render module's dependency list from the platform's and the instance's committed module files, and its main-module view from their local views (nil when an input carries no cue.mod/local-module.cue, or when the caller did not enable local replacements). platformDir and instanceDir are the absolute directories the two inputs are served from during the build.
Local replacements promote under the precedence dependencies do: the platform's whole, the instance's only for paths the platform's dependency list does not name (an instance replacement on a platform-named path is inert: the platform decides which bytes execute for every path it names). Entries a local file lists that the promoted list lacks join it, so a module-path replacement's target arrives with its version. Every replaced path is listed with a placeholder version of its major when the inputs give it none, so the coverage invariant holds for a replaced OPM path; a version-less dependency no promoted replacement covers is refused.
func (*Promotion) LocalModuleFile ¶
LocalModuleFile renders the render module's cue.mod/local-module.cue: the main-module dependency view, which is the promoted list with each input's entry directing cue/load to serve that module path from its staged directory and every promoted local replacement written as the input wrote it. cue/load reads this file in place of module.cue's deps when present, so the promoted list is repeated here rather than patched in.
func (*Promotion) ModuleFile ¶
ModuleFile renders the render module's cue.mod/module.cue: identity, language version and the promoted dependency list, in modfile's canonical format.
type ReplacementRow ¶
type ReplacementRow struct {
Path string
Target string
// By is "platform" or "instance".
By string
}
ReplacementRow names one local replacement the render module honours: the replaced major-qualified path, its target (an absolute directory, or a module path for a module replacement) and the input whose cue.mod/local-module.cue supplied it.
type Staged ¶
type Staged struct {
// Dir is the render module's root: cue.mod/module.cue,
// cue.mod/local-module.cue and render.cue live here, and nothing else.
Dir string
// Overlay holds every file of an overlay-mode input, keyed under Dir at
// the directory its local-module.cue replacement names (<Dir>/instance,
// <Dir>/platform). Build serves them to cue/load through
// load.Config.Overlay; none of them is written to Dir. Empty when both
// inputs are on disk.
Overlay map[string][]byte
// Skew holds the per-path resolved-versions rows (D18), instance list
// against platform list.
Skew []VersionRow
// Replacements holds one row per local replacement the render module
// honours (an input's own cue.mod/local-module.cue, promoted), in path
// order. Nil unless the caller enabled local replacements and an input
// carried one that promotion kept.
Replacements []ReplacementRow
}
Staged is one render module written to a directory: what the kernel needs to build it and to report on the version skew it was staged under.
func Stage ¶
func Stage(dir string, instance, platform *module.Source, runtimeName string, localReplacements bool) (*Staged, error)
Stage writes the render module for instance and platform into dir (which must exist and be empty): promotes the two module files, writes the cue.mod pair, verifies OPM-path coverage, compares skew, and writes the glue. An overlay-mode input is not written: its entries are re-keyed under dir onto Staged.Overlay for Build to serve from memory, and an on-disk input is referenced in place. It performs no build.
localReplacements decides what an input's own cue.mod/local-module.cue means: true promotes its replacements into the render module's main-module view (platform's whole, instance's on paths the platform does not name) and reports them on Staged.Replacements; false refuses, before anything is written, an input whose file carries a replacement, since silently dropping the file is what made a developer's redirection invisible at render time. An input without the file stages identically either way.
type VersionRow ¶
type VersionRow struct {
// Path is the major-qualified module path compared.
Path string
// ModuleVersion is the version the instance module's cue.mod requires.
ModuleVersion string
// PlatformVersion is the version the platform module's tidied list
// carries. Empty when the platform does not list the path (the instance's
// own entry is then what the render resolves).
PlatformVersion string
// Newer is true when the instance requires a build newer than the
// platform carries: the D7 skew case the caller's policy decides.
Newer bool
}
VersionRow is one resolved-versions comparison row (0019 D18): for an OPM-namespace path the instance module requires, the build the instance asked for and the build the platform carries. It is plain data with no severity; Newer flags the one case D7 makes a policy question.
func CompareSkew ¶
func CompareSkew(platform, instance *ModFile) ([]VersionRow, error)
CompareSkew compares the instance module's committed dependency list against the platform module's, per OPM-namespace path the instance requires, and returns the rows in lexical path order. The render module's promoted list is never an input here: the platform wins every shared path there by construction, so skew would be invisible (D18).