From 26da2752ac710cc640485a6949f29a747d773cc8 Mon Sep 17 00:00:00 2001 From: Liquid369 Date: Tue, 24 Nov 2026 05:28:04 +0700 Subject: [PATCH] Build: ask brew for the coreutils prefix in gitian-build.py Two PATH prepends and the gsha256sum probe hardcoded /usr/local, which is Homebrew's prefix on Intel only; on Apple Silicon it is /opt/homebrew. With that gnubin directory absent from PATH, the osslsigncode hash check echo ' inputs/osslsigncode-2.0.tar.gz' | sha256sum -c resolves sha256sum to Apple's /sbin build, which takes the checksum list only as a file argument and answers a list on stdin with "usage: sha256sum [-bctwz] [files ...]" and exit 1, so check_call raises before any descriptor runs. Measured both ways on arm64: absent prefix gives the usage error, brew's prefix gives "OK". Asking brew keeps /usr/local when brew is missing, so Intel hosts see no change. The probe moves to shutil.which, which finds gsha256sum under either prefix. The old path test could not match on arm64, so every run added coreutils to the brew install list whether or not it was present. The --build path is the change that ran end to end on an arm64 host for v6.0.0-alpha.0, 1h23m30s, matching another signer on all three OSes. setup_darwin is not reached by --build, so --setup stays unverified. --- contrib/gitian-build.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/contrib/gitian-build.py b/contrib/gitian-build.py index 9cc7247cd0cc..192fe036b9a8 100755 --- a/contrib/gitian-build.py +++ b/contrib/gitian-build.py @@ -6,10 +6,29 @@ import argparse import os +import shutil import subprocess import sys +def coreutils_gnubin(): + """Directory holding GNU coreutils under its unprefixed names. + + Homebrew's prefix is /usr/local on Intel and /opt/homebrew on Apple Silicon, so ask + brew rather than assuming. This has to be ahead of /sbin on PATH: macOS ships its own + sha256sum, and "echo ' ' | sha256sum -c" below needs the checksum list on + stdin, which Apple's build rejects with a usage error. + """ + prefix = '/usr/local' + try: + out = subprocess.check_output(['brew', '--prefix'], universal_newlines=True, encoding='utf8').strip() + if out: + prefix = out + except (OSError, subprocess.CalledProcessError): + pass + return os.path.join(prefix, 'opt', 'coreutils', 'libexec', 'gnubin') + + def setup_linux(): global args, workdir if os.path.isfile('/usr/bin/apt-get'): @@ -89,13 +108,13 @@ def setup_darwin(): programs += ['wget'] if not os.path.isfile('/usr/local/bin/git'): programs += ['git'] - if not os.path.isfile('/usr/local/bin/gsha256sum'): + if shutil.which('gsha256sum') is None: programs += ['coreutils'] if args.docker: print('Experimental setup for macOS host') if len(programs) > 0: subprocess.check_call(['brew', 'install'] + programs) - os.environ['PATH'] = '/usr/local/opt/coreutils/libexec/gnubin' + os.pathsep + os.environ['PATH'] + os.environ['PATH'] = coreutils_gnubin() + os.pathsep + os.environ['PATH'] elif args.kvm or not args.docker: print('KVM and LXC are not supported under macOS at this time.') sys.exit(0) @@ -327,7 +346,7 @@ def main(): sys.exit(0) if args.host_os == 'darwin': - os.environ['PATH'] = '/usr/local/opt/coreutils/libexec/gnubin' + os.pathsep + os.environ['PATH'] + os.environ['PATH'] = coreutils_gnubin() + os.pathsep + os.environ['PATH'] args.linux = 'l' in args.os args.windows = 'w' in args.os