2222
2323import argparse
2424import datetime
25+ import os
2526import shutil
26- import subprocess
2727import sys
2828
29+ from pathlib import Path
30+
2931from utils .common import (
3032 ROOT_DIR , SETUP_DIR , appdataXml , copyPackageFiles , copySourceCode ,
31- extractVersion , makeCheckSum , toUpload , writeFile
33+ extractVersion , freshFolder , makeCheckSum , systemCall , toUpload , writeFile
3234)
3335
3436
@@ -49,115 +51,83 @@ def appImage(args: argparse.Namespace) -> None:
4951
5052 print ("" )
5153 print ("Build AppImage" )
52- print ("==============" )
53- print ("" )
54+ print ("=" * 120 )
5455
55- linuxTag = args .linux_tag
56- pythonVer = args .python_version
56+ mLinux = args .linux
57+ mArch = args .arch
58+ pyVer = args .python
5759
5860 # Version Info
59- # ============
60-
6161 pkgVers , _ , relDate = extractVersion ()
6262 relDate = datetime .datetime .strptime (relDate , "%Y-%m-%d" )
63- print ("" )
6463
6564 # Set Up Folder
66- # =============
67-
6865 bldDir = ROOT_DIR / "dist_appimage"
69- bldPkg = f"novelwriter_{ pkgVers } "
66+ bldPkg = f"novelwriter-{ pkgVers } -{ mArch } "
67+ bldImg = f"{ bldPkg } .AppImage"
7068 outDir = bldDir / bldPkg
7169 imgDir = bldDir / "appimage"
72-
73- # Set Up Folders
74- # ==============
70+ appDir = bldDir / f"novelWriter-{ mArch } "
7571
7672 bldDir .mkdir (exist_ok = True )
77-
78- if outDir .exists ():
79- print ("Removing old build files ..." )
80- print ("" )
81- shutil .rmtree (outDir )
82-
83- outDir .mkdir ()
84-
85- if imgDir .exists ():
86- print ("Removing old build metadata files ..." )
87- print ("" )
88- shutil .rmtree (imgDir )
89-
90- imgDir .mkdir ()
73+ freshFolder (outDir )
74+ freshFolder (imgDir )
75+ freshFolder (appDir )
9176
9277 # Remove old AppImages
9378 if images := bldDir .glob ("*.AppImage" ):
9479 print ("Removing old AppImages" )
95- print ("" )
9680 for image in images :
9781 image .unlink ()
9882
9983 # Copy novelWriter Source
100- # =======================
101-
10284 print ("Copying novelWriter source ..." )
103- print ("" )
104-
10585 copySourceCode (outDir )
10686
107- print ("" )
10887 print ("Copying or generating additional files ..." )
109- print ("" )
110-
11188 copyPackageFiles (outDir )
11289
11390 # Write Metadata
114- # ==============
115-
11691 writeFile (imgDir / "novelwriter.appdata.xml" , appdataXml ())
117- print ("Wrote: novelwriter.appdata.xml" )
118-
92+ writeFile (imgDir / "requirements.txt" , str (outDir ))
11993 writeFile (imgDir / "entrypoint.sh" , (
120- '#! /bin/bash \n '
94+ f"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${{APPDIR}}/usr/lib/ { mArch } -linux-gnu/ \n "
12195 '{{ python-executable }} -sE ${APPDIR}/opt/python{{ python-version }}/bin/novelwriter "$@"'
12296 ))
123- print ("Wrote: entrypoint.sh" )
124-
125- writeFile (imgDir / "requirements.txt" , str (outDir ))
126- print ("Wrote: requirements.txt" )
12797
12898 shutil .copyfile (SETUP_DIR / "data" / "novelwriter.desktop" , imgDir / "novelwriter.desktop" )
12999 print ("Copied: novelwriter.desktop" )
130100
131- shutil .copyfile (SETUP_DIR / "icons" / "novelwriter.svg" , imgDir / "novelwriter.svg" )
132- print ("Copied: novelwriter.svg" )
133-
134- shutil .copyfile (
135- SETUP_DIR / "data" / "hicolor" / "256x256" / "apps" / "novelwriter.png" ,
136- imgDir / "novelwriter.png"
137- )
101+ shutil .copyfile (SETUP_DIR / "icons" / "novelwriter.png" , imgDir / "novelwriter.png" )
138102 print ("Copied: novelwriter.png" )
139103
140- # Build AppImage
141- # ==============
142-
143- try :
144- subprocess .call ([
145- sys .executable , "-m" , "python_appimage" , "build" , "app" ,
146- "-l" , linuxTag , "-p" , pythonVer , "appimage"
147- ], cwd = bldDir )
148- except Exception as exc :
149- print ("AppImage build: FAILED" )
150- print ("" )
151- print (str (exc ))
152- print ("" )
153- sys .exit (1 )
154-
155- bldFile = list (bldDir .glob ("*.AppImage" ))[0 ]
156- outFile = bldDir / f"novelWriter-{ pkgVers } .AppImage"
157- bldFile .rename (outFile )
158- shaFile = makeCheckSum (outFile .name , cwd = bldDir )
159-
160- toUpload (outFile )
104+ # Build AppDir
105+ systemCall ([
106+ sys .executable , "-m" , "python_appimage" , "build" , "app" , "--no-packaging" ,
107+ "-l" , f"{ mLinux } _{ mArch } " , "-p" , pyVer , "appimage"
108+ ], cwd = bldDir )
109+
110+ # Copy Libraries
111+ libPath = Path (f"/usr/lib/{ mArch } -linux-gnu" )
112+ appLibs = appDir / "usr" / "lib" / f"{ mArch } -linux-gnu"
113+ appLibs .mkdir (exist_ok = True )
114+ shutil .copyfile (libPath / "libxcb-cursor.so.0" , appLibs / "libxcb-cursor.so.0" )
115+
116+ # Build Image
117+ env = os .environ .copy ()
118+ env ["ARCH" ] = mArch
119+ systemCall ([
120+ "appimagetool" , "--no-appstream" , "--updateinformation" ,
121+ f"gh-releases-zsync|vkbo|novelwriter|latest|novelwriter-*-{ mArch } .AppImage.zsync" ,
122+ str (appDir ), bldImg
123+ ], cwd = bldDir , env = env )
124+
125+ updFile = bldDir / f"{ bldImg } .zsync"
126+ bldFile = bldDir / bldImg
127+ shaFile = makeCheckSum (bldFile .name , cwd = bldDir )
128+
129+ toUpload (bldFile )
130+ toUpload (updFile )
161131 toUpload (shaFile )
162132
163133 return
0 commit comments