Skip to main content

build_cache_key

Function build_cache_key 

Source
pub fn build_cache_key<F: Filesystem>(
    fs: &F,
    workspace: &Workspace,
    graph: &TaskGraph,
    task: &TaskId,
    host_env: &BTreeMap<EnvVarName, String>,
    predecessor_streams: &BTreeMap<TaskId, PredecessorStreamHashes>,
    algo: HashAlgo,
) -> Result<CacheKey, BuildKeyError>
Expand description

Derive the cache key for one task in workspace per CACHE-001..009.

The function gathers the four canonical ingredients of CACHE-005 to CACHE-008 from the supplied state:

  • The task’s TaskAction, via workspace lookup.
  • The files matched by the task’s inputs patterns, with each file’s content hash under algo. Patterns are resolved through fs.
  • The hard-edge predecessors enumerated from graph, joined with their captured stream hashes from predecessor_streams.
  • The environment contribution: the task’s from_host allow-list resolved against host_env, and the task’s overrides map.

host_env is the caller-snapshotted host environment, restricted to names that pass EnvVarName validation. Only names actually present in the host process appear in the map; a name in the task’s from_host allow-list that does not appear in host_env is treated as absent (CACHE-008’s 0x00 marker). The function does NOT read std::env. Callers SHOULD snapshot the host environment once per haz run and thread the same snapshot into every cache-key derivation in that run.

predecessor_streams is the executor’s running record of which predecessor produced which stream hashes. It MUST contain an entry for every hard-edge predecessor of task per graph, or the function returns BuildKeyError::PredecessorStreamsMissing.

§Errors

See BuildKeyError for the failure modes.