Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions tests/rustfmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ use rustfmt_config_proc_macro::{nightly_only_test, rustfmt_only_ci_test};

/// Run the rustfmt executable and return its output.
fn rustfmt(args: &[&str]) -> (String, String) {
let mut bin_dir = env::current_exe().unwrap();
bin_dir.pop(); // chop off test exe name
if bin_dir.ends_with("deps") {
bin_dir.pop();
}
let cmd = bin_dir.join(format!("rustfmt{}", env::consts::EXE_SUFFIX));
let cmd = env!("CARGO_BIN_EXE_rustfmt");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who sets CARGO_BIN_EXE_rustfmt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cargo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How long has cargo set CARGO_BIN_EXE_rustfmt? Would we need to updated the docs to let users know that they'll need a minimum cargo version in order to run the test suite?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That has been there before 1.60. No idea on when (I did backfill some MSRVs in the docs but didn't go back far enough for this).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's fine, I just wasn't aware of CARGO_BIN_EXE_rustfmt and thought maybe it was something newer that we needed to make sure people knew about, but if it's been around for a while and we can rely on cargo to set it when running cargo test then I think we should be good to go

let bin_dir = Path::new(cmd).parent().unwrap();

// Ensure the rustfmt binary runs from the local target dir.
let path = env::var_os("PATH").unwrap_or_default();
let mut paths = env::split_paths(&path).collect::<Vec<_>>();
paths.insert(0, bin_dir);
paths.insert(0, bin_dir.to_owned());
let new_path = env::join_paths(paths).unwrap();

match Command::new(&cmd).args(args).env("PATH", new_path).output() {
Expand Down
Loading