]> git.lizzy.rs Git - rust.git/blobdiff - build_system/utils.rs
Sync from rust 8e9c93df464b7ada3fc7a1c8ccddd9dcb24ee0a0
[rust.git] / build_system / utils.rs
index 2d2778d2fc0c7f968aac5e2aa55a09d67f7de272..48da64906e2a4b30189c82535f560a899e547510 100644 (file)
@@ -1,7 +1,54 @@
+use std::env;
 use std::fs;
+use std::io::Write;
 use std::path::Path;
 use std::process::{self, Command, Stdio};
-use std::io::Write;
+
+pub(crate) fn cargo_command(
+    cargo: impl AsRef<Path>,
+    subcommand: &str,
+    triple: Option<&str>,
+    source_dir: &Path,
+) -> Command {
+    let mut cmd = Command::new(cargo.as_ref());
+    cmd.arg(subcommand)
+        .arg("--manifest-path")
+        .arg(source_dir.join("Cargo.toml"))
+        .arg("--target-dir")
+        .arg(source_dir.join("target"));
+
+    if let Some(triple) = triple {
+        cmd.arg("--target").arg(triple);
+    }
+
+    cmd
+}
+
+pub(crate) fn hyperfine_command(
+    warmup: u64,
+    runs: u64,
+    prepare: Option<Command>,
+    a: Command,
+    b: Command,
+) -> Command {
+    let mut bench = Command::new("hyperfine");
+
+    if warmup != 0 {
+        bench.arg("--warmup").arg(warmup.to_string());
+    }
+
+    if runs != 0 {
+        bench.arg("--runs").arg(runs.to_string());
+    }
+
+    if let Some(prepare) = prepare {
+        bench.arg("--prepare").arg(format!("{:?}", prepare));
+    }
+
+    bench.arg(format!("{:?}", a)).arg(format!("{:?}", b));
+
+    bench
+}
 
 #[track_caller]
 pub(crate) fn try_hard_link(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
@@ -55,3 +102,7 @@ pub(crate) fn copy_dir_recursively(from: &Path, to: &Path) {
         }
     }
 }
+
+pub(crate) fn is_ci() -> bool {
+    env::var("CI").as_ref().map(|val| &**val) == Ok("true")
+}