Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try go fix cargo fmt invocation #4620

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions clippy_dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ regex = "1"
lazy_static = "1.0"
shell-escape = "0.1"
walkdir = "2"
home = "0.5.0"
32 changes: 21 additions & 11 deletions clippy_dev/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use home;
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need this in 2018 edition

Suggested change
use home;

use shell_escape::escape;
use std::ffi::OsStr;
use std::io;
Expand Down Expand Up @@ -31,6 +32,26 @@ struct FmtContext {
verbose: bool,
}

fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
let mut args = vec!["+nightly", "fmt", "--all"];
if context.check {
args.push("--");
args.push("--check");
}
// in case something aliases cargo=cargo --foo, the order of args will be messed up
// because we will end up with cargo --foo +nightly fmt but the "+nightly" needs to come first
// get the absolute path to the cargo binary inside $CARGO_HOME
let cargo_home = home::cargo_home().expect("failed to get cargo home path!");
let cargo_path = cargo_home.join("bin").join("cargo");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let cargo_path = cargo_home.join("bin").join("cargo");
let cargo_path = cargo_home.join("bin").join(format!("cargo{}", std::env::consts::EXE_SUFFIX));

assert!(
cargo_path.is_file(),
format!("ERROR: '{}' is not a path to the cargo binary!", cargo_path.display())
);
let success = exec(context, cargo_path, path, &args)?;

Ok(success)
}

pub fn run(check: bool, verbose: bool) {
fn try_run(context: &FmtContext) -> Result<bool, CliError> {
let mut success = true;
Expand Down Expand Up @@ -134,17 +155,6 @@ fn exec(
Ok(success)
}

fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
let mut args = vec!["+nightly", "fmt", "--all"];
if context.check {
args.push("--");
args.push("--check");
}
let success = exec(context, "cargo", path, &args)?;

Ok(success)
}

fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
let program = "rustfmt";
let dir = std::env::current_dir()?;
Expand Down