use std::process::Command;
use const_format::concatcp;
#[cfg(feature = "unstable")]
const UNSTABLE: &str = "+unstable";
#[cfg(not(feature = "unstable"))]
const UNSTABLE: &str = "";
#[cfg(feature = "color")]
const COLOR: &str = "+color";
#[cfg(not(feature = "color"))]
const COLOR: &str = "";
#[cfg(feature = "allow_insecure_urls")]
const INSECURE_URLS: &str = "+allow_insecure_urls";
#[cfg(not(feature = "allow_insecure_urls"))]
const INSECURE_URLS: &str = "";
#[cfg(feature = "allow_invalid_certs")]
const INVALID_CERTS: &str = "+allow_invalid_certs";
#[cfg(not(feature = "allow_invalid_certs"))]
const INVALID_CERTS: &str = "";
fn main() {
let out_dir = std::env::var("OUT_DIR").unwrap();
std::fs::copy("share/third_party_licenses.md", format!("{out_dir}/third_party_licenses.md"))
.expect("failed to copy third party licenses");
std::fs::copy("LICENSE", format!("{out_dir}/LICENSE")).expect("failed to copy licenses");
let commit_id = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.filter(|output| !output.stdout.is_empty())
.map(|output| String::from_utf8(output.stdout).unwrap())
.unwrap_or_else(|| String::from("UNKNOWN"));
println!(
"cargo:rustc-env=SEAPLANE_VER_WITH_HASH=v{} ({})",
env!("CARGO_PKG_VERSION"),
commit_id.trim()
);
println!(
"cargo:rustc-env=SEAPLANE_BUILD_FEATURES={}",
concatcp!(COLOR, " ", UNSTABLE, " ", INSECURE_URLS, " ", INVALID_CERTS)
);
}