-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbuild.py
More file actions
789 lines (630 loc) · 23.8 KB
/
build.py
File metadata and controls
789 lines (630 loc) · 23.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
#!/usr/bin/env python
"""Build script for FastSM using PyInstaller - supports Windows and macOS."""
import os
import re
import subprocess
import sys
import shutil
import tempfile
import platform as platform_mod
from pathlib import Path
from version import APP_NAME, APP_VERSION, APP_DESCRIPTION, APP_COPYRIGHT, APP_VENDOR
def get_platform():
"""Get the current platform."""
if sys.platform == "darwin":
return "macos"
elif sys.platform == "win32":
return "windows"
else:
return "linux"
def get_git_commit_sha():
"""Get the current git commit SHA."""
try:
result = subprocess.run(
["git", "rev-parse", "HEAD"],
capture_output=True, text=True
)
if result.returncode == 0:
return result.stdout.strip()
except Exception:
pass
return None
def create_build_info_file(script_dir: Path):
"""Create build_info.txt with commit SHA in script directory for PyInstaller to bundle."""
commit_sha = get_git_commit_sha()
if commit_sha:
build_info_path = script_dir / "build_info.txt"
with open(build_info_path, 'w') as f:
f.write(commit_sha)
print(f"Created build_info.txt: commit {commit_sha[:8]}")
return build_info_path
return None
def cleanup_build_info_file(script_dir: Path):
"""Remove build_info.txt after build to keep source directory clean."""
build_info_path = script_dir / "build_info.txt"
if build_info_path.exists():
build_info_path.unlink()
print("Cleaned up build_info.txt")
def get_hidden_imports():
"""Get list of hidden imports that PyInstaller might miss."""
return [
# wx submodules
"wx.adv",
"wx.html",
"wx.xml",
# mastodon
"mastodon",
"mastodon.Mastodon",
# atproto
"atproto",
"atproto.xrpc_client",
"atproto.xrpc_client.models",
# Our packages
"models",
"models.user",
"platforms",
"platforms.base",
"platforms.mastodon",
"platforms.mastodon.account",
"platforms.mastodon.models",
"platforms.bluesky",
"platforms.bluesky.account",
"GUI",
"GUI.main",
"GUI.tweet",
"GUI.view",
"GUI.options",
"GUI.account_options",
"GUI.chooser",
"GUI.misc",
"GUI.lists",
"GUI.custom_timelines",
# Other modules
"config",
"timeline",
"streaming",
"mastodon_api",
"application",
"sound",
"speak",
"version",
# keyboard_handler
"keyboard_handler",
"keyboard_handler.wx_handler",
# speech backend (replaces accessible_output2)
"prism",
"prism.core",
"prism.lib",
"sound_lib",
"sound_lib.stream",
"sound_lib.output",
# requests/urllib
"requests",
"urllib3",
"certifi",
"charset_normalizer",
"idna",
# Other
"json",
"threading",
"datetime",
"pickle",
"pyperclip",
# Spell check
"enchant",
]
def get_data_files(script_dir: Path):
"""Get list of data files to include in the bundle.
Note: sounds, keymaps, and docs are copied separately to the root
of the distribution folder after the build.
"""
datas = []
# Include build_info.txt if it exists (created before build)
build_info = script_dir / "build_info.txt"
if build_info.exists():
datas.append((str(build_info), "."))
return datas
def copy_data_files(script_dir: Path, dest_dir: Path, include_docs: bool = True):
"""Copy data files to the distribution folder root.
Args:
script_dir: Source directory
dest_dir: Destination directory
include_docs: Whether to include docs folder (False for macOS app bundle)
"""
# Sounds folder
sounds_src = script_dir / "sounds"
if sounds_src.exists():
sounds_dst = dest_dir / "sounds"
print("Copying sounds folder...")
if sounds_dst.exists():
shutil.rmtree(sounds_dst)
shutil.copytree(sounds_src, sounds_dst)
# Keymaps folder (invisible hotkeys only supported on Windows)
keymaps_src = script_dir / "keymaps"
if keymaps_src.exists():
keymaps_dst = dest_dir / "keymaps"
print("Copying keymaps folder...")
if keymaps_dst.exists():
shutil.rmtree(keymaps_dst)
shutil.copytree(keymaps_src, keymaps_dst)
# Docs folder (skip for macOS app bundle - goes in DMG instead)
if include_docs:
docs_src = script_dir / "docs"
if docs_src.exists():
docs_dst = dest_dir / "docs"
print("Copying docs folder...")
if docs_dst.exists():
shutil.rmtree(docs_dst)
shutil.copytree(docs_src, docs_dst)
def get_binaries():
"""Get platform-specific binaries to include."""
binaries = []
if sys.platform == "win32":
# Include sound_lib DLLs
try:
import sound_lib
sl_path = Path(sound_lib.__file__).parent
for dll in sl_path.glob("*.dll"):
binaries.append((str(dll), "sound_lib"))
except ImportError:
pass
# Note: macOS sound_lib binaries are handled by hooks/hook-sound_lib.py
# to exclude incompatible x86 (i386/ppc) binaries
return binaries
def build_windows(script_dir: Path, output_dir: Path) -> tuple:
"""Build for Windows using PyInstaller.
Returns:
Tuple of (success: bool, artifact_path: Path or None)
"""
dist_dir = output_dir / "dist"
build_dir = output_dir / "build"
# Clean previous build
for d in [dist_dir, build_dir]:
if d.exists():
print(f"Cleaning {d}...")
shutil.rmtree(d)
output_dir.mkdir(parents=True, exist_ok=True)
# Create build_info.txt BEFORE building command so get_data_files can include it
create_build_info_file(script_dir)
# Build PyInstaller command
main_script = script_dir / "FastSM.pyw"
cmd = [
sys.executable, "-m", "PyInstaller",
"--name", APP_NAME,
"--windowed", # No console window
"--noconfirm", # Overwrite without asking
f"--distpath={dist_dir}",
f"--workpath={build_dir}",
f"--specpath={output_dir}",
]
# Add hidden imports
for imp in get_hidden_imports():
cmd.extend(["--hidden-import", imp])
# Add data files
for src, dst in get_data_files(script_dir):
cmd.extend(["--add-data", f"{src}{os.pathsep}{dst}"])
# Add binaries
for src, dst in get_binaries():
cmd.extend(["--add-binary", f"{src}{os.pathsep}{dst}"])
# Collect all submodules for key packages
cmd.extend(["--collect-all", "prism"])
cmd.extend(["--collect-all", "sound_lib"])
cmd.extend(["--collect-all", "keyboard_handler"])
# Enchant is imported inside try/except so PyInstaller can't trace it
cmd.extend(["--collect-submodules", "enchant"])
cmd.extend(["--collect-data", "enchant"])
# Add runtime hook to redirect stderr to config directory early
runtime_hook = script_dir / "runtime_hook.py"
if runtime_hook.exists():
cmd.extend(["--runtime-hook", str(runtime_hook)])
# Add main script
cmd.append(str(main_script))
print(f"Building {APP_NAME} v{APP_VERSION} for Windows...")
print(f"Output: {output_dir}")
print()
try:
result = subprocess.run(cmd, cwd=script_dir)
finally:
# Clean up build_info.txt from source directory
cleanup_build_info_file(script_dir)
if result.returncode != 0:
return False, None
# The output will be in dist_dir / APP_NAME
app_dir = dist_dir / APP_NAME
if not app_dir.exists():
print("Error: Build output not found")
return False, None
# Copy data files to root of distribution folder
copy_data_files(script_dir, app_dir)
# Create zip file for distribution
zip_path = create_windows_zip(output_dir, app_dir)
return True, zip_path
def create_windows_zip(output_dir: Path, app_dir: Path) -> Path:
"""Create a zip file of the Windows build for distribution."""
import zipfile
zip_name = f"{APP_NAME}-Windows-Portable.zip"
zip_path = output_dir / zip_name
if zip_path.exists():
zip_path.unlink()
print(f"Creating zip: {zip_name}...")
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
for file_path in app_dir.rglob('*'):
if file_path.is_file():
arc_name = Path(APP_NAME) / file_path.relative_to(app_dir)
zipf.write(file_path, arc_name)
zip_size_mb = zip_path.stat().st_size / (1024 * 1024)
print(f"Zip created: {zip_path}")
print(f"Zip size: {zip_size_mb:.1f} MB")
return zip_path
def build_linux(script_dir: Path, output_dir: Path) -> tuple:
"""Build for Linux using PyInstaller.
Produces a directory distribution under dist_dir and a .tar.gz beside it.
Returns:
Tuple of (success: bool, artifact_path: Path or None)
"""
dist_dir = output_dir / "dist"
build_dir = output_dir / "build"
for d in [dist_dir, build_dir]:
if d.exists():
print(f"Cleaning {d}...")
shutil.rmtree(d)
output_dir.mkdir(parents=True, exist_ok=True)
create_build_info_file(script_dir)
main_script = script_dir / "FastSM.pyw"
cmd = [
sys.executable, "-m", "PyInstaller",
"--name", APP_NAME,
"--windowed",
"--noconfirm",
f"--distpath={dist_dir}",
f"--workpath={build_dir}",
f"--specpath={output_dir}",
f"--additional-hooks-dir={script_dir / 'hooks'}",
]
for imp in get_hidden_imports():
cmd.extend(["--hidden-import", imp])
for src, dst in get_data_files(script_dir):
cmd.extend(["--add-data", f"{src}{os.pathsep}{dst}"])
# Collect native-backed packages so PyInstaller bundles their .so files.
cmd.extend(["--collect-all", "sound_lib"])
cmd.extend(["--collect-all", "keyboard_handler"])
cmd.extend(["--collect-all", "prism"])
rthook = script_dir / "hooks" / "rthook-platform_utils.py"
if rthook.exists():
cmd.extend(["--runtime-hook", str(rthook)])
cmd.append(str(main_script))
print(f"Building {APP_NAME} v{APP_VERSION} for Linux...")
print(f"Output: {output_dir}")
print()
try:
result = subprocess.run(cmd, cwd=script_dir)
finally:
cleanup_build_info_file(script_dir)
if result.returncode != 0:
return False, None
app_dir = dist_dir / APP_NAME
if not app_dir.exists():
print("Error: Build output not found")
return False, None
copy_data_files(script_dir, app_dir)
_patch_prism_libgio(app_dir / "_internal")
_strip_bundled_system_libs(app_dir / "_internal")
tar_path = create_linux_tarball(output_dir, app_dir)
return True, tar_path
# Audio/system libs that PyInstaller pulls in from the build runner but which
# must come from the user's system instead. The CI runner is older than many
# user distros, and a stale bundled libasound/libpulse silently breaks BASS
# playback when its plugins ABI-mismatch the system's PipeWire/PulseAudio.
_LINUX_SYSTEM_LIB_PATTERNS = (
"libasound.so*",
"libpulse.so*",
"libpulsecommon-*.so*",
# Two copies of GLib loaded at once (bundled + system, pulled in via system
# libs like dbus) trigger "cannot register existing type 'GSeekable'" and
# g_once_init_leave assertion failures. Force single-copy via the system.
"libglib-2.0.so*",
"libgio-2.0.so*",
"libgobject-2.0.so*",
"libgmodule-2.0.so*",
"libgthread-2.0.so*",
# Once the system libgio loads, it needs its own (newer) transitive deps —
# util-linux (MOUNT_2_40+), selinux, pcre2. Bundled copies from the CI
# runner lack newer symbols, so fall through to system for these too.
"libmount.so*",
"libblkid.so*",
"libuuid.so*",
"libselinux.so*",
"libpcre2-8.so*",
# libsystemd from the CI runner ships with newer ABI symbols than older user
# systemds expose — bundling .so.0 statically (rather than letting the
# dynamic loader resolve to the system copy) breaks on those distros.
"libsystemd.so*",
# prismatoid's auditwheel-hashed copies of the same libs, which PyInstaller
# also propagates up to _internal/. Without removing these, libprism's RPATH
# finds its own libgio and GLib ends up registered twice. Safe to drop once
# libprism has been patchelf'd to use the bare libgio soname.
"libgio-2-*.so*",
"libgmodule-2-*.so*",
"libmount-*.so*",
"libblkid-*.so*",
"libselinux-*.so*",
"libpcre2-8-*.so*",
"libsystemd-*.so*",
)
def _strip_bundled_system_libs(internal_dir: Path):
"""Remove audio libs that should resolve from the user's system, not the bundle."""
if not internal_dir.exists():
return
for pattern in _LINUX_SYSTEM_LIB_PATTERNS:
for path in internal_dir.glob(pattern):
print(f"Removing bundled system lib: {path.name}")
path.unlink()
_HASHED_LIBGIO_RE = re.compile(r"^libgio-2-[0-9a-f]+\.0\.so\.0\..+$")
def _patch_prism_libgio(internal_dir: Path):
"""Rewrite libprism's NEEDED libgio from prismatoid's auditwheel-hashed
soname back to the bare ``libgio-2.0.so.0``.
Prism ships libprism linked against its own hashed libgio copy (e.g.
``libgio-2-867cbb79.0.so.0.6800.4``) while wxPython/GTK loads the system
libgio-2.0.so.0. Having both in one process makes GLib try to register
GSeekable/GPollableInputStream twice, which aborts initialization. Forcing
libprism onto the bare soname means one libgio serves the whole app.
"""
libprism = internal_dir / "prism" / "_native" / "libprism.so"
if not libprism.exists():
return
try:
needed = subprocess.run(
["patchelf", "--print-needed", str(libprism)],
capture_output=True, text=True, check=True,
).stdout.splitlines()
except (FileNotFoundError, subprocess.CalledProcessError) as e:
print(f"Warning: could not inspect libprism.so ({e}); skipping libgio rewrite")
return
for entry in (line.strip() for line in needed):
if _HASHED_LIBGIO_RE.match(entry):
subprocess.run(
["patchelf", "--replace-needed", entry, "libgio-2.0.so.0", str(libprism)],
check=True,
)
print(f"Patched libprism.so: NEEDED {entry} -> libgio-2.0.so.0")
return
def create_linux_tarball(output_dir: Path, app_dir: Path) -> Path:
"""Create a .tar.gz of the Linux build for distribution."""
import tarfile
tar_name = f"{APP_NAME}-Linux-Portable.tar.gz"
tar_path = output_dir / tar_name
if tar_path.exists():
tar_path.unlink()
print(f"Creating tarball: {tar_name}...")
with tarfile.open(tar_path, 'w:gz') as tar:
tar.add(app_dir, arcname=APP_NAME)
size_mb = tar_path.stat().st_size / (1024 * 1024)
print(f"Tarball created: {tar_path}")
print(f"Tarball size: {size_mb:.1f} MB")
return tar_path
def build_macos(script_dir: Path, output_dir: Path) -> tuple:
"""Build for macOS using PyInstaller.
Returns:
Tuple of (success: bool, artifact_path: Path or None)
"""
import plistlib
dist_dir = output_dir / "dist"
build_dir = output_dir / "build"
# Clean previous build
for d in [dist_dir, build_dir]:
if d.exists():
print(f"Cleaning {d}...")
shutil.rmtree(d)
output_dir.mkdir(parents=True, exist_ok=True)
# Create build_info.txt BEFORE building command so get_data_files can include it
create_build_info_file(script_dir)
# Bundle identifier
bundle_id = f"me.masonasons.{APP_NAME.lower()}"
main_script = script_dir / "FastSM.pyw"
cmd = [
sys.executable, "-m", "PyInstaller",
"--name", APP_NAME,
"--windowed", # Create .app bundle
"--noconfirm",
f"--distpath={dist_dir}",
f"--workpath={build_dir}",
f"--specpath={output_dir}",
f"--osx-bundle-identifier={bundle_id}",
f"--additional-hooks-dir={script_dir / 'hooks'}", # Custom hooks (e.g., sound_lib fix)
]
# Add hidden imports
for imp in get_hidden_imports():
cmd.extend(["--hidden-import", imp])
# Add data files
for src, dst in get_data_files(script_dir):
cmd.extend(["--add-data", f"{src}{os.pathsep}{dst}"])
# Note: sound_lib binaries are handled by hooks/hook-sound_lib.py
# which excludes incompatible x86 (i386/ppc) binaries on macOS
# Runtime hook to fix platform_utils.paths.embedded_data_path() for PyInstaller
rthook = script_dir / "hooks" / "rthook-platform_utils.py"
if rthook.exists():
cmd.extend(["--runtime-hook", str(rthook)])
# Collect keyboard_handler and the speech backend
cmd.extend(["--collect-all", "keyboard_handler"])
cmd.extend(["--collect-all", "prism"])
# Add main script
cmd.append(str(main_script))
print(f"Building {APP_NAME} v{APP_VERSION} for macOS...")
print(f"Output: {output_dir}")
print()
try:
result = subprocess.run(cmd, cwd=script_dir)
finally:
# Clean up build_info.txt from source directory
cleanup_build_info_file(script_dir)
if result.returncode != 0:
return False, None
# The app bundle will be in dist_dir
app_path = dist_dir / f"{APP_NAME}.app"
if not app_path.exists():
print("Error: App bundle not found")
return False, None
# Update Info.plist
plist_path = app_path / "Contents" / "Info.plist"
if plist_path.exists():
print("Updating Info.plist...")
with open(plist_path, 'rb') as f:
plist = plistlib.load(f)
plist.update({
'CFBundleName': APP_NAME,
'CFBundleDisplayName': APP_NAME,
'CFBundleIdentifier': bundle_id,
'CFBundleVersion': APP_VERSION,
'CFBundleShortVersionString': APP_VERSION,
'NSHumanReadableCopyright': APP_COPYRIGHT,
'LSMinimumSystemVersion': '10.13',
'NSHighResolutionCapable': True,
'NSAppleEventsUsageDescription': f'{APP_NAME} needs accessibility access for screen reader support.',
})
with open(plist_path, 'wb') as f:
plistlib.dump(plist, f)
# Copy data files to Resources folder (docs go in DMG, not app)
resources_dir = app_path / "Contents" / "Resources"
resources_dir.mkdir(parents=True, exist_ok=True)
copy_data_files(script_dir, resources_dir, include_docs=False)
# Code sign the app
sign_macos_app(app_path)
# Create DMG
dmg_path = create_macos_dmg(output_dir, app_path, script_dir)
return True, dmg_path
def get_signing_identity():
"""Find a code signing identity."""
try:
result = subprocess.run(
["security", "find-identity", "-v", "-p", "codesigning"],
capture_output=True, text=True
)
if result.returncode == 0:
output = result.stdout
for line in output.split('\n'):
if 'Developer ID Application' in line:
parts = line.split('"')
if len(parts) >= 2:
return parts[1]
for line in output.split('\n'):
if 'Apple Development' in line or 'Mac Developer' in line:
parts = line.split('"')
if len(parts) >= 2:
return parts[1]
return "-" # Ad-hoc signing
except FileNotFoundError:
pass
return "-"
def sign_macos_app(app_path: Path):
"""Sign the macOS app bundle."""
signing_identity = get_signing_identity()
print(f"Signing app with identity: {signing_identity}")
# Clear extended attributes
subprocess.run(["xattr", "-cr", str(app_path)], capture_output=True)
# Collect binaries to sign
binaries = []
for ext in ['*.so', '*.dylib']:
binaries.extend(app_path.rglob(ext))
main_exec = app_path / "Contents" / "MacOS" / APP_NAME
if main_exec.exists():
binaries.append(main_exec)
binaries.sort(key=lambda p: len(p.parts), reverse=True)
print(f"Signing {len(binaries)} binaries...")
# Remove signatures
for binary in binaries:
subprocess.run(["codesign", "--remove-signature", str(binary)], capture_output=True)
# Sign binaries
for binary in binaries:
subprocess.run(["codesign", "--force", "--sign", signing_identity, str(binary)], capture_output=True)
# Sign app bundle
result = subprocess.run(
["codesign", "--force", "--sign", signing_identity, str(app_path)],
capture_output=True, text=True
)
if result.returncode == 0:
print("Code signing successful!")
else:
print(f"Code signing warning: {result.stderr}")
def create_macos_dmg(output_dir: Path, app_path: Path, script_dir: Path) -> Path:
"""Create a DMG disk image for macOS distribution."""
dmg_name = f"{APP_NAME}-{APP_VERSION}.dmg"
dmg_path = output_dir / dmg_name
if dmg_path.exists():
dmg_path.unlink()
print(f"Creating DMG: {dmg_name}...")
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = Path(temp_dir)
# Copy app
temp_app = temp_path / app_path.name
shutil.copytree(app_path, temp_app, symlinks=True)
# Copy docs
docs_src = script_dir / "docs"
if docs_src.exists():
shutil.copytree(docs_src, temp_path / "Documentation", dirs_exist_ok=True)
# Create Applications symlink
try:
(temp_path / "Applications").symlink_to("/Applications")
except OSError:
pass
# Create DMG
result = subprocess.run([
"hdiutil", "create",
"-volname", APP_NAME,
"-srcfolder", str(temp_path),
"-ov",
"-format", "UDZO",
"-imagekey", "zlib-level=9",
str(dmg_path)
], capture_output=True, text=True)
if result.returncode == 0:
dmg_size_mb = dmg_path.stat().st_size / (1024 * 1024)
print(f"DMG created: {dmg_path}")
print(f"DMG size: {dmg_size_mb:.1f} MB")
else:
print(f"DMG creation failed: {result.stderr}")
return None
# Sign DMG
signing_identity = get_signing_identity()
if signing_identity and signing_identity != "-":
subprocess.run([
"codesign", "--force", "--sign", signing_identity,
"--timestamp", str(dmg_path)
], capture_output=True)
return dmg_path
def main():
"""Build FastSM executable using PyInstaller."""
script_dir = Path(__file__).parent.resolve()
platform = get_platform()
print(f"Detected platform: {platform}")
output_dir = Path.home() / "app_dist" / APP_NAME
print(f"Building {APP_NAME} v{APP_VERSION} with PyInstaller...")
print(f"Output: {output_dir}")
print()
if platform == "windows":
success, artifact_path = build_windows(script_dir, output_dir)
elif platform == "macos":
success, artifact_path = build_macos(script_dir, output_dir)
elif platform == "linux":
success, artifact_path = build_linux(script_dir, output_dir)
else:
print(f"Unsupported platform: {platform}")
sys.exit(1)
if success:
print()
print("=" * 50)
print("Build completed successfully!")
print(f"Output: {output_dir}")
if artifact_path and artifact_path.exists():
dest_path = script_dir / artifact_path.name
print(f"Copying to source folder: {dest_path}")
shutil.copy2(artifact_path, dest_path)
print(f"Artifact: {dest_path}")
print("=" * 50)
else:
print()
print("=" * 50)
print("Build failed!")
print("=" * 50)
sys.exit(1)
if __name__ == "__main__":
main()