Skip to main content

execute

Function execute 

Source
pub fn execute<P: Ports>(
    whole: &TargetGraph,
    graph: &TargetGraph,
    plan: &Plan,
    choices: RunChoices,
    remote_off: &RemoteSwitch,
    ports: &mut PortSet<P>,
) -> Result<Vec<ActionOutcome>>
Expand description

Builds every target of graph as plan says, and returns one outcome per target, in id order.

plan must be the plan made from graph; the value of every build setting is the one plan holds. choices are the choices of the command that makes the run. A target starts once everything it depends on has succeeded. Its key is then finished from what those dependencies produced: when its last build recorded that key and everything it produced is still stored, the target is not run and its outputs are put back in place; otherwise its action runs. What an action produced is stored first, its row recorded after, and its outcome logged whatever it is, so a row never names content that is not held and a failure is never recorded as a result.

An action may leave a regular file or a directory of regular files at each output path. A directory is stored file by file with a manifest of its paths, is put back whole or not at all, and is one digest in the key of every target that depends on it. An output that is anything else, or a directory holding anything else, is refused for one of the reasons of OutputRefusal, and the target fails.

An action that fails is an outcome, not an error. What a failure does to the rest of the build is choices.on_failure’s to say: under OnFailure::Stop nothing more is begun, and under OnFailure::KeepGoing only the targets that depend on the failed one are skipped.

A target’s description is expanded with its command, from the same paths and with the settings plan holds, and handed to the strategy with it; expanding one cannot fail, and it is no part of the key.

whole is the graph of the whole workspace, the one graph was narrowed from, or graph itself. A target of whole that graph leaves out is no part of the build: it has no outcome, no event and no row, and whatever it left in the workspace stays.

Under choices.rerun of Rerun::Tests a test runs whatever its recorded result says, and its new result is recorded; any other target settles as before.

choices.remote says how the remote cache is used. When it reads, a worker asks the remote for a target that must run before it runs it: a usable result the remote holds is stored as a run would store its own and the target ends OutcomeClass::Fetched, without its action running and without being reported as started. A miss runs the action. A call that fails under RemoteFailure::Lenient is reported once through the reporter’s remote call, turns the remote off through remote_off and runs the action; under RemoteFailure::Strict it fails the build. A target whose row stands is restored without asking the remote. With RemotePolicy::OFF the remote is never called.

When it also writes, a worker sends what an action it ran produced to the remote once that is in the content store, and before the target’s row is recorded. A failed action, a target restored from its row and a target fetched from the remote send nothing. A failed upload is handled as a failed lookup is; an input file that changed after its digest was taken is reported through the reporter’s remote call, sends nothing for that target, and leaves the remote on.

remote_off is the caller’s, so that a remote turned off stays off, and is reported once, across every run of one command: a caller that runs twice for one command passes the same switch to both.

The build is shown through the reporter port, always from the calling thread: that it begins, once nothing can refuse it any more; each action as a worker begins it; each target’s outcome, once its event is logged; and the count of the outcomes last, unless the build ends in an error. An outcome is reported with what its action printed, read back from the content store, for a target that ran as for one that is cached.

Under choices.live of LiveOutput::OneAction one running action at a time is shown as it prints: what it writes is reported while it runs, and its outcome is then reported with nothing left to show. The outcome of a target that ends meanwhile is logged at once and reported after that action’s. What is stored and what is returned are the same under either choice.

§Errors

Before anything runs, returns the first failure met, in this order:

  1. Error::ForeignPlan when plan was not made from graph;
  2. whatever the manifest port returns;
  3. Error::UploadUnsandboxed when choices.remote writes to the remote or has it run actions, and the workspace’s actions run bare;
  4. Error::OutputConflict when two outputs of whole would be written to one place;
  5. for the first target, in id order, whose expanded command cannot run or whose environment cannot be read: Error::NoProgram when it names no program, Error::Refused when the program is outside the workspace’s ceiling, and whatever the host port returns when it cannot report the value of a variable the target marks unkeyed.

Once the build is under way, returns the first of: Error::Adapter, naming the remote cache and the call, for a failed call under RemoteFailure::Strict; the log port’s failure to append an event; Error::CanonicalJson for a key that cannot be serialized; Error::Adapter, naming the action cache, for a dependency that succeeded and has no row; the content store’s failure to read the manifest of a recorded output; and its failure to read what a target printed, which is Error::Adapter naming the content store when that content is no longer held. After such an error no port is asked anything more, and no count is reported. Otherwise returns whatever the dispatcher port itself returns.

When the dispatcher returns success and a target has no outcome, returns Error::DispatcherFault naming those targets: the port’s contract is that every task is run and every result reaches the build, so a build never reports success, or a summary, with a target missing. What ended before is recorded and logged already, and stays.