refactor: move plist gen into setup.py

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel Powers
2023-01-08 21:08:21 -07:00
parent b7e7a087f8
commit f912d55177
9 changed files with 139 additions and 170 deletions
+10
View File
@@ -0,0 +1,10 @@
<?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.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
</dict>
</plist>
+142
View File
@@ -0,0 +1,142 @@
#! /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 )
SRC_DIR="$SCRIPT_DIR/../.."
RLS_DIR="$SRC_DIR/dist_macos"
cleanup () {
if [ -d "$BUILD_DIR" ]; then
rm -rf "$BUILD_DIR"
fi
}
trap cleanup EXIT
echo "Building in: $BUILD_DIR"
OLD_CWD="$(pwd)"
VERSION="$(awk '/^__version__/{print substr($NF,2,length($NF)-2)}' $SRC_DIR/novelwriter/__init__.py)"
pushd "$SRC_DIR" || exit 1
python3 setup.py manual qtlrelease sample gen-plist
ls -lah .
popd || exit 1
pushd "$BUILD_DIR"/ || exit 1
echo "Downloading Miniconda ..."
# install Miniconda, a self-contained Python distribution
curl -LO 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"
echo "Creating conda env ..."
# create conda env
conda create -n novelWriter -c conda-forge python=3.10 --yes
source activate novelWriter
echo "installing dictionaries ..."
conda install -c conda-forge enchant hunspell-en --yes
echo "installing python deps ..."
# install dependencies
pip install -r "$SRC_DIR/requirements.txt"
# leave conda env
conda deactivate
echo "Building app bundle ..."
# create .app Framework
mkdir -p novelWriter.app/Contents/
mkdir novelWriter.app/Contents/MacOS novelWriter.app/Contents/Resources novelWriter.app/Contents/Resources/novelWriter
cp $SRC_DIR/setup/macos/Info.plist novelWriter.app/Contents/Info.plist
echo "Copying miniconda env to bundle ..."
# copy Miniconda env
cp -R ~/miniconda/envs/novelWriter/* novelWriter.app/Contents/Resources/
echo "Copying novelWriter to bundle ..."
# copy novelWriter
FILES_COPY=(
"CHANGELOG.md" "MANIFEST.in" "CREDITS.md" "LICENSE.md"
"CONTRIBUTING.md" "CODE_OF_CONDUCT.md" "i18n" "novelwriter"
"novelWriter.py"
)
for file in "${FILES_COPY[@]}"; do
echo "Copying $SRC_DIR/$file ..."
cp -R $SRC_DIR/$file novelWriter.app/Contents/Resources/novelWriter/
done
cp $SRC_DIR/setup/macos/novelwriter.icns novelWriter.app/Contents/Resources/
# 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.py $@
EOF
# make executable
chmod a+x novelWriter.app/Contents/MacOS/novelWriter
#do codesigning
#sudo codesign --sign - --deep --force --entitlements "$SCRIPT_DIR/../macos/App.entitlements" --options runtime "novelWriter.app/Contents/MacOS/novelWriter"
# remove bloat
pushd novelWriter.app/Contents/Resources || exit 1
echo "Cleaning unused files from bundle ..."
# cleanup commands HERE
find . -type d -iname '__pycache__' -print0 | xargs -0 rm -r
rm -rf pkgs
rm -rf cmake
rm -rf share/{gtk-,}doc
#remove web engine
rm lib/python3.*/site-packages/PyQt5/QtWebEngine* || true
rm -r lib/python3.*/site-packages/PyQt5/Qt/translations/qtwebengine* || true
rm lib/python3.*/site-packages/PyQt5/Qt/resources/qtwebengine* || true
rm -r lib/python3.*/site-packages/PyQt5/Qt/qml/QtWebEngine* || true
rm -r lib/python3.*/site-packages/PyQt5/Qt/plugins/webview/libqtwebview* || true
rm lib/python3.*/site-packages/PyQt5/Qt/libexec/QtWebEngineProcess* || true
rm lib/python3.*/site-packages/PyQt5/Qt/lib/libQt5WebEngine* || true
popd || exit 1
popd || exit 1
echo "Packageing App ..."
mkdir -p $RLS_DIR
# generate .dmg
brew install create-dmg
# "--skip-jenkins" is a temporary workaround for https://github.com/create-dmg/create-dmg/issues/72
create-dmg --volname "novelWriter $VERSION" --volicon $SCR_DIR/setup/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 $RLS_DIR/novelWriter-"${VERSION}"-macos.dmg "$BUILD_DIR"/
pushd $BUILD_DIR || exit 1
zip -qr novelWriter.app.zip novelWriter.app
popd || exit 1
mv $BUILD_DIR/novelWriter.app.zip $RLS_DIR/novelWriter-"${VERSION}"-macos.zip
+19
View File
@@ -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
Binary file not shown.