Skip to main content

Crate buildl_core

Crate buildl_core 

Source
Expand description

Domain data, ports, and pure pipeline logic for the buildl build system.

This crate is the centre buildl’s other crates depend on. It depends on no other buildl crate, on no Lua runtime, and on no filesystem, process, thread, network, environment or clock API, so every pipeline flow can be exercised against in-memory implementations of its ports.

§Responsibilities

  • The domain values the pipeline phases hand to one another.
  • The ports: traits through which the pipeline reaches build-file evaluation, storage, hashing, and execution.
  • The pure logic of each phase: Load → Resolve → Plan → Execute → Record.

§Non-responsibilities

  • Implementing any port. Concrete adapters live in the buildl-lua and buildl crates.
  • Reading or writing anything. A value arrives from a caller or through a port.

§Where things live

ModuleHolds
errorthe one error enum and the crate-wide Result alias
typesthe validated domain values — names, identities, instants, declarations and the plugins, if any, whose code made each, the target graph, action keys, cache rows, the ceiling, the plugins a workspace names and what it lets each have, the plan, ready actions, outcomes, log events, what one run was asked for — and the as-written values a build file stages
jsonthe one canonical serializer every byte of output goes through, and the one reader that takes such bytes back
portsevery trait in the crate: the ports through which everything outside it is reached, and the bundle that names one implementation of each, with the set that holds one instance of each
loadLoad, the first phase: build files, and the last result of each discovery target, to validated, sorted declarations
resolveResolve, the second phase: declarations to the target graph, that graph cut down to the targets one run was asked for, and the targets a query reaches
planPlan, the third phase: the target graph to a verdict per target, with what the build wants
executeExecute and Record, the last phase: a plan to one outcome per target, each result recorded as the last step of its action and reported once it is logged
placementwhere every output lives and what a command’s placeholders stand for once they are placed; used by Plan, Execute and verify, and not a phase
grantsthe build’s authority: which programs a build made, everything a build wants, the wants a plugin’s targets may not have, which plugins are behind each want, and the approver’s answer; not a phase
pipelinethe phases run in sequence over one bundle of ports, one method per command, and the commands that need only some of the ports as functions over those ports alone: the three that reach only build files and the state that holds discovery results, doctor, and log
historythe read side of the build log: the newest run of a target that left output
verifyverify, which serves one command and is not a phase: cached targets put back in place, a sample of them re-run, and each re-run compared with what was cached
watchwhat a watching run decides from the changes it sees: what a batch of changed paths starts, and the loop that builds, waits and reacts; serves one command and is not a phase
discoverythe last result of each discovery target, read back from the build log and the content store for a second load of the build files; several pipeline functions use it, and it is not a phase
suggestthe nearest declared name to one that names nothing, for any module that refuses a name

Each phase has its own module, named for the phase. Five rules keep that arrangement navigable:

  1. No phase module names another. Phases communicate through values, and pipeline owns the sequence, so a phase that imported the next would be bypassing it. history, verify, watch and discovery are not phases: each serves a command, or several, and may name a phase’s internals. placement and grants are neither: several phases name them, and they name no phase.
  2. types holds no decisions between different concepts. A type there may decide things about its own kind — Timestamp::duration_since decides whether two instants of the same type went backwards, Label::resolve decides which of three reference forms it was handed — but logic needing two different concepts to decide something belongs to the phase that decides it.
  3. One concept, one type. types is the only place a domain value is declared, so nothing downstream invents a second spelling of a name that already exists.
  4. ports never gains a production implementation. A real implementation means doing I/O, which this crate does not do; the only implementations here are test fakes.
  5. Every phase module is exercised against in-memory implementations of the ports it uses. Its pure helpers, which need no port, are tested in the file under test; its flows through a port are tested in this crate’s integration tests, against fakes built from the public API alone, so anything a fake does an adapter crate can do too.

§Status

Pre-release. Load is implemented: load walks the workspace’s build files through the DeclarationSource port and returns their declarations validated and sorted, and Pipeline::check runs it twice to catch a build file that declares differently on each evaluation. Resolve is implemented: resolve turns those declarations into a TargetGraph, refusing a name declared twice, a reference that names nothing or the wrong kind of thing, and a dependency cycle; Pipeline::graph runs both phases. Plan is implemented: plan refuses a build that wants more than its workspace’s Ceiling allows, gives every target an ActionKey from what the ports report, and compares it with the key the target’s last build recorded, so each target is clean, dirty with a reason, or conditional on a dependency’s output; the Plan also holds the value of every build setting for the run, which is where Execute reads them; Pipeline::plan runs all three phases. Execute and Record are implemented: execute gives every output a path under the workspace’s output directory, expands every command and holds its program to the Ceiling before anything runs, then runs the plan through the Dispatcher port. A target whose finished key equals the one its last build recorded, with every recorded output still in the ContentStore, is cached; any other runs through the ExecStrategy port. An output is a regular file or a directory of regular files: its OutputManifest is stored beside the files it names, and the digest of that manifest is the output’s digest. Recording is the last step of each action — its outputs into the content store, then its CacheRow, then one OutcomeEvent in the EventLog — so a failure leaves no row. Pipeline::build runs all four phases and returns one ActionOutcome per target; what a failure does to the rest of the build is the caller’s OnFailure. Pipeline::build and Pipeline::test put the plan’s wanted set to the Approver port after planning, and negotiate turns a denial into Error::NotApproved: a refusal runs nothing, even when every target is cached. Pipeline::plan never asks.

A plugin’s declarations carry an Origin: the chain of PluginRefs, outermost first, whose code made them, and a graph Node keeps it. plan holds every want of a node with plugins to each plugin in its chain, the plugin’s manifest and the workspace’s PluginCap for it, before it asks the Ceiling: a want outside either is Error::PluginRefused, and so is a target that reaches the network when the cap does not allow it. An Attribution says which plugins’ targets are behind each want; the plan, the Approver and a Checkup carry it for display, and it is no part of an ActionKey.

A run works on the whole workspace or on the targets a Scope names, with everything they depend on: narrow cuts the graph down before Plan, so Pipeline::plan and Pipeline::build neither plan nor build a target outside it, while two outputs claiming one place are still refused across the whole workspace. A build writes down the graph of the whole workspace through the GraphRecord port before it plans, and is shown through the Reporter port as it goes: that it began, each action as a worker begins it, each target’s outcome with what its action printed — for a cached target as for one that ran — and the count last. Under LiveOutput::OneAction one running action at a time is shown as it prints. An action a signal ended fails its target as OutcomeClass::Killed, and an input that is not a regular file is refused by Plan from what the Digester reports as an InputStat. Hasher takes the digest of bytes handed in pieces. A Query, deps or rdeps of one target, asks which targets that target needs or which need it: reach answers it over a TargetGraph, in the Direction it names. pipeline::check, pipeline::graph and pipeline::query run the three commands that reach only build files for a caller that holds a DeclarationSource, a RunHistory and a ContentStore. A workspace that declares a discovery target is loaded again with the last result of each, read from those two ports, and the second load may not declare different discovery targets than the first (Error::DiscoveryChanged); Pipeline::plan, Pipeline::verify and gc do the same, and Plan::stale_discovery names the discovery targets a plan finds not clean. Pipeline::build and Pipeline::test build the discovery targets first, as a build of just them, and load the second time with the results that leaves. A LoggedRun reads back from the build log through RunHistory, and pipeline::log returns a target’s last run with what it printed. pipeline::doctor reports what a workspace’s build wants against its ceiling as a Checkup, every want outside the ceiling listed and none refused, for a caller that holds a DeclarationSource, a Manifest, a RunHistory and a ContentStore.

A target no cache row stands for may be served by a cache other machines share, reached through the RemoteCache port. Pipeline::set_remote sets the RemotePolicy of a build and a test run: a RemoteUse, a RemoteFailure and a RemoteExecution. With the remote on, a worker asks the port for the result of a RemoteAction built from the ready action before it runs anything. A RemoteHit is used only when it is a clean success for the declared outputs; every blob is checked against its digest and stored before the row is written, and the target ends as OutcomeClass::Fetched. A miss runs the action, and under RemoteUse::ReadWrite a run that succeeded is uploaded, its blobs read from the content store through BlobSource. A failed call warns once and turns the remote off for the rest of the command under RemoteFailure::Lenient, and fails the command under RemoteFailure::Strict; a result that is not usable is a failure of the same kind. NoRemote is the port of a workspace that names none, and every command but build and test never calls it.

A verify compares what cached targets produce when re-run with what was cached. Pipeline::verify plans as a build does, asks the Approver as a build does, then verify puts the outputs of every target whose last build still stands back in place and re-runs a Sample of those targets through the ExecStrategy port. A Verification holds a Check per target it looked at: the re-run reproduced the outputs, differed at the first output and file an OutputDifference names, failed, or was never begun because a target it needs was not put back. It counts the targets with nothing cached and the ones the sample left out. A verify records no row, forgets none, logs no event and reports nothing, and no output of a re-run is put in place.

This file holds only module declarations and re-exports, so it carries no logic to unit-test.

Re-exports§

pub use error::ActionFound;
pub use error::DeclarationField;
pub use error::DeclarationSite;
pub use error::DeclaredKind;
pub use error::Error;
pub use error::EvaluationFailure;
pub use error::EvaluationLimit;
pub use error::NameKind;
pub use error::PortName;
pub use error::RemoteFlagConflict;
pub use error::RemoteVariable;
pub use error::Result;
pub use error::TreeFault;
pub use error::UnsandboxedRemote;
pub use execute::ensure_sandboxed_remote;
pub use execute::execute;
pub use grants::negotiate;
pub use history::LastRun;
pub use load::load;
pub use pipeline::Collected;
pub use pipeline::Pipeline;
pub use pipeline::Shown;
pub use pipeline::doctor;
pub use pipeline::doctor;
pub use pipeline::gc;
pub use pipeline::gc;
pub use pipeline::log;
pub use pipeline::log;
pub use plan::plan;
pub use ports::ActionCache;
pub use ports::Approver;
pub use ports::BlobSource;
pub use ports::Changes;
pub use ports::Clock;
pub use ports::ContentStore;
pub use ports::Cycles;
pub use ports::DeclarationSource;
pub use ports::Digester;
pub use ports::Dispatcher;
pub use ports::EventLog;
pub use ports::ExecStrategy;
pub use ports::GraphRecord;
pub use ports::Host;
pub use ports::IgnoreRules;
pub use ports::Manifest;
pub use ports::NoRemote;
pub use ports::NothingIgnored;
pub use ports::PortSet;
pub use ports::Ports;
pub use ports::RemoteCache;
pub use ports::Reporter;
pub use ports::RunHistory;
pub use ports::StatCache;
pub use ports::Sweep;
pub use ports::ToolResolver;
pub use ports::WatchReport;
pub use resolve::narrow;
pub use resolve::narrow;
pub use resolve::reach;
pub use resolve::reach;
pub use resolve::resolve;
pub use types::Action;
pub use types::ActionKey;
pub use types::ActionOutcome;
pub use types::Alias;
pub use types::Approval;
pub use types::ApproverMode;
pub use types::Argument;
pub use types::Attribution;
pub use types::Blob;
pub use types::BuildFile;
pub use types::Built;
pub use types::CacheRow;
pub use types::Captured;
pub use types::Ceiling;
pub use types::ChangeBatch;
pub use types::ChangedPath;
pub use types::Channel;
pub use types::Check;
pub use types::Checkup;
pub use types::Command;
pub use types::CommitId;
pub use types::Cycle;
pub use types::Declaration;
pub use types::DeclarationOrder;
pub use types::Declared;
pub use types::DecodedTree;
pub use types::DenialReason;
pub use types::DepProducts;
pub use types::Description;
pub use types::Diagnostic;
pub use types::Difference;
pub use types::Digest;
pub use types::Direction;
pub use types::Directory;
pub use types::DirtyReason;
pub use types::Discovered;
pub use types::EntryChange;
pub use types::EntryKind;
pub use types::EntryName;
pub use types::EnvMark;
pub use types::EnvName;
pub use types::EnvValue;
pub use types::Evaluated;
pub use types::Executed;
pub use types::Execution;
pub use types::Exit;
pub use types::ExpandedDescription;
pub use types::FieldName;
pub use types::FileChange;
pub use types::FileMode;
pub use types::FileStat;
pub use types::Found;
pub use types::FoundEntry;
pub use types::FoundKind;
pub use types::Freshness;
pub use types::GitUrl;
pub use types::Hasher;
pub use types::HeaderName;
pub use types::HostPath;
pub use types::IgnoredPath;
pub use types::Ignoring;
pub use types::InfraKind;
pub use types::InputDigest;
pub use types::InputKind;
pub use types::InputStat;
pub use types::InstanceName;
pub use types::Isolation;
pub use types::KeyComponents;
pub use types::Label;
pub use types::LiveOutput;
pub use types::LiveSink;
pub use types::Loaded;
pub use types::LogLine;
pub use types::LoggedRun;
pub use types::MachineFolders;
pub use types::NetworkAccess;
pub use types::Node;
pub use types::NodeId;
pub use types::OnFailure;
pub use types::Origin;
pub use types::OutcomeClass;
pub use types::OutcomeEvent;
pub use types::OutputDifference;
pub use types::OutputManifest;
pub use types::OutputName;
pub use types::OutputPath;
pub use types::OutputRefusal;
pub use types::OutputSource;
pub use types::OwnComponents;
pub use types::Plan;
pub use types::PlannedKey;
pub use types::Platform;
pub use types::PlatformProperties;
pub use types::PlatformPropertyName;
pub use types::PluginCap;
pub use types::PluginChain;
pub use types::PluginName;
pub use types::PluginNetwork;
pub use types::PluginRef;
pub use types::PluginSource;
pub use types::PluginVersion;
pub use types::PluginViolation;
pub use types::Produced;
pub use types::Program;
pub use types::Provenance;
pub use types::Purpose;
pub use types::Query;
pub use types::RawOutcome;
pub use types::Reaction;
pub use types::ReadyAction;
pub use types::Reference;
pub use types::RemoteAction;
pub use types::RemoteCall;
pub use types::RemoteContent;
pub use types::RemoteExecution;
pub use types::RemoteFailure;
pub use types::RemoteFile;
pub use types::RemoteHit;
pub use types::RemoteJobs;
pub use types::RemoteNotice;
pub use types::RemoteOutput;
pub use types::RemoteOutputDirectory;
pub use types::RemoteOutputFile;
pub use types::RemotePlatform;
pub use types::RemotePolicy;
pub use types::RemoteScheme;
pub use types::RemoteSettings;
pub use types::RemoteSettingsBuilder;
pub use types::RemoteSwitch;
pub use types::RemoteTree;
pub use types::RemoteTreeFile;
pub use types::RemoteUpload;
pub use types::RemoteUrl;
pub use types::RemoteUse;
pub use types::Rerun;
pub use types::RetryCount;
pub use types::Rev;
pub use types::RootPath;
pub use types::Rule;
pub use types::RunChoices;
pub use types::Sample;
pub use types::Scope;
pub use types::Setting;
pub use types::SettingName;
pub use types::SettingValue;
pub use types::SourcePath;
pub use types::StagedAlias;
pub use types::StagedDeclaration;
pub use types::StagedEnv;
pub use types::StagedFile;
pub use types::StagedItem;
pub use types::StagedMark;
pub use types::StagedRule;
pub use types::StagedSetting;
pub use types::StagedSubdir;
pub use types::StagedTarget;
pub use types::StatEntry;
pub use types::StoredFile;
pub use types::Summary;
pub use types::TagName;
pub use types::Tally;
pub use types::Target;
pub use types::TargetGraph;
pub use types::TargetName;
pub use types::TargetRole;
pub use types::Timeout;
pub use types::Timestamp;
pub use types::TokenSource;
pub use types::ToolIdentity;
pub use types::Tree;
pub use types::TreeEntry;
pub use types::TreePath;
pub use types::Trigger;
pub use types::Turn;
pub use types::Unfinished;
pub use types::Uploaded;
pub use types::Verdict;
pub use types::Verification;
pub use types::Want;
pub use types::WantedSet;
pub use types::WatchLayout;
pub use types::Watched;
pub use types::Workers;
pub use types::Workspace;
pub use types::Written;
pub use verify::verify;
pub use watch::react;
pub use watch::watch;

Modules§

error
The crate’s one error type and the Result alias every fallible call returns.
execute
Execute, the fourth phase: from a plan to a finished build.
grants
Grants: the build’s authority — which programs a build made, everything a build wants, and the approver’s answer.
history
The read side of the build log: which of a target’s logged runs a reader is shown.
json
The one way a value in this crate becomes JSON bytes, and the one way such bytes become a value again.
load
Load, the first phase: from a workspace root to the validated declarations of every build file it reaches.
pipeline
The pipeline: the phases run in sequence, each command a prefix of that sequence.
plan
Plan, the third phase: from the target graph to what a build of it would do.
ports
The ports: the traits through which this crate reaches everything outside itself.
resolve
Resolve, the second phase: from the declarations of every build file to the target graph.
types
The domain vocabulary: the validated values the pipeline’s phases hand to one another, and the as-written values a build file stages before they are validated.
verify
Verify: re-running a workspace’s cached targets and comparing what they produce.
watch
What a watching run decides from the changes it sees.