renderstage

package
v1.0.0-alpha.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

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

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

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

View Source
const ModFileName = "cue.mod/module.cue"

ModFileName is the module file path relative to a module root.

View Source
const RenderFileName = "render.cue"

RenderFileName is the generated glue file's name inside the render module.

View Source
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 Alternatives

func Alternatives(universe []string, missing string) []string

Alternatives returns every contract key in universe other than missing that shares its base (the FQN before the final "@"), in contract-key order (the kube-aware apiVersion ladder, 0010 D34/D4): "a transformer exists for a different version of this primitive".

func Build

func Build(cueCtx *cue.Context, staged *Staged, env []string) (cue.Value, error)

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

func ImportPath(qualifiedModule, pkgDir, pkgName string) (string, error)

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

func IsOPMPath(path string) bool

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 RegistryEnv

func RegistryEnv(registry string) []string

RegistryEnv returns a copy of the process environment with CUE_REGISTRY overridden when registry is non-empty, and nil otherwise (cue/load then reads the process environment unchanged). Never os.Setenv.

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

func ReplacedVersion(qualifiedPath string) (string, error)

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

func VerifyCoverage(written []byte, filename string, inputs map[string]*ModFile) error

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.7").
	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 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.
	Deps map[string]Dep
}

ModFile is the parsed view of one input's committed cue.mod/module.cue.

func ParseModFile

func ParseModFile(data []byte, filename string) (*ModFile, error)

ParseModFile parses a module.cue in its standard (strict) format: every dependency carries its major in the path and a canonical version. filename is used for error messages only.

func ReadModFile

func ReadModFile(src *module.Source) (*ModFile, error)

ReadModFile reads and parses the cue.mod/module.cue of a staged source tree: from the overlay in overlay mode, from disk in on-disk mode.

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 input module's qualified path to the absolute
	// directory cue/load serves it from (the local-module.cue replaceWith).
	Replacements map[string]string
}

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, platformDir, instanceDir string) (*Promotion, error)

Promote derives the render module's dependency list from the platform's and the instance's committed module files. platformDir and instanceDir are the absolute directories the two inputs are served from during the build.

func (*Promotion) LocalModuleFile

func (p *Promotion) LocalModuleFile() ([]byte, error)

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

func (p *Promotion) ModuleFile() ([]byte, error)

ModuleFile renders the render module's cue.mod/module.cue: identity, language version and the promoted dependency list, in modfile's canonical format.

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, as does a
	// materialized overlay-mode input tree.
	Dir string

	// Instance and Platform are the two committed module files the render
	// module was promoted from.
	Instance, Platform *ModFile

	// Promotion is the derived dependency list (D13).
	Promotion *Promotion

	// Skew holds the per-path resolved-versions rows (D18), instance list
	// against platform list.
	Skew []VersionRow

	// InstanceImport and PlatformImport are the generated import paths.
	InstanceImport, PlatformImport string
}

Staged is one render module written to a directory, with everything the kernel needs to build it and to report on how it was derived.

func Stage

func Stage(dir string, instance, platform *module.Source, runtimeName string) (*Staged, error)

Stage writes the render module for instance and platform into dir (which must exist and be empty): materializes an overlay-mode input under it, promotes the two module files, writes the cue.mod pair, verifies OPM-path coverage, compares skew, and writes the glue. It performs no build.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL