Skip to content

Commit a04f7c4

Browse files
committed
Mock .git for packaging purposes
1 parent 58c2499 commit a04f7c4

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ license = "Apache-2.0"
55
name = "ilc"
66
repository = "https://github.com/tilpner/ilc"
77
version = "0.3.0"
8+
build = "build.rs"
89
exclude = [".cargo/**"]
910

1011
[[bin]]

build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::fs::{self, File};
2+
use std::path::Path;
3+
4+
fn main() {
5+
let path = Path::new(".git").join("refs").join("heads").join("master");
6+
if !path.exists() {
7+
let _ = fs::create_dir_all(path.parent().unwrap());
8+
let _ = File::create(&path);
9+
}
10+
}

cli/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mod stats;
3535

3636
pub struct Cli {
3737
pub version: String,
38-
pub master_hash: String,
38+
pub master_hash: Option<String>,
3939
}
4040

4141
pub fn main(cli: Cli) {
@@ -44,7 +44,10 @@ pub fn main(cli: Cli) {
4444
info!("Compiled with FUSEs")
4545
}
4646

47-
let version = format!("{} ({})", cli.version, cli.master_hash);
47+
let version = match cli.master_hash {
48+
Some(ref h) => format!("{} ({})", cli.version, h),
49+
None => cli.version.clone(),
50+
};
4851
let args = App::new("ilc")
4952
.version(&version[..])
5053
.setting(AppSettings::GlobalVersion)

cli/src/stats.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use error;
1313

1414
struct StatFormat {
1515
version: String,
16-
master_hash: String,
16+
master_hash: Option<String>,
1717
time: String,
1818
stats: Stats,
1919
}
@@ -28,7 +28,9 @@ impl Serialize for StatFormat {
2828
where S: Serializer
2929
{
3030
try!(s.serialize_struct_elt("version", &self.0.version));
31-
try!(s.serialize_struct_elt("master_hash", &self.0.master_hash));
31+
if let &Some(ref h) = &self.0.master_hash {
32+
try!(s.serialize_struct_elt("master_hash", h));
33+
}
3234
try!(s.serialize_struct_elt("time", &self.0.time));
3335
try!(s.serialize_struct_elt("stats", &self.0.stats));
3436
Ok(None)

src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ extern crate ilc_cli;
22

33
use ilc_cli::Cli;
44

5-
static MASTER: &'static str = include_str!("../.git/refs/heads/master");
5+
static MASTER_HASH: &'static str = include_str!("../.git/refs/heads/master");
66

77
fn main() {
88
ilc_cli::main(Cli {
99
version: env!("CARGO_PKG_VERSION").into(),
10-
master_hash: MASTER.trim_right().into(),
10+
master_hash: if MASTER_HASH.is_empty() {
11+
None
12+
} else {
13+
Some(MASTER_HASH.trim_right().to_owned())
14+
},
1115
});
1216
}

0 commit comments

Comments
 (0)