Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit ba33f3c

Browse files
author
Jorge Aparicio
committed
include git commit hash and date in version output (-V)
plus update the CHANGELOG
1 parent 5ef2e87 commit ba33f3c

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Changed
1111

1212
- `itmdump` no longer depends on the `mkfifo` command.
13+
- `itmdump`, which normally uses named pipes, now fallbacks to regular files to
14+
be work on Windows.
15+
- `itmdump` now is restrictive with about the arguments it receives. Before, a
16+
second argument would simply be ignored, but, now, that has become a hard
17+
error.
18+
- `itmdump` version output (`-V`) now includes the git commit hash and date.
1319

1420
## v0.1.0 - 2016-10-03
1521

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[package]
22
authors = ["Jorge Aparicio <[email protected]>"]
3+
build = "build.rs"
34
description = "Tool to parse and dump ITM packets"
45
documentation = "https://docs.rs/itm"
56
keywords = ["parse", "tool", "ARM", "ITM"]

build.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use std::env;
2+
use std::error::Error;
3+
use std::fs::File;
4+
use std::io::Write;
5+
use std::path::PathBuf;
6+
use std::process::Command;
7+
8+
struct IgnoredError {}
9+
10+
impl<E> From<E> for IgnoredError
11+
where E: Error
12+
{
13+
fn from(_: E) -> IgnoredError {
14+
IgnoredError {}
15+
}
16+
}
17+
18+
fn main() {
19+
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
20+
21+
File::create(out_dir.join("commit-info.txt"))
22+
.unwrap()
23+
.write_all(commit_info().as_bytes())
24+
.unwrap();
25+
}
26+
27+
fn commit_info() -> String {
28+
match (commit_hash(), commit_date()) {
29+
(Ok(hash), Ok(date)) => format!(" ({} {})", hash.trim(), date.trim()),
30+
_ => String::new(),
31+
}
32+
}
33+
34+
fn commit_hash() -> Result<String, IgnoredError> {
35+
Ok(try!(String::from_utf8(try!(Command::new("git")
36+
.args(&["rev-parse", "--short", "HEAD"])
37+
.output())
38+
.stdout)))
39+
}
40+
41+
fn commit_date() -> Result<String, IgnoredError> {
42+
Ok(try!(String::from_utf8(try!(Command::new("git")
43+
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
44+
.output())
45+
.stdout)))
46+
}

src/bin/itmdump.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn main() {
5656

5757
fn run() -> Result<()> {
5858
let matches = App::new("itmdump")
59-
.version(env!("CARGO_PKG_VERSION"))
59+
.version(include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt")))
6060
.arg(Arg::with_name("PATH").help("Named pipe to use").required(true))
6161
.get_matches();
6262

0 commit comments

Comments
 (0)