diff options
author | Sebastiaan Lokhorst <sebastiaanlokhorst@gmail.com> | 2019-10-30 22:38:39 +0300 |
---|---|---|
committer | Sebastiaan Lokhorst <sebastiaanlokhorst@gmail.com> | 2019-10-30 22:52:48 +0300 |
commit | 21dafc3cc3fa5c57b03054330679cf250b944c34 (patch) | |
tree | a3d5e81c52dbef87b0a6b09daf4a8e9c10543531 /mac | |
parent | 7101378ba6429bf79c6c804b6acae3c92a6a3cce (diff) |
MacOS: Use PyInstaller to build app
Diffstat (limited to 'mac')
-rw-r--r-- | mac/Info.plist.template | 37 | ||||
-rw-r--r-- | mac/gajim.spec | 54 | ||||
-rw-r--r-- | mac/launch.sh.template | 3 | ||||
-rwxr-xr-x | mac/makebundle.py | 66 |
4 files changed, 73 insertions, 87 deletions
diff --git a/mac/Info.plist.template b/mac/Info.plist.template deleted file mode 100644 index 5185e67da..000000000 --- a/mac/Info.plist.template +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> -<plist version="1.0"> -<dict> - <key>CFBundleExecutable</key> - <string>launch.sh</string> - <key>CFBundleIdentifier</key> - <string>org.gajim.mac</string> - <key>CFBundleInfoDictionaryVersion</key> - <string>6.0</string> - <key>CFBundleName</key> - <string>Gajim</string> - <key>CFBundlePackageType</key> - <string>APPL</string> - <key>CFBundleShortVersionString</key> - <string>${short_version_string}</string> - <key>CFBundleSignature</key> - <string>DASH</string> - <key>CFBundleVersion</key> - <string>${version}</string> - <key>CFBundleIconFile</key> - <string>Gajim</string> - <key>CFBundleURLTypes</key> - <array> - <dict> - <key>CFBundleTypeRole</key> - <string>Viewer</string> - <key>CFBundleURLName</key> - <string>XMPP</string> - <key>CFBundleURLSchemes</key> - <array> - <string>xmpp</string> - </array> - </dict> - </array> -</dict> -</plist> diff --git a/mac/gajim.spec b/mac/gajim.spec new file mode 100644 index 000000000..a2accddf4 --- /dev/null +++ b/mac/gajim.spec @@ -0,0 +1,54 @@ +# -*- mode: python -*- + +block_cipher = None + +cwd = os.getcwd() +icon = os.path.join(cwd, "mac", "Gajim.icns") + +info_plist = { + "CFBundleDisplayName": "Gajim", + "NSHighResolutionCapable": True, +} + +import sys +sys.path.insert(0, os.path.join(cwd)) +from gajim.common.modules import MODULES +hiddenimports = ['gajim.common.modules.' + m for m in MODULES] +sys.path.pop(0) + +a = Analysis(['launch.py'], + pathex=[cwd], + binaries=[], + datas=[('gajim', 'gajim')], + hiddenimports=hiddenimports, + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + [], + exclude_binaries=True, + name='launch', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=False ) +coll = COLLECT(exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + name='launch') +app = BUNDLE(coll, + name='Gajim.app', + icon=icon, + info_plist=info_plist, + bundle_identifier='org.gajim.gajim') diff --git a/mac/launch.sh.template b/mac/launch.sh.template deleted file mode 100644 index a31ebf580..000000000 --- a/mac/launch.sh.template +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -${bin_path} diff --git a/mac/makebundle.py b/mac/makebundle.py index d9b8571b8..9ed38ca64 100755 --- a/mac/makebundle.py +++ b/mac/makebundle.py @@ -1,58 +1,30 @@ #!/usr/bin/env python3 import os -import shutil import sys -from string import Template -from os.path import join -import argparse - -EXEC_TEMPLATE = 'mac/launch.sh.template' -PLIST_TEMPLATE = 'mac/Info.plist.template' -ICNS_FILE = 'mac/Gajim.icns' - - -def fill_template(in_path, out_path, vars): - with open(in_path, 'r') as f: - templ = Template(f.read()) - filled_templ = templ.substitute(vars) - with open(out_path, 'w') as f: - f.write(filled_templ) - - -def create_executable(exec_path, bin_path): - fill_template(EXEC_TEMPLATE, exec_path, { - 'bin_path': bin_path - }) - os.chmod(exec_path, 0o755) - - -def create_plist(plist_path, version): - fill_template(PLIST_TEMPLATE, plist_path, { - 'version': version, - 'short_version_string': version - }) - +from argparse import ArgumentParser +from subprocess import run, check_output, CalledProcessError if __name__ == '__main__': if not os.path.isdir('mac'): sys.exit("can't find the 'mac' directory. make sure you run " "this script from the project root") - parser = argparse.ArgumentParser(description='Create a macOS .app bundle.') - parser.add_argument('bundle', help='bundle output location') - parser.add_argument('--version', default='0.0.1', - help='version number of the .app bundle') - parser.add_argument('--bin-path', default='/usr/local/bin/gajim', - help='location of the actual executable') + parser = ArgumentParser(description='Create a macOS .app bundle. ' + 'Requires PyInstaller and hdiutil (macOS).') + parser.add_argument('--version', help='version number of the .app bundle') args = parser.parse_args() - bundle = args.bundle - - os.mkdir(bundle) - os.mkdir(join(bundle, 'Contents')) - os.mkdir(join(bundle, 'Contents/MacOS')) - os.mkdir(join(bundle, 'Contents/Resources')) - - create_executable(join(bundle, 'Contents/MacOS/launch.sh'), bin_path=args.bin_path) - create_plist(join(bundle, 'Contents/Info.plist'), version=args.version) - shutil.copy(ICNS_FILE, join(bundle, 'Contents/Resources/Gajim.icns')) + if args.version: + print("args.version:", version) + version = args.version + else: + try: + version = check_output(['git', 'describe', '--tags']).decode().strip() + except CalledProcessError: + version = 'unknown' + dmg_name = 'gajim-{}.dmg'.format(version) + + run(['cp', 'mac/gajim.spec', 'gajim.spec'], check=True) # the .spec has to be in the project root + run(['pyinstaller', 'gajim.spec'], check=True) + run(['rm', '-rf', 'dist/launch']) # we only want Gajim.app in the dmg + run(['hdiutil', 'create', '-volname', 'Gajim', '-srcfolder', 'dist', '-ov', '-format', 'UDZO', dmg_name], check=True) |