Skip to content

Commit 2ec6d63

Browse files
committed
encode nightly version, commit, date into binary
1 parent 0966953 commit 2ec6d63

File tree

7 files changed

+52
-46
lines changed

7 files changed

+52
-46
lines changed

Diff for: Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ readme = "README.md"
1212
license = "MIT"
1313
categories = ["command-line-utilities"]
1414
keywords = ["git", "gui", "cli", "terminal", "ui"]
15+
build = "build.rs"
1516

1617
[dependencies]
1718
anyhow = "1.0"
@@ -65,6 +66,9 @@ which = "6.0"
6566
pretty_assertions = "1.4"
6667
tempfile = "3"
6768

69+
[build-dependencies]
70+
chrono = { version = "0.4", default-features = false, features = ["clock"] }
71+
6872
[badges]
6973
maintenance = { status = "actively-developed" }
7074

Diff for: Makefile

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ debug:
1616
RUST_BACKTRACE=true cargo run --features=timing -- ${ARGS}
1717

1818
build-release:
19-
cargo build --release --locked
19+
GITUI_RELEASE=1 cargo build --release --locked
2020

2121
release-mac: build-release
2222
strip target/release/gitui
@@ -42,7 +42,7 @@ build-linux-musl-debug:
4242
cargo build --target=x86_64-unknown-linux-musl
4343

4444
build-linux-musl-release:
45-
cargo build --release --target=x86_64-unknown-linux-musl
45+
GITUI_RELEASE=1 cargo build --release --target=x86_64-unknown-linux-musl
4646

4747
test-linux-musl:
4848
cargo test --workspace --target=x86_64-unknown-linux-musl
@@ -64,9 +64,9 @@ build-linux-arm-debug:
6464
cargo build --target=arm-unknown-linux-gnueabihf
6565

6666
build-linux-arm-release:
67-
cargo build --release --target=aarch64-unknown-linux-gnu
68-
cargo build --release --target=armv7-unknown-linux-gnueabihf
69-
cargo build --release --target=arm-unknown-linux-gnueabihf
67+
GITUI_RELEASE=1 cargo build --release --target=aarch64-unknown-linux-gnu
68+
GITUI_RELEASE=1 cargo build --release --target=armv7-unknown-linux-gnueabihf
69+
GITUI_RELEASE=1 cargo build --release --target=arm-unknown-linux-gnueabihf
7070

7171
test:
7272
cargo test --workspace
@@ -100,4 +100,4 @@ licenses:
100100
cargo bundle-licenses --format toml --output THIRDPARTY.toml
101101

102102
clean:
103-
cargo clean
103+
cargo clean

Diff for: build.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
fn get_git_hash() -> String {
2+
use std::process::Command;
3+
4+
let commit = Command::new("git")
5+
.arg("rev-parse")
6+
.arg("--short")
7+
.arg("--verify")
8+
.arg("HEAD")
9+
.output();
10+
if let Ok(commit_output) = commit {
11+
let commit_string =
12+
String::from_utf8_lossy(&commit_output.stdout);
13+
14+
return commit_string.lines().next().unwrap_or("").into();
15+
}
16+
17+
panic!("Can not get git commit: {}", commit.unwrap_err());
18+
}
19+
20+
fn main() {
21+
let build_date = chrono::Local::now().date_naive();
22+
23+
let build_name = if std::env::var("GITUI_RELEASE").is_ok() {
24+
format!(
25+
"{} {} ({})",
26+
env!("CARGO_PKG_VERSION"),
27+
build_date,
28+
get_git_hash()
29+
)
30+
} else {
31+
format!("nightly {} ({})", build_date, get_git_hash())
32+
};
33+
34+
println!("cargo:warning=buildname '{}'", build_name);
35+
println!("cargo:rustc-env=GITUI_BUILD_NAME={}", build_name);
36+
}

Diff for: src/args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::bug_report;
22
use anyhow::{anyhow, Result};
33
use asyncgit::sync::RepoPath;
44
use clap::{
5-
crate_authors, crate_description, crate_name, crate_version, Arg,
5+
crate_authors, crate_description, crate_name, Arg,
66
Command as ClapApp,
77
};
88
use simplelog::{Config, LevelFilter, WriteLogger};
@@ -63,7 +63,7 @@ pub fn process_cmdline() -> Result<CliArgs> {
6363
fn app() -> ClapApp {
6464
ClapApp::new(crate_name!())
6565
.author(crate_authors!())
66-
.version(crate_version!())
66+
.version(env!("GITUI_BUILD_NAME"))
6767
.about(crate_description!())
6868
.help_template(
6969
"\

Diff for: src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ mod string_utils;
4343
mod strings;
4444
mod tabs;
4545
mod ui;
46-
mod version;
4746
mod watcher;
4847

4948
use crate::{app::App, args::process_cmdline};

Diff for: src/popups/help.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::{
66
app::Environment,
77
keys::{key_match, SharedKeyConfig},
88
strings, ui,
9-
version::Version,
109
};
1110
use anyhow::Result;
1211
use asyncgit::hash;
@@ -70,7 +69,10 @@ impl DrawableComponent for HelpPopup {
7069

7170
f.render_widget(
7271
Paragraph::new(Line::from(vec![Span::styled(
73-
Cow::from(format!("gitui {}", Version::new(),)),
72+
Cow::from(format!(
73+
"gitui {}",
74+
env!("GITUI_BUILD_NAME"),
75+
)),
7476
Style::default(),
7577
)]))
7678
.alignment(Alignment::Right),

Diff for: src/version.rs

-35
This file was deleted.

0 commit comments

Comments
 (0)