Skip to content

Commit

Permalink
feat: add a macos build script
Browse files Browse the repository at this point in the history
Signed-off-by: Rachel Powers <[email protected]>
  • Loading branch information
Ryex committed Dec 1, 2022
1 parent 347266a commit 93543dc
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 0 deletions.
60 changes: 60 additions & 0 deletions macos/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>novelwriter</string>
<key>CFBundleGetInfoString</key>
<string>novelWriter: A markdown-like text editor for planning and writing novels.</string>
<key>CFBundleIconFile</key>
<string>novelwriter.icns</string>
<key>CFBundleIdentifier</key>
<string>io.novelwriter.novelWriter</string>
<key>CFBundleName</key>
<string>novelWriter</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>2.0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2.0.1</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>NSHumanReadableCopyright</key>
<string>© 2018–2022, Veronica Berglyd Olsen <[email protected]></string>
<key>IFMajorVersion</key>
<integer>0</integer>
<key>IFMinorVersion</key>
<integer>1</integer>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>nwx</string>
</array>
<key>CFBundleTypeName</key>
<string>novelWriter Project</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>TEXT</string>
<string>utxt</string>
<string>TUTX</string>
<string>****</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
</array>
</dict>
</plist>
60 changes: 60 additions & 0 deletions macos/Info.plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>{MACOSX_BUNDLE_EXACUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>{MACOSX_BUNDLE_INFO_STRING}</string>
<key>CFBundleIconFile</key>
<string>{MACOSX_BUNDLE_ICON_FILE}</string>
<key>CFBundleIdentifier</key>
<string>{MACOSX_BUNDLE_IDENTIFIER}</string>
<key>CFBundleName</key>
<string>{MACOSX_BUNDLE_NAME}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>{MACOSX_BUNDLE_SHORT_VERSION}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>{MACOSX_BUNDLE_VERSION}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>NSHumanReadableCopyright</key>
<string>{MACOSX_BUNDLE_COPYRIGHT}</string>
<key>IFMajorVersion</key>
<integer>0</integer>
<key>IFMinorVersion</key>
<integer>1</integer>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>nwx</string>
</array>
<key>CFBundleTypeName</key>
<string>novelWriter Project</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>TEXT</string>
<string>utxt</string>
<string>TUTX</string>
<string>****</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
</array>
</dict>
</plist>
92 changes: 92 additions & 0 deletions macos/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#! /bin/bash

# use RAM disk if possible
if [ -d /dev/shm ]; then
TEMP_BASE=/dev/shm
else
TEMP_BASE=/tmp
fi

BUILD_DIR=$(mktemp -d "$TEMP_BASE/novelWriter-build-XXXXXX")

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

cleanup () {
if [ -d "$BUILD_DIR" ]; then
rm -rf "$BUILD_DIR"
fi
}

trap cleanup EXIT

OLD_CWD="$(pwd)"

VERSION="$(awk '/^__version__/{print substr($NF,2,length($NF)-2)}' $SCRIPT_DIR/../novelwriter/__init__.py)"


pushd "$BUILD_DIR"/ || exit 1

# install Miniconda, a self-contained Python distribution
wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
bash Miniconda3-latest-MacOSX-x86_64.sh -b -p ~/miniconda -f
rm Miniconda3-latest-MacOSX-x86_64.sh
export PATH="$HOME/miniconda/bin:$PATH"

# create conda env
conda create -n novelWriter python --yes
source activate novelWriter

# install dependencies
pip install -r "$SCRIPT_DIR/../requirements.txt"

# leave conda env
source deactivate

# create .app Framework
mkdir -p novelWriter.app/Contents/
mkdir novelWriter.app/Contents/MacOS novelWriter.app/Contents/Resources novelWriter.app/Contents/Resources/novelWriter
mv $SCRIPT_DIR/../macos/Info.plist novelWriter.app/Contents/Info.plist

# copy Miniconda env
cp -R ~/miniconda/envs/novelWriter/* novelWriter.app/Contents/Resources/

# copy Pext
cp -R $SCRIPT_DIR/../* novelWriter.app/Contents/Resources/novelWriter/


# create entry script
cat > novelWriter.app/Contents/MacOS/novelWriter <<\EOF
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
$DIR/../Resources/bin/python -sE $DIR/../Resources/novelWriter/novelwriter $@
EOF

# make executable
chmod a+x novelWriter.app/Contents/MacOS/novelWriter

# remove bloat
pushd novelWriter.app/Contents/Resources || exit 1

# cleanup commands HERE
find . -type d -iname '__pycache__' -print0 | xargs -0 rm -r

#remove web engine
rm lib/python3.7/site-packages/PyQt5/QtWebEngine* || true
rm -r lib/python3.7/site-packages/PyQt5/Qt/translations/qtwebengine* || true
rm lib/python3.7/site-packages/PyQt5/Qt/resources/qtwebengine* || true
rm -r lib/python3.7/site-packages/PyQt5/Qt/qml/QtWebEngine* || true
rm -r lib/python3.7/site-packages/PyQt5/Qt/plugins/webview/libqtwebview* || true
rm lib/python3.7/site-packages/PyQt5/Qt/libexec/QtWebEngineProcess* || true
rm lib/python3.7/site-packages/PyQt5/Qt/lib/libQt5WebEngine* || true

popd || exit 1
popd || exit 1


# generate .dmg

brew install create-dmg
# "--skip-jenkins" is a temporary workaround for https://github.com/create-dmg/create-dmg/issues/72
create-dmg --skip-jenkins --volname "novelWriter $VERSION" --volicon $SCRIPT_DIR/../macos/novelwriter.icns \
--window-pos 200 120 --window-size 800 400 --icon-size 100 --icon novelWriter.app 200 190 --hide-extension novelWriter.app \
--app-drop-link 600 185 novelWriter-"${VERSION}".dmg "$BUILD_DIR"/
19 changes: 19 additions & 0 deletions macos/generate_icns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /usr/bin/env bash

if ! command -v png2icns &> /dev/null
then
echo "png2icns cound not be found, it is required. Please install a package like icnsutils or libicns."
exit
fi

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

mkdir -p $SCRIPT_DIR/icons

for size in 16x16 32x32 48x48 128x128 256x256; do
cp $SCRIPT_DIR/../setup/data/hicolor/$size/apps/novelwriter.png $SCRIPT_DIR/icons/icon_${size}px.png
done

png2icns $SCRIPT_DIR/novelwriter.icns $SCRIPT_DIR/icons/icon_*px.png

rm -r $SCRIPT_DIR/icons
26 changes: 26 additions & 0 deletions macos/generate_plist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))

SETTINGS = {
"MACOSX_BUNDLE_COPYRIGHT": "© 2018–2022, Veronica Berglyd Olsen <[email protected]>",
"MACOSX_BUNDLE_IDENTIFIER": "io.novelwriter.novelWriter",
"MACOSX_BUNDLE_NAME": "novelWriter",
"MACOSX_BUNDLE_EXACUTABLE_NAME": "novelwriter",
"MACOSX_BUNDLE_ICON_FILE": "novelwriter.icns",
"MACOSX_BUNDLE_INFO_STRING": "novelWriter: A markdown-like text editor for planning and writing novels.",
"MACOSX_BUNDLE_SHORT_VERSION": "2.0.1", # Must be purely numerical
"MACOSX_BUNDLE_VERSION": "2.0.1", # Must be purely numerical
}

if __name__ == "__main__":

template_filename = os.path.join(SCRIPT_DIR, "Info.plist.in")
with open(template_filename, "r") as tmfile:
template = tmfile.read()

plist = template.format(**SETTINGS)

plist_filename = os.path.join(SCRIPT_DIR, "Info.plist")
with open(plist_filename, "w") as plistfile:
plistfile.write(plist)
Binary file added macos/novelwriter.icns
Binary file not shown.

0 comments on commit 93543dc

Please sign in to comment.