package compile¶
Package compile turns factory source into a buildable Go module: it parses and validates the factory, resolves its imports, reads each Go library's schema, runs the compile-time checks, generates main.go and one package per UB library, and optionally runs `go build`. The CLI's compile command is a thin flag layer over Run.
Functions¶
func DeriveStackName¶
DeriveStackName returns the stack name a source path implies: the lowercased basename of the file's directory.
func FactorySourcePath¶
FactorySourcePath returns the factory source file named by path.
func GoMajorMinor¶
GoMajorMinor returns the running Go toolchain's `\
func NewProjectResolver¶
NewProjectResolver returns the resolver compile uses to fetch import sources: a local resolver for relative paths and a remote resolver for everything else.
func ParseFactorySyntaxSource¶
func ParseFactorySyntaxSource(
path string,
src []byte,
) (*syntax.File, syntax.SourceFileSpec, error)
ParseFactorySyntaxSource parses source and returns typed source plus source metadata.
func ProjectLockVersions¶
ProjectLockVersions reads dependency project-lock from dir and returns each repository's selected version, or nil when no project-lock is present, in which case the walk uses the version on each import string.
func ReadGoSchema¶
func ReadGoSchema(
sourcePath string, extra ...goschema.ModuleRoot,
) (*ubruntime.LibrarySchema, []string, error)
ReadGoSchema reads a fetched Go library's source from sourcePath and returns its schema plus any warnings about registered types whose sibling Output struct could not be located. A missing path returns nil values with no error, which lets fake resolvers in tests fall through without having to write a real library to disk. Any other failure mode (missing Library() function, parse error, malformed source) is propagated so a broken import fails the compile. extra lists module roots beyond the library's own that the schema walker may read source from.
func Run¶
Run compiles a factory per the options.
func UnobinSchemaRoots¶
UnobinSchemaRoots returns the module roots schema extraction should read beyond a library's own: the unobin module when its source is reachable, otherwise nothing. replaceUnobin may be a relative path. stderr receives toolchain progress when a cache miss downloads the module.
func WrapProjectLockSources¶
func WrapProjectLockSources(
resolver resolve.Resolver,
projectLock *deps.ProjectLock,
) resolve.Resolver
WrapProjectLockSources fetches project-lock remote imports by commit and verifies UB hashes.
func WrapReplaces¶
func WrapReplaces(
resolver resolve.Resolver, root, replaceUnobin string, replace map[deps.Dependency]string,
) (resolve.Resolver, error)
WrapReplaces wraps resolver so that a replaced unobin and each project replace entry resolve to a local directory instead of fetching. Replace paths are taken relative to root.
Types¶
type Options¶
type Options struct {
// FactoryPath is the factory source file or directory to compile.
FactoryPath string
// OutDir receives main.go, go.mod, and the generated UB-library
// packages; `-` streams main.go to Stdout instead.
OutDir string
// StackName overrides the stack name; empty derives it from the
// factory file's parent directory.
StackName string
// LibraryPath is the library-path identity to embed in the binary.
LibraryPath string
// GoVersion is the toolchain version the generated go.mod declares.
GoVersion string
// Version is the release version stamped into the built binary.
Version string
// CLIVersion is the compiling CLI's own version; the generated
// go.mod pins unobin to it so the factory links the runtime its
// compile checks ran with. "dev" requires a replace.
CLIVersion string
// ReplaceUnobin substitutes a local path for the unobin repository.
ReplaceUnobin string
// ReplaceGoModules maps a Go module path to the local path that
// serves it, for both the import resolver and the generated go.mod.
ReplaceGoModules map[string]string
// Build runs `go build` in OutDir after writing the source.
Build bool
// NewResolver constructs the import resolver for a project root;
// nil uses NewProjectResolver.
NewResolver func(projectDir string) (resolve.Resolver, error)
// Stdout and Stderr receive the run's output; nil defaults to the
// process streams.
Stdout io.Writer
Stderr io.Writer
// Reporter receives warnings and notices. Nil preserves text output.
Reporter diagnostic.Reporter
// TypeObserver, when set, receives every expression the stack's
// type checks infer, with its type. The residual-Unknown harness
// uses it; nil compiles without recording.
TypeObserver func(e lang.Expr, t typecheck.Type)
}
Options configures one compile run.
type Result¶
type Result struct {
FactoryName string
Version string
ContentRevision string
LibraryPath string
SourcePath string
ProjectDir string
OutputDir string
MainGoPath string
GoModPath string
AssetsPath string
Built bool
BinaryPath string
Files []filechange.Change
}
func RunResult¶
type SchemaCache¶
SchemaCache memoizes Go library schema reads by source path.
func NewSchemaCache¶
NewSchemaCache returns a cache that reads through ReadGoSchema with extra as the module roots for every lookup.
func NewSchemaCacheWithReader¶
func NewSchemaCacheWithReader(
read func(sourcePath string) (*ubruntime.LibrarySchema, []string, error),
) *SchemaCache
NewSchemaCacheWithReader returns a cache that reads through read.