2020-02-13 05:00:44 +00:00
|
|
|
#!/usr/bin/env bash
|
2013-04-14 06:09:40 +00:00
|
|
|
|
2016-05-25 17:21:05 +00:00
|
|
|
# Script to produce an OS X installer .pkg and .app(.zip)
|
|
|
|
|
2024-07-05 02:02:01 +00:00
|
|
|
usage() {
|
|
|
|
echo "Build macOS packages, optionally signing and notarizing them."
|
|
|
|
echo "Usage: $0 options"
|
|
|
|
echo "Options:"
|
|
|
|
echo " -s Enables code signing"
|
|
|
|
echo " -f <APP_KEY.p12> Path to .p12 file for application signing"
|
|
|
|
echo " -i <INSTALLER_KEY.p12> Path to .p12 file for installer signing"
|
|
|
|
echo " -p <PASSWORD> Password for the .p12 files (necessary to access the certificates)"
|
|
|
|
echo " -e <entitlements file> (Optional) Path to an entitlements XML file"
|
|
|
|
echo " -n Enables notarization. This will fail if code signing is not also enabled."
|
|
|
|
echo " -j <API_KEY.JSON> Path to JSON file generated with `rcodesign encode-app-store-connect-api-key` (required for notarization)"
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
set -x
|
|
|
|
set -e
|
|
|
|
|
|
|
|
SIGN=
|
|
|
|
NOTARIZE=
|
|
|
|
|
2024-10-06 23:38:21 +00:00
|
|
|
ARM64_DEPLOY_TARGET='MACOSX_DEPLOYMENT_TARGET=11.0'
|
|
|
|
X86_64_DEPLOY_TARGET='MACOSX_DEPLOYMENT_TARGET=10.9'
|
|
|
|
|
2024-10-13 19:30:00 +00:00
|
|
|
# As of this writing, the most recent Rust release supports macOS back to 10.12.
|
|
|
|
# The first supported version of macOS on arm64 is 10.15, so any Rust is fine for arm64.
|
|
|
|
# We wish to support back to 10.9 on x86-64; the last version of Rust to support that is
|
|
|
|
# version 1.73.0.
|
|
|
|
RUST_VERSION_X86_64=1.73.0
|
|
|
|
|
2024-07-05 02:02:01 +00:00
|
|
|
while getopts "sf:i:p:e:nj:" opt; do
|
|
|
|
case $opt in
|
|
|
|
s) SIGN=1;;
|
|
|
|
f) P12_APP_FILE=$(realpath "$OPTARG");;
|
|
|
|
i) P12_INSTALL_FILE=$(realpath "$OPTARG");;
|
|
|
|
p) P12_PASSWORD="$OPTARG";;
|
|
|
|
e) ENTITLEMENTS_FILE=$(realpath "$OPTARG");;
|
|
|
|
n) NOTARIZE=1;;
|
|
|
|
j) API_KEY_FILE=$(realpath "$OPTARG");;
|
|
|
|
\?) usage;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -n "$SIGN" ] && ([ -z "$P12_APP_FILE" ] || [-z "$P12_INSTALL_FILE"] || [ -z "$P12_PASSWORD" ]); then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$NOTARIZE" ] && [ -z "$API_KEY_FILE" ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2019-11-28 19:37:43 +00:00
|
|
|
VERSION=$(git describe --always --dirty 2>/dev/null)
|
2013-04-14 06:09:40 +00:00
|
|
|
if test -z "$VERSION" ; then
|
2016-04-20 06:34:12 +00:00
|
|
|
echo "Could not get version from git"
|
2019-02-28 13:08:02 +00:00
|
|
|
if test -f version; then
|
2019-11-28 19:37:43 +00:00
|
|
|
VERSION=$(cat version)
|
2019-02-28 13:08:02 +00:00
|
|
|
fi
|
2013-04-14 06:09:40 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Version is $VERSION"
|
|
|
|
|
2019-11-28 19:37:43 +00:00
|
|
|
PKGDIR=$(mktemp -d)
|
2024-07-05 02:02:01 +00:00
|
|
|
echo "$PKGDIR"
|
2012-05-30 07:27:50 +00:00
|
|
|
|
2019-01-26 00:45:06 +00:00
|
|
|
SRC_DIR=$PWD
|
2016-05-25 17:21:05 +00:00
|
|
|
OUTPUT_PATH=${FISH_ARTEFACT_PATH:-~/fish_built}
|
|
|
|
|
2024-07-07 18:49:08 +00:00
|
|
|
mkdir -p "$PKGDIR/build_x86_64" "$PKGDIR/build_arm64" "$PKGDIR/root" "$PKGDIR/intermediates" "$PKGDIR/dst"
|
2021-10-17 20:07:25 +00:00
|
|
|
|
2024-07-07 18:49:08 +00:00
|
|
|
# Build and install for arm64.
|
2021-10-17 20:07:25 +00:00
|
|
|
# Pass FISH_USE_SYSTEM_PCRE2=OFF because a system PCRE2 on macOS will not be signed by fish,
|
|
|
|
# and will probably not be built universal, so the package will fail to validate/run on other systems.
|
2024-07-07 18:49:08 +00:00
|
|
|
# Note CMAKE_OSX_ARCHITECTURES is still relevant for the Mac app.
|
|
|
|
{ cd "$PKGDIR/build_arm64" \
|
2024-10-06 20:36:33 +00:00
|
|
|
&& cmake \
|
2024-07-07 18:49:08 +00:00
|
|
|
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
|
|
|
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-ld_classic" \
|
|
|
|
-DWITH_GETTEXT=OFF \
|
|
|
|
-DRust_CARGO_TARGET=aarch64-apple-darwin \
|
2024-10-06 23:38:21 +00:00
|
|
|
-DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' \
|
2024-07-07 18:49:08 +00:00
|
|
|
-DFISH_USE_SYSTEM_PCRE2=OFF \
|
|
|
|
"$SRC_DIR" \
|
2024-10-06 23:38:21 +00:00
|
|
|
&& env $ARM64_DEPLOY_TARGET make VERBOSE=1 -j 12 \
|
|
|
|
&& env DESTDIR="$PKGDIR/root/" $ARM64_DEPLOY_TARGET make install;
|
2024-07-07 18:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Build for x86-64 but do not install; instead we will make some fat binaries inside the root.
|
2024-10-13 19:30:00 +00:00
|
|
|
# Set RUST_VERSION_X86_64 to the last version of Rust that supports macOS 10.9.
|
2024-07-07 18:49:08 +00:00
|
|
|
{ cd "$PKGDIR/build_x86_64" \
|
2024-10-06 20:36:33 +00:00
|
|
|
&& cmake \
|
2024-07-07 18:49:08 +00:00
|
|
|
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
|
|
|
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-ld_classic" \
|
|
|
|
-DWITH_GETTEXT=OFF \
|
2024-10-13 19:30:00 +00:00
|
|
|
-DRust_TOOLCHAIN="$RUST_VERSION_X86_64" \
|
2024-07-07 18:49:08 +00:00
|
|
|
-DRust_CARGO_TARGET=x86_64-apple-darwin \
|
2024-10-06 23:38:21 +00:00
|
|
|
-DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' \
|
2024-07-07 18:49:08 +00:00
|
|
|
-DFISH_USE_SYSTEM_PCRE2=OFF "$SRC_DIR" \
|
2024-10-06 23:38:21 +00:00
|
|
|
&& env $X86_64_DEPLOY_TARGET make VERBOSE=1 -j 12; }
|
2024-07-07 18:49:08 +00:00
|
|
|
|
|
|
|
# Fatten them up.
|
|
|
|
for FILE in "$PKGDIR"/root/usr/local/bin/*; do
|
|
|
|
X86_FILE="$PKGDIR/build_x86_64/$(basename $FILE)"
|
|
|
|
rcodesign macho-universal-create --output "$FILE" "$FILE" "$X86_FILE"
|
|
|
|
chmod 755 "$FILE"
|
|
|
|
done
|
2024-07-05 02:02:01 +00:00
|
|
|
|
|
|
|
if test -n "$SIGN"; then
|
|
|
|
echo "Signing executables"
|
|
|
|
ARGS=(
|
|
|
|
--p12-file "$P12_APP_FILE"
|
|
|
|
--p12-password "$P12_PASSWORD"
|
|
|
|
--code-signature-flags runtime
|
|
|
|
--for-notarization
|
|
|
|
)
|
|
|
|
if [ -n "$ENTITLEMENTS_FILE" ]; then
|
|
|
|
ARGS+=(--entitlements-xml-file "$ENTITLEMENTS_FILE")
|
|
|
|
fi
|
|
|
|
for FILE in "$PKGDIR"/root/usr/local/bin/*; do
|
|
|
|
(set +x; rcodesign sign "${ARGS[@]}" "$FILE")
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2020-02-11 06:25:49 +00:00
|
|
|
pkgbuild --scripts "$SRC_DIR/build_tools/osx_package_scripts" --root "$PKGDIR/root/" --identifier 'com.ridiculousfish.fish-shell-pkg' --version "$VERSION" "$PKGDIR/intermediates/fish.pkg"
|
|
|
|
productbuild --package-path "$PKGDIR/intermediates" --distribution "$SRC_DIR/build_tools/osx_distribution.xml" --resources "$SRC_DIR/build_tools/osx_package_resources/" "$OUTPUT_PATH/fish-$VERSION.pkg"
|
2021-01-31 21:52:19 +00:00
|
|
|
|
2024-07-05 02:02:01 +00:00
|
|
|
if test -n "$SIGN"; then
|
|
|
|
echo "Signing installer"
|
|
|
|
ARGS=(
|
|
|
|
--p12-file "$P12_INSTALL_FILE"
|
|
|
|
--p12-password "$P12_PASSWORD"
|
|
|
|
--code-signature-flags runtime
|
|
|
|
--for-notarization
|
|
|
|
)
|
|
|
|
(set +x; rcodesign sign "${ARGS[@]}" "$OUTPUT_PATH/fish-$VERSION.pkg")
|
|
|
|
fi
|
2013-10-06 00:06:22 +00:00
|
|
|
|
2024-07-04 23:12:12 +00:00
|
|
|
# Make the app
|
2024-10-06 23:38:21 +00:00
|
|
|
(cd "$PKGDIR/build_arm64" && env $ARM64_DEPLOY_TARGET make -j 12 fish_macapp)
|
|
|
|
(cd "$PKGDIR/build_x86_64" && env $X86_64_DEPLOY_TARGET make -j 12 fish_macapp)
|
2024-07-07 18:49:08 +00:00
|
|
|
|
2024-10-25 03:25:22 +00:00
|
|
|
# Make the app's /usr/local/bin binaries universal. Note fish.app/Contents/MacOS/fish already is, courtesy of CMake.
|
2024-07-07 18:49:08 +00:00
|
|
|
cd "$PKGDIR/build_arm64"
|
|
|
|
for FILE in fish.app/Contents/Resources/base/usr/local/bin/*; do
|
|
|
|
X86_FILE="$PKGDIR/build_x86_64/fish.app/Contents/Resources/base/usr/local/bin/$(basename $FILE)"
|
|
|
|
rcodesign macho-universal-create --output "$FILE" "$FILE" "$X86_FILE"
|
|
|
|
|
|
|
|
# macho-universal-create screws up the permissions.
|
|
|
|
chmod 755 "$FILE"
|
|
|
|
done
|
|
|
|
|
2024-07-05 02:02:01 +00:00
|
|
|
if test -n "$SIGN"; then
|
|
|
|
echo "Signing app"
|
|
|
|
ARGS=(
|
|
|
|
--p12-file "$P12_APP_FILE"
|
|
|
|
--p12-password "$P12_PASSWORD"
|
|
|
|
--code-signature-flags runtime
|
|
|
|
--for-notarization
|
|
|
|
)
|
|
|
|
if [ -n "$ENTITLEMENTS_FILE" ]; then
|
|
|
|
ARGS+=(--entitlements-xml-file "$ENTITLEMENTS_FILE")
|
|
|
|
fi
|
|
|
|
(set +x; rcodesign sign "${ARGS[@]}" "fish.app")
|
|
|
|
|
|
|
|
fi
|
2024-07-07 18:49:08 +00:00
|
|
|
|
|
|
|
cp -R "fish.app" "$OUTPUT_PATH/fish-$VERSION.app"
|
2024-07-05 02:02:01 +00:00
|
|
|
cd "$OUTPUT_PATH"
|
|
|
|
|
|
|
|
# Maybe notarize.
|
|
|
|
if test -n "$NOTARIZE"; then
|
|
|
|
echo "Notarizing"
|
|
|
|
rcodesign notarize --staple --wait --max-wait-seconds 1800 --api-key-file "$API_KEY_FILE" "$OUTPUT_PATH/fish-$VERSION.pkg"
|
|
|
|
rcodesign notarize --staple --wait --max-wait-seconds 1800 --api-key-file "$API_KEY_FILE" "$OUTPUT_PATH/fish-$VERSION.app"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Zip it up.
|
|
|
|
zip -r "fish-$VERSION.app.zip" "fish-$VERSION.app" && rm -Rf "fish-$VERSION.app"
|
2016-05-25 17:11:02 +00:00
|
|
|
|
2024-07-04 23:12:12 +00:00
|
|
|
rm -rf "$PKGDIR"
|