From 47b615e767c4f9eb5f4de06491637ccabe73b600 Mon Sep 17 00:00:00 2001
From: Kasper Dissing Bargsteen <kb@concordium.com>
Date: Fri, 14 Apr 2023 10:53:33 +0200
Subject: [PATCH 1/2] Fix mac build script

---
 scripts/distribution/macOS-package/build.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/distribution/macOS-package/build.sh b/scripts/distribution/macOS-package/build.sh
index 7f9c309fc8..ea1e1cc3ea 100755
--- a/scripts/distribution/macOS-package/build.sh
+++ b/scripts/distribution/macOS-package/build.sh
@@ -24,7 +24,7 @@ readonly collectorDir="$macPackageDir/../../../collector"
 readonly consensusDir="$macPackageDir/../../../concordium-consensus"
 
 readonly toolsDir="$macPackageDir/tools"
-readonly macdylibbundlerDir="$toolsDir/macdylibbundler-1.0.0"
+readonly macdylibbundlerDir="$toolsDir/macdylibbundler-1.0.5"
 
 readonly buildDir="$macPackageDir/build"
 readonly payloadDir="$buildDir/payload"
@@ -226,7 +226,7 @@ function getDylibbundler() {
         logInfo " -- Downloading..."
         mkdir "$toolsDir"
         cd "$macPackageDir"
-        curl -sSL "https://github.com/auriamg/macdylibbundler/archive/refs/tags/1.0.0.zip" > "$toolsDir/dylibbundler.zip" \
+        curl -sSL "https://github.com/auriamg/macdylibbundler/archive/refs/tags/1.0.5.zip" > "$toolsDir/dylibbundler.zip" \
                     && logInfo " -- Unzipping..." \
                     && cd "$toolsDir" \
                     && unzip "dylibbundler.zip" \
@@ -248,7 +248,7 @@ function collectDylibs() {
         local fileToFix=${1:?"Missing file to fix with dylibbundler"};
         cd "$payloadDir/Library/Concordium Node"
         # Paths to search for dylibs are added with the '-s' flag.
-        "$macdylibbundlerDir/dylibbundler" --fix-file "$fileToFix" --bundle-deps --dest-dir "./libs" --install-path "@executable_path/libs/" --overwrite-dir \
+        "$macdylibbundlerDir/dylibbundler" --fix-file "$fileToFix" --bundle-deps --dest-dir "./libs" --install-path "@executable_path/libs/" --create-dir \
             -s "$concordiumDylibDir" \
             -s "$stackSnapshotDir" \
             $stackLibDirs # Unquoted on purpose to use as arguments correctly

From dbd7d9c84d1e024bf5aaf2fafbe808b89ce332a0 Mon Sep 17 00:00:00 2001
From: Kasper Dissing Bargsteen <kb@concordium.com>
Date: Mon, 17 Apr 2023 09:55:50 +0200
Subject: [PATCH 2/2] Document why create-dir should be used over overwrite-dir

---
 scripts/distribution/macOS-package/build.sh | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scripts/distribution/macOS-package/build.sh b/scripts/distribution/macOS-package/build.sh
index ea1e1cc3ea..9ad0aee5de 100755
--- a/scripts/distribution/macOS-package/build.sh
+++ b/scripts/distribution/macOS-package/build.sh
@@ -248,6 +248,10 @@ function collectDylibs() {
         local fileToFix=${1:?"Missing file to fix with dylibbundler"};
         cd "$payloadDir/Library/Concordium Node"
         # Paths to search for dylibs are added with the '-s' flag.
+        # We use `--create-dir` to ensure that the `./libs` folder exists.
+        # But we should not use `--overwrite-dir` even though it implies `--create-dir`
+        # because it will delete the libs folder if it already exists, which would delete 
+        # the results of previous calls to `collectDylibsFor`.
         "$macdylibbundlerDir/dylibbundler" --fix-file "$fileToFix" --bundle-deps --dest-dir "./libs" --install-path "@executable_path/libs/" --create-dir \
             -s "$concordiumDylibDir" \
             -s "$stackSnapshotDir" \