forked from Electron-Cash/Electron-Cash
-
Notifications
You must be signed in to change notification settings - Fork 53
/
make_osx
executable file
·262 lines (225 loc) · 10.9 KB
/
make_osx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
build_dir=$(dirname "$0")
test -n "$build_dir" -a -d "$build_dir" || (echo "Cannot determine build dir. FIXME!" && exit 1)
. "$build_dir"/../base.sh # functions we use below
OSX_COMPAT=""
OSX_REQ_BIN="-osx"
DARWIN_VER=$(uname -r | cut -f 1 -d .)
if ((DARWIN_VER < 17)); then
fail "Minimum OSX High Sierra is required to build"
fi
REQUIREMENTS_BINARIES="requirements-binaries${OSX_REQ_BIN}.txt"
function DoCodeSignMaybe { # ARGS: infoName fileOrDirName codesignIdentity
infoName="$1"
file="$2"
identity="$3"
deep=""
if [ -z "$identity" ]; then
# we are ok with them not passing anything; master script calls us unconditionally even if no identity is specified
return
fi
if [ -d "$file" ]; then
deep="--deep"
fi
if [ -z "$infoName" ] || [ -z "$file" ] || [ -z "$identity" ] || [ ! -e "$file" ]; then
fail "Argument error to internal function DoCodeSignMaybe()"
fi
preserve_arg="--preserve-metadata=requirements,entitlements"
hardened_arg=""
hardened_info=""
if ((DARWIN_VER >= 18)); then
# On Mojave or above, we codesign with the "hardened runtime" which
# is required for notarization.
# See: https://github.com/pyinstaller/pyinstaller/issues/4629
preserve_arg=""
hardened_arg="--entitlements=${build_dir}/entitlements.plist -o runtime"
hardened_info=" (Hardened Runtime)"
fi
info "Code signing ${infoName}${hardened_info}..."
codesign -f -v $deep -s "$identity" $preserve_arg $hardened_arg "$file" || fail "Could not code sign ${infoName}"
}
cd $build_dir/../..
VERSION=`git_describe_filtered`
# Paramterize
BUILDDIR=/tmp/electron-cash-build
LIBSECP_COMMIT="69ccf0d2f758b1a4df9cde8222459381e08fc1dc"
# Compute major.minor Python version from above using Bash array magic
MAJ_MIN=(${PYTHON_VERSION//./ })
MAJ_MIN=${MAJ_MIN[0]}.${MAJ_MIN[1]}
which xcodebuild > /dev/null 2>&1 || fail "Please install Xcode and xcode command line tools to continue"
# Code Signing: See https://developer.apple.com/library/archive/documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html
APP_SIGN=""
if [ -n "$1" ]; then
# Test the identity is valid for signing by doing this hack. There is no other way to do this.
cp -f /bin/ls ./CODESIGN_TEST
codesign -s "$1" --dryrun -f ./CODESIGN_TEST > /dev/null 2>&1
res=$?
rm -f ./CODESIGN_TEST
if ((res)); then
fail "Code signing identity \"$1\" appears to be invalid."
fi
unset res
APP_SIGN="$1"
info "Code signing enabled using identity \"$APP_SIGN\""
else
warn "Code signing DISABLED. Specify a valid macOS Developer identity installed on the system as the first argument to this script to enable signing."
fi
have_brew=`which brew`
have_macports=`which port`
if [ -n "$have_brew" ]; then
info "Ensuring build prerequisites are installed via brew"
for a in autoconf automake coreutils gettext libtool openssl@1.1 readline sqlite3 xz zlib swig ; do
brew list $a > /dev/null 2>&1
if [ "$?" != "0" ]; then
info "Installing $a"
brew install "$a" || fail "Could not install $a"
else
info "$a found"
fi
done
elif [ -n "$have_macports" ]; then
have_port_swig_python=`port installed | grep swig-python`
if [ -z "$have_port_swig_python" ]; then
fail "Please install swig-python: sudo port install swig-python"
fi
else
fail "This script requires either brew or MacPorts. Please install either of these package managers and re-run this script."
fi
have_swig=`which swig`
if [ -z "$have_swig" ]; then
warn "Please install 'swig' to run this script:"
info "If using brew: brew install swig"
info "If using MacPorts: sudo port install swig-python"
info "Lastly, ensure 'swig' is in your PATH"
fail "'swig' not found in path, cannot proceed"
fi
info "Installing Python $PYTHON_VERSION" # NB: $PYTHON_VERSION comes from ../base.sh
export PATH=~/.pyenv/bin:~/.pyenv/versions/${PYTHON_VERSION}/bin:~/.pyenv/shims:~/Library/Python/${MAJ_MIN}/bin:"$PATH"
if [ -d "~/.pyenv" ]; then
pyenv update
else
curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash > /dev/null 2>&1
fi
if ~/.pyenv/bin/pyenv versions | grep -q "$PYTHON_VERSION"; then
warn "Python $PYTHON_VERSION already exists in pyenv!"
warn "We will proceed to use this version but you really should start with a fresh, clean version of Python by removing ~/.pyenv altogether."
else
# Pre-download the tarball and verify its hash
mkdir -p ~/.pyenv/cache
download_if_not_exist ~/.pyenv/cache/Python-$PYTHON_VERSION.tar.xz "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tar.xz"
verify_hash ~/.pyenv/cache/Python-$PYTHON_VERSION.tar.xz $PYTHON_SRC_TARBALL_HASH
fi
# The below just switches to this python version if already installed..
# or does a build-install from the file in ~/.pyenv/cache if not installed
PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install -s -v $PYTHON_VERSION && \
pyenv global $PYTHON_VERSION && pyenv rehash || \
fail "Unable to use Python $PYTHON_VERSION"
# We use a hashed requirements file for even the build tools to prevent
# dependency attacks even in the build process
info "Installing dmgbuild, requests, and other build tools we need..."
# Ensure we have wheel because otherwise we get warnings about not having it (even though below installs it again)
python3 -m pip install --user --upgrade wheel || fail "Failed to install wheel"
python3 -m pip install -I --user -r contrib/osx/requirements-osx-build.txt \
|| fail "Could not install osx-requirements"
info "Installing PyInstaller"
# Just use regular, latest PyInstaller 4.2+ from pypi
python3 -m pip install pyinstaller --user --upgrade && pyenv rehash || fail "Could not install PyInstaller"
info "Using these versions for building $PACKAGE:" # NB: PACKAGE var comes from ../base.sh
sw_vers
python3 --version
echo -n "Pyinstaller "
pyinstaller --version
rm -rf ./dist
rm -rf $BUILDDIR > /dev/null 2>&1
mkdir -p $BUILDDIR
info "Making locale..."
python3 ./contrib/make_locale || fail "Failed to make locale..."
info "Downloading libusb..."
curl -L https://github.com/cculianu/Electron-Cash-Build-Tools/releases/download/v1.0/libusb-1.0.21.el_capitan.bottle.tar.gz | \
tar xz --directory $BUILDDIR || fail "Could not download libusb"
verify_hash $BUILDDIR/libusb/1.0.21/lib/libusb-1.0.dylib d147e7382dfa676d93e8b17d160d50f68e4b01f58f3647c90a8899a7a0519ca3 # this exits on failure
cp -fp $BUILDDIR/libusb/1.0.21/lib/libusb-1.0.dylib contrib/osx || fail "Could not copy libusb"
# Build ZBar
contrib/make_zbar && mv -vf electroncash/libzbar.0.dylib contrib/osx/. || fail "Could not build ZBar"
info "Building libsecp256k1"
pushd contrib/secp256k1 || fail "Could not chdir to contrib/secp256k1"
git checkout "$LIBSECP_COMMIT^{commit}" || fail "Could not check out secp256k1 $LIBSECP_COMMIT"
git clean -f -x -q
./autogen.sh || fail "Could not run autogen for secp256k1"
./configure \
--enable-module-recovery \
--enable-experimental \
--enable-module-ecdh \
--disable-jni \
--with-bignum=no \
--enable-module-schnorr \
--disable-tests \
--disable-static \
--enable-shared || fail "Could not configure for secp256k1"
make -j4 || fail "Could not build secp256k1"
#git checkout master # Undo the previous explicit checkout to this hash
popd
cp -fp contrib/secp256k1/.libs/libsecp256k1.0.dylib contrib/osx || fail "Could not copy secp256k1 binary to its destination"
info "Building integrated Tor"
contrib/make_zlib && contrib/make_libevent && contrib/make_openssl && contrib/make_tor || fail "Could not build Tor"
info "Installing requirements..."
python3 -m pip install -r ./contrib/deterministic-build/requirements-pip.txt --user || fail "Could not install pip"
python3 -m pip install -r ./contrib/deterministic-build/requirements-osx.txt --user || fail "Could not install requirements"
python3 -m pip install -r ./contrib/deterministic-build/${REQUIREMENTS_BINARIES} --user || fail "Could not install binary requirements"
info "Installing hardware wallet requirements..."
python3 -m pip install -r ./contrib/deterministic-build/requirements-hw.txt --user || \
fail "Could not install hardware wallet requirements"
info "Building $PACKAGE..."
python3 setup.py install --user > /dev/null || fail "Could not build $PACKAGE"
info "Building binary"
pyinstaller --clean --noconfirm --ascii --name $VERSION contrib/osx/osx.spec || fail "Could not build binary"
info "Adding bitcoincash & simpleledger & cashacct URI types to Info.plist"
# NB: Make sure there are no trailing spaces after the '\' characters here
plutil -insert 'CFBundleURLTypes' \
-xml \
'<array> '\
'<dict> '\
' <key>CFBundleURLName</key> '\
' <string>bitcoincash</string> '\
' <key>CFBundleURLSchemes</key> '\
' <array><string>bitcoincash</string></array> '\
'</dict> '\
'<dict> '\
' <key>CFBundleURLName</key> '\
' <string>simpleledger</string> '\
' <key>CFBundleURLSchemes</key> '\
' <array><string>simpleledger</string></array> '\
'</dict> '\
'<dict> '\
' <key>CFBundleURLName</key> '\
' <string>CashAccount</string> '\
' <key>CFBundleURLSchemes</key> '\
' <array><string>cashacct</string></array> '\
'</dict> '\
'</array>' \
-- dist/$PACKAGE.app/Contents/Info.plist \
|| fail "Could not add keys to Info.plist. Make sure the program 'plutil' exists and is installed."
plutil -insert 'NSCameraUsageDescription' \
-string 'Electron Cash would like to access the camera to scan for QR codes' \
-- dist/$PACKAGE.app/Contents/Info.plist \
|| fail "Could not add keys to Info.plist. Make sure the program 'plutil' exists and is installed."
FORCE_MOJAVE_DARK=1 # Set to 1 to try and add the Info.plist key to force mojave dark mode support.
# On PyQt 5.14.1, it doesn't work, but on 5.15.2 it does.
if ((DARWIN_VER >= 18 && FORCE_MOJAVE_DARK)); then
# Add a key to Info.plist key to support Mojave dark mode
info "Adding Mojave dark mode support to Info.plist"
plutil -insert 'NSRequiresAquaSystemAppearance' -bool NO -- dist/"$PACKAGE".app/Contents/Info.plist \
|| fail "Could not set Info.plist NSRequiresAquaSystemAppearance"
fi
# Sign the Tor binary separately
DoCodeSignMaybe "tor binary" "dist/${PACKAGE}.app/Contents/MacOS/electroncash/tor/bin/tor" "$APP_SIGN"
# Finally, codesign the whole thing
DoCodeSignMaybe ".app bundle" "dist/${PACKAGE}.app" "$APP_SIGN"
info "Creating .DMG"
dmgbuild -D PACKAGE=$PACKAGE -s contrib/osx/dmgbuild.spec "" "dist/${PACKAGE}-${VERSION}-macosx${OSX_COMPAT}.dmg" || fail "Could not create .DMG"
DoCodeSignMaybe ".DMG" "dist/${PACKAGE}-${VERSION}-macosx${OSX_COMPAT}.dmg" "$APP_SIGN" # If APP_SIGN is empty will be a noop
if [ -z "$APP_SIGN" ]; then
warn "App was built successfully but was not code signed. Users may get security warnings from macOS."
warn "Specify a valid code signing identity as the first argument to this script to enable code signing."
fi
rm -fr $BUILDDIR