Documentation
¶
Overview ¶
Package compile turns factory source into a buildable Go module: it parses and validates the stack, 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.
Index ¶
- func DeriveStackName(stackPath string) string
- func GoMajorMinor() string
- func LockedVersions(dir string) (map[string]string, error)
- func NewProjectResolver(stackDir string) (resolve.Resolver, error)
- func PrintSchemaWarnings(out io.Writer, alias string, warnings []string)
- func ReadGoSchema(sourcePath string, extra ...goschema.ModuleRoot) (*ubruntime.LibrarySchema, []string, error)
- func Run(opts Options) error
- func UnobinSchemaRoots(stderr io.Writer, replaceUnobin, version string) []goschema.ModuleRoot
- func WrapReplaces(resolver resolve.Resolver, root, replaceUnobin string, ...) (resolve.Resolver, error)
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeriveStackName ¶
DeriveStackName returns the stack name a source path implies: the lowercased basename of the file's directory.
func GoMajorMinor ¶
func GoMajorMinor() string
GoMajorMinor returns the running Go toolchain's `<major>.<minor>` so the generated go.mod's `go` directive matches the current toolchain.
func LockedVersions ¶
LockedVersions reads unobin.lock from dir and returns each repository's selected version, or nil when no lock is present, in which case the walk uses the version on each import string.
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 PrintSchemaWarnings ¶
PrintSchemaWarnings emits each warning string to out prefixed with the import alias the schema came from.
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 UnobinSchemaRoots ¶ added in v0.7.0
func UnobinSchemaRoots(stderr io.Writer, replaceUnobin, version string) []goschema.ModuleRoot
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 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 manifest replace entry resolve to a local directory instead of fetching. Replace paths are taken relative to root.
Types ¶
type Options ¶
type Options struct {
// StackPath is the factory source to compile.
StackPath 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
// stack 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 stack directory;
// nil uses NewProjectResolver.
NewResolver func(stackDir string) (resolve.Resolver, error)
// Stdout and Stderr receive the run's output; nil defaults to the
// process streams.
Stdout io.Writer
Stderr io.Writer
// 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.