17
17
#
18
18
19
19
import plistlib
20
- import subprocess , sys , re , os , shutil , stat , os .path
20
+ import sys , re , os , shutil , stat , os .path
21
21
from argparse import ArgumentParser
22
22
from ds_store import DSStore
23
23
from mac_alias import Alias
24
24
from pathlib import Path
25
+ from subprocess import PIPE , run
25
26
from typing import List , Optional
26
27
27
28
# This is ported from the original macdeployqt with modifications
@@ -199,14 +200,13 @@ def getFrameworks(binaryPath: str, verbose: int) -> List[FrameworkInfo]:
199
200
if verbose :
200
201
print ("Inspecting with otool: " + binaryPath )
201
202
otoolbin = os .getenv ("OTOOL" , "otool" )
202
- otool = subprocess .Popen ([otoolbin , "-L" , binaryPath ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , universal_newlines = True )
203
- o_stdout , o_stderr = otool .communicate ()
203
+ otool = run ([otoolbin , "-L" , binaryPath ], stdout = PIPE , stderr = PIPE , universal_newlines = True )
204
204
if otool .returncode != 0 :
205
- sys .stderr .write (o_stderr )
205
+ sys .stderr .write (otool . stderr )
206
206
sys .stderr .flush ()
207
207
raise RuntimeError ("otool failed with return code {}" .format (otool .returncode ))
208
208
209
- otoolLines = o_stdout .split ("\n " )
209
+ otoolLines = otool . stdout .split ("\n " )
210
210
otoolLines .pop (0 ) # First line is the inspected binary
211
211
if ".framework" in binaryPath or binaryPath .endswith (".dylib" ):
212
212
otoolLines .pop (0 ) # Frameworks and dylibs list themselves as a dependency.
@@ -225,7 +225,7 @@ def getFrameworks(binaryPath: str, verbose: int) -> List[FrameworkInfo]:
225
225
226
226
def runInstallNameTool (action : str , * args ):
227
227
installnametoolbin = os .getenv ("INSTALLNAMETOOL" , "install_name_tool" )
228
- subprocess . check_call ([installnametoolbin , "-" + action ] + list (args ))
228
+ run ([installnametoolbin , "-" + action ] + list (args ), check = True )
229
229
230
230
def changeInstallName (oldName : str , newName : str , binaryPath : str , verbose : int ):
231
231
if verbose :
@@ -247,7 +247,7 @@ def runStrip(binaryPath: str, verbose: int):
247
247
if verbose :
248
248
print ("Using strip:" )
249
249
print (" stripped" , binaryPath )
250
- subprocess . check_call ([stripbin , "-x" , binaryPath ])
250
+ run ([stripbin , "-x" , binaryPath ], check = True )
251
251
252
252
def copyFramework (framework : FrameworkInfo , path : str , verbose : int ) -> Optional [str ]:
253
253
if framework .sourceFilePath .startswith ("Qt" ):
@@ -658,23 +658,6 @@ ds.close()
658
658
659
659
if config .dmg is not None :
660
660
661
- def runHDIUtil (verb : str , image_basename : str , ** kwargs ) -> int :
662
- hdiutil_args = ["hdiutil" , verb , image_basename + ".dmg" ]
663
- if "capture_stdout" in kwargs :
664
- del kwargs ["capture_stdout" ]
665
- run = subprocess .check_output
666
- else :
667
- if verbose :
668
- hdiutil_args .append ("-verbose" )
669
- run = subprocess .check_call
670
-
671
- for key , value in kwargs .items ():
672
- hdiutil_args .append ("-" + key )
673
- if value is not True :
674
- hdiutil_args .append (str (value ))
675
-
676
- return run (hdiutil_args , universal_newlines = True )
677
-
678
661
print ("+ Preparing .dmg disk image +" )
679
662
680
663
if verbose :
@@ -687,17 +670,14 @@ if config.dmg is not None:
687
670
688
671
if verbose :
689
672
print ("Creating temp image for modification..." )
690
- try :
691
- runHDIUtil ( "create" , appname + ".temp" , srcfolder = "dist" , format = "UDRW" , size = size , volname = appname , ov = True )
692
- except subprocess . CalledProcessError as e :
693
- sys . exit ( e . returncode )
673
+
674
+ tempname = appname + ".temp.dmg"
675
+
676
+ run ([ "hdiutil" , "create" , tempname , "-srcfolder" , "dist" , "-format" , "UDRW" , "-size" , str ( size ), "-volname" , appname ], check = True , universal_newlines = True )
694
677
695
678
if verbose :
696
679
print ("Attaching temp image..." )
697
- try :
698
- output = runHDIUtil ("attach" , appname + ".temp" , readwrite = True , noverify = True , noautoopen = True , capture_stdout = True )
699
- except subprocess .CalledProcessError as e :
700
- sys .exit (e .returncode )
680
+ output = run (["hdiutil" , "attach" , tempname , "-readwrite" ], check = True , universal_newlines = True , stdout = PIPE ).stdout
701
681
702
682
m = re .search (r"/Volumes/(.+$)" , output )
703
683
disk_root = m .group (0 )
@@ -714,15 +694,11 @@ if config.dmg is not None:
714
694
715
695
print ("+ Finalizing .dmg disk image +" )
716
696
717
- subprocess . run (["hdiutil" , "detach" , "/Volumes/{}" .format (appname )], universal_newlines = True )
697
+ run (["hdiutil" , "detach" , "/Volumes/{}" .format (appname )], universal_newlines = True )
718
698
719
- try :
720
- runHDIUtil ("convert" , appname + ".temp" , format = "UDBZ" , o = appname + ".dmg" , ov = True )
721
- except subprocess .CalledProcessError as e :
722
- print (e )
723
- sys .exit (e .returncode )
699
+ run (["hdiutil" , "convert" , tempname , "-format" , "UDZO" , "-o" , appname , "-imagekey" , "zlib-level=9" ], check = True , universal_newlines = True )
724
700
725
- os .unlink (appname + ".temp.dmg" )
701
+ os .unlink (tempname )
726
702
727
703
# ------------------------------------------------
728
704
0 commit comments