Skip to content

Commit 5fda98a

Browse files
authored
refactor(cache): rename execute cache_base_path to workspace_root (#434)
## Why `crates/vite_task` had two unrelated fields both named `cache_base_path`, which was a trap for anyone reading across the cache code: - In [`session/mod.rs`](crates/vite_task/src/session/mod.rs), it meant the **cache directory** — the parent of all `vN` schema-version subdirs. - In [`execute/mod.rs`](crates/vite_task/src/session/execute/mod.rs), it meant the **workspace root** — the directory that relative paths stored in cache entries (inputs, outputs, archives) are resolved against. It is literally set to `self.workspace_path`. Same name, opposite halves of the cache machinery (where the cache lives vs. what cached paths point at). ## What This PR renames the `execute` one to `workspace_root`, naming it for the value it actually holds and disambiguating it from the cache directory. The doc comment is updated to spell out the role. All 10 references (the `ExecutionContext` field and the `execute_spawn` parameter it feeds) are renamed. The `session` field was renamed to `cache_root` in the parent PR (#433), so after both PRs the two concepts read clearly: | Field | Where | Meaning | | --- | --- | --- | | `cache_root` | session | parent of all `vN` cache dirs | | `cache_path` | session | this build's versioned dir (`…/v13`) | | `workspace_root` | execute | dir that cached relative paths anchor to | | `cache_dir` | execute | where cache files (db, archives) are stored | Pure rename + doc tidy; no behavior change. `cargo check -p vite_task` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 7ed8c9d commit 5fda98a

1 file changed

Lines changed: 31 additions & 33 deletions

File tree

  • crates/vite_task/src/session/execute

crates/vite_task/src/session/execute/mod.rs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ struct ExecutionContext<'a> {
7373
reporter: &'a RefCell<Box<dyn GraphExecutionReporter>>,
7474
/// The execution cache for looking up and storing cached results.
7575
cache: &'a ExecutionCache,
76-
/// Base path for resolving relative paths in cache entries.
77-
/// Typically the workspace root.
78-
cache_base_path: &'a Arc<AbsolutePath>,
76+
/// Workspace root that relative paths in cache entries (inputs, outputs,
77+
/// archives) are resolved against.
78+
workspace_root: &'a Arc<AbsolutePath>,
7979
/// Directory where cache files (db, archives) are stored.
8080
cache_dir: &'a AbsolutePath,
8181
/// Public-facing program name (e.g. `vp`), used in user-facing error
@@ -241,7 +241,7 @@ impl ExecutionContext<'_> {
241241
leaf_reporter,
242242
spawn_execution,
243243
self.cache,
244-
self.cache_base_path,
244+
self.workspace_root,
245245
self.cache_dir,
246246
self.program_name,
247247
self.fast_fail_token.clone(),
@@ -339,7 +339,7 @@ pub async fn execute_spawn(
339339
mut leaf_reporter: Box<dyn LeafExecutionReporter>,
340340
spawn_execution: &SpawnExecution,
341341
cache: &ExecutionCache,
342-
cache_base_path: &Arc<AbsolutePath>,
342+
workspace_root: &Arc<AbsolutePath>,
343343
cache_dir: &AbsolutePath,
344344
program_name: &str,
345345
fast_fail_token: CancellationToken,
@@ -355,7 +355,7 @@ pub async fn execute_spawn(
355355
// Compute globbed inputs from positive globs at execution time
356356
// Globs are already workspace-root-relative (resolved at task graph stage)
357357
let globbed_inputs = match compute_globbed_inputs(
358-
cache_base_path,
358+
workspace_root,
359359
&cache_metadata.input_config.positive_globs,
360360
&cache_metadata.input_config.negative_globs,
361361
) {
@@ -370,7 +370,7 @@ pub async fn execute_spawn(
370370
}
371371
};
372372

373-
match cache.try_hit(cache_metadata, &globbed_inputs, cache_base_path).await {
373+
match cache.try_hit(cache_metadata, &globbed_inputs, workspace_root).await {
374374
Ok(Ok(cached)) => (
375375
// Cache hit — we can replay the cached outputs
376376
CacheStatus::Hit { replayed_duration: cached.duration },
@@ -421,7 +421,7 @@ pub async fn execute_spawn(
421421
// I/O error so users know to clear the cache.
422422
if let Some(ref archive_name) = cached.output_archive {
423423
let archive_path = cache_dir.join(archive_name.as_str());
424-
if let Err(err) = archive::extract_output_archive(cache_base_path, &archive_path) {
424+
if let Err(err) = archive::extract_output_archive(workspace_root, &archive_path) {
425425
let err = err.context(vite_str::format!(
426426
"failed to restore cached outputs from {}; the archive may have been deleted \
427427
or corrupted. Run `{program_name} cache clean` to clear the cache.",
@@ -595,7 +595,7 @@ pub async fn execute_spawn(
595595
#[cfg(fspy)]
596596
{
597597
outcome.path_accesses.as_ref().zip(fspy_negatives.as_deref()).map(|(raw, negs)| {
598-
let tracked = TrackedPathAccesses::from_raw(raw, cache_base_path, negs);
598+
let tracked = TrackedPathAccesses::from_raw(raw, workspace_root, negs);
599599
let read_write_overlap = tracked
600600
.path_reads
601601
.keys()
@@ -638,31 +638,29 @@ pub async fn execute_spawn(
638638
// the correct post-exec hash.
639639
let empty_path_reads = HashMap::default();
640640
let path_reads = tracking.as_ref().map_or(&empty_path_reads, |t| &t.path_reads);
641-
match PostRunFingerprint::create(path_reads, cache_base_path, &globbed_inputs) {
641+
match PostRunFingerprint::create(path_reads, workspace_root, &globbed_inputs) {
642642
Ok(post_run_fingerprint) => {
643643
// Collect output files and create archive
644-
let output_archive =
645-
match collect_and_archive_outputs(metadata, cache_base_path, cache_dir)
646-
{
647-
Ok(archive) => archive,
648-
Err(err) => {
649-
let result = (
650-
CacheUpdateStatus::NotUpdated(
651-
CacheNotUpdatedReason::CacheDisabled,
652-
),
653-
Some(ExecutionError::Cache {
654-
kind: CacheErrorKind::Update,
655-
source: err,
656-
}),
657-
);
658-
leaf_reporter.finish(
659-
Some(outcome.exit_status),
660-
result.0,
661-
result.1,
662-
);
663-
return SpawnOutcome::Spawned(outcome.exit_status);
664-
}
665-
};
644+
let output_archive = match collect_and_archive_outputs(
645+
metadata,
646+
workspace_root,
647+
cache_dir,
648+
) {
649+
Ok(archive) => archive,
650+
Err(err) => {
651+
let result = (
652+
CacheUpdateStatus::NotUpdated(
653+
CacheNotUpdatedReason::CacheDisabled,
654+
),
655+
Some(ExecutionError::Cache {
656+
kind: CacheErrorKind::Update,
657+
source: err,
658+
}),
659+
);
660+
leaf_reporter.finish(Some(outcome.exit_status), result.0, result.1);
661+
return SpawnOutcome::Spawned(outcome.exit_status);
662+
}
663+
};
666664

667665
let new_cache_value = CacheEntryValue {
668666
post_run_fingerprint,
@@ -772,7 +770,7 @@ impl Session<'_> {
772770
let execution_context = ExecutionContext {
773771
reporter: &reporter,
774772
cache,
775-
cache_base_path: &self.workspace_path,
773+
workspace_root: &self.workspace_path,
776774
cache_dir: &self.cache_path,
777775
program_name: self.program_name.as_str(),
778776
fast_fail_token: CancellationToken::new(),

0 commit comments

Comments
 (0)