Commit 21dafc3c authored by Sebastiaan Lokhorst's avatar Sebastiaan Lokhorst

MacOS: Use PyInstaller to build app

parent 7101378b
Pipeline #4429 passed with stages
in 2 minutes and 53 seconds
<?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>
# -*- 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')
#!/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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment