Skip to content

Commit

Permalink
Merge pull request #6 from zevlee/macos-build
Browse files Browse the repository at this point in the history
Add macos build system
  • Loading branch information
zevlee authored Feb 14, 2023
2 parents 38f37bf + 938d202 commit a8fcbe7
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
5 changes: 5 additions & 0 deletions macos/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

brew install python3 qt

echo "Done"
59 changes: 59 additions & 0 deletions macos/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/sh

APP=hello-world-qt
NAME="Hello World"

if [ ! -d ../venv ]; then
echo "Setting up virtual environment..."
python3 -m venv --system-site-packages venv
. venv/bin/activate
python3 -m pip install --upgrade pip
PYINSTALLER_COMPILE_BOOTLOADER=1 PYI_STATIC_ZLIB=1 python3 -m pip install -r ../requirements.txt
else
. ../venv/bin/activate
fi

echo "Preparing app..."

version=$(cat ../VERSION)
cp "$APP.spec" "$APP@.spec"
sed -i '' "s/'VERSION'/'$version'/g" "$APP@.spec"
if [ ! -z "$1" ]; then
sed -i '' "s/codesign_identity=''/codesign_identity='$1'/g" "$APP@.spec"
fi

echo "Running pyinstaller..."

python3 -OO -m PyInstaller "$APP@.spec" --noconfirm

if [ ! -z "$2" ]; then
echo "Notarizing app..."
cd dist
ditto -ck --sequesterRsrc --keepParent "$NAME.app" "$APP-$version-$(uname -m).zip"
if [ ! -z "$3" ]; then
xcrun notarytool submit "$APP-$version-$(uname -m).zip" --apple-id "$2" --team-id "$3" --password "$4" --wait
else
xcrun notarytool submit "$APP-$version-$(uname -m).zip" --keychain-profile "$2" --wait
fi
xcrun stapler staple "$NAME.app"
cd ..
fi

echo "Building dmg..."

hdiutil create -size $(($(du -sk "dist/$NAME.app"/ | awk '{print $1}')*175/100))k -fs HFS+ -volname "$NAME" -o "$APP.dmg"
dir="$(echo $(hdiutil attach $APP.dmg | cut -f 3) | cut -f 1)"
mv "dist/$NAME.app" "$dir"
ln -s /Applications "$dir"
hdiutil detach "$dir"
hdiutil convert "$APP.dmg" -format UDZO -o "$APP-$version-$(uname -m).dmg"
echo $(shasum -a 256 "$APP-$version-$(uname -m).dmg") > "$APP-$version-$(uname -m).dmg.sha256"

echo "Cleaning up..."

deactivate
rm -r build dist "$APP.dmg" "$APP@.spec"
if [ ! -d ../venv ]; then
rm -r venv
fi
mv "$APP-$version-$(uname -m).dmg"* ../..
8 changes: 8 additions & 0 deletions macos/entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
</dict>
</plist>
Binary file added macos/hello-world-qt.icns
Binary file not shown.
64 changes: 64 additions & 0 deletions macos/hello-world-qt.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

a = Analysis(
['../hello-world-qt'],
pathex=[],
binaries=[],
datas=[
('../lib', 'lib'),
('../org.example.HelloWorldQt.svg', '.'),
('../LICENSE', '.'),
('../VERSION', '.')
],
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='hello-world-qt',
icon='hello-world-qt.icns',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False,
codesign_identity='',
entitlements_file='entitlements.plist'
)

coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='hello-world-qt'
)

app = BUNDLE(
coll,
name='Hello World.app',
icon='hello-world-qt.icns',
bundle_identifier='org.example.HelloWorldQt',
version='VERSION'
)

0 comments on commit a8fcbe7

Please sign in to comment.