summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSebastian Holmin <sebastian.holmin@mullvad.net>2024-05-02 15:50:16 +0200
committerSebastian Holmin <sebastian.holmin@mullvad.net>2024-05-16 02:04:18 +0200
commit7cf5962c49cdca5f7bd5cac6aec2451d760f3814 (patch)
treef14bd995548aeb2d10dbf8c487c16d40e372094f
parent0c7ee46161a38f4911eeaa77c5839a22c3aa4f5b (diff)
downloadmullvadvpn-7cf5962c49cdca5f7bd5cac6aec2451d760f3814.tar.xz
mullvadvpn-7cf5962c49cdca5f7bd5cac6aec2451d760f3814.zip
Fix unnecessary rebuilds of `mullvad-version`
-rw-r--r--mullvad-version/build.rs49
1 files changed, 34 insertions, 15 deletions
diff --git a/mullvad-version/build.rs b/mullvad-version/build.rs
index 08145b0924..008ec8d104 100644
--- a/mullvad-version/build.rs
+++ b/mullvad-version/build.rs
@@ -75,6 +75,40 @@ fn get_dev_suffix(target: Target, product_version: &str) -> Option<String> {
Target::Desktop => product_version.to_owned(),
};
+ let git_dir = Path::new("..").join(".git");
+
+ // If we build our output on information about HEAD we need to re-run if HEAD moves
+ let head_path = git_dir.join("HEAD");
+ if head_path.exists() {
+ println!("cargo:rerun-if-changed={}", head_path.display());
+ }
+
+ let output = Command::new("git")
+ .arg("branch")
+ .arg("--show-current")
+ .output()
+ .ok()?;
+ let current_branch = String::from_utf8(output.stdout).unwrap();
+ // If we build our output on information about a git reference, we need to re-run
+ // if it moves. Instead of trying to be smart, just re-run if any git reference moves.
+ let git_current_branch_ref = git_dir
+ .join("refs")
+ .join("heads")
+ .join(current_branch.trim());
+ if git_current_branch_ref.exists() {
+ println!(
+ "cargo:rerun-if-changed={}",
+ git_current_branch_ref.display()
+ );
+ }
+ let git_current_branch_ref = git_dir.join("refs").join("tags").join(&release_tag);
+ if git_current_branch_ref.exists() {
+ println!(
+ "cargo:rerun-if-changed={}",
+ git_current_branch_ref.display()
+ );
+ }
+
// Get the git commit hashes for the latest release and current HEAD
// Return `None` if unable to find the hash for HEAD.
let head_commit_hash = git_rev_parse_commit_hash("HEAD")?;
@@ -94,21 +128,6 @@ fn get_dev_suffix(target: Target, product_version: &str) -> Option<String> {
///
/// Returns `None` if executing the `git rev-parse` command fails for some reason.
fn git_rev_parse_commit_hash(git_ref: &str) -> Option<String> {
- let git_dir = Path::new("..").join(".git");
- // If we build our output on information about HEAD we need to re-run if HEAD moves
- if git_ref == "HEAD" {
- let head_path = git_dir.join("HEAD");
- if head_path.exists() {
- println!("cargo:rerun-if-changed={}", head_path.display());
- }
- }
- // If we build our output on information about a git reference, we need to re-run
- // if it moves. Instead of trying to be smart, just re-run if any git reference moves.
- let git_refs_dir = git_dir.join("refs");
- if git_refs_dir.exists() {
- println!("cargo:rerun-if-changed={}", git_refs_dir.display());
- }
-
let output = Command::new("git")
.arg("rev-parse")
.arg(format!("{git_ref}^{{commit}}"))