63 lines
2.3 KiB
Rust
63 lines
2.3 KiB
Rust
pub fn main() {
|
|
println!("pwd: {}", std::env::current_dir().unwrap().display());
|
|
println!("cargo:rerun-if-changed=../../action_schema.xsd");
|
|
|
|
// Find xml_schema_generator in the path or in cargo bin directory
|
|
let cargo_home = std::env::var("CARGO_HOME").unwrap_or_else(|_| {
|
|
if cfg!(windows) {
|
|
format!("{}/.cargo", std::env::var("USERPROFILE").unwrap())
|
|
} else {
|
|
format!("{}/.cargo", std::env::var("HOME").unwrap())
|
|
}
|
|
});
|
|
|
|
let bin_dir = format!("{}/bin", cargo_home);
|
|
let paths = vec![bin_dir];
|
|
|
|
// Find the executable
|
|
let executable_name = if cfg!(windows) {
|
|
"xml_schema_generator.exe"
|
|
} else {
|
|
"xml_schema_generator"
|
|
};
|
|
|
|
let executable_path = paths.iter()
|
|
.map(|p| format!("{}/{}", p, executable_name))
|
|
.find(|p| std::path::Path::new(p).exists());
|
|
|
|
// If the executable isn't in any of the checked paths, try to install it
|
|
let executable = match executable_path {
|
|
Some(path) => path,
|
|
None => {
|
|
println!("cargo:warning=xml_schema_generator not found, trying to install it");
|
|
// Install xml_schema_generator using cargo install
|
|
let status = std::process::Command::new("cargo")
|
|
.args(["install", "xml_schema_generator"])
|
|
.status()
|
|
.expect("Failed to run cargo install");
|
|
|
|
if !status.success() {
|
|
panic!("Failed to install xml_schema_generator");
|
|
}
|
|
|
|
// Now it should be in the cargo bin directory
|
|
format!("{}/bin/{}", cargo_home, executable_name)
|
|
}
|
|
};
|
|
|
|
println!("cargo:warning=Using xml_schema_generator at: {}", executable);
|
|
|
|
// Run the generator
|
|
let output = std::process::Command::new(&executable)
|
|
.arg("--derive")
|
|
.arg("Clone, Debug, Deserialize, Serialize")
|
|
.arg("../../action_schema.xsd")
|
|
.arg("src/schema.rs")
|
|
.output()
|
|
.expect(&format!("Failed to execute {}", executable));
|
|
|
|
if !output.status.success() {
|
|
panic!("xml_schema_generator failed: {}",
|
|
String::from_utf8_lossy(&output.stderr));
|
|
}
|
|
} |