bound

package
v0.0.57 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bound runs a harness binding's commands: one command line, as a subprocess of the engine with a deadline, its output captured. The command runs in a process group of its own, and the whole group is killed at the deadline or when the caller's context ends, so nothing the command started can make the engine wait past it. It works on Linux and macOS; elsewhere Run refuses.

It also says what goes into a bound command: Fill fills a line's placeholders and Environ builds the environment a run's commands get, for the start command, which runs in the engine's pty, as for the ones Run runs. And it reads what a result command printed: Outcome.Result.

Index

Constants

View Source
const MaxStdout = 64 << 10

MaxStdout is how many bytes of a command's standard output are kept: its start.

Variables

This section is empty.

Functions

func Environ

func Environ(base []string, run, change, spec string) []string

Environ returns a new environment for a run's commands: base without the agent session's variables, the terminal's and any earlier PHYSA_RUN, PHYSA_CHANGE or PHYSA_SPEC, then TERM=xterm-256color and the run, change and spec file added. Every other variable is kept as it is.

func Fill

func Fill(line, change, run string) string

Fill returns line with every {change} replaced by change, as the Change: trailer names it (<pursuit>/<change>), and every {run} by run, the run's number. A value made only of letters, digits, '_', '.', '/' and '-' goes in as written, so a placeholder inside a quoted argument still works; any other value is single-quoted, each ' in it written as quote, backslash, quote, quote. Pursuit slugs and change names are slugs today, so the quoting is a defence.

Types

type Command

type Command struct {
	// Line is the command line, run as /bin/sh -c Line.
	Line string
	// Dir is the directory the command runs in.
	Dir string
	// Env is the command's whole environment, as KEY=value lines; nothing is
	// taken from the engine's own.
	Env []string
	// Timeout is the command's deadline, from its start.
	Timeout time.Duration
	// Tail is how many bytes of the command's standard error are kept: its
	// end.
	Tail int
}

Command is one bound command line to run.

type Outcome

type Outcome struct {
	Code   int
	Stdout []byte
	Stderr string
	Cut    bool
	Err    error
}

Outcome is how a command ended. Err is set when it could not be run at all. Cut is set when it was killed, at its deadline or because the caller's context ended; Code then means nothing.

func Run

func Run(ctx context.Context, c Command) Outcome

Run runs c and waits for it. At c.Timeout, or when ctx ends, it kills the command's whole process group and returns an Outcome with Cut set. A process the command left behind holding its output delays Run by at most a second: the output is then closed and what was read is returned.

func (Outcome) Result

func (o Outcome) Result() (Result, string)

Result reads a result command's outcome: the result it printed, or the reason it printed none: it was cut at its deadline, could not be run, exited with a code other than 0, or its standard output is not one JSON object. Keys it does not know are ignored. Whether the branch, commit and pr are acceptable is the store's to say.

type Result

type Result struct {
	Branch string `json:"branch"`
	Commit string `json:"commit"`
	PR     string `json:"pr"`
}

Result is what a bound result command printed: where a run's work ended up.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL