Skip to content

Commit f99ac17

Browse files
branchseerclaude
andcommitted
Resolve vt and vtt runtime paths using compile-time manifest diffing
Use `join(runtime_manifest, diff(compile_time_bin, compile_time_manifest))` consistently for both binaries. Add build.rs to vite_task_plan to emit compile-time binary paths. Don't assume vt and vtt share the same directory. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bb14537 commit f99ac17

File tree

35 files changed

+129
-74
lines changed

35 files changed

+129
-74
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ vite_task = { path = "crates/vite_task" }
147147
vite_task_bin = { path = "crates/vite_task_bin" }
148148
vite_task_graph = { path = "crates/vite_task_graph" }
149149
vite_task_plan = { path = "crates/vite_task_plan" }
150-
vite_task_tools = { path = "crates/vite_task_tools" }
151150
vite_workspace = { path = "crates/vite_workspace" }
152151
vt100 = "0.16.2"
153152
wax = "0.7.0"

crates/vite_task_bin/tests/e2e_snapshots/main.rs

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ fn get_shell_exe() -> std::path::PathBuf {
5858
}
5959
}
6060

61+
/// Resolve a binary's runtime path from its compile-time path.
62+
///
63+
/// Computes `join(runtime_manifest, diff(compile_time_bin, compile_time_manifest))`.
64+
/// This handles cases where compile-time and runtime paths differ (e.g. CI caches).
6165
#[expect(
6266
clippy::disallowed_types,
6367
reason = "PathBuf required for compile-time/runtime binary path remapping"
@@ -68,28 +72,38 @@ fn resolve_runtime_bin_path(compile_time_bin_path: &str) -> AbsolutePathBuf {
6872
let runtime_manifest =
6973
std::path::PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap());
7074

71-
let compile_time_repo_root = compile_time_manifest.parent().unwrap().parent().unwrap();
72-
let runtime_repo_root = runtime_manifest.parent().unwrap().parent().unwrap();
73-
74-
let relative_bin = diff_paths(&compile_time_bin, compile_time_repo_root).unwrap_or_else(|| {
75+
let relative_bin = diff_paths(&compile_time_bin, &compile_time_manifest).unwrap_or_else(|| {
7576
panic!(
76-
"Failed to diff binary path. bin={} repo_root={}",
77+
"Failed to diff binary path. bin={} manifest={}",
7778
compile_time_bin.display(),
78-
compile_time_repo_root.display(),
79+
compile_time_manifest.display(),
7980
)
8081
});
81-
let runtime_bin = runtime_repo_root.join(&relative_bin);
82+
let runtime_bin = runtime_manifest.join(&relative_bin);
8283

83-
assert!(
84-
runtime_bin.exists(),
85-
"Remapped binary path does not exist: {} (relative: {})",
86-
runtime_bin.display(),
87-
relative_bin.display(),
88-
);
84+
let runtime_bin = runtime_bin.canonicalize().unwrap_or_else(|_| {
85+
panic!(
86+
"Remapped binary path does not exist: {} (relative: {})",
87+
runtime_bin.display(),
88+
relative_bin.display(),
89+
)
90+
});
8991

9092
AbsolutePathBuf::new(runtime_bin).unwrap()
9193
}
9294

95+
/// Derive the compile-time path of `vtt` from the compile-time path of `vt`.
96+
/// Both binaries are workspace binaries built into the same target directory.
97+
#[expect(
98+
clippy::disallowed_types,
99+
reason = "Path/String required for compile-time binary path derivation"
100+
)]
101+
fn compile_time_vtt_path() -> std::string::String {
102+
let vt = std::path::Path::new(COMPILE_TIME_VT_PATH);
103+
let vtt_name = if cfg!(windows) { "vtt.exe" } else { "vtt" };
104+
vt.with_file_name(vtt_name).to_str().unwrap().to_owned()
105+
}
106+
93107
#[derive(serde::Deserialize, Debug)]
94108
#[serde(untagged)]
95109
enum Step {
@@ -267,15 +281,13 @@ fn run_case_inner(tmpdir: &AbsolutePath, fixture_path: &std::path::Path, fixture
267281
// Get shell executable for running steps
268282
let shell_exe = get_shell_exe();
269283

270-
// Prepare PATH for e2e tests: include vt binary directory (vtt is in the same directory
271-
// since all workspace binaries are built into the same target/<profile>/ directory).
284+
// Prepare PATH for e2e tests: include vt and vtt binary directories.
285+
let bin_dirs: [Arc<OsStr>; 2] = [COMPILE_TIME_VT_PATH, &compile_time_vtt_path()].map(|p| {
286+
let bin = resolve_runtime_bin_path(p);
287+
Arc::<OsStr>::from(bin.parent().unwrap().as_path().as_os_str())
288+
});
272289
let e2e_env_path = join_paths(
273-
std::iter::once({
274-
let vt_path = resolve_runtime_bin_path(COMPILE_TIME_VT_PATH);
275-
let vt_dir = vt_path.parent().unwrap();
276-
vt_dir.as_path().as_os_str().into()
277-
})
278-
.chain(
290+
bin_dirs.into_iter().chain(
279291
// the existing PATH
280292
split_paths(&env::var_os("PATH").unwrap())
281293
.map(|path| Arc::<OsStr>::from(path.into_os_string())),

crates/vite_task_plan/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ clap = { workspace = true, features = ["derive"] }
3636
copy_dir = { workspace = true }
3737
cow-utils = { workspace = true }
3838
insta = { workspace = true, features = ["glob", "json", "redactions", "filters", "ron"] }
39+
pathdiff = { workspace = true }
3940
serde_json = { workspace = true }
4041
tempfile = { workspace = true }
4142
tokio = { workspace = true, features = ["rt", "macros"] }

crates/vite_task_plan/build.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![expect(clippy::disallowed_types, reason = "build script uses std types")]
2+
3+
fn main() {
4+
// OUT_DIR is something like `<target>/<profile>/build/<crate>-<hash>/out`.
5+
// Navigate up to `<target>/<profile>` to find workspace binaries.
6+
let out_dir = std::env::var("OUT_DIR").unwrap();
7+
let out_path = std::path::Path::new(&out_dir);
8+
// out -> build/<crate>-<hash> -> build -> <profile>
9+
let profile_dir = out_path.parent().unwrap().parent().unwrap().parent().unwrap();
10+
11+
for (env_name, bin_name) in [
12+
("COMPILE_TIME_VT_PATH", if cfg!(windows) { "vt.exe" } else { "vt" }),
13+
("COMPILE_TIME_VTT_PATH", if cfg!(windows) { "vtt.exe" } else { "vtt" }),
14+
] {
15+
println!("cargo::rustc-env={env_name}={}", profile_dir.join(bin_name).display());
16+
}
17+
}

crates/vite_task_plan/tests/plan_snapshots/fixtures/additional-env/snapshots/query - env-test synthetic task in user task.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/additional-env
7676
],
7777
"all_envs": {
7878
"NO_COLOR": "1",
79-
"PATH": "<workspace>/node_modules/.bin:<tools>",
79+
"PATH": "<workspace>/node_modules/.bin:<tools>:<tools>",
8080
"TEST_VAR": "hello_world"
8181
},
8282
"cwd": "<workspace>/"

crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-override/snapshots/query - --cache does not override per-task cache false.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-overri
4444
],
4545
"all_envs": {
4646
"NO_COLOR": "1",
47-
"PATH": "<workspace>/node_modules/.bin:<tools>"
47+
"PATH": "<workspace>/node_modules/.bin:<tools>:<tools>"
4848
},
4949
"cwd": "<workspace>/"
5050
}

crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-override/snapshots/query - --cache enables script caching.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-overri
7676
],
7777
"all_envs": {
7878
"NO_COLOR": "1",
79-
"PATH": "<workspace>/node_modules/.bin:<tools>"
79+
"PATH": "<workspace>/node_modules/.bin:<tools>:<tools>"
8080
},
8181
"cwd": "<workspace>/"
8282
}

crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-override/snapshots/query - --cache enables task caching even when cache.tasks is false.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-overri
7676
],
7777
"all_envs": {
7878
"NO_COLOR": "1",
79-
"PATH": "<workspace>/node_modules/.bin:<tools>"
79+
"PATH": "<workspace>/node_modules/.bin:<tools>:<tools>"
8080
},
8181
"cwd": "<workspace>/"
8282
}

crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-override/snapshots/query - --cache on task with per-task cache true enables caching.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-cli-overri
7676
],
7777
"all_envs": {
7878
"NO_COLOR": "1",
79-
"PATH": "<workspace>/node_modules/.bin:<tools>"
79+
"PATH": "<workspace>/node_modules/.bin:<tools>:<tools>"
8080
},
8181
"cwd": "<workspace>/"
8282
}

0 commit comments

Comments
 (0)