]> git.lizzy.rs Git - rust.git/blobdiff - src/bootstrap/toolstate.rs
Rollup merge of #68485 - kingslef:fix/test-60976, r=nikomatsakis
[rust.git] / src / bootstrap / toolstate.rs
index a6d9ef38e57b1684b84351733b0abe60f726ebb9..b068c8200acecb86302a162f6b402c0871d70919 100644 (file)
@@ -1,25 +1,25 @@
-use serde::{Deserialize, Serialize};
+use crate::builder::{Builder, RunConfig, ShouldRun, Step};
 use build_helper::t;
-use std::time;
-use std::fs;
-use std::io::{Seek, SeekFrom};
+use serde::{Deserialize, Serialize};
 use std::collections::HashMap;
-use crate::builder::{Builder, RunConfig, ShouldRun, Step};
+use std::env;
 use std::fmt;
-use std::process::Command;
+use std::fs;
+use std::io::{Seek, SeekFrom};
 use std::path::PathBuf;
-use std::env;
+use std::process::Command;
+use std::time;
 
 // Each cycle is 42 days long (6 weeks); the last week is 35..=42 then.
 const BETA_WEEK_START: u64 = 35;
 
-#[cfg(linux)]
+#[cfg(target_os = "linux")]
 const OS: Option<&str> = Some("linux");
 
 #[cfg(windows)]
 const OS: Option<&str> = Some("windows");
 
-#[cfg(all(not(linux), not(windows)))]
+#[cfg(all(not(target_os = "linux"), not(windows)))]
 const OS: Option<&str> = None;
 
 type ToolstateData = HashMap<Box<str>, ToolState>;
@@ -38,11 +38,15 @@ pub enum ToolState {
 
 impl fmt::Display for ToolState {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "{}", match self {
-            ToolState::TestFail => "test-fail",
-            ToolState::TestPass => "test-pass",
-            ToolState::BuildFail => "build-fail",
-        })
+        write!(
+            f,
+            "{}",
+            match self {
+                ToolState::TestFail => "test-fail",
+                ToolState::TestPass => "test-pass",
+                ToolState::BuildFail => "build-fail",
+            }
+        )
     }
 }
 
@@ -120,9 +124,7 @@ fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) {
     let output = t!(String::from_utf8(output.stdout));
 
     for (tool, submodule) in STABLE_TOOLS.iter().chain(NIGHTLY_TOOLS.iter()) {
-        let changed = output.lines().any(|l| {
-            l.starts_with("M") && l.ends_with(submodule)
-        });
+        let changed = output.lines().any(|l| l.starts_with("M") && l.ends_with(submodule));
         eprintln!("Verifying status of {}...", tool);
         if !changed {
             continue;
@@ -179,8 +181,10 @@ fn run(self, builder: &Builder<'_>) {
                     eprintln!("error: Tool `{}` should be test-pass but is {}", tool, state);
                 } else if in_beta_week {
                     did_error = true;
-                    eprintln!("error: Tool `{}` should be test-pass but is {} during beta week.",
-                        tool, state);
+                    eprintln!(
+                        "error: Tool `{}` should be test-pass but is {} during beta week.",
+                        tool, state
+                    );
                 }
             }
         }
@@ -210,11 +214,8 @@ fn toolstates(&self) -> HashMap<Box<str>, ToolState> {
                 // Ensure the parent directory always exists
                 t!(std::fs::create_dir_all(parent));
             }
-            let mut file = t!(fs::OpenOptions::new()
-                .create(true)
-                .write(true)
-                .read(true)
-                .open(path));
+            let mut file =
+                t!(fs::OpenOptions::new().create(true).write(true).read(true).open(path));
 
             serde_json::from_reader(&mut file).unwrap_or_default()
         } else {
@@ -233,11 +234,8 @@ pub fn save_toolstate(&self, tool: &str, state: ToolState) {
                 // Ensure the parent directory always exists
                 t!(std::fs::create_dir_all(parent));
             }
-            let mut file = t!(fs::OpenOptions::new()
-                .create(true)
-                .read(true)
-                .write(true)
-                .open(path));
+            let mut file =
+                t!(fs::OpenOptions::new().create(true).read(true).write(true).open(path));
 
             let mut current_toolstates: HashMap<Box<str>, ToolState> =
                 serde_json::from_reader(&mut file).unwrap_or_default();
@@ -275,10 +273,7 @@ pub fn save_toolstate(&self, tool: &str, state: ToolState) {
 ///
 ///       * See <https://help.github.com/articles/about-commit-email-addresses/>
 ///           if a private email by GitHub is wanted.
-fn commit_toolstate_change(
-    current_toolstate: &ToolstateData,
-    in_beta_week: bool,
-) {
+fn commit_toolstate_change(current_toolstate: &ToolstateData, in_beta_week: bool) {
     fn git_config(key: &str, value: &str) {
         let status = Command::new("git").arg("config").arg("--global").arg(key).arg(value).status();
         let success = match status {
@@ -303,7 +298,8 @@ fn git_config(key: &str, value: &str) {
     let git_credential_path = PathBuf::from(t!(env::var("HOME"))).join(".git-credentials");
     t!(fs::write(&git_credential_path, credential));
 
-    let status = Command::new("git").arg("clone")
+    let status = Command::new("git")
+        .arg("clone")
         .arg("--depth=1")
         .arg(t!(env::var("TOOLSTATE_REPO")))
         .status();
@@ -379,7 +375,7 @@ fn change_toolstate(
     let mut regressed = false;
     for repo_state in old_toolstate {
         let tool = &repo_state.tool;
-        let state = if cfg!(linux) {
+        let state = if cfg!(target_os = "linux") {
             &repo_state.linux
         } else if cfg!(windows) {
             &repo_state.windows
@@ -402,10 +398,7 @@ fn change_toolstate(
         std::process::exit(1);
     }
 
-    let commit = t!(std::process::Command::new("git")
-        .arg("rev-parse")
-        .arg("HEAD")
-        .output());
+    let commit = t!(std::process::Command::new("git").arg("rev-parse").arg("HEAD").output());
     let commit = t!(String::from_utf8(commit.stdout));
 
     let toolstate_serialized = t!(serde_json::to_string(&current_toolstate));
@@ -413,7 +406,7 @@ fn change_toolstate(
     let history_path = format!("rust-toolstate/history/{}.tsv", OS.expect("linux/windows only"));
     let mut file = t!(fs::read_to_string(&history_path));
     let end_of_first_line = file.find('\n').unwrap();
-    file.insert_str(end_of_first_line, &format!("{}\t{}\n", commit, toolstate_serialized));
+    file.insert_str(end_of_first_line, &format!("\n{}\t{}", commit.trim(), toolstate_serialized));
     t!(fs::write(&history_path, file));
 }