added support for building macOS

This commit is contained in:
Louise Fox 2018-01-20 19:33:16 -08:00
parent ff1172134e
commit d3d5fdf687
10 changed files with 115 additions and 23 deletions

2
.gitignore vendored
View File

@ -5,6 +5,8 @@ build/
dist/
*.egg/
/electrum.py
/electrum-mac.py
.DS_Store
contrib/pyinstaller/
Electrum.egg-info/
gui/qt/icons_rc.py

View File

@ -118,7 +118,7 @@ Create translations (optional)::
./contrib/make_locale
Run::
./electrum
@ -159,14 +159,9 @@ Mac OS X / macOS
----------------
::
# On MacPorts installs:
sudo python3 setup-release.py py2app
# On Homebrew installs:
ARCHFLAGS="-arch i386 -arch x86_64" sudo python3 setup-release.py py2app --includes sip
sudo hdiutil create -fs HFS+ -volname "Electrum" -srcfolder dist/Electrum.app dist/electrum-VERSION-macosx.dmg
sh ./setup-mac.sh
sudo sh ./install-mac.sh
Windows
-------
@ -178,4 +173,3 @@ Android
-------
See `gui/kivy/Readme.txt` file.

View File

@ -9,8 +9,8 @@ for i, x in enumerate(sys.argv):
break
else:
raise BaseException('no version')
home = '/Users/voegtlin/electrum/'
import os
home = os.getcwd() + '/'
block_cipher=None
# see https://github.com/pyinstaller/pyinstaller/issues/2005
@ -56,7 +56,7 @@ a = Analysis([home+'electrum',
# http://stackoverflow.com/questions/19055089/pyinstaller-onefile-warning-pyconfig-h-when-importing-scipy-or-scipy-signal
for d in a.datas:
if 'pyconfig' in d[0]:
if 'pyconfig' in d[0]:
a.datas.remove(d)
break
@ -82,4 +82,3 @@ app = BUNDLE(exe,
'NSHighResolutionCapable':'True'
}
)

View File

@ -45,6 +45,7 @@ script_dir = os.path.dirname(os.path.realpath(__file__))
is_bundle = getattr(sys, 'frozen', False)
is_local = not is_bundle and os.path.exists(os.path.join(script_dir, "electrum.desktop"))
is_android = 'ANDROID_DATA' in os.environ
is_macOS = sys.platform == 'darwin'
# move this back to gui/kivy/__init.py once plugins are moved
os.environ['KIVY_DATA_DIR'] = os.path.abspath(os.path.dirname(__file__)) + '/gui/kivy/data/'
@ -73,14 +74,16 @@ def check_imports():
from google.protobuf import descriptor_pb2
from jsonrpclib import SimpleJSONRPCServer
# make sure that certificates are here
assert os.path.exists(requests.utils.DEFAULT_CA_BUNDLE_PATH)
if not is_macOS:
# cannot check if path exists inside zip on macOS
assert os.path.exists(requests.utils.DEFAULT_CA_BUNDLE_PATH)
if not is_android:
check_imports()
# load local module as electrum
if is_local or is_android:
if is_local or is_android or is_macOS:
import imp
imp.load_module('electrum', *imp.find_module('lib'))
imp.load_module('electrum_gui', *imp.find_module('gui'))
@ -339,7 +342,7 @@ if __name__ == '__main__':
config_options['cwd'] = os.getcwd()
# fixme: this can probably be achieved with a runtime hook (pyinstaller)
if is_bundle and os.path.exists(os.path.join(sys._MEIPASS, 'is_portable')):
if is_bundle and hasattr(sys, '_MEIPASS') and os.path.exists(os.path.join(sys._MEIPASS, 'is_portable')):
config_options['portable'] = True
if config_options.get('portable'):

View File

@ -45,6 +45,7 @@ script_dir = os.path.dirname(os.path.realpath(__file__))
is_bundle = getattr(sys, 'frozen', False)
is_local = not is_bundle and os.path.exists(os.path.join(script_dir, "electrum.desktop"))
is_android = 'ANDROID_DATA' in os.environ
is_macOS = sys.platform == 'darwin'
# move this back to gui/kivy/__init.py once plugins are moved
os.environ['KIVY_DATA_DIR'] = os.path.abspath(os.path.dirname(__file__)) + '/gui/kivy/data/'
@ -73,14 +74,16 @@ def check_imports():
from google.protobuf import descriptor_pb2
from jsonrpclib import SimpleJSONRPCServer
# make sure that certificates are here
assert os.path.exists(requests.utils.DEFAULT_CA_BUNDLE_PATH)
if not is_macOS:
# cannot check if path exists inside zip on macOS
assert os.path.exists(requests.utils.DEFAULT_CA_BUNDLE_PATH)
if not is_android:
check_imports()
# load local module as electrum
if is_local or is_android:
if is_local or is_android or is_macOS:
import imp
imp.load_module('electrum', *imp.find_module('lib'))
imp.load_module('electrum_gui', *imp.find_module('gui'))
@ -339,7 +342,7 @@ if __name__ == '__main__':
config_options['cwd'] = os.getcwd()
# fixme: this can probably be achieved with a runtime hook (pyinstaller)
if is_bundle and os.path.exists(os.path.join(sys._MEIPASS, 'is_portable')):
if is_bundle and hasattr(sys, '_MEIPASS') and os.path.exists(os.path.join(sys._MEIPASS, 'is_portable')):
config_options['portable'] = True
if config_options.get('portable'):

15
install_mac.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/sh
sudo sh ./clean.sh
VERSION=$(cat lib/version.py \
| grep ELECTRUM_VERSION \
| sed "s/[',]//g" \
| tr -d '[[:space:]]')
VERSION=${VERSION//ELECTRUM_VERSION=/}
echo "Creating package $VERSION"
sudo python3 setup.py sdist
echo "Creating python app using py2app"
sudo ARCHFLAGS="-arch i386 -arch x86_64" sudo python3 setup-release.py py2app --includes sip
echo "Creating python Electrum.app and .dmg"
sudo hdiutil create -fs HFS+ -volname "Electrum" -srcfolder dist/Electrum.app dist/electrum-$VERSION-macosx.dmg
echo "Done!"

View File

@ -1,5 +1,7 @@
ELECTRUM_VERSION = '3.0.5.1' # version of the client package
PROTOCOL_VERSION = '1.1' # protocol version requested
# version of the client package
ELECTRUM_VERSION = '3.0.5.1'
# protocol version requested
PROTOCOL_VERSION = '1.1'
# The hash of the mnemonic seed must begin with this
SEED_PREFIX = '01' # Standard wallet

View File

@ -12,6 +12,7 @@ sudo chown -R "$USER":admin /Library/Caches/Homebrew
brew install python3
brew link python3
brew postinstall python3
brew install protobuf
# Python setuptools
curl https://bootstrap.pypa.io/ez_setup.py -o - | python3
@ -20,3 +21,5 @@ pip3 install pyqt5
# Setup
python3 setup.py install
pyrcc5 icons.qrc -o gui/qt/icons_rc.py icons.qrc -o gui/qt/icons_rc.py
protoc --proto_path=lib/ --python_out=lib/ lib/paymentrequest.proto

71
setup-release.py Normal file
View File

@ -0,0 +1,71 @@
"""
py2app build script for Electrum Bitcoin Private
Usage (Mac OS X):
python setup.py py2app
"""
from setuptools import setup
from plistlib import Plist
import requests
import os
import shutil
from lib.version import ELECTRUM_VERSION as version
name = "Electrum"
mainscript = 'electrum-mac'
plist = Plist.fromFile('Info.plist')
plist.update(dict(CFBundleIconFile='electrum.icns'))
CERT_PATH = requests.certs.where()
shutil.copy(mainscript, mainscript + '.py')
mainscript += '.py'
extra_options = dict(
setup_requires=['py2app'],
app=[mainscript],
packages=[
'electrum',
'electrum_gui',
'electrum_gui.qt',
'electrum_plugins',
'electrum_plugins.audio_modem',
'electrum_plugins.cosigner_pool',
'electrum_plugins.email_requests',
'electrum_plugins.greenaddress_instant',
'electrum_plugins.hw_wallet',
'electrum_plugins.keepkey',
'electrum_plugins.labels',
'electrum_plugins.ledger',
'electrum_plugins.trezor',
'electrum_plugins.digitalbitbox',
'electrum_plugins.trustedcoin',
'electrum_plugins.virtualkeyboard',
],
package_dir={
'electrum': 'lib',
'electrum_gui': 'gui',
'electrum_plugins': 'plugins'
},
data_files=[CERT_PATH],
options=dict(py2app=dict(argv_emulation=False,
includes=['sip'],
packages=['lib', 'gui', 'plugins'],
iconfile='electrum.icns',
plist=plist,
resources=["icons"])),
)
setup(
name=name,
version=version,
**extra_options
)
# Remove the copied py file
os.remove(mainscript)

View File

@ -46,7 +46,7 @@ setup(
'jsonrpclib-pelix',
'pyblake2',
'PySocks>=1.6.6',
'PyQt5'
'PyQt5',
],
packages=[
'electrum',