From f912d55177c6c1f3f7580e9531a55b550076960d Mon Sep 17 00:00:00 2001
From: Rachel Powers <508861+Ryex@users.noreply.github.com>
Date: Sun, 8 Jan 2023 21:08:21 -0700
Subject: [PATCH] refactor: move plist gen into setup.py
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
---
.github/workflows/build.yml | 15 +--
macos/Info.plist | 60 ------------
macos/Info.plist.in | 60 ------------
macos/generate_plist.py | 26 ------
setup.py | 116 ++++++++++++++++++++++++
{macos => setup/macos}/App.entitlements | 0
{macos => setup/macos}/build.sh | 30 +++---
{macos => setup/macos}/generate_icns.sh | 2 +-
{macos => setup/macos}/novelwriter.icns | Bin
9 files changed, 139 insertions(+), 170 deletions(-)
delete mode 100644 macos/Info.plist
delete mode 100644 macos/Info.plist.in
delete mode 100644 macos/generate_plist.py
rename {macos => setup/macos}/App.entitlements (100%)
rename {macos => setup/macos}/build.sh (82%)
rename {macos => setup/macos}/generate_icns.sh (95%)
rename {macos => setup/macos}/novelwriter.icns (100%)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e34ab056..1f66fb62 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -76,22 +76,17 @@ jobs:
- name: Build (macOS)
if: runner.os == 'macOS'
run: |
- ./macos/build.sh
+ ./setup/macos/build.sh
##
# UPLOAD BUILDS
##
- - name: Upload binary zip (macOS)
+ - name: Upload binary zip / dmg (macOS)
if: runner.os == 'macOS'
uses: actions/upload-artifact@v3
with:
name: novelWriter-${{ matrix.name }}-${{ env.VERSION }}.app.zip
- path: novelWriter.app.zip
-
- - name: Upload dmg (macOS)
- if: runner.os == 'macOS'
- uses: actions/upload-artifact@v3
- with:
- name: novelWriter-${{ matrix.name }}-${{ env.VERSION }}.dmg
- path: novelWriter-${{ env.VERSION }}.dmg
+ path: |
+ dist_macos/novelWriter-${{ env.VERSION }}.zip
+ dist_macos/novelWriter-${{ env.VERSION }}.dmg
diff --git a/macos/Info.plist b/macos/Info.plist
deleted file mode 100644
index 6db23257..00000000
--- a/macos/Info.plist
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-
-
- NSPrincipalClass
- NSApplication
- NSHighResolutionCapable
- True
- CFBundleDevelopmentRegion
- English
- CFBundleExecutable
- novelwriter
- CFBundleGetInfoString
- novelWriter: A markdown-like text editor for planning and writing novels.
- CFBundleIconFile
- novelwriter.icns
- CFBundleIdentifier
- io.novelwriter.novelWriter
- CFBundleName
- novelWriter
- CFBundleInfoDictionaryVersion
- 6.0
- CFBundleShortVersionString
- 2.0.1
- CFBundleSignature
- ????
- CFBundleVersion
- 2.0.1
- CFBundlePackageType
- APPL
- NSHumanReadableCopyright
- © 2018–2022, Veronica Berglyd Olsen <code@vkbo.net>
- IFMajorVersion
- 0
- IFMinorVersion
- 1
- CFBundleDocumentTypes
-
-
- CFBundleTypeExtensions
-
- nwx
-
- CFBundleTypeName
- novelWriter Project
- CFBundleTypeOSTypes
-
- TEXT
- utxt
- TUTX
- ****
-
- CFBundleTypeRole
- Viewer
- LSHandlerRank
- Alternate
-
-
-
-
\ No newline at end of file
diff --git a/macos/Info.plist.in b/macos/Info.plist.in
deleted file mode 100644
index f5ab4d2c..00000000
--- a/macos/Info.plist.in
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-
-
- NSPrincipalClass
- NSApplication
- NSHighResolutionCapable
- True
- CFBundleDevelopmentRegion
- English
- CFBundleExecutable
- {MACOSX_BUNDLE_EXACUTABLE_NAME}
- CFBundleGetInfoString
- {MACOSX_BUNDLE_INFO_STRING}
- CFBundleIconFile
- {MACOSX_BUNDLE_ICON_FILE}
- CFBundleIdentifier
- {MACOSX_BUNDLE_IDENTIFIER}
- CFBundleName
- {MACOSX_BUNDLE_NAME}
- CFBundleInfoDictionaryVersion
- 6.0
- CFBundleShortVersionString
- {MACOSX_BUNDLE_SHORT_VERSION}
- CFBundleSignature
- ????
- CFBundleVersion
- {MACOSX_BUNDLE_VERSION}
- CFBundlePackageType
- APPL
- NSHumanReadableCopyright
- {MACOSX_BUNDLE_COPYRIGHT}
- IFMajorVersion
- 0
- IFMinorVersion
- 1
- CFBundleDocumentTypes
-
-
- CFBundleTypeExtensions
-
- nwx
-
- CFBundleTypeName
- novelWriter Project
- CFBundleTypeOSTypes
-
- TEXT
- utxt
- TUTX
- ****
-
- CFBundleTypeRole
- Viewer
- LSHandlerRank
- Alternate
-
-
-
-
\ No newline at end of file
diff --git a/macos/generate_plist.py b/macos/generate_plist.py
deleted file mode 100644
index 2f6e3c26..00000000
--- a/macos/generate_plist.py
+++ /dev/null
@@ -1,26 +0,0 @@
-import os
-
-SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
-
-SETTINGS = {
- "MACOSX_BUNDLE_COPYRIGHT": "© 2018–2022, Veronica Berglyd Olsen ",
- "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)
diff --git a/setup.py b/setup.py
index 75bcd2b1..dced8caa 100755
--- a/setup.py
+++ b/setup.py
@@ -71,6 +71,25 @@ def extractVersion():
return numVers, hexVers, relDate
+def extractCopyright():
+ """Extract the novelWriter copyright notice without having to import
+ anything else from the main package.
+ """
+ copyright = "Unknown"
+ initFile = os.path.join("novelwriter", "__init__.py")
+ try:
+ with open(initFile, mode="r", encoding="utf-8") as inFile:
+ for aLine in inFile:
+ if aLine.startswith("__copyright__"):
+ copyright = (aLine).partition("=")[2].strip().strip('"')
+ except Exception as exc:
+ print("Could not read file: %s" % initFile)
+ print(str(exc))
+
+ print("novelWriter copyright: %s " % (copyright))
+
+ return copyright
+
def compactVersion(numVers):
"""Make the version number more compact."""
@@ -395,6 +414,98 @@ def buildQtI18nTS(sysArgs):
return
+##
+# Generage MacOS PList
+##
+
+def genMacOSPlist():
+
+ # Set Up Folder
+ # =============
+
+ numVers, _, _ = extractVersion()
+ pkgVers = compactVersion(numVers)
+
+ outDir = "setup/macos"
+
+ macosBundleName = "novelWriter"
+ macosBundleExeName = "novelWriter"
+ macosBundleInfo = "novelWriter: A markdown-like text editor for planning and writing novels."
+ macosBundleIcon = "novelwriter.icns"
+ macosBundleIdent = "io.novelwriter.novelWriter"
+ macosBundleSVers = pkgVers
+ macosBundleVers = numVers
+ macosBundleCopyright = extractCopyright()
+
+ # These keys are no longer used but are present for compatability
+ macosBundleVersMajor, macosBundleVersMinor, _ = pkgVers.split(".")
+
+
+ plistXML = (
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "NSPrincipalClass\n"
+ "NSApplication\n"
+ "NSHighResolutionCapable\n"
+ "True\n"
+ "CFBundleDevelopmentRegion\n"
+ "English\n"
+ "CFBundleExecutable\n"
+ f"{macosBundleExeName}\n"
+ "CFBundleGetInfoString\n"
+ f"{macosBundleInfo}\n"
+ "CFBundleIconFile\n"
+ f"{macosBundleIcon}\n"
+ "CFBundleIdentifier\n"
+ f"{macosBundleIdent}\n"
+ "CFBundleName\n"
+ f"{macosBundleName}\n"
+ "CFBundleInfoDictionaryVersion\n"
+ "6.0\n"
+ "CFBundleShortVersionString\n"
+ f"{macosBundleSVers}\n"
+ "CFBundleSignature\n"
+ "????\n"
+ "CFBundleVersion\n"
+ f"{macosBundleVers}\n"
+ "CFBundlePackageType\n"
+ "APPL\n"
+ "NSHumanReadableCopyright\n"
+ f"{macosBundleCopyright}\n"
+ "IFMajorVersion\n"
+ f"{macosBundleVersMajor}\n"
+ "IFMinorVersion\n"
+ f"{macosBundleVersMinor}\n"
+ "CFBundleDocumentTypes\n"
+ " \n"
+ " \n"
+ " CFBundleTypeExtensions\n"
+ " \n"
+ " nwx\n"
+ " \n"
+ " CFBundleTypeName\n"
+ " novelWriter Project\n"
+ " CFBundleTypeOSTypes\n"
+ " \n"
+ " TEXT\n"
+ " utxt\n"
+ " TUTX\n"
+ " ****\n"
+ " \n"
+ " CFBundleTypeRole\n"
+ " Viewer\n"
+ " LSHandlerRank\n"
+ " Alternate\n"
+ " \n"
+ " \n"
+ "\n"
+ "\n"
+ )
+
+ writeFile(f"{outDir}/Info.plist", plistXML)
+
##
# Sample Project ZIP File Builder (sample)
@@ -1862,6 +1973,7 @@ if __name__ == "__main__":
" The files to be updated must be provided as arguments.",
" qtlrelease Build the language files for internationalisation.",
" clean-assets Delete assets built by manual, sample and qtlrelease.",
+ " gen-plist Generates an Info.plist for use in a MacOS Bundle",
"",
"Python Packaging:",
"",
@@ -1943,6 +2055,10 @@ if __name__ == "__main__":
if "clean-assets" in sys.argv:
sys.argv.remove("clean-assets")
cleanBuiltAssets()
+
+ if "gen-plist" in sys.argv:
+ sys.argv.remove("gen-plist")
+ genMacOSPlist()
# Python Packaging
# ================
diff --git a/macos/App.entitlements b/setup/macos/App.entitlements
similarity index 100%
rename from macos/App.entitlements
rename to setup/macos/App.entitlements
diff --git a/macos/build.sh b/setup/macos/build.sh
similarity index 82%
rename from macos/build.sh
rename to setup/macos/build.sh
index b04491aa..9fd91acc 100755
--- a/macos/build.sh
+++ b/setup/macos/build.sh
@@ -11,6 +11,10 @@ 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"
@@ -23,11 +27,11 @@ echo "Building in: $BUILD_DIR"
OLD_CWD="$(pwd)"
-VERSION="$(awk '/^__version__/{print substr($NF,2,length($NF)-2)}' $SCRIPT_DIR/../novelwriter/__init__.py)"
+VERSION="$(awk '/^__version__/{print substr($NF,2,length($NF)-2)}' $SRC_DIR/novelwriter/__init__.py)"
-pushd "$SCRIPT_DIR/../" || exit 1
+pushd "$SRC_DIR" || exit 1
-python3 setup.py manual qtlrelease sample
+python3 setup.py manual qtlrelease sample gen-plist
ls -lah .
@@ -52,7 +56,7 @@ conda install -c conda-forge enchant hunspell-en --yes
echo "installing python deps ..."
# install dependencies
-pip install -r "$SCRIPT_DIR/../requirements.txt"
+pip install -r "$SRC_DIR/requirements.txt"
# leave conda env
conda deactivate
@@ -61,7 +65,7 @@ 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 $SCRIPT_DIR/../macos/Info.plist novelWriter.app/Contents/Info.plist
+cp $SRC_DIR/setup/macos/Info.plist novelWriter.app/Contents/Info.plist
echo "Copying miniconda env to bundle ..."
# copy Miniconda env
@@ -77,13 +81,11 @@ FILES_COPY=(
)
for file in "${FILES_COPY[@]}"; do
- echo "Copying $SCRIPT_DIR/../$file ..."
- cp -R $SCRIPT_DIR/../$file novelWriter.app/Contents/Resources/novelWriter/
+ echo "Copying $SRC_DIR/$file ..."
+ cp -R $SRC_DIR/$file novelWriter.app/Contents/Resources/novelWriter/
done
-cp $SCRIPT_DIR/../macos/novelwriter.icns novelWriter.app/Contents/Resources/
-#cp -R $SCRIPT_DIR/../* novelWriter.app/Contents/Resources/novelWriter/
-
+cp $SRC_DIR/setup/macos/novelwriter.icns novelWriter.app/Contents/Resources/
# create entry script
cat > novelWriter.app/Contents/MacOS/novelWriter <<\EOF
@@ -123,16 +125,18 @@ 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 $SCRIPT_DIR/../macos/novelwriter.icns \
+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 novelWriter-"${VERSION}".dmg "$BUILD_DIR"/
+ --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 novelWriter.app.zip
\ No newline at end of file
+mv $BUILD_DIR/novelWriter.app.zip $RLS_DIR/novelWriter-"${VERSION}"-macos.zip
diff --git a/macos/generate_icns.sh b/setup/macos/generate_icns.sh
similarity index 95%
rename from macos/generate_icns.sh
rename to setup/macos/generate_icns.sh
index ef4747dc..ecc70255 100755
--- a/macos/generate_icns.sh
+++ b/setup/macos/generate_icns.sh
@@ -16,4 +16,4 @@ done
png2icns $SCRIPT_DIR/novelwriter.icns $SCRIPT_DIR/icons/icon_*px.png
-rm -r $SCRIPT_DIR/icons
\ No newline at end of file
+rm -r $SCRIPT_DIR/icons
diff --git a/macos/novelwriter.icns b/setup/macos/novelwriter.icns
similarity index 100%
rename from macos/novelwriter.icns
rename to setup/macos/novelwriter.icns