]> git.lizzy.rs Git - rust.git/blobdiff - src/bootstrap/sanity.rs
Auto merge of #67940 - JohnTitor:rustc-guide, r=JohnTitor
[rust.git] / src / bootstrap / sanity.rs
index bffe748f37cc16270661c756ffa9b0099bb61be7..8ff7056e628f32349a86b36e1bda086efd5762be 100644 (file)
@@ -10,7 +10,7 @@
 
 use std::collections::HashMap;
 use std::env;
-use std::ffi::{OsString, OsStr};
+use std::ffi::{OsStr, OsString};
 use std::fs;
 use std::path::PathBuf;
 use std::process::Command;
@@ -26,30 +26,31 @@ struct Finder {
 
 impl Finder {
     fn new() -> Self {
-        Self {
-            cache: HashMap::new(),
-            path: env::var_os("PATH").unwrap_or_default()
-        }
+        Self { cache: HashMap::new(), path: env::var_os("PATH").unwrap_or_default() }
     }
 
     fn maybe_have<S: AsRef<OsStr>>(&mut self, cmd: S) -> Option<PathBuf> {
         let cmd: OsString = cmd.as_ref().into();
         let path = &self.path;
-        self.cache.entry(cmd.clone()).or_insert_with(|| {
-            for path in env::split_paths(path) {
-                let target = path.join(&cmd);
-                let mut cmd_exe = cmd.clone();
-                cmd_exe.push(".exe");
-
-                if target.is_file()                   // some/path/git
+        self.cache
+            .entry(cmd.clone())
+            .or_insert_with(|| {
+                for path in env::split_paths(path) {
+                    let target = path.join(&cmd);
+                    let mut cmd_exe = cmd.clone();
+                    cmd_exe.push(".exe");
+
+                    if target.is_file()                   // some/path/git
                     || path.join(&cmd_exe).exists()   // some/path/git.exe
-                    || target.join(&cmd_exe).exists() // some/path/git/git.exe
-                {
-                    return Some(target);
+                    || target.join(&cmd_exe).exists()
+                    // some/path/git/git.exe
+                    {
+                        return Some(target);
+                    }
                 }
-            }
-            None
-        }).clone()
+                None
+            })
+            .clone()
     }
 
     fn must_have<S: AsRef<OsStr>>(&mut self, cmd: S) -> PathBuf {
@@ -77,11 +78,17 @@ pub fn check(build: &mut Build) {
     }
 
     // We need cmake, but only if we're actually building LLVM or sanitizers.
-    let building_llvm = build.hosts.iter()
-        .map(|host| build.config.target_config
-            .get(host)
-            .map(|config| config.llvm_config.is_none())
-            .unwrap_or(true))
+    let building_llvm = build
+        .hosts
+        .iter()
+        .map(|host| {
+            build
+                .config
+                .target_config
+                .get(host)
+                .map(|config| config.llvm_config.is_none())
+                .unwrap_or(true)
+        })
         .any(|build_llvm_ourselves| build_llvm_ourselves);
     if building_llvm || build.config.sanitizers {
         cmd_finder.must_have("cmake");
@@ -119,17 +126,29 @@ pub fn check(build: &mut Build) {
         }
     }
 
-    build.config.python = build.config.python.take().map(|p| cmd_finder.must_have(p))
+    build.config.python = build
+        .config
+        .python
+        .take()
+        .map(|p| cmd_finder.must_have(p))
         .or_else(|| cmd_finder.maybe_have("python2.7"))
         .or_else(|| cmd_finder.maybe_have("python2"))
         .or_else(|| env::var_os("BOOTSTRAP_PYTHON").map(PathBuf::from)) // set by bootstrap.py
         .or_else(|| Some(cmd_finder.must_have("python")));
 
-    build.config.nodejs = build.config.nodejs.take().map(|p| cmd_finder.must_have(p))
+    build.config.nodejs = build
+        .config
+        .nodejs
+        .take()
+        .map(|p| cmd_finder.must_have(p))
         .or_else(|| cmd_finder.maybe_have("node"))
         .or_else(|| cmd_finder.maybe_have("nodejs"));
 
-    build.config.gdb = build.config.gdb.take().map(|p| cmd_finder.must_have(p))
+    build.config.gdb = build
+        .config
+        .gdb
+        .take()
+        .map(|p| cmd_finder.must_have(p))
         .or_else(|| cmd_finder.maybe_have("gdb"));
 
     // We're gonna build some custom C code here and there, host triples
@@ -169,15 +188,13 @@ pub fn check(build: &mut Build) {
 
     for target in &build.targets {
         // Can't compile for iOS unless we're on macOS
-        if target.contains("apple-ios") &&
-           !build.build.contains("apple-darwin") {
+        if target.contains("apple-ios") && !build.build.contains("apple-darwin") {
             panic!("the iOS target is only supported on macOS");
         }
 
         if target.contains("-none-") || target.contains("nvptx") {
             if build.no_std(*target).is_none() {
-                let target = build.config.target_config.entry(target.clone())
-                    .or_default();
+                let target = build.config.target_config.entry(target.clone()).or_default();
 
                 target.no_std = true;
             }
@@ -192,22 +209,20 @@ pub fn check(build: &mut Build) {
             // If this is a native target (host is also musl) and no musl-root is given,
             // fall back to the system toolchain in /usr before giving up
             if build.musl_root(*target).is_none() && build.config.build == *target {
-                let target = build.config.target_config.entry(target.clone())
-                    .or_default();
+                let target = build.config.target_config.entry(target.clone()).or_default();
                 target.musl_root = Some("/usr".into());
             }
             match build.musl_root(*target) {
                 Some(root) => {
                     if fs::metadata(root.join("lib/libc.a")).is_err() {
-                        panic!("couldn't find libc.a in musl dir: {}",
-                               root.join("lib").display());
+                        panic!("couldn't find libc.a in musl dir: {}", root.join("lib").display());
                     }
                 }
-                None => {
-                    panic!("when targeting MUSL either the rust.musl-root \
+                None => panic!(
+                    "when targeting MUSL either the rust.musl-root \
                             option or the target.$TARGET.musl-root option must \
-                            be specified in config.toml")
-                }
+                            be specified in config.toml"
+                ),
             }
         }
 
@@ -217,7 +232,8 @@ pub fn check(build: &mut Build) {
             // Studio, so detect that here and error.
             let out = output(Command::new("cmake").arg("--help"));
             if !out.contains("Visual Studio") {
-                panic!("
+                panic!(
+                    "
 cmake does not support Visual Studio generators.
 
 This is likely due to it being an msys/cygwin build of cmake,
@@ -228,7 +244,8 @@ pub fn check(build: &mut Build) {
 package instead of cmake:
 
 $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
-");
+"
+                );
             }
         }
     }
@@ -240,8 +257,10 @@ pub fn check(build: &mut Build) {
     if build.config.channel == "stable" {
         let stage0 = t!(fs::read_to_string(build.src.join("src/stage0.txt")));
         if stage0.contains("\ndev:") {
-            panic!("bootstrapping from a dev compiler in a stable release, but \
-                    should only be bootstrapping from a released compiler!");
+            panic!(
+                "bootstrapping from a dev compiler in a stable release, but \
+                    should only be bootstrapping from a released compiler!"
+            );
         }
     }
 }