mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 18:53:39 +00:00
Use rustfmt given by RUSTFMT env var (#4419)
This commit is contained in:
parent
2a8ff209f6
commit
14d53f75c9
@ -1,5 +1,7 @@
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{quote, ToTokens};
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
|
||||
pub fn fold_quote<F, I, T>(input: impl Iterator<Item = I>, f: F) -> TokenStream
|
||||
where
|
||||
@ -25,7 +27,12 @@ pub fn debug_with_rustfmt(input: &TokenStream) {
|
||||
use std::io::Write;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
let mut child = Command::new("rustfmt")
|
||||
let rustfmt_var = env::var_os("RUSTFMT");
|
||||
let rustfmt = match &rustfmt_var {
|
||||
Some(rustfmt) => rustfmt,
|
||||
None => OsStr::new("rustfmt"),
|
||||
};
|
||||
let mut child = Command::new(rustfmt)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
|
@ -7,6 +7,7 @@ use cargo_metadata;
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::io::{self, Write};
|
||||
@ -129,6 +130,15 @@ fn execute() -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
fn rustfmt_command() -> Command {
|
||||
let rustfmt_var = env::var_os("RUSTFMT");
|
||||
let rustfmt = match &rustfmt_var {
|
||||
Some(rustfmt) => rustfmt,
|
||||
None => OsStr::new("rustfmt"),
|
||||
};
|
||||
Command::new(rustfmt)
|
||||
}
|
||||
|
||||
fn convert_message_format_to_rustfmt_args(
|
||||
message_format: &str,
|
||||
rustfmt_args: &mut Vec<String>,
|
||||
@ -205,7 +215,7 @@ fn handle_command_status(status: Result<i32, io::Error>) -> i32 {
|
||||
}
|
||||
|
||||
fn get_rustfmt_info(args: &[String]) -> Result<i32, io::Error> {
|
||||
let mut command = Command::new("rustfmt")
|
||||
let mut command = rustfmt_command()
|
||||
.stdout(std::process::Stdio::inherit())
|
||||
.args(args)
|
||||
.spawn()
|
||||
@ -484,7 +494,7 @@ fn run_rustfmt(
|
||||
println!();
|
||||
}
|
||||
|
||||
let mut command = Command::new("rustfmt")
|
||||
let mut command = rustfmt_command()
|
||||
.stdout(stdout)
|
||||
.args(files)
|
||||
.args(&["--edition", edition])
|
||||
|
@ -13,6 +13,8 @@ use serde_json as json;
|
||||
use thiserror::Error;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::io::{self, BufRead};
|
||||
use std::process;
|
||||
|
||||
@ -94,7 +96,12 @@ fn run_rustfmt(files: &HashSet<String>, ranges: &[Range]) -> Result<(), FormatDi
|
||||
debug!("Files: {:?}", files);
|
||||
debug!("Ranges: {:?}", ranges);
|
||||
|
||||
let exit_status = process::Command::new("rustfmt")
|
||||
let rustfmt_var = env::var_os("RUSTFMT");
|
||||
let rustfmt = match &rustfmt_var {
|
||||
Some(rustfmt) => rustfmt,
|
||||
None => OsStr::new("rustfmt"),
|
||||
};
|
||||
let exit_status = process::Command::new(rustfmt)
|
||||
.args(files)
|
||||
.arg("--file-lines")
|
||||
.arg(ranges_as_json)
|
||||
|
Loading…
Reference in New Issue
Block a user