Skip to content

Commit d233e51

Browse files
committed
Build - improve mac release script
1 parent ba3c8d1 commit d233e51

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

app/mac-release.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,93 @@ cp -R ../../../../../../app/gui/qt/lang app/gui/qt/lang
3535

3636
rm -rf app/server/beam/tau/.elixir_ls
3737

38+
# Now need to fix some things. Firstly, the crypto library found within Elixir releases appears
39+
# to be linked ot the OpenSSL library found on the build machine. This is a problem as the OpenSSL
40+
# library on the build machine may not be available on the target machine. To fix this, we copy the
41+
# OpenSSL library into the release and then update the crypto library to link to the local copy.
42+
43+
cd "${SCRIPT_DIR}"/build/macOS_Release/Sonic\ Pi.app/Contents/Resources/server/beam/tau/_build/prod/rel/tau/lib/crypto-*/priv/lib
44+
45+
# Use otool to list linked libraries and grep for OpenSSL, then extract the first path
46+
openssl_lib=$(otool -L crypto.so | grep -E '/openssl.*/libcrypto.*\.dylib' | awk '{print $1}')
47+
48+
# Check if the OpenSSL library was found
49+
if [ -n "$openssl_lib" ]; then
50+
set -x
51+
echo "OpenSSL library found: $openssl_lib"
52+
cp "$openssl_lib" .
53+
filename_with_ext=$(basename "$openssl_lib")
54+
install_name_tool -change "$openssl_lib" "@loader_path/$filename_with_ext" crypto.so
55+
install_name_tool -change "$openssl_lib" "@loader_path/$filename_with_ext" otp_test_engine.so
56+
set +x
57+
else
58+
echo "No OpenSSL library found in $file"
59+
fi
60+
61+
# Next we need to remove all symlinks in the _build release directory and replace them with the
62+
# actual content (or delete the symlinks if the content is missing)
63+
replace_symlink() {
64+
local symlink="$1"
65+
local target=$(readlink "$symlink")
66+
67+
# Resolve the absolute path of the symlink's target
68+
local absolute_target
69+
if [[ "$target" = /* ]]; then
70+
# Absolute path
71+
absolute_target="$target"
72+
else
73+
# Relative path
74+
local symlink_dir
75+
symlink_dir="$(cd "$(dirname "$symlink")" && pwd)"
76+
absolute_target="$symlink_dir/$target"
77+
fi
78+
absolute_target="$(cd "$(dirname "$absolute_target")" && pwd)/$(basename "$absolute_target")"
79+
80+
if [ -e "$absolute_target" ]; then
81+
echo "Found symlink: $symlink -> $absolute_target"
82+
83+
# Preserve permissions of the original symlink
84+
local permissions
85+
permissions=$(stat -f "%Lp" "$symlink")
86+
87+
# Create a temporary location to copy the content
88+
local tmp_copy="${symlink}.tmp"
89+
90+
# Check if the symlink points to a file or directory
91+
if [ -d "$absolute_target" ]; then
92+
echo "Copying directory $absolute_target to temporary location $tmp_copy"
93+
cp -R "$absolute_target" "$tmp_copy"
94+
else
95+
echo "Copying file $absolute_target to temporary location $tmp_copy"
96+
cp "$absolute_target" "$tmp_copy"
97+
fi
98+
99+
# Remove the symlink and move the copied content to the original location
100+
echo "Removing symlink $symlink"
101+
rm "$symlink"
102+
103+
echo "Renaming $tmp_copy to $symlink"
104+
mv "$tmp_copy" "$symlink"
105+
106+
# Restore original permissions
107+
chmod "$permissions" "$symlink"
108+
109+
echo "Replaced symlink with actual content and restored permissions."
110+
else
111+
# If the target doesn't exist, the symlink is broken
112+
echo "Warning: Broken symlink detected. Removing $symlink (points to $target)"
113+
rm "$symlink"
114+
fi
115+
}
116+
117+
118+
cd "${SCRIPT_DIR}/build/macOS_Release/Sonic\ Pi.app/Contents/Resources/server/beam/tau/_build"
119+
120+
find . -type l | while IFS= read -r symlink; do
121+
replace_symlink "$symlink"
122+
done
123+
124+
38125
echo "
39126
40127
app/build/macOS_Release/Sonic Pi.app is now ready for signing, notarising and releasing...

0 commit comments

Comments
 (0)