Skip to content

Commit

Permalink
chore: ckb version tweaks (nervosnetwork#449)
Browse files Browse the repository at this point in the history
- rerun build.rs to get latest version info when any file has changed.
- include pre version.
  • Loading branch information
doitian committed Apr 11, 2019
1 parent 45a5fca commit 6573165
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 0 additions & 2 deletions build.rs
@@ -1,6 +1,4 @@
fn main() {
// Don't rebuild even if nothing changed
println!("cargo:rerun-if-changed=build.rs");
// forward git repo hashes we build at
println!(
"cargo:rustc-env=COMMIT_DESCRIBE={}",
Expand Down
19 changes: 17 additions & 2 deletions util/build-info/src/lib.rs
Expand Up @@ -12,6 +12,14 @@ macro_rules! get_version {
let patch = env!("CARGO_PKG_VERSION_PATCH")
.parse::<u16>()
.expect("CARGO_PKG_VERSION_PATCH parse success");
let dash_pre = {
let pre = env!("CARGO_PKG_VERSION_PRE");
if pre == "" {
pre.to_string()
} else {
"-".to_string() + pre
}
};

let host_compiler = $crate::get_channel();
let commit_describe = option_env!("COMMIT_DESCRIBE").map(|s| s.to_string());
Expand All @@ -20,6 +28,7 @@ macro_rules! get_version {
major,
minor,
patch,
dash_pre,
host_compiler,
commit_describe,
commit_date,
Expand All @@ -28,18 +37,23 @@ macro_rules! get_version {
}

// some code taken and adapted from RLS and cargo
#[derive(Debug)]
pub struct Version {
pub major: u8,
pub minor: u8,
pub patch: u16,
pub dash_pre: String,
pub host_compiler: Option<String>,
pub commit_describe: Option<String>,
pub commit_date: Option<String>,
}

impl Version {
pub fn short(&self) -> String {
format!("{}.{}.{}", self.major, self.minor, self.patch)
format!(
"{}.{}.{}{}",
self.major, self.minor, self.patch, self.dash_pre
)
}

pub fn long(&self) -> String {
Expand All @@ -52,10 +66,11 @@ impl std::fmt::Display for Version {
if self.commit_describe.is_some() {
write!(
f,
"{}.{}.{} ({} {})",
"{}.{}.{}{} ({} {})",
self.major,
self.minor,
self.patch,
self.dash_pre,
self.commit_describe.clone().unwrap_or_default().trim(),
self.commit_date.clone().unwrap_or_default().trim(),
)?;
Expand Down

0 comments on commit 6573165

Please sign in to comment.