diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs index e5c85ddb3a9..2f9953330f4 100644 --- a/src/build_helper/lib.rs +++ b/src/build_helper/lib.rs @@ -8,12 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - use std::fs::File; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; -use std::{fs, env}; use std::time::{SystemTime, UNIX_EPOCH}; +use std::{env, fs}; /// A helper macro to `unwrap` a result except also print out details like: /// @@ -25,10 +24,12 @@ use std::time::{SystemTime, UNIX_EPOCH}; /// using a `Result` with `try!`, but this may change one day... #[macro_export] macro_rules! t { - ($e:expr) => (match $e { - Ok(e) => e, - Err(e) => panic!("{} failed with {}", stringify!($e), e), - }) + ($e:expr) => { + match $e { + Ok(e) => e, + Err(e) => panic!("{} failed with {}", stringify!($e), e), + } + }; } pub fn run(cmd: &mut Command) { @@ -45,14 +46,17 @@ pub fn run_silent(cmd: &mut Command) { pub fn try_run_silent(cmd: &mut Command) -> bool { let status = match cmd.status() { Ok(status) => status, - Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", - cmd, e)), + Err(e) => fail(&format!( + "failed to execute command: {:?}\nerror: {}", + cmd, e + )), }; if !status.success() { - println!("\n\ncommand did not execute successfully: {:?}\n\ - expected success, got: {}\n\n", - cmd, - status); + println!( + "\n\ncommand did not execute successfully: {:?}\n\ + expected success, got: {}\n\n", + cmd, status + ); } status.success() } @@ -66,18 +70,22 @@ pub fn run_suppressed(cmd: &mut Command) { pub fn try_run_suppressed(cmd: &mut Command) -> bool { let output = match cmd.output() { Ok(status) => status, - Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", - cmd, e)), + Err(e) => fail(&format!( + "failed to execute command: {:?}\nerror: {}", + cmd, e + )), }; if !output.status.success() { - println!("\n\ncommand did not execute successfully: {:?}\n\ - expected success, got: {}\n\n\ - stdout ----\n{}\n\ - stderr ----\n{}\n\n", - cmd, - output.status, - String::from_utf8_lossy(&output.stdout), - String::from_utf8_lossy(&output.stderr)); + println!( + "\n\ncommand did not execute successfully: {:?}\n\ + expected success, got: {}\n\n\ + stdout ----\n{}\n\ + stderr ----\n{}\n\n", + cmd, + output.status, + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ); } output.status.success() } @@ -93,9 +101,9 @@ pub fn gnu_target(target: &str) -> String { } pub fn make(host: &str) -> PathBuf { - if host.contains("bitrig") || host.contains("dragonfly") || - host.contains("freebsd") || host.contains("netbsd") || - host.contains("openbsd") { + if host.contains("bitrig") || host.contains("dragonfly") || host.contains("freebsd") + || host.contains("netbsd") || host.contains("openbsd") + { PathBuf::from("gmake") } else { PathBuf::from("make") @@ -105,23 +113,27 @@ pub fn make(host: &str) -> PathBuf { pub fn output(cmd: &mut Command) -> String { let output = match cmd.stderr(Stdio::inherit()).output() { Ok(status) => status, - Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", - cmd, e)), + Err(e) => fail(&format!( + "failed to execute command: {:?}\nerror: {}", + cmd, e + )), }; if !output.status.success() { - panic!("command did not execute successfully: {:?}\n\ - expected success, got: {}", - cmd, - output.status); + panic!( + "command did not execute successfully: {:?}\n\ + expected success, got: {}", + cmd, output.status + ); } String::from_utf8(output.stdout).unwrap() } pub fn rerun_if_changed_anything_in_dir(dir: &Path) { - let mut stack = dir.read_dir().unwrap() - .map(|e| e.unwrap()) - .filter(|e| &*e.file_name() != ".git") - .collect::>(); + let mut stack = dir.read_dir() + .unwrap() + .map(|e| e.unwrap()) + .filter(|e| &*e.file_name() != ".git") + .collect::>(); while let Some(entry) = stack.pop() { let path = entry.path(); if entry.file_type().unwrap().is_dir() { @@ -134,7 +146,9 @@ pub fn rerun_if_changed_anything_in_dir(dir: &Path) { /// Returns the last-modified time for `path`, or zero if it doesn't exist. pub fn mtime(path: &Path) -> SystemTime { - fs::metadata(path).and_then(|f| f.modified()).unwrap_or(UNIX_EPOCH) + fs::metadata(path) + .and_then(|f| f.modified()) + .unwrap_or(UNIX_EPOCH) } /// Returns whether `dst` is up to date given that the file or files in `src` @@ -175,11 +189,12 @@ impl Drop for NativeLibBoilerplate { // If Err is returned, then everything is up-to-date and further build actions can be skipped. // Timestamps are created automatically when the result of `native_lib_boilerplate` goes out // of scope, so all the build actions should be completed until then. -pub fn native_lib_boilerplate(src_name: &str, - out_name: &str, - link_name: &str, - search_subdir: &str) - -> Result { +pub fn native_lib_boilerplate( + src_name: &str, + out_name: &str, + link_name: &str, + search_subdir: &str, +) -> Result { let current_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); let src_dir = current_dir.join("..").join(src_name); rerun_if_changed_anything_in_dir(&src_dir); @@ -192,11 +207,17 @@ pub fn native_lib_boilerplate(src_name: &str, } else { println!("cargo:rustc-link-lib=static={}", link_name); } - println!("cargo:rustc-link-search=native={}", out_dir.join(search_subdir).display()); + println!( + "cargo:rustc-link-search=native={}", + out_dir.join(search_subdir).display() + ); let timestamp = out_dir.join("rustbuild.timestamp"); if !up_to_date(Path::new("build.rs"), ×tamp) || !up_to_date(&src_dir, ×tamp) { - Ok(NativeLibBoilerplate { src_dir: src_dir, out_dir: out_dir }) + Ok(NativeLibBoilerplate { + src_dir: src_dir, + out_dir: out_dir, + }) } else { Err(()) } @@ -214,10 +235,12 @@ pub fn sanitizer_lib_boilerplate(sanitizer_name: &str) -> Result return Err(()), }; - native_lib_boilerplate("libcompiler_builtins/compiler-rt", - sanitizer_name, - &link_name, - search_path) + native_lib_boilerplate( + "libcompiler_builtins/compiler-rt", + sanitizer_name, + &link_name, + search_path, + ) } fn dir_up_to_date(src: &Path, threshold: SystemTime) -> bool {