mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Use built
to determine version information
This commit is contained in:
parent
0c43f82176
commit
6c9ba48674
5 changed files with 104 additions and 35 deletions
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");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue