Looking for dependencies on test for a better UX
This commit is contained in:
38
build.rs
Normal file
38
build.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
// build.rs -- Compile-time detection of optional build tools.
|
||||
//
|
||||
// Sets cfg flags that integration tests use to gracefully skip when
|
||||
// tools are missing instead of panicking with scary error messages.
|
||||
//
|
||||
// has_cmake cmake is in PATH
|
||||
// has_cpp_compiler g++, clang++, or cl is in PATH
|
||||
// has_git git is in PATH
|
||||
// has_arduino_cli arduino-cli is in PATH
|
||||
//
|
||||
// Usage in tests:
|
||||
// #[cfg_attr(not(has_cmake), ignore = "cmake not found")]
|
||||
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
fn has_tool(name: &str) -> bool {
|
||||
Command::new(name)
|
||||
.arg("--version")
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status()
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if has_tool("cmake") {
|
||||
println!("cargo:rustc-cfg=has_cmake");
|
||||
}
|
||||
if has_tool("g++") || has_tool("clang++") || has_tool("cl") {
|
||||
println!("cargo:rustc-cfg=has_cpp_compiler");
|
||||
}
|
||||
if has_tool("git") {
|
||||
println!("cargo:rustc-cfg=has_git");
|
||||
}
|
||||
if has_tool("arduino-cli") {
|
||||
println!("cargo:rustc-cfg=has_arduino_cli");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user