Skip to content

Commit

Permalink
Debug system calls on osx (#715)
Browse files Browse the repository at this point in the history
* Debug system calls on osx

* Fix missing function rename

* Rename function more explicitly

* Move helper function to utils

* Update missing check_calls

* Use % formatting
  • Loading branch information
m-kuhn authored Sep 4, 2023
1 parent 3d38fd4 commit 8e65a5d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
25 changes: 16 additions & 9 deletions constructor/osxpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@
from os.path import abspath, dirname, exists, isdir, join
from pathlib import Path
from plistlib import dump as plist_dump
from subprocess import check_call
from tempfile import NamedTemporaryFile

from . import preconda
from .conda_interface import conda_context
from .construct import ns_platform, parse
from .imaging import write_images
from .utils import add_condarc, approx_size_kb, fill_template, get_final_channels, preprocess, rm_rf
from .utils import (
add_condarc,
approx_size_kb,
explained_check_call,
fill_template,
get_final_channels,
preprocess,
rm_rf,
)

OSX_DIR = join(dirname(__file__), "osx")
CACHE_DIR = PACKAGE_ROOT = PACKAGES_DIR = SCRIPTS_DIR = None
Expand Down Expand Up @@ -342,7 +349,7 @@ def pkgbuild(name, identifier=None, version=None, install_location=None):
args += ["--install-location", install_location]
output = os.path.join(PACKAGES_DIR, f"{name}.pkg")
args += [output]
check_call(args)
explained_check_call(args)
return output


Expand All @@ -362,15 +369,15 @@ def pkgbuild_prepare_installation(info):
# set to the sum of the compressed tarballs, which is not representative
try:
# expand to apply patches
check_call(["pkgutil", "--expand", pkg, f"{pkg}.expanded"])
explained_check_call(["pkgutil", "--expand", pkg, f"{pkg}.expanded"])
payload_xml = os.path.join(f"{pkg}.expanded", "PackageInfo")
tree = ET.parse(payload_xml)
root = tree.getroot()
payload = root.find("payload")
payload.set("installKBytes", str(approx_pkgs_size_kb))
tree.write(payload_xml)
# repack
check_call(["pkgutil", "--flatten", f"{pkg}.expanded", pkg])
explained_check_call(["pkgutil", "--flatten", f"{pkg}.expanded", pkg])
return pkg
finally:
shutil.rmtree(f"{pkg}.expanded")
Expand Down Expand Up @@ -463,7 +470,7 @@ def create(info, verbose=False):
"com.apple.security.cs.allow-dyld-environment-variables": True,
}
plist_dump(plist, f)
check_call(
explained_check_call(
[
# hardcode to system location to avoid accidental clobber in PATH
"/usr/bin/codesign",
Expand Down Expand Up @@ -524,19 +531,19 @@ def create(info, verbose=False):
for name in names:
args.extend(['--package', join(PACKAGES_DIR, "%s.pkg" % name)])
args.append(xml_path)
check_call(args)
explained_check_call(args)
modify_xml(xml_path, info)

identity_name = info.get('signing_identity_name')
check_call([
explained_check_call([
"/usr/bin/productbuild",
"--distribution", xml_path,
"--package-path", PACKAGES_DIR,
"--identifier", info.get("reverse_domain_identifier", info['name']),
"tmp.pkg" if identity_name else info['_outpath']
])
if identity_name:
check_call([
explained_check_call([
# hardcode to system location to avoid accidental clobber in PATH
'/usr/bin/productsign', '--sign', identity_name,
"tmp.pkg",
Expand Down
9 changes: 9 additions & 0 deletions constructor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@
from os import sep, unlink
from os.path import basename, isdir, isfile, islink, normpath
from shutil import rmtree
from subprocess import check_call

from ruamel import yaml

logger = logging.getLogger(__name__)


def explained_check_call(args):
"""
Execute a system process and debug the invocation
"""
logger.debug("Executing: %s", " ".join(args))
return check_call(args)


def filename_dist(dist):
""" Return the filename of a distribution. """
if hasattr(dist, 'to_filename'):
Expand Down

0 comments on commit 8e65a5d

Please sign in to comment.