Skip to content

Commit a42aa94

Browse files
committed
macdeploy: remove runHDIUtil in favor of directly calling subprocess.run
1 parent adaa262 commit a42aa94

File tree

1 file changed

+15
-39
lines changed

1 file changed

+15
-39
lines changed

contrib/macdeploy/macdeployqtplus

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
#
1818

1919
import plistlib
20-
import subprocess, sys, re, os, shutil, stat, os.path
20+
import sys, re, os, shutil, stat, os.path
2121
from argparse import ArgumentParser
2222
from ds_store import DSStore
2323
from mac_alias import Alias
2424
from pathlib import Path
25+
from subprocess import PIPE, run
2526
from typing import List, Optional
2627

2728
# This is ported from the original macdeployqt with modifications
@@ -199,14 +200,13 @@ def getFrameworks(binaryPath: str, verbose: int) -> List[FrameworkInfo]:
199200
if verbose:
200201
print("Inspecting with otool: " + binaryPath)
201202
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)
204204
if otool.returncode != 0:
205-
sys.stderr.write(o_stderr)
205+
sys.stderr.write(otool.stderr)
206206
sys.stderr.flush()
207207
raise RuntimeError("otool failed with return code {}".format(otool.returncode))
208208

209-
otoolLines = o_stdout.split("\n")
209+
otoolLines = otool.stdout.split("\n")
210210
otoolLines.pop(0) # First line is the inspected binary
211211
if ".framework" in binaryPath or binaryPath.endswith(".dylib"):
212212
otoolLines.pop(0) # Frameworks and dylibs list themselves as a dependency.
@@ -225,7 +225,7 @@ def getFrameworks(binaryPath: str, verbose: int) -> List[FrameworkInfo]:
225225

226226
def runInstallNameTool(action: str, *args):
227227
installnametoolbin=os.getenv("INSTALLNAMETOOL", "install_name_tool")
228-
subprocess.check_call([installnametoolbin, "-"+action] + list(args))
228+
run([installnametoolbin, "-"+action] + list(args), check=True)
229229

230230
def changeInstallName(oldName: str, newName: str, binaryPath: str, verbose: int):
231231
if verbose:
@@ -247,7 +247,7 @@ def runStrip(binaryPath: str, verbose: int):
247247
if verbose:
248248
print("Using strip:")
249249
print(" stripped", binaryPath)
250-
subprocess.check_call([stripbin, "-x", binaryPath])
250+
run([stripbin, "-x", binaryPath], check=True)
251251

252252
def copyFramework(framework: FrameworkInfo, path: str, verbose: int) -> Optional[str]:
253253
if framework.sourceFilePath.startswith("Qt"):
@@ -658,23 +658,6 @@ ds.close()
658658

659659
if config.dmg is not None:
660660

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-
678661
print("+ Preparing .dmg disk image +")
679662

680663
if verbose:
@@ -687,17 +670,14 @@ if config.dmg is not None:
687670

688671
if verbose:
689672
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)
694677

695678
if verbose:
696679
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
701681

702682
m = re.search(r"/Volumes/(.+$)", output)
703683
disk_root = m.group(0)
@@ -714,15 +694,11 @@ if config.dmg is not None:
714694

715695
print("+ Finalizing .dmg disk image +")
716696

717-
subprocess.run(["hdiutil", "detach", "/Volumes/{}".format(appname)], universal_newlines=True)
697+
run(["hdiutil", "detach", "/Volumes/{}".format(appname)], universal_newlines=True)
718698

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)
724700

725-
os.unlink(appname + ".temp.dmg")
701+
os.unlink(tempname)
726702

727703
# ------------------------------------------------
728704

0 commit comments

Comments
 (0)