Documentation
¶
Index ¶
- func Load(ctx context.Context, pkgdir string, f func(*exec.Cmd) error) error
- func LoadPkg(ctx context.Context, pkgdir, pkgname string, scope *types.Scope, ...) error
- func LoadTargets(ctx context.Context, pkgdir, pkgname string, targets []string, ...) error
- func Run(ctx context.Context, pkgdir string, args ...string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load builds a Go binary out of the Go package at `pkgdir` and a special main function. It then prepares an exec.Cmd for running that binary and passes it to a callback function.
After the Go package at `pkgdir` is loaded, it is scanned for exported symbols whose types satisfy the fab.Target interface. Those become named targets runnable from the command line of the generated binary. For the command line, the exported names are transformed from Upper to lower case, and from CamelCase to snake_case.
The arguments for the generated binary are:
- "-v" [optional] run verbosely
- DIR [required] the directory in which rules should run
- OUTFILE [required] the name of a file in which to write the output
...followed by zero or more targets names (downcased and snake_cased as described). If there are zero targets, a target named Default is used, if one is defined; otherwise this is an error.
The output of the binary, placed in OUTFILE, is a JSON-encoded array of error strings produced by the targets that ran. If this are no errors, this will be an empty array.
func LoadTargets ¶
func Run ¶
Run uses Load to load the Go package in the given directory and turn it into an executable binary. It then runs the program as:
PROG [-v] CWD TMPFILE ARGS...
where CWD is the current working directory, TMPFILE is the name of a temporary file where the program sends its output, and ARGS are the additional arguments passed to Run.
Run parses the output in the temporary file: a JSON-encoded list of error strings. If the list is empty, Run returns nil. Otherwise it converts those strings to an error (using multierr.Combine if there are two or more) and returns it.
Types ¶
This section is empty.