notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit f050de6b7a6e2fc8b95bad571c536ea6e3165893
parent d97dcb147d79c866f79dd6b76e3ccca7302fe425
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 10 Jan 2025 06:04:20 -0800

build: fix missing GIT_COMMIT_HASH in some cases

Some people try to build without git, this adds a fallback so that
compilation still works in those cases.

Changelog-Fixed: Fix GIT_COMMIT_HASH compilation issue
Fixes: https://github.com/damus-io/notedeck/issues/634
Fixes: https://github.com/damus-io/notedeck/issues/633

Diffstat:
Mcrates/notedeck_columns/build.rs | 29++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/crates/notedeck_columns/build.rs b/crates/notedeck_columns/build.rs @@ -1,10 +1,29 @@ use std::process::Command; +fn fallback() { + if let Some(dirname) = std::env::current_dir() + .as_ref() + .ok() + .and_then(|cwd| cwd.file_name().and_then(|fname| fname.to_str())) + { + println!("cargo:rustc-env=GIT_COMMIT_HASH={}", dirname); + } else { + println!("cargo:rustc-env=GIT_COMMIT_HASH=unknown"); + } +} + fn main() { - if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() { - if output.status.success() { - let hash = String::from_utf8_lossy(&output.stdout); - println!("cargo:rustc-env=GIT_COMMIT_HASH={}", hash.trim()); - } + let output = if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() { + output + } else { + fallback(); + return; + }; + + if output.status.success() { + let hash = String::from_utf8_lossy(&output.stdout); + println!("cargo:rustc-env=GIT_COMMIT_HASH={}", hash.trim()); + } else { + fallback(); } }