From d17d8eb3eea0f11c0ccc7f435d3a959cae30f336 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 24 Nov 2019 17:23:02 -0800 Subject: [PATCH] Rely on std::process::Command's path search --- test_suite/build.rs | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/test_suite/build.rs b/test_suite/build.rs index eaaabcb2f..526e2a4e2 100644 --- a/test_suite/build.rs +++ b/test_suite/build.rs @@ -1,28 +1,22 @@ -use std::env; -use std::path::PathBuf; +use std::process::{Command, ExitStatus, Stdio}; #[cfg(not(windows))] -const CARGO_EXPAND_BIN: &str = "cargo-expand"; +const CARGO_EXPAND: &str = "cargo-expand"; #[cfg(windows)] -const CARGO_EXPAND_BIN: &str = "cargo-expand.exe"; +const CARGO_EXPAND: &str = "cargo-expand.exe"; -/// Scans paths in PATH env variable for a presence of `CARGO_EXPAND_BIN` file. -fn is_cargo_expand_present() -> bool { - if let Ok(var) = env::var("PATH") { - for path in var.split(":").map(PathBuf::from) { - let cargo_expand_path = path.join(CARGO_EXPAND_BIN); - if cargo_expand_path.exists() { - return true; - } - } - } - - false -} - -pub fn main() { - if is_cargo_expand_present() { +fn main() { + if Command::new(CARGO_EXPAND) + .arg("--version") + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .as_ref() + .map(ExitStatus::success) + .unwrap_or(false) + { println!("cargo:rustc-cfg=cargo_expand"); } }