e9342dd53a4a5efa5aefba825766860f2aef7a87
[quassel.git] / scripts / build / macosx_makePackage.sh
1 #!/bin/bash
2 # Don't consider packaging a success if any commands fail
3 # See http://redsymbol.net/articles/unofficial-bash-strict-mode/
4 set -euo pipefail
5
6 myname=$0
7 if [ -s "$myname" ] && [ -x "$myname" ]; then
8     # $myname is already a valid file name
9
10     mypath=$myname
11 else
12     case "$myname" in
13     /*) exit 1;;             # absolute path - do not search PATH
14     *)
15         # Search all directories from the PATH variable. Take
16         # care to interpret leading and trailing ":" as meaning
17         # the current directory; the same is true for "::" within
18         # the PATH.
19
20         # Replace leading : with . in PATH, store in p
21         p=${PATH/#:/.:}
22         # Replace trailing : with .
23         p=${p//%:/:.}
24         # Replace :: with :.:
25         p=${p//::/:.:}
26         # Temporary input field separator, see FAQ #1
27         OFS=$IFS IFS=:
28         # Split the path on colons and loop through each of them
29         for dir in $p; do
30                 [ -f "$dir/$myname" ] || continue # no file
31                 [ -x "$dir/$myname" ] || continue # not executable
32                 mypath=$dir/$myname
33                 break           # only return first matching file
34         done
35         # Restore old input field separator
36         IFS=$OFS
37         ;;
38     esac
39 fi
40
41 if [ ! -f "$mypath" ]; then
42     echo >&2 "cannot find full path name: $myname"
43     exit 1
44 fi
45
46 SCRIPTDIR=$(dirname $mypath)
47 QUASSEL_VERSION=$(git describe)
48 BUILDTYPE=$1
49
50 # check the working dir
51 # Default to "." using Bash default-value syntax
52 WORKINGDIR="${2:-.}"
53 WORKINGDIR="${WORKINGDIR}/"
54 PACKAGETMPDIR="${WORKINGDIR}PACKAGE_TMP_DIR_${BUILDTYPE}"
55 QUASSEL_DMG="Quassel${BUILDTYPE}_MacOSX-x86_64_${QUASSEL_VERSION}.dmg"
56
57 # Default to null string
58 if [[ -z ${3:-} ]]; then
59         ADDITIONAL_PLUGINS=""
60 else
61         # Options provided, append to list
62         ADDITIONAL_PLUGINS=",$3"
63 fi
64
65 echo "ADDITIONAL_PLUGINS: ${ADDITIONAL_PLUGINS}"
66
67 mkdir $PACKAGETMPDIR
68 case $BUILDTYPE in
69 "Client")
70         cp -r ${WORKINGDIR}Quassel\ Client.app ${PACKAGETMPDIR}/
71         ${SCRIPTDIR}/macosx_DeployApp.py --plugins=qcocoa,qgenericbearer,qcorewlanbearer,qmacstyle${ADDITIONAL_PLUGINS} "${PACKAGETMPDIR}/Quassel Client.app"
72         ;;
73 "Core")
74         cp ${WORKINGDIR}quasselcore ${PACKAGETMPDIR}/
75         ${SCRIPTDIR}/macosx_DeployApp.py --nobundle --plugins=qsqlite,qsqlpsql${ADDITIONAL_PLUGINS} ${PACKAGETMPDIR}
76         ;;
77 "Mono")
78         cp -r ${WORKINGDIR}Quassel.app ${PACKAGETMPDIR}/
79         ${SCRIPTDIR}/macosx_DeployApp.py --plugins=qsqlite,qsqlpsql,qcocoa,qgenericbearer,qcorewlanbearer,qmacstyle${ADDITIONAL_PLUGINS} "${PACKAGETMPDIR}/Quassel.app"
80         ;;
81 *)
82         echo >&2 "Valid parameters are \"Client\", \"Core\", or \"Mono\"."
83         rmdir ${PACKAGETMPDIR}
84         exit 1
85         ;;
86 esac
87
88 echo "Creating macOS disk image with hdiutil: 'Quassel ${BUILDTYPE} - ${QUASSEL_VERSION}'"
89
90 # Modern macOS versions support APFS, however default to HFS+ for now in order
91 # to ensure old macOS versions can parse the package and display the warning
92 # about being out of date.  This mirrors the approach taken by Qt's macdeployqt
93 # tool.  In the future if this isn't needed, just remove "-fs HFS+" to revert
94 # to default.
95 #
96 # See https://doc.qt.io/qt-5/macos-deployment.html
97
98 # hdiutil seems to have a bit of a reputation for failing to create disk images
99 # for various reasons.
100 #
101 # If you've come here to see why on earth your macOS build is failing despite
102 # making changes entirely unrelated to macOS, you have my sympathy.
103 #
104 # There are two main approaches:
105 #
106 # 1.  Let hdiutil calculate a size automatically
107 #
108 # 2.  Separately calculate the size with a margin of error, then specify this
109 #     to hdiutil during disk image creation.
110 #
111 # Both seem to have caused issues, but in recent tests, option #1 seemed more
112 # reliable.
113 #
114 # Option 1:
115
116 hdiutil create -srcfolder ${PACKAGETMPDIR} -format UDBZ -fs HFS+ -volname "Quassel ${BUILDTYPE} - ${QUASSEL_VERSION}" "${WORKINGDIR}${QUASSEL_DMG}" >/dev/null
117
118 # If hdiutil changes over time and fails often, you can try the other option.
119 #
120 # Option 2:
121 #
122 #PACKAGESIZE_MARGIN="1.1"
123 #PACKAGESIZE=$(echo "$(du -ms ${PACKAGETMPDIR} | cut -f1) * $PACKAGESIZE_MARGIN" | bc)
124 #echo "PACKAGESIZE: $PACKAGESIZE MB"
125 #hdiutil create -srcfolder ${PACKAGETMPDIR} -format UDBZ -fs HFS+ -size ${PACKAGESIZE}M -volname "Quassel ${BUILDTYPE} - ${QUASSEL_VERSION}" "${WORKINGDIR}${QUASSEL_DMG}" >/dev/null
126
127
128 # Regardless of choice, clean up the packaging temporary directory
129 rm -rf ${PACKAGETMPDIR}