Skip to content

Commit 964405d

Browse files
committed
test: Add support for cargo's build-dir v2 layout
1 parent 5042b96 commit 964405d

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/test/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,8 +1130,23 @@ fn rustfmt() -> PathBuf {
11301130
let mut me = env::current_exe().expect("failed to get current executable");
11311131
// Chop of the test name.
11321132
me.pop();
1133-
// Chop off `deps`.
1134-
me.pop();
1133+
1134+
// Handle Cargo's old and new filesystem layouts
1135+
// * v1: `target/<profile>/deps/test-bin-[HASH][EXE]`
1136+
// * v2: `target/<profile>/build/<pkgname>/[HASH]/out/test-bin-[HASH][EXE]`
1137+
if me.ends_with("deps") {
1138+
// Chop off `deps`.
1139+
me.pop();
1140+
} else if me.ends_with("out") {
1141+
// Chop off `out`.
1142+
me.pop();
1143+
// Chop off `<hash>`.
1144+
me.pop();
1145+
// Chop off `<pkgname>`.
1146+
me.pop();
1147+
// Chop off `build`.
1148+
me.pop();
1149+
}
11351150

11361151
me.push("rustfmt");
11371152
assert!(

tests/cargo-fmt/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@ use rustfmt_config_proc_macro::rustfmt_only_ci_test;
1010
fn cargo_fmt(args: &[&str]) -> (String, String) {
1111
let mut bin_dir = env::current_exe().unwrap();
1212
bin_dir.pop(); // chop off test exe name
13+
14+
// Handle Cargo's old and new filesystem layouts
15+
// * v1: `target/<profile>/deps/test-bin-[HASH][EXE]`
16+
// * v2: `target/<profile>/build/<pkgname>/[HASH]/out/test-bin-[HASH][EXE]`
1317
if bin_dir.ends_with("deps") {
1418
bin_dir.pop();
19+
} else if bin_dir.ends_with("out") {
20+
bin_dir.pop(); // chop off `out`
21+
bin_dir.pop(); // chop off `<hash>`
22+
bin_dir.pop(); // chop off `<pkgname>`
23+
bin_dir.pop(); // chop off `build`
1524
}
1625
let cmd = bin_dir.join(format!("cargo-fmt{}", env::consts::EXE_SUFFIX));
1726

0 commit comments

Comments
 (0)