Documentation
¶
Overview ¶
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.
Index ¶
- func DeriveStackName(factoryPath string) string
- func FactorySourcePath(path string) (string, error)
- func GoMajorMinor() string
- func NewProjectResolver(projectDir string) (resolve.Resolver, error)
- func ParseFactorySyntaxSource(path string, src []byte) (*syntax.File, string, error)
- func PrintSchemaWarnings(out io.Writer, alias string, warnings []string)
- func ProjectLockVersions(dir string) (map[string]string, error)
- 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 WrapProjectLockSources(resolver resolve.Resolver, projectLock *deps.ProjectLock) resolve.Resolver
- func WrapReplaces(resolver resolve.Resolver, root, replaceUnobin string, ...) (resolve.Resolver, error)
- type Options
- type SchemaCache
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 FactorySourcePath ¶
FactorySourcePath returns the factory source file named by path.
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 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 ¶
ParseFactorySyntaxSource parses source and returns typed source plus the canonical source body embedded in generated factories.
func PrintSchemaWarnings ¶
PrintSchemaWarnings emits each warning string to out prefixed with the import alias the schema came from.
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 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 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
// 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 SchemaCache ¶
type SchemaCache struct {
// contains filtered or unexported fields
}
SchemaCache memoizes Go library schema reads by source path. The module roots are fixed for a compile run, so one cache serves every import site and a library imported at the factory root and by composite bodies is parsed once.
func NewSchemaCache ¶
func NewSchemaCache(extra ...goschema.ModuleRoot) *SchemaCache
NewSchemaCache returns a cache that reads through ReadGoSchema with extra as the module roots for every lookup.
func (*SchemaCache) Read ¶
func (c *SchemaCache) Read(sourcePath string) (*ubruntime.LibrarySchema, []string, error)
Read returns the schema and warnings for the Go library source at sourcePath, reading it on first use and replaying the stored result after. A failed read is not stored, so the error reaches every site that asks.