11# -*- mode: python -*-
22import sys
3+ import platform
34import os .path as os_path
45import simplejson as json
6+ import subprocess
57
68os_type = sys .platform
79block_cipher = None
@@ -11,9 +13,30 @@ def libModule(module, source, dest):
1113 m = __import__ (module )
1214 module_path = os_path .dirname (m .__file__ )
1315 del m
14- print (f"libModule { (os . path .join (module_path , source ), dest )} " )
16+ print (f"libModule { (os_path .join (module_path , source ), dest )} " )
1517 return ( os_path .join (module_path , source ), dest )
1618
19+ def is_tool (prog ):
20+ for dir in os .environ ['PATH' ].split (os .pathsep ):
21+ if os .path .exists (os .path .join (dir , prog )):
22+ try :
23+ subprocess .call ([os .path .join (dir , prog )],
24+ stdout = subprocess .PIPE ,
25+ stderr = subprocess .STDOUT )
26+ except (OSError , e ):
27+ return False
28+ return True
29+ return False
30+
31+ # Set this to True if codesigning macOS bundles. Requires an Apple issued developer ID certificate.
32+ code_sign = False
33+ codesigner = 'fuzzbawls@pivx.org'
34+
35+ # detect CPU architecture
36+ cpu_arch = platform .processor ()
37+ if os_type == 'darwin' :
38+ if cpu_arch == 'arm' : cpu_arch = 'arm64'
39+ if cpu_arch == 'i386' : cpu_arch = 'x86_64'
1740
1841# look for version string
1942version_str = ''
@@ -89,22 +112,23 @@ exe = EXE(pyz,
89112 strip = False ,
90113 upx = False ,
91114 console = False ,
92- icon = os .path .join (base_dir , 'img' , f'spmt.{ "icns" if os_type == "darwin" else "ico" } ' ))
93-
94- #coll = COLLECT(exe,
95- # a.binaries,
96- # a.zipfiles,
97- # a.datas,
98- # strip=False,
99- # upx=True,
100- # name='app')
115+ target_arch = f'{ cpu_arch } ' ,
116+ entitlements_file = 'contrib/macdeploy/entitlements.plist' ,
117+ codesign_identity = f'{ codesigner if code_sign == True else "" } ' ,
118+ icon = os_path .join (base_dir , 'img' , f'spmt.{ "icns" if os_type == "darwin" else "ico" } ' ))
101119
102120if os_type == 'darwin' :
103121 app = BUNDLE (exe ,
104122 name = 'SecurePivxMasternodeTool.app' ,
105123 icon = os_path .join (base_dir , 'img' , 'spmt.icns' ),
106- bundle_identifier = None ,
107- info_plist = {'NSHighResolutionCapable' : 'True' })
124+ bundle_identifier = 'io.pivx.spmt' ,
125+ info_plist = {
126+ 'NSHighResolutionCapable' : 'True' ,
127+ 'CFBundleVersion' : version_str ,
128+ 'CFBundleShortVersionString' : version_str ,
129+ 'NSPrincipalClass' : 'NSApplication' ,
130+ 'LSApplicationCategoryType' : 'public.app-category.finance'
131+ })
108132
109133
110134# Prepare bundles
@@ -121,33 +145,60 @@ os.chdir(dist_path)
121145if os_type == 'win32' :
122146 os .chdir (base_dir )
123147 # Rename dist Dir
124- dist_path_win = os_path .join (base_dir , 'SPMT-v' + version_str + ' -Win64' )
148+ dist_path_win = os_path .join (base_dir , f 'SPMT-v{ version_str } -Win64' )
125149 os .rename (dist_path , dist_path_win )
126- # Create NSIS compressed installer
127- print ('Creating Windows installer (requires NSIS)' )
128- os .system (f'"{ os .path .join ("c:" , "program files (x86)" , "NSIS" , "makensis.exe" )} " { os .path .join (base_dir , "setup.nsi" )} ' )
150+ # Check for NSIS
151+ prog_path = os .environ ["ProgramFiles(x86)" ]
152+ nsis_bin = os_path .join (prog_path , "NSIS" , "makensis.exe" )
153+ if os_path .exists (nsis_bin ):
154+ # Create NSIS compressed installer
155+ print ('Creating Windows installer' )
156+ os .system (f'"{ nsis_bin } " { os_path .join (base_dir , "setup.nsi" )} ' )
157+ else :
158+ print ('NSIS not found, cannot build windows installer.' )
129159
130160
131161if os_type == 'linux' :
132162 os .chdir (base_dir )
133163 # Rename dist Dir
134- dist_path_linux = os_path .join (base_dir , 'SPMT-v' + version_str + ' -gnu_linux' )
164+ dist_path_linux = os_path .join (base_dir , f 'SPMT-v{ version_str } - { cpu_arch } -gnu_linux' )
135165 os .rename (dist_path , dist_path_linux )
136166 # Compress dist Dir
137167 print ('Compressing Linux App Folder' )
138- os .system (f'tar -zcvf SPMT-v{ version_str } -x86_64 -gnu_linux.tar.gz -C { base_dir } SPMT-v{ version_str } -gnu_linux' )
168+ os .system (f'tar -zcvf SPMT-v{ version_str } -{ cpu_arch } -gnu_linux.tar.gz -C { base_dir } SPMT-v{ version_str } - { cpu_arch } -gnu_linux' )
139169
140170
141171if os_type == 'darwin' :
142172 os .chdir (base_dir )
143173 # Rename dist Dir
144- dist_path_mac = os_path .join (base_dir , 'SPMT-v' + version_str + '-MacOSX ' )
174+ dist_path_mac = os_path .join (base_dir , f 'SPMT-v{ version_str } - { cpu_arch } -MacOS ' )
145175 os .rename (dist_path , dist_path_mac )
146176 # Remove 'app' folder
147- print ("Removin 'app' folder" )
177+ print ("Removing 'app' folder" )
148178 os .chdir (dist_path_mac )
149179 os .system ('rm -rf app' )
150180 os .chdir (base_dir )
151181 # Compress dist Dir
152182 print ('Compressing Mac App Folder' )
153- os .system (f'tar -zcvf SPMT-v{ version_str } -MacOSX.tar.gz -C { base_dir } SPMT-v{ version_str } -MacOSX' )
183+ os .system (f'tar -zcvf SPMT-v{ version_str } -{ cpu_arch } -MacOS.tar.gz -C { base_dir } SPMT-v{ version_str } -{ cpu_arch } -MacOS' )
184+
185+ # dmg image creation uses the node.js appdmg package
186+ if is_tool ("appdmg" ):
187+ # Prepare dmg
188+ print ("Preparing distribution dmg installer" )
189+ os .chdir (dist_path_mac )
190+ with open (os_path .join (base_dir , 'contrib/macdeploy' , 'appdmg.json.in' )) as conf :
191+ confdata = conf .read ()
192+ confdata = confdata .replace ('%version%' , version_str )
193+ confdata = confdata .replace ('%signer%' , f'{ codesigner if code_sign == True else "" } ' )
194+ with open ('appdmg.json' , 'w' ) as newconf :
195+ newconf .write (confdata )
196+
197+ os .system (f'sed \" s/PACKAGE_NAME/SPMT { version_str } /\" < \" ../contrib/macdeploy/background.svg\" | rsvg-convert -f png -d 72 -p 72 | convert - background.tiff@2x.png' )
198+ os .system ('convert background.tiff@2x.png -resize 500x320 background.tiff.png' )
199+ os .system ('tiffutil -cathidpicheck background.tiff.png background.tiff@2x.png -out background.tiff' )
200+ os .remove ('background.tiff.png' )
201+ os .system (f'appdmg appdmg.json ../SPMT-v{ version_str } -{ cpu_arch } -MacOS.dmg' )
202+ os .remove ('background.tiff@2x.png' )
203+ else :
204+ print ("appdmg not found, skipping DMG creation" )
0 commit comments