//
// true => deny, false => warn
pub deny_warnings: Option<bool>,
+
+ pub llvm_skip_rebuild: Option<bool>,
}
pub enum Subcommand {
Fix {
paths: Vec<PathBuf>,
},
+ Format {
+ check: bool,
+ },
Doc {
paths: Vec<PathBuf>,
},
impl Default for Subcommand {
fn default() -> Subcommand {
- Subcommand::Build {
- paths: vec![PathBuf::from("nowhere")],
- }
+ Subcommand::Build { paths: vec![PathBuf::from("nowhere")] }
}
}
impl Flags {
pub fn parse(args: &[String]) -> Flags {
let mut extra_help = String::new();
- let mut subcommand_help = String::from("\
+ let mut subcommand_help = String::from(
+ "\
Usage: x.py <subcommand> [options] [<paths>...]
Subcommands:
check Compile either the compiler or libraries, using cargo check
clippy Run clippy
fix Run cargo fix
+ fmt Run rustfmt
test Build and run some test suites
bench Build and run some benchmarks
doc Build documentation
dist Build distribution artifacts
install Install distribution artifacts
-To learn more about a subcommand, run `./x.py <subcommand> -h`"
+To learn more about a subcommand, run `./x.py <subcommand> -h`",
);
let mut opts = Options::new();
opts.optmulti("", "exclude", "build paths to exclude", "PATH");
opts.optopt("", "on-fail", "command to run on failure", "CMD");
opts.optflag("", "dry-run", "dry run; don't build anything");
- opts.optopt("", "stage",
+ opts.optopt(
+ "",
+ "stage",
"stage to build (indicates compiler to use/test, e.g., stage 0 uses the \
bootstrap compiler, stage 1 the stage 0 rustc artifacts, etc.)",
- "N");
- opts.optmulti("", "keep-stage", "stage(s) to keep without recompiling \
- (pass multiple times to keep e.g., both stages 0 and 1)", "N");
+ "N",
+ );
+ opts.optmulti(
+ "",
+ "keep-stage",
+ "stage(s) to keep without recompiling \
+ (pass multiple times to keep e.g., both stages 0 and 1)",
+ "N",
+ );
opts.optopt("", "src", "path to the root of the rust checkout", "DIR");
opts.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS");
opts.optflag("h", "help", "print this help message");
"VALUE",
);
opts.optopt("", "error-format", "rustc error format", "FORMAT");
+ opts.optopt(
+ "",
+ "llvm-skip-rebuild",
+ "whether rebuilding llvm should be skipped \
+ a VALUE of TRUE indicates that llvm will not be rebuilt \
+ VALUE overrides the skip-rebuild option in config.toml.",
+ "VALUE",
+ );
// fn usage()
let usage =
|| (s == "check")
|| (s == "clippy")
|| (s == "fix")
+ || (s == "fmt")
|| (s == "test")
|| (s == "bench")
|| (s == "doc")
);
opts.optflag("", "no-doc", "do not run doc tests");
opts.optflag("", "doc", "only run doc tests");
- opts.optflag(
- "",
- "bless",
- "update all stderr/stdout files of failing ui tests",
- );
+ opts.optflag("", "bless", "update all stderr/stdout files of failing ui tests");
opts.optopt(
"",
"compare-mode",
"",
"pass",
"force {check,build,run}-pass tests to this mode.",
- "check | build | run"
+ "check | build | run",
);
opts.optflag(
"",
"clean" => {
opts.optflag("", "all", "clean all build artifacts");
}
+ "fmt" => {
+ opts.optflag("", "check", "check formatting instead of applying.");
+ }
_ => {}
};
./x.py fix src/libcore src/libproc_macro",
);
}
+ "fmt" => {
+ subcommand_help.push_str(
+ "\n
+Arguments:
+ This subcommand optionally accepts a `--check` flag which succeeds if formatting is correct and
+ fails if it is not. For example:
+
+ ./x.py fmt
+ ./x.py fmt --check",
+ );
+ }
"test" => {
subcommand_help.push_str(
"\n
_ => {}
};
// Get any optional paths which occur after the subcommand
- let paths = matches.free[1..]
- .iter()
- .map(|p| p.into())
- .collect::<Vec<PathBuf>>();
+ let paths = matches.free[1..].iter().map(|p| p.into()).collect::<Vec<PathBuf>>();
let cfg_file = matches.opt_str("config").map(PathBuf::from).or_else(|| {
if fs::metadata("config.toml").is_ok() {
let maybe_rules_help = Builder::get_help(&build, subcommand.as_str());
extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str());
- } else if subcommand.as_str() != "clean" {
+ } else if !(subcommand.as_str() == "clean" || subcommand.as_str() == "fmt") {
extra_help.push_str(
- format!(
- "Run `./x.py {} -h -v` to see a list of available paths.",
- subcommand
- ).as_str(),
+ format!("Run `./x.py {} -h -v` to see a list of available paths.", subcommand)
+ .as_str(),
);
}
DocTests::Yes
},
},
- "bench" => Subcommand::Bench {
- paths,
- test_args: matches.opt_strs("test-args"),
- },
+ "bench" => Subcommand::Bench { paths, test_args: matches.opt_strs("test-args") },
"doc" => Subcommand::Doc { paths },
"clean" => {
if !paths.is_empty() {
usage(1, &opts, &subcommand_help, &extra_help);
}
- Subcommand::Clean {
- all: matches.opt_present("all"),
- }
+ Subcommand::Clean { all: matches.opt_present("all") }
}
+ "fmt" => Subcommand::Format { check: matches.opt_present("check") },
"dist" => Subcommand::Dist { paths },
"install" => Subcommand::Install { paths },
_ => {
dry_run: matches.opt_present("dry-run"),
on_fail: matches.opt_str("on-fail"),
rustc_error_format: matches.opt_str("error-format"),
- keep_stage: matches.opt_strs("keep-stage")
- .into_iter().map(|j| j.parse().expect("`keep-stage` should be a number"))
+ keep_stage: matches
+ .opt_strs("keep-stage")
+ .into_iter()
+ .map(|j| j.parse().expect("`keep-stage` should be a number"))
.collect(),
host: split(&matches.opt_strs("host"))
.into_iter()
.map(|p| p.into())
.collect::<Vec<_>>(),
deny_warnings: parse_deny_warnings(&matches),
+ llvm_skip_rebuild: matches.opt_str("llvm-skip-rebuild").map(|s| s.to_lowercase()).map(
+ |s| s.parse::<bool>().expect("`llvm-skip-rebuild` should be either true or false"),
+ ),
}
}
}
pub fn test_args(&self) -> Vec<&str> {
match *self {
Subcommand::Test { ref test_args, .. } | Subcommand::Bench { ref test_args, .. } => {
- test_args
- .iter()
- .flat_map(|s| s.split_whitespace())
- .collect()
+ test_args.iter().flat_map(|s| s.split_whitespace()).collect()
}
_ => Vec::new(),
}
pub fn rustc_args(&self) -> Vec<&str> {
match *self {
- Subcommand::Test { ref rustc_args, .. } => rustc_args
- .iter()
- .flat_map(|s| s.split_whitespace())
- .collect(),
+ Subcommand::Test { ref rustc_args, .. } => {
+ rustc_args.iter().flat_map(|s| s.split_whitespace()).collect()
+ }
_ => Vec::new(),
}
}
pub fn compare_mode(&self) -> Option<&str> {
match *self {
- Subcommand::Test {
- ref compare_mode, ..
- } => compare_mode.as_ref().map(|s| &s[..]),
+ Subcommand::Test { ref compare_mode, .. } => compare_mode.as_ref().map(|s| &s[..]),
_ => None,
}
}
pub fn pass(&self) -> Option<&str> {
match *self {
- Subcommand::Test {
- ref pass, ..
- } => pass.as_ref().map(|s| &s[..]),
+ Subcommand::Test { ref pass, .. } => pass.as_ref().map(|s| &s[..]),
_ => None,
}
}
}
fn split(s: &[String]) -> Vec<String> {
- s.iter()
- .flat_map(|s| s.split(','))
- .map(|s| s.to_string())
- .collect()
+ s.iter().flat_map(|s| s.split(',')).map(|s| s.to_string()).collect()
}
fn parse_deny_warnings(matches: &getopts::Matches) -> Option<bool> {
Some("deny") => Some(true),
Some("warn") => Some(false),
Some(value) => {
- eprintln!(
- r#"invalid value for --warnings: {:?}, expected "warn" or "deny""#,
- value,
- );
+ eprintln!(r#"invalid value for --warnings: {:?}, expected "warn" or "deny""#, value,);
process::exit(1);
- },
+ }
None => None,
}
}