diff options
| author | Cole Helbling <cole.e.helbling@outlook.com> | 2023-02-25 13:44:51 -0800 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2023-02-28 16:57:21 +0100 |
| commit | 8062cc74fc94bbe073189e78328901606c859d41 (patch) | |
| tree | a75910734d6ef20b868f27a19e6c557bfbeda9c2 | |
| parent | cf4884f2a3e946abb0d420b27c4df8ad7a0d1977 (diff) | |
| download | mullvadvpn-8062cc74fc94bbe073189e78328901606c859d41.tar.xz mullvadvpn-8062cc74fc94bbe073189e78328901606c859d41.zip | |
Allow building without .git directory
Nixpkgs does not keep around .git directories by default since they are
not totally deterministic. This new HEAD hash check will obviously fail
without a .git.
| -rw-r--r-- | mullvad-version/build.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/mullvad-version/build.rs b/mullvad-version/build.rs index 3025487b55..18a8b8422b 100644 --- a/mullvad-version/build.rs +++ b/mullvad-version/build.rs @@ -53,12 +53,14 @@ fn get_product_version(target: Target) -> String { .trim() .to_owned(); - let dev_suffix = get_dev_suffix(target, &version); - - format!("{version}{dev_suffix}") + if let Some(dev_suffix) = get_dev_suffix(target, &version) { + format!("{version}{dev_suffix}") + } else { + version + } } -fn get_dev_suffix(target: Target, product_version: &str) -> String { +fn get_dev_suffix(target: Target, product_version: &str) -> Option<String> { // Compute the expected tag name for the release named `product_version` let release_tag = match target { Target::Android => format!("android/{product_version}"), @@ -67,17 +69,16 @@ fn get_dev_suffix(target: Target, product_version: &str) -> String { // Get the git commit hashes for the latest release and current HEAD let product_version_commit_hash = git_rev_parse_commit_hash(&release_tag); - let current_head_commit_hash = - git_rev_parse_commit_hash("HEAD").expect("HEAD must have a commit hash"); + let current_head_commit_hash = git_rev_parse_commit_hash("HEAD")?; // If we are not currently building the release tag, we are on a development build. // Adjust product version string accordingly. if product_version_commit_hash.as_ref() != Some(¤t_head_commit_hash) { let hash_suffix = ¤t_head_commit_hash[..GIT_HASH_DEV_SUFFIX_LEN]; - format!("-dev-{hash_suffix}") - } else { - "".to_owned() + return Some(format!("-dev-{hash_suffix}")); } + + None } /// Returns the commit hash for the commit that `git_ref` is pointing to |
