Skip to content

Commit

Permalink
fix: unwrap panic if build run outside git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
igordejanovic committed Oct 11, 2024
1 parent ccf30ef commit 59fed34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions rustemo-compiler/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
Expand All @@ -42,7 +47,7 @@ fn get_git_hash_if_building_compiler() -> Option<String> {

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

Expand Down

0 comments on commit 59fed34

Please sign in to comment.