From 59fed34c2879553139f4643c3fbae7b235ca2d41 Mon Sep 17 00:00:00 2001 From: Igor Dejanovic Date: Fri, 11 Oct 2024 21:19:37 +0200 Subject: [PATCH] fix: `unwrap` panic if build run outside git repo --- CHANGELOG.md | 7 +++++++ rustemo-compiler/build.rs | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ed2d45d..a0c44235 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # [Unreleased] +# [0.6.2] - 2024-10-11 + +## Fixed + +- `unwrap` panic if rustemo-compiler is built outside of git repo (e.g. from crates.io). + + # [0.6.1] - 2024-10-02 ## Changed diff --git a/rustemo-compiler/build.rs b/rustemo-compiler/build.rs index 8e43b0cd..b86ce3e9 100644 --- a/rustemo-compiler/build.rs +++ b/rustemo-compiler/build.rs @@ -24,7 +24,12 @@ fn main() { .or_else(get_git_hash_if_building_compiler) .unwrap_or_default(); - println!("cargo:rustc-env=GIT_HASH=-{}", cut_git_hash(&git_hash)); + if git_hash.len() > 0 { + println!("cargo:rustc-env=GIT_HASH=-{}", cut_git_hash(&git_hash)); + } else { + println!("cargo:rustc-env=GIT_HASH="); + } + } fn get_git_hash_if_building_compiler() -> Option { @@ -42,7 +47,7 @@ fn get_git_hash_if_building_compiler() -> Option { fn cut_git_hash(hash: &str) -> &str { const CUT_COUNT: usize = 10; - let end_idx = hash.char_indices().nth(CUT_COUNT).unwrap().0; + let end_idx = hash.char_indices().map(|x| x.0).nth(CUT_COUNT).unwrap_or(hash.len()); &hash[..end_idx] }