Skip to content

Commit ef22670

Browse files
authored
Enable Cargo's new build-dir layout in tests+ci (#6879)
* test: Add support for cargo's build-dir v2 layout * chore: Move CI to use Cargo's v2 layout
1 parent 5042b96 commit ef22670

5 files changed

Lines changed: 29 additions & 2 deletions

File tree

.github/workflows/linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ jobs:
3838
- name: Build and Test
3939
env:
4040
RUSTFLAGS: -D warnings
41+
CARGO_UNSTABLE_BUILD_DIR_NEW_LAYOUT: true
4142
run: cargo run --manifest-path ci/Cargo.toml build-and-test

.github/workflows/mac.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ jobs:
3434
- name: Build and Test
3535
env:
3636
RUSTFLAGS: -D warnings
37+
CARGO_UNSTABLE_BUILD_DIR_NEW_LAYOUT: true
3738
run: cargo run --manifest-path ci/Cargo.toml build-and-test

.github/workflows/windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ jobs:
6060
- name: Build and Test
6161
env:
6262
RUSTFLAGS: -D warnings
63+
CARGO_UNSTABLE_BUILD_DIR_NEW_LAYOUT: true
6364
run: cargo run --manifest-path ci/Cargo.toml build-and-test

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)