mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Merge pull request #268 from taskchampion/use-built
Use `built` to determine version information
This commit is contained in:
commit
64b319bd20
5 changed files with 104 additions and 35 deletions
87
Cargo.lock
generated
87
Cargo.lock
generated
|
@ -535,6 +535,16 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "built"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4f346b6890a0dfa7266974910e7df2d5088120dd54721b9b0e5aae1ae5e05715"
|
||||||
|
dependencies = [
|
||||||
|
"cargo-lock",
|
||||||
|
"git2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.6.1"
|
version = "3.6.1"
|
||||||
|
@ -574,11 +584,26 @@ dependencies = [
|
||||||
"bytes 1.0.1",
|
"bytes 1.0.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cargo-lock"
|
||||||
|
version = "7.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a19807e9f4f8af2c8ece4236ed7d229b9179da1f3f2ba44e765c7ba934748f99"
|
||||||
|
dependencies = [
|
||||||
|
"semver 1.0.3",
|
||||||
|
"serde",
|
||||||
|
"toml",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.67"
|
version = "1.0.67"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
|
checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
|
||||||
|
dependencies = [
|
||||||
|
"jobserver",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
|
@ -1140,6 +1165,19 @@ dependencies = [
|
||||||
"wasi 0.10.2+wasi-snapshot-preview1",
|
"wasi 0.10.2+wasi-snapshot-preview1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "git2"
|
||||||
|
version = "0.13.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d9831e983241f8c5591ed53f17d874833e2fa82cac2625f3888c50cbfe136cba"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"libc",
|
||||||
|
"libgit2-sys",
|
||||||
|
"log",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gitignore"
|
name = "gitignore"
|
||||||
version = "1.0.7"
|
version = "1.0.7"
|
||||||
|
@ -1430,6 +1468,15 @@ version = "0.4.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jobserver"
|
||||||
|
version = "0.1.22"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "972f5ae5d1cb9c6ae417789196c803205313edde988685da5e3aae0827b9e7fd"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.50"
|
version = "0.3.50"
|
||||||
|
@ -1499,6 +1546,30 @@ version = "0.2.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
|
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libgit2-sys"
|
||||||
|
version = "0.12.21+1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "86271bacd72b2b9e854c3dcfb82efd538f15f870e4c11af66900effb462f6825"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"libz-sys",
|
||||||
|
"pkg-config",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libz-sys"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "de5435b8549c16d423ed0c03dbaafe57cf6c3344744f1242520d59c9d8ecec66"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linked-hash-map"
|
name = "linked-hash-map"
|
||||||
version = "0.5.4"
|
version = "0.5.4"
|
||||||
|
@ -2556,6 +2627,15 @@ dependencies = [
|
||||||
"semver-parser 0.10.2",
|
"semver-parser 0.10.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f3aac57ee7f3272d8395c6e4f502f434f0e289fcd62876f70daa008c20dcabe"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver-parser"
|
name = "semver-parser"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
@ -2869,6 +2949,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
"atty",
|
"atty",
|
||||||
|
"built",
|
||||||
"chrono",
|
"chrono",
|
||||||
"dirs-next",
|
"dirs-next",
|
||||||
"env_logger 0.8.3",
|
"env_logger 0.8.3",
|
||||||
|
@ -3411,6 +3492,12 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vcpkg"
|
||||||
|
version = "0.2.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "025ce40a007e1907e58d5bc1a594def78e5573bb0b1160bc389634e8f12e4faa"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vec_map"
|
name = "vec_map"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
|
|
|
@ -33,6 +33,9 @@ serde_json = { version = "*", optional = true }
|
||||||
[dependencies.taskchampion]
|
[dependencies.taskchampion]
|
||||||
path = "../taskchampion"
|
path = "../taskchampion"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
built = { version = "0.5", features = ["git2"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_cmd = "^1.0.3"
|
assert_cmd = "^1.0.3"
|
||||||
predicates = "^1.0.7"
|
predicates = "^1.0.7"
|
||||||
|
|
33
cli/build.rs
33
cli/build.rs
|
@ -1,34 +1,3 @@
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Query HEAD revision and expose as $TC_GIT_REV during build
|
built::write_built_file().expect("Failed to acquire build-time information");
|
||||||
//
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
|
use crate::built_info;
|
||||||
use termcolor::{ColorSpec, WriteColor};
|
use termcolor::{ColorSpec, WriteColor};
|
||||||
|
|
||||||
pub(crate) fn execute<W: WriteColor>(w: &mut W) -> Result<(), crate::Error> {
|
pub(crate) fn execute<W: WriteColor>(w: &mut W) -> Result<(), crate::Error> {
|
||||||
write!(w, "TaskChampion ")?;
|
write!(w, "TaskChampion ")?;
|
||||||
w.set_color(ColorSpec::new().set_bold(true))?;
|
w.set_color(ColorSpec::new().set_bold(true))?;
|
||||||
write!(w, "{}", env!("CARGO_PKG_VERSION"))?;
|
write!(w, "{}", built_info::PKG_VERSION)?;
|
||||||
w.reset()?;
|
w.reset()?;
|
||||||
|
|
||||||
if let Some(h) = option_env!("TC_GIT_REV") {
|
if let (Some(version), Some(dirty)) = (built_info::GIT_VERSION, built_info::GIT_DIRTY) {
|
||||||
write!(w, " (git rev: {})", h)?;
|
if dirty {
|
||||||
|
write!(w, " (git version: {} with un-committed changes)", version)?;
|
||||||
|
} else {
|
||||||
|
write!(w, " (git version: {})", version)?;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
writeln!(w)?;
|
writeln!(w)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -44,6 +44,11 @@ mod settings;
|
||||||
mod table;
|
mod table;
|
||||||
mod usage;
|
mod usage;
|
||||||
|
|
||||||
|
/// See https://docs.rs/built
|
||||||
|
pub(crate) mod built_info {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/built.rs"));
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) use errors::Error;
|
pub(crate) use errors::Error;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue