Ignore expansion test if cargo-expand subcommand isn't present

This commit is contained in:
Evgenii P
2019-11-03 20:31:08 +08:00
parent 640f8e0e82
commit 9a0e4e0176
3 changed files with 30 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
use std::env;
use std::path::PathBuf;
#[cfg(not(windows))]
const CARGO_EXPAND_BIN: &str = "cargo-expand";
#[cfg(windows)]
const CARGO_EXPAND_BIN: &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() {
println!("cargo:rustc-cfg=cargo_expand");
}
}