// Copyright (C) 2026 Elias Wendland // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, version 3 exclusively. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . use clap::CommandFactory; use std::{env, fs, path::Path, process::Command}; #[path = "src/args.rs"] mod args; fn command_output(command: &str, args: &[&str]) -> String { Command::new(command) .args(args) .output() .ok() .filter(|output| output.status.success()) .map(|output| String::from_utf8_lossy(&output.stdout).trim().to_owned()) .filter(|output| !output.is_empty()) .unwrap_or_else(|| "unknown".to_owned()) } fn main() { let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR is set by Cargo"); let version = env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "unknown".to_owned()); let rustc_version = command_output( &env::var("RUSTC").unwrap_or_else(|_| "rustc".to_owned()), &["--version"], ); let target = env::var("TARGET").unwrap_or_else(|_| "unknown".to_owned()); println!("cargo:rustc-env=CONVERTIS_RUSTC_VERSION={rustc_version}"); println!("cargo:rustc-env=CONVERTIS_TARGET={target}"); let version_text = format!( "{}\nbuild-time: {}\ncommit: {}\ntarget: {}\nrustc: {}", version, command_output("date", &["-u", "+%Y-%m-%d %H:%M:%S UTC"]), command_output("git", &["rev-parse", "--short", "HEAD"]), target, rustc_version, ); fs::write(Path::new(&out_dir).join("version.txt"), version_text).unwrap(); let man_dir = Path::new("target/man"); fs::create_dir_all(man_dir).unwrap(); let command = args::Args::command() .name("convertis") .version(env!("CARGO_PKG_VERSION")); let mut buffer = Vec::new(); clap_mangen::Man::new(command).render(&mut buffer).unwrap(); fs::write(man_dir.join("convertis.1"), buffer).unwrap(); }