]> git.lizzy.rs Git - rust.git/blobdiff - src/bootstrap/flags.rs
Rollup merge of #68279 - GuillaumeGomez:clean-up-e0198, r=Dylan-DPC
[rust.git] / src / bootstrap / flags.rs
index 7b49cc0a9298cc059b56e2c2670e214bf78c02a5..1fbdd50a51133d4636c7b1bf5069c887a32dfcb0 100644 (file)
@@ -38,6 +38,8 @@ pub struct Flags {
     //
     // true => deny, false => warn
     pub deny_warnings: Option<bool>,
+
+    pub llvm_skip_rebuild: Option<bool>,
 }
 
 pub enum Subcommand {
@@ -53,6 +55,9 @@ pub enum Subcommand {
     Fix {
         paths: Vec<PathBuf>,
     },
+    Format {
+        check: bool,
+    },
     Doc {
         paths: Vec<PathBuf>,
     },
@@ -85,16 +90,15 @@ pub enum Subcommand {
 
 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:
@@ -102,6 +106,7 @@ pub fn parse(args: &[String]) -> Flags {
     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
@@ -109,7 +114,7 @@ pub fn parse(args: &[String]) -> Flags {
     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();
@@ -123,12 +128,20 @@ pub fn parse(args: &[String]) -> Flags {
         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");
@@ -139,6 +152,14 @@ pub fn parse(args: &[String]) -> Flags {
             "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 =
@@ -160,6 +181,7 @@ pub fn parse(args: &[String]) -> Flags {
                 || (s == "check")
                 || (s == "clippy")
                 || (s == "fix")
+                || (s == "fmt")
                 || (s == "test")
                 || (s == "bench")
                 || (s == "doc")
@@ -192,11 +214,7 @@ pub fn parse(args: &[String]) -> Flags {
                 );
                 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",
@@ -207,7 +225,7 @@ pub fn parse(args: &[String]) -> Flags {
                     "",
                     "pass",
                     "force {check,build,run}-pass tests to this mode.",
-                    "check | build | run"
+                    "check | build | run",
                 );
                 opts.optflag(
                     "",
@@ -222,6 +240,9 @@ pub fn parse(args: &[String]) -> Flags {
             "clean" => {
                 opts.optflag("", "all", "clean all build artifacts");
             }
+            "fmt" => {
+                opts.optflag("", "check", "check formatting instead of applying.");
+            }
             _ => {}
         };
 
@@ -323,6 +344,17 @@ pub fn parse(args: &[String]) -> Flags {
         ./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
@@ -367,10 +399,7 @@ pub fn parse(args: &[String]) -> Flags {
             _ => {}
         };
         // 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() {
@@ -388,12 +417,10 @@ pub fn parse(args: &[String]) -> Flags {
 
             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(),
             );
         }
 
@@ -424,10 +451,7 @@ pub fn parse(args: &[String]) -> Flags {
                     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() {
@@ -435,10 +459,9 @@ pub fn parse(args: &[String]) -> Flags {
                     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 },
             _ => {
@@ -452,8 +475,10 @@ pub fn parse(args: &[String]) -> Flags {
             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()
@@ -472,6 +497,9 @@ pub fn parse(args: &[String]) -> Flags {
                 .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"),
+            ),
         }
     }
 }
@@ -480,10 +508,7 @@ impl Subcommand {
     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(),
         }
@@ -491,10 +516,9 @@ pub fn test_args(&self) -> Vec<&str> {
 
     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(),
         }
     }
@@ -529,28 +553,21 @@ pub fn rustfix_coverage(&self) -> bool {
 
     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> {
@@ -558,12 +575,9 @@ 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,
     }
 }