Skip to content

Commit

Permalink
Rely on std::process::Command's path search
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 25, 2019
1 parent bcaebdb commit d17d8eb
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions test_suite/build.rs
Original file line number Diff line number Diff line change
@@ -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");
}
}

0 comments on commit d17d8eb

Please sign in to comment.