Use built to determine version information
This commit is contained in:
@@ -33,6 +33,9 @@ serde_json = { version = "*", optional = true }
|
||||
[dependencies.taskchampion]
|
||||
path = "../taskchampion"
|
||||
|
||||
[build-dependencies]
|
||||
built = { version = "0.5", features = ["git2"] }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "^1.0.3"
|
||||
predicates = "^1.0.7"
|
||||
|
||||
33
cli/build.rs
33
cli/build.rs
@@ -1,34 +1,3 @@
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
// Query HEAD revision and expose as $TC_GIT_REV during build
|
||||
//
|
||||
// Adapted from https://stackoverflow.com/questions/43753491
|
||||
let cmd = Command::new("git")
|
||||
.args(&["rev-parse", "--short", "HEAD"])
|
||||
.spawn()
|
||||
// Wait for process to exit
|
||||
.and_then(|cmd| cmd.wait_with_output())
|
||||
// Handle error if failed to launch git
|
||||
.map_err(|_e| println!("cargo:warning=Failed to run 'git' to determine HEAD rev"))
|
||||
// Remap to Some/None for simpler error handling
|
||||
.ok()
|
||||
// Handle command failing
|
||||
.and_then(|o| {
|
||||
if o.status.success() {
|
||||
Some(o)
|
||||
} else {
|
||||
println!(
|
||||
"cargo:warning='git' exited with non-zero exit code while determining HEAD rev"
|
||||
);
|
||||
None
|
||||
}
|
||||
})
|
||||
// Get output as UTF-8 string
|
||||
.map(|out| String::from_utf8(out.stdout).expect("Invalid output in stdout"));
|
||||
|
||||
// Only output git rev if successful
|
||||
if let Some(h) = cmd {
|
||||
println!("cargo:rustc-env=TC_GIT_REV={}", h);
|
||||
}
|
||||
built::write_built_file().expect("Failed to acquire build-time information");
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
use crate::built_info;
|
||||
use termcolor::{ColorSpec, WriteColor};
|
||||
|
||||
pub(crate) fn execute<W: WriteColor>(w: &mut W) -> Result<(), crate::Error> {
|
||||
write!(w, "TaskChampion ")?;
|
||||
w.set_color(ColorSpec::new().set_bold(true))?;
|
||||
write!(w, "{}", env!("CARGO_PKG_VERSION"))?;
|
||||
write!(w, "{}", built_info::PKG_VERSION)?;
|
||||
w.reset()?;
|
||||
|
||||
if let Some(h) = option_env!("TC_GIT_REV") {
|
||||
write!(w, " (git rev: {})", h)?;
|
||||
if let (Some(version), Some(dirty)) = (built_info::GIT_VERSION, built_info::GIT_DIRTY) {
|
||||
if dirty {
|
||||
write!(w, " (git version: {} with un-committed changes)", version)?;
|
||||
} else {
|
||||
write!(w, " (git version: {})", version)?;
|
||||
};
|
||||
}
|
||||
writeln!(w)?;
|
||||
Ok(())
|
||||
|
||||
@@ -44,6 +44,11 @@ mod settings;
|
||||
mod table;
|
||||
mod usage;
|
||||
|
||||
/// See https://docs.rs/built
|
||||
pub(crate) mod built_info {
|
||||
include!(concat!(env!("OUT_DIR"), "/built.rs"));
|
||||
}
|
||||
|
||||
pub(crate) use errors::Error;
|
||||
use settings::Settings;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user