Skip to content

Commit

Permalink
encode nightly version, commit, date into binary
Browse files Browse the repository at this point in the history
  • Loading branch information
extrawurst committed Mar 27, 2024
1 parent 92e0fac commit 89e9f85
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 46 deletions.
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ readme = "README.md"
license = "MIT"
categories = ["command-line-utilities"]
keywords = ["git", "gui", "cli", "terminal", "ui"]
build = "build.rs"

[dependencies]
anyhow = "1.0"
Expand Down Expand Up @@ -64,6 +65,9 @@ which = "6.0"
pretty_assertions = "1.4"
tempfile = "3"

[build-dependencies]
compile-time = "0.2"

[badges]
maintenance = { status = "actively-developed" }

Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ debug:
RUST_BACKTRACE=true cargo run --features=timing -- ${ARGS}

build-release:
cargo build --release --locked
GITUI_RELEASE=1 cargo build --release --locked

release-mac: build-release
strip target/release/gitui
Expand All @@ -42,7 +42,7 @@ build-linux-musl-debug:
cargo build --target=x86_64-unknown-linux-musl

build-linux-musl-release:
cargo build --release --target=x86_64-unknown-linux-musl
GITUI_RELEASE=1 cargo build --release --target=x86_64-unknown-linux-musl

test-linux-musl:
cargo test --workspace --target=x86_64-unknown-linux-musl
Expand All @@ -64,9 +64,9 @@ build-linux-arm-debug:
cargo build --target=arm-unknown-linux-gnueabihf

build-linux-arm-release:
cargo build --release --target=aarch64-unknown-linux-gnu
cargo build --release --target=armv7-unknown-linux-gnueabihf
cargo build --release --target=arm-unknown-linux-gnueabihf
GITUI_RELEASE=1 cargo build --release --target=aarch64-unknown-linux-gnu
GITUI_RELEASE=1 cargo build --release --target=armv7-unknown-linux-gnueabihf
GITUI_RELEASE=1 cargo build --release --target=arm-unknown-linux-gnueabihf

test:
cargo test --workspace
Expand Down Expand Up @@ -100,4 +100,4 @@ licenses:
cargo bundle-licenses --format toml --output THIRDPARTY.toml

clean:
cargo clean
cargo clean
38 changes: 38 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
fn get_git_hash() -> String {
use std::process::Command;

let commit = Command::new("git")
.arg("rev-parse")
.arg("--short")
.arg("--verify")
.arg("HEAD")
.output();
if let Ok(commit_output) = commit {
let commit_string =
String::from_utf8_lossy(&commit_output.stdout);

return commit_string.lines().next().unwrap_or("").into();
}

panic!("Can not get git commit: {}", commit.unwrap_err());
}

fn main() {
let build_name = if std::env::var("GITUI_RELEASE").is_ok() {
format!(
"{} {} ({})",
env!("CARGO_PKG_VERSION"),
compile_time::date_str!(),
get_git_hash()
)
} else {
format!(
"nightly {} ({})",
compile_time::date_str!(),
get_git_hash()
)
};

println!("cargo:warning=buildname '{}'", build_name);
println!("cargo:rustc-env=GITUI_BUILD_NAME={}", build_name);
}
4 changes: 2 additions & 2 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::bug_report;
use anyhow::{anyhow, Result};
use asyncgit::sync::RepoPath;
use clap::{
crate_authors, crate_description, crate_name, crate_version, Arg,
crate_authors, crate_description, crate_name, Arg,
Command as ClapApp,
};
use simplelog::{Config, LevelFilter, WriteLogger};
Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn process_cmdline() -> Result<CliArgs> {
fn app() -> ClapApp {
ClapApp::new(crate_name!())
.author(crate_authors!())
.version(crate_version!())
.version(env!("GITUI_BUILD_NAME"))
.about(crate_description!())
.help_template(
"\
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ mod string_utils;
mod strings;
mod tabs;
mod ui;
mod version;
mod watcher;

use crate::{app::App, args::process_cmdline};
Expand Down
6 changes: 4 additions & 2 deletions src/popups/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
app::Environment,
keys::{key_match, SharedKeyConfig},
strings, ui,
version::Version,
};
use anyhow::Result;
use asyncgit::hash;
Expand Down Expand Up @@ -70,7 +69,10 @@ impl DrawableComponent for HelpPopup {

f.render_widget(
Paragraph::new(Line::from(vec![Span::styled(
Cow::from(format!("gitui {}", Version::new(),)),
Cow::from(format!(
"gitui {}",
env!("GITUI_BUILD_NAME"),
)),
Style::default(),
)]))
.alignment(Alignment::Right),
Expand Down
35 changes: 0 additions & 35 deletions src/version.rs

This file was deleted.

0 comments on commit 89e9f85

Please sign in to comment.