From 9e0ccb13bd6e5e2f2a2bc1a1973430f0f750b4c7 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Wed, 23 Sep 2026 03:33:06 +0000 Subject: [PATCH] Tolerate expanded-component pkg layout on newer macOS pkgutil --expand may yield the component as an already-expanded directory rather than an archived file; handle both. List the expanded contents in the error message if the layout is unexpected. --- scripts/guibuild.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/guibuild.py b/scripts/guibuild.py index e0ac014..1474220 100755 --- a/scripts/guibuild.py +++ b/scripts/guibuild.py @@ -446,20 +446,27 @@ def force_macos_user_install(pkg: Path) -> None: raise RuntimeError("Unexpected distribution.xml: not found") dist_xml.write_text(new_xml) - # Edit postinstall inside the (still archived) component pkg. - components = [p for p in expanded.glob("*.pkg") if p.is_file()] + # Edit postinstall inside the component pkg. Depending on the macOS + # version, --expand leaves the component as an archived file (needs a + # nested expand/flatten round) or as an already-expanded directory. + components = list(expanded.glob("*.pkg")) if len(components) != 1: - raise RuntimeError(f"Unexpected pkg layout: components={components}") + contents = sorted(p.name for p in expanded.iterdir()) + raise RuntimeError(f"Unexpected pkg layout: components={components} in {contents}") component = components[0] - comp_dir = expanded / (component.stem + "-component") - subprocess.run(["pkgutil", "--expand", str(component), str(comp_dir)], check=True) + if component.is_dir(): + comp_dir = component + else: + comp_dir = expanded / (component.stem + "-component") + subprocess.run(["pkgutil", "--expand", str(component), str(comp_dir)], check=True) postinstall = comp_dir / "Scripts" / "postinstall" script = postinstall.read_text() if 'sudo -u "$USER" ' not in script: raise RuntimeError("Unexpected postinstall script: sudo prefix not found") postinstall.write_text(script.replace('sudo -u "$USER" ', "")) - subprocess.run(["pkgutil", "--flatten", str(comp_dir), str(component)], check=True) - shutil.rmtree(comp_dir) + if comp_dir is not component: + subprocess.run(["pkgutil", "--flatten", str(comp_dir), str(component)], check=True) + shutil.rmtree(comp_dir) subprocess.run(["pkgutil", "--flatten", str(expanded), str(pkg)], check=True) shutil.rmtree(expanded)