use mcai_license::McaiWorkerLicense;
use std::{io::Write, str::FromStr};
pub fn build_mcai_info() {
let manifest = cargo_toml::Manifest::from_path("./Cargo.toml").unwrap();
if let Some(inherited_license) = manifest.package.clone().unwrap().license {
if let Ok(license) = inherited_license.get() {
if let Err(error) = McaiWorkerLicense::from_str(license) {
println!("cargo:warning={}. Possible values: 'Commercial', 'Private' or a SPDX Open Source license identifier.", error);
}
} else {
println!("cargo:warning=License field is not properly inherited");
}
} else {
println!("cargo:warning=License field is mandatory for MCAI workers");
}
let package = serde_json::to_string(&manifest.package).unwrap();
let dst = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).join("mcai_build.rs");
let mut built_file = std::fs::File::create(dst).unwrap();
let content = format!("serde_json::from_str(r#\"{}\"#).unwrap()", package);
built_file.write_all(content.as_bytes()).unwrap();
println!("cargo:rerun-if-changed=build.rs")
}