]> git.lizzy.rs Git - rust.git/blobdiff - src/bootstrap/lib.rs
Clean up `&args[..]`, use more readable `args.iter()` instead
[rust.git] / src / bootstrap / lib.rs
index 3a7034f7bb24adc92197b963a26cce74a2472d1c..a4e35bf6d475b64919072f4bd42686250e9de746 100644 (file)
 use crate::builder::Kind;
 use crate::config::{LlvmLibunwind, TargetSelection};
 use crate::util::{
-    exe, libdir, mtime, output, run, run_suppressed, t, try_run, try_run_suppressed, CiEnv,
+    check_run, exe, libdir, mtime, output, run, run_suppressed, t, try_run, try_run_suppressed,
+    CiEnv,
 };
 
 mod builder;
@@ -609,7 +610,7 @@ fn dir_is_empty(dir: &Path) -> bool {
     /// This avoids contributors checking in a submodule change by accident.
     pub fn maybe_update_submodules(&self) {
         // WARNING: keep this in sync with the submodules hard-coded in bootstrap.py
-        const BOOTSTRAP_SUBMODULES: &[&str] = &[
+        let mut bootstrap_submodules: Vec<&str> = vec![
             "src/tools/rust-installer",
             "src/tools/cargo",
             "src/tools/rls",
@@ -617,6 +618,11 @@ pub fn maybe_update_submodules(&self) {
             "library/backtrace",
             "library/stdarch",
         ];
+        // As in bootstrap.py, we include `rust-analyzer` if `build.vendor` was set in
+        // `config.toml`.
+        if self.config.vendor {
+            bootstrap_submodules.push("src/tools/rust-analyzer");
+        }
         // Avoid running git when there isn't a git checkout.
         if !self.config.submodules(&self.rust_info) {
             return;
@@ -632,7 +638,7 @@ pub fn maybe_update_submodules(&self) {
             // Sample output: `submodule.src/rust-installer.path src/tools/rust-installer`
             let submodule = Path::new(line.splitn(2, ' ').nth(1).unwrap());
             // avoid updating submodules twice
-            if !BOOTSTRAP_SUBMODULES.iter().any(|&p| Path::new(p) == submodule)
+            if !bootstrap_submodules.iter().any(|&p| Path::new(p) == submodule)
                 && channel::GitInfo::new(false, submodule).is_git()
             {
                 self.update_submodule(submodule);
@@ -956,6 +962,17 @@ fn try_run_quiet(&self, cmd: &mut Command) -> bool {
         try_run_suppressed(cmd)
     }
 
+    /// Runs a command, printing out nice contextual information if it fails.
+    /// Returns false if do not execute at all, otherwise returns its
+    /// `status.success()`.
+    fn check_run(&self, cmd: &mut Command) -> bool {
+        if self.config.dry_run {
+            return true;
+        }
+        self.verbose(&format!("running: {:?}", cmd));
+        check_run(cmd, self.is_verbose())
+    }
+
     pub fn is_verbose(&self) -> bool {
         self.verbosity > 0
     }
@@ -1492,14 +1509,20 @@ fn install(&self, src: &Path, dstdir: &Path, perms: u32) {
         let dst = dstdir.join(src.file_name().unwrap());
         self.verbose_than(1, &format!("Install {:?} to {:?}", src, dst));
         t!(fs::create_dir_all(dstdir));
+        drop(fs::remove_file(&dst));
         {
             if !src.exists() {
                 panic!("Error: File \"{}\" not found!", src.display());
             }
-            self.copy(src, &dst);
+            let metadata = t!(src.symlink_metadata());
+            if let Err(e) = fs::copy(&src, &dst) {
+                panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
+            }
+            t!(fs::set_permissions(&dst, metadata.permissions()));
+            let atime = FileTime::from_last_access_time(&metadata);
+            let mtime = FileTime::from_last_modification_time(&metadata);
+            t!(filetime::set_file_times(&dst, atime, mtime));
         }
-        // NOTE: when using hard-links, this will also update the permissions on the original file.
-        // We never use permissions that are more restrictive than the original, so this shouldn't cause any issues.
         chmod(&dst, perms);
     }