Skip to content

Commit 89e9f85

Browse files
committed
encode nightly version, commit, date into binary
1 parent 92e0fac commit 89e9f85

File tree

8 files changed

+84
-46
lines changed

8 files changed

+84
-46
lines changed

Cargo.lock

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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"
@@ -64,6 +65,9 @@ which = "6.0"
6465
pretty_assertions = "1.4"
6566
tempfile = "3"
6667

68+
[build-dependencies]
69+
compile-time = "0.2"
70+
6771
[badges]
6872
maintenance = { status = "actively-developed" }
6973

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

build.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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_name = if std::env::var("GITUI_RELEASE").is_ok() {
22+
format!(
23+
"{} {} ({})",
24+
env!("CARGO_PKG_VERSION"),
25+
compile_time::date_str!(),
26+
get_git_hash()
27+
)
28+
} else {
29+
format!(
30+
"nightly {} ({})",
31+
compile_time::date_str!(),
32+
get_git_hash()
33+
)
34+
};
35+
36+
println!("cargo:warning=buildname '{}'", build_name);
37+
println!("cargo:rustc-env=GITUI_BUILD_NAME={}", build_name);
38+
}

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
"\

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};

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),

src/version.rs

-35
This file was deleted.

0 commit comments

Comments
 (0)