From f1511cdb957ec4d0d09a41ef5bfc039a6e190e5c Mon Sep 17 00:00:00 2001 From: Chad Norvell Date: Tue, 15 Mar 2022 20:46:58 -0700 Subject: pw_env_setup: Support M1 Macs via Rosetta If we're running on an M1 (arm64) Mac, pretend to be on an amd64 Mac instead. The environment will run transparently via Rosetta. Bug: b/224408077 Change-Id: I003ee41302e88760ec9528875e0c764b4484bd33 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/88340 Commit-Queue: Chad Norvell Reviewed-by: Rob Mohr --- pw_env_setup/get_pw_env_setup.sh | 5 +++++ pw_env_setup/py/pw_env_setup/cipd_setup/update.py | 8 +++++++- pw_env_setup/py/pw_env_setup/cipd_setup/wrapper.py | 18 ++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) (limited to 'pw_env_setup') diff --git a/pw_env_setup/get_pw_env_setup.sh b/pw_env_setup/get_pw_env_setup.sh index 0317b2e7a..ff74220bd 100755 --- a/pw_env_setup/get_pw_env_setup.sh +++ b/pw_env_setup/get_pw_env_setup.sh @@ -46,6 +46,11 @@ if [ "$ARCH" = "x86_64" ]; then ARCH="amd64" fi +# Support `mac-arm64` through Rosetta until `mac-arm64` binaries are ready +if [[ "$OS" = "mac" ] && [ "$ARCH" = "arm64" ]]; then + ARCH="amd64" +fi + for HASH in $(git --git-dir="$PW_ROOT/.git" --no-pager log --max-count=10 --format=format:%H); do URL="https://storage.googleapis.com/pigweed-envsetup/$OS-$ARCH" URL="$URL/$HASH/pw_env_setup" diff --git a/pw_env_setup/py/pw_env_setup/cipd_setup/update.py b/pw_env_setup/py/pw_env_setup/cipd_setup/update.py index 27acfbee9..eb2b835b1 100755 --- a/pw_env_setup/py/pw_env_setup/cipd_setup/update.py +++ b/pw_env_setup/py/pw_env_setup/cipd_setup/update.py @@ -134,7 +134,13 @@ def platform(): else: arch = platform_module.machine() - return '{}-{}'.format(osname, arch).lower() + platform_arch = '{}-{}'.format(osname, arch).lower() + + # Support `mac-arm64` through Rosetta until `mac-arm64` binaries are ready + if platform_arch == 'mac-arm64': + return 'mac-amd64' + + return platform_arch def all_package_files(env_vars, package_files): diff --git a/pw_env_setup/py/pw_env_setup/cipd_setup/wrapper.py b/pw_env_setup/py/pw_env_setup/cipd_setup/wrapper.py index 466f2911e..6ca7db3c9 100755 --- a/pw_env_setup/py/pw_env_setup/cipd_setup/wrapper.py +++ b/pw_env_setup/py/pw_env_setup/cipd_setup/wrapper.py @@ -133,6 +133,16 @@ def arch_normalized(): raise Exception('unrecognized arch: {}'.format(machine)) +def platform_arch_normalized(): + platform_arch = '{}-{}'.format(platform_normalized(), arch_normalized()) + + # Support `mac-arm64` through Rosetta until `mac-arm64` binaries are ready + if platform_arch == 'mac-arm64': + platform_arch = 'mac-amd64' + + return platform_arch + + def user_agent(): """Generate a user-agent based on the project name and current hash.""" @@ -160,7 +170,7 @@ def actual_hash(path): def expected_hash(): """Pulls expected hash from digests file.""" - expected_plat = '{}-{}'.format(platform_normalized(), arch_normalized()) + expected_plat = platform_arch_normalized() with open(DIGESTS_FILE, 'r') as ins: for line in ins: @@ -223,7 +233,7 @@ brew uninstall python && brew install python print('=' * 70) raise - full_platform = '{}-{}'.format(platform_normalized(), arch_normalized()) + full_platform = platform_arch_normalized() if full_platform not in SUPPORTED_PLATFORMS: raise UnsupportedPlatform(full_platform) @@ -293,8 +303,8 @@ def bootstrap(client, silent=('PW_ENVSETUP_QUIET' in os.environ)): os.makedirs(client_dir) if not silent: - print('Bootstrapping cipd client for {}-{}'.format( - platform_normalized(), arch_normalized())) + print('Bootstrapping cipd client for {}'.format( + platform_arch_normalized())) tmp_path = client + '.tmp' with open(tmp_path, 'wb') as tmp: -- cgit v1.2.3