mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00

### What does this PR try to resolve? This PR reworks `cargo-test-support` and `testsuite` to use Snapbox's [`cargo_bin!()`](https://docs.rs/snapbox/latest/snapbox/cmd/macro.cargo_bin.html) instead of [`cargo_bin()`](https://docs.rs/snapbox/latest/snapbox/cmd/fn.cargo_bin.html) which makes assumptions about the structure of Cargo's build directory. `cargo_bin!()` uses `CARGO_BIN_EXE_*` for locating the `cargo` binary which should be more resilient to directory/layout changes. Linking a relevant Zulip discussion [here](https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/cargo_bin_exe.20and.20tests/with/513638220)[#t-cargo > cargo_bin_exe and tests](https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/cargo_bin_exe.20and.20tests/with/513638220) As shown in that link, we could make these variables available at runtime and not need to do this. However, `cargo-test-support`, as an API, is a bit weird in that it is baking in support for one specific binary. This can be confusing for callers and makes it more annoying for callers provide their own `fn cargo`, e.g. see crate-ci/cargo-fixit#7 ### Implementation Notes `cargo_bin!()` only works when being called from the `testsuite` as it's only set when executing integration tests and `cargo-test-support` is a regular crate. To make this change, I introduced an extension trait `CargoProjectExt` in `testsuite` for running `.cargo()` and implemented it on `Project`. In `cargo-test-support` other functionality relies on `.cargo()` so these also needed to be moved to `testsuite` * [`src/tools.rs`](https://github.com/rust-lang/cargo/blob/master/crates/cargo-test-support/src/tools.rs) * Parts [`src/cross_compile`](https://github.com/rust-lang/cargo/blob/master/crates/cargo-test-support/src/cross_compile.rs) * I had to split this up unfortunately, as `disabled()` requires running Cargo to check if we should disable cross compile tests. * Other fns in `cross_compile` are used in `cargo-test-support` so moving everything to `testsuite` would have ended up requiring moving many things to test suite. ### How to test and review this PR? I'd definitely recommend reviewing commit by commit. There are a lot of diffs due to the nature of reorganizing things. I did my best to split things things into smaller PRs but they still contain a lot of `use` statement diffs. r? @epage