diff options
author | Till Höppner | 2016-03-09 18:56:15 +0100 |
---|---|---|
committer | Till Höppner | 2016-03-09 18:56:15 +0100 |
commit | a04f7c45e5f6e0d656d6e6a87d63ce2bcaa0865b (patch) | |
tree | cbe502d0287b4d40a3cee98d433973a4336ae710 | |
parent | 58c249954e7bb8776f213248d9ca220a27c372b7 (diff) | |
download | ilc-a04f7c45e5f6e0d656d6e6a87d63ce2bcaa0865b.tar.gz ilc-a04f7c45e5f6e0d656d6e6a87d63ce2bcaa0865b.tar.xz ilc-a04f7c45e5f6e0d656d6e6a87d63ce2bcaa0865b.zip |
Mock .git for packaging purposes
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | build.rs | 10 | ||||
-rw-r--r-- | cli/src/lib.rs | 7 | ||||
-rw-r--r-- | cli/src/stats.rs | 6 | ||||
-rw-r--r-- | src/main.rs | 8 |
5 files changed, 26 insertions, 6 deletions
@@ -5,6 +5,7 @@ license = "Apache-2.0" name = "ilc" repository = "https://github.com/tilpner/ilc" version = "0.3.0" +build = "build.rs" exclude = [".cargo/**"] [[bin]] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..4915967 --- /dev/null +++ b/build.rs @@ -0,0 +1,10 @@ +use std::fs::{self, File}; +use std::path::Path; + +fn main() { + let path = Path::new(".git").join("refs").join("heads").join("master"); + if !path.exists() { + let _ = fs::create_dir_all(path.parent().unwrap()); + let _ = File::create(&path); + } +} diff --git a/cli/src/lib.rs b/cli/src/lib.rs index ba7f792..937ae99 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -35,7 +35,7 @@ mod stats; pub struct Cli { pub version: String, - pub master_hash: String, + pub master_hash: Option<String>, } pub fn main(cli: Cli) { @@ -44,7 +44,10 @@ pub fn main(cli: Cli) { info!("Compiled with FUSEs") } - let version = format!("{} ({})", cli.version, cli.master_hash); + let version = match cli.master_hash { + Some(ref h) => format!("{} ({})", cli.version, h), + None => cli.version.clone(), + }; let args = App::new("ilc") .version(&version[..]) .setting(AppSettings::GlobalVersion) diff --git a/cli/src/stats.rs b/cli/src/stats.rs index 390a200..8c92cc6 100644 --- a/cli/src/stats.rs +++ b/cli/src/stats.rs @@ -13,7 +13,7 @@ use error; struct StatFormat { version: String, - master_hash: String, + master_hash: Option<String>, time: String, stats: Stats, } @@ -28,7 +28,9 @@ impl Serialize for StatFormat { where S: Serializer { try!(s.serialize_struct_elt("version", &self.0.version)); - try!(s.serialize_struct_elt("master_hash", &self.0.master_hash)); + if let &Some(ref h) = &self.0.master_hash { + try!(s.serialize_struct_elt("master_hash", h)); + } try!(s.serialize_struct_elt("time", &self.0.time)); try!(s.serialize_struct_elt("stats", &self.0.stats)); Ok(None) diff --git a/src/main.rs b/src/main.rs index 0cdab68..09a0e83 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,11 +2,15 @@ extern crate ilc_cli; use ilc_cli::Cli; -static MASTER: &'static str = include_str!("../.git/refs/heads/master"); +static MASTER_HASH: &'static str = include_str!("../.git/refs/heads/master"); fn main() { ilc_cli::main(Cli { version: env!("CARGO_PKG_VERSION").into(), - master_hash: MASTER.trim_right().into(), + master_hash: if MASTER_HASH.is_empty() { + None + } else { + Some(MASTER_HASH.trim_right().to_owned()) + }, }); } |