Skip to content

Commit bb2db92

Browse files
committed
Merge #65: [Build] Add distribution packaging functionality
c9ab415 [Build] Add distribution packaging functionality (Fuzzbawls) Pull request description: Adds code to the `.spec` file used to create the distribution binaries. Requires `pyinstaller`. The macOS binaries further require the node.js `appdmg` package for `.dmg` creation, and a valid Apple issued developer ID certificate for code signing. ACKs for top commit: Liquid369: utACK c9ab415 Tree-SHA512: a2d71bd747e334036159c02dd6e2252418ae29b87c5b557350218853b3e79fdfe1fe92f32217489836c6d5d2882afb9ae870c4af1d81539d787a75a97ef11a3a
2 parents 324371e + c9ab415 commit bb2db92

File tree

4 files changed

+137
-21
lines changed

4 files changed

+137
-21
lines changed

SecurePivxMasternodeTool.spec

Lines changed: 72 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# -*- mode: python -*-
22
import sys
3+
import platform
34
import os.path as os_path
45
import simplejson as json
6+
import subprocess
57

68
os_type = sys.platform
79
block_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
1942
version_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

102120
if 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)
121145
if 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

131161
if 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

141171
if 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")

contrib/macdeploy/appdmg.json.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"title": "SPMT %version%",
3+
"icon": "../img/spmt.icns",
4+
"icon-size": 96,
5+
"background": "background.tiff",
6+
"contents": [
7+
{ "x": 370, "y": 156, "type": "link", "path": "/Applications" },
8+
{ "x": 128, "y": 156, "type": "file", "path": "SecurePivxMasternodeTool.app" }
9+
],
10+
"code-sign": {
11+
"signing-identity": "%signer%"
12+
}
13+
}

contrib/macdeploy/background.svg

Lines changed: 34 additions & 0 deletions
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
6+
<true/>
7+
<key>com.apple.security.cs.disable-library-validation</key>
8+
<true/>
9+
<key>com.apple.security.automation.apple-events</key>
10+
<true/>
11+
<key>com.apple.security.cs.allow-jit</key>
12+
<true/>
13+
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
14+
<true/>
15+
<key>com.apple.security.device.camera</key>
16+
<true/>
17+
</dict>
18+
</plist>

0 commit comments

Comments
 (0)