From 8d3ab2eeb6e382286a8a784b797461ece2561f55 Mon Sep 17 00:00:00 2001 From: Stephanie Kim Date: Thu, 25 Apr 2024 20:04:21 +0000 Subject: [PATCH] [depot_tools] Update clang_format.py with new path Look for both new and old paths when checking the buildtools/ dir. Currently, there's different binaries for mac x64 and mac arm64. Depending on the host cpu, only one is downloaded to buildtools/mac, meaning that there is an overlap in buildtools/mac. When we migrate to clang-format, buildtools/mac will be for mac x64 and buildtools/mac_arm64 will be for mac arm64. - Verified locally on my macbook that the mac_arm64 path correctly gets chosen. Migration CL: https://chromium-review.googlesource.com/c/chromium/src/+/5484590 Bug: b/336843583, Change-Id: I26f80dff0e39b7ae31ed5d0a1d8e436eb19fbb3d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5484138 Reviewed-by: Joanna Wang Commit-Queue: Stephanie Kim --- clang_format.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/clang_format.py b/clang_format.py index c32995e424..b72b978d07 100755 --- a/clang_format.py +++ b/clang_format.py @@ -8,6 +8,7 @@ clang-format binaries are pulled down from Google Cloud Storage whenever you sync Chrome, to platform-specific locations. This script knows how to locate those tools, assuming the script is invoked from inside a Chromium checkout.""" +import detect_host_arch import gclient_paths import os import subprocess @@ -40,11 +41,23 @@ def FindClangFormatToolInChromiumTree(): 'Set CHROMIUM_BUILDTOOLS_PATH to use outside of a chromium ' 'checkout.') - tool_path = os.path.join(bin_path, - 'clang-format' + gclient_paths.GetExeSuffix()) - if not os.path.exists(tool_path): - raise NotFoundError('File does not exist: %s' % tool_path) - return tool_path + # TODO(b/336843583): Remove old_tool_path when migrated over + old_tool_path = os.path.join(bin_path, + 'clang-format' + gclient_paths.GetExeSuffix()) + + new_bin_path = bin_path + arch = detect_host_arch.HostArch() + if sys.platform == 'darwin' and arch == 'arm64': + new_bin_path += '_arm64' + new_tool_path = os.path.join(new_bin_path, 'format', + 'clang-format' + gclient_paths.GetExeSuffix()) + + possible_paths = [new_tool_path, old_tool_path] + for path in possible_paths: + if os.path.exists(path): + return path + raise NotFoundError('File does not exist in either path: %s' % + possible_paths) def FindClangFormatScriptInChromiumTree(script_name):