-
-
Notifications
You must be signed in to change notification settings - Fork 787
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rely on std::process::Command's path search
- Loading branch information
Showing
1 changed file
with
14 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |