Documentation
¶
Overview ¶
Package gen is the compiler side of the plugin protocol: which backends exist, how a request is built, and what happens to the files that come back.
The `plugin` package is the surface a backend author sees.
Index ¶
- Constants
- Variables
- func Builtin(name string) (plugin.Backend, bool)
- func BuiltinNames() []string
- func CheckDirectives(target string, model *ir.Model, desc plugin.Description) []*plugin.Diagnostic
- func Clean(out string) ([]string, error)
- func Fatal(diags []*plugin.Diagnostic) bool
- func Mark(out string) error
- func Owned(out string) bool
- func Resolve(name string) (plugin.Backend, error)
- func Watch(done <-chan struct{}, path string, onChange func())
- func Write(out string, files []*plugin.File) ([]string, error)
- type Mode
- type Result
- type Session
- type Stale
- type Subprocess
- type Target
Constants ¶
const CommandPrefix = "tdl-gen-"
CommandPrefix is prefixed to a target name to find its executable on PATH, the way git and protoc find their subcommands.
const DefaultTimeout = 2 * time.Minute
DefaultTimeout bounds how long a plugin has to answer, so a hung plugin fails with a diagnosis.
const MarkerName = ".tdl-output"
MarkerName is the file tdl drops in a directory it writes to, so --clean knows the directory is its own.
const WatchInterval = time.Second
WatchInterval is how often a watched file is polled.
Variables ¶
var ErrNotOurs = errors.New("the output directory was not written by tdl")
ErrNotOurs is returned when --clean is asked to empty a directory that has files but no marker.
Functions ¶
func BuiltinNames ¶
func BuiltinNames() []string
BuiltinNames lists the compiled-in backends, sorted.
func CheckDirectives ¶
func CheckDirectives(target string, model *ir.Model, desc plugin.Description) []*plugin.Diagnostic
CheckDirectives compares the directives a target block uses against what its backend says it understands.
A declared directive with the wrong number or kind of arguments is an error, reported before anything is generated. An undeclared directive is a warning and is passed through anyway, since a backend may handle more than it advertises.
func Clean ¶
Clean empties an output directory tdl owns, leaving the marker. A missing or empty directory is fine; one with contents and no marker is ErrNotOurs.
func Fatal ¶ added in v0.1.8
func Fatal(diags []*plugin.Diagnostic) bool
Fatal reports whether any diagnostic is an error rather than a warning.
func Resolve ¶
Resolve returns the backend serving a target: the compiled-in one if there is one, otherwise tdl-gen-<name> on PATH. A built-in name cannot be shadowed from PATH.
func Watch ¶
func Watch(done <-chan struct{}, path string, onChange func())
Watch calls onChange whenever path's contents change, until done is closed. It compares contents rather than modification time, so a rewrite with no change does not trigger. A poll landing mid-save may see a truncated file; the next poll corrects it.
Types ¶
type Result ¶
type Result struct {
Target string
Written []string
Removed []string
Stale []Stale
Diagnostics []*plugin.Diagnostic
}
Result is what one target produced.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a plugin kept alive across generations. A plugin that declared reuse serves many requests on one connection and must treat each as independent.
func Open ¶
func Open(ctx context.Context, sub *Subprocess) (*Session, error)
Open starts a plugin and holds the connection if it declared reuse; otherwise each generation gets a fresh process. A failed handshake is an error.
func (*Session) Describe ¶
func (s *Session) Describe() plugin.Description
Describe reports what the plugin said about itself when it was opened.
type Subprocess ¶
Subprocess is a backend running as tdl-gen-<name>. It implements plugin.Backend, so callers treat a plugin and a compiled-in backend the same way.
func Find ¶
func Find(name string) (*Subprocess, error)
Find locates the executable for a target name.
func (*Subprocess) Describe ¶
func (s *Subprocess) Describe() plugin.Description
Describe starts the plugin, shakes hands, and stops it again. Generate starts a process of its own.