Updating Clang format binaries

Instructions on how to update the clang-format binaries that come with a checkout of Chromium.

Prerequisites

You'll also need permissions to upload to the appropriate google storage bucket. Chromium infrastructure team members have this, and others can be granted the permission based on need. If you need this permission, mention this in the tracking bug.

Fetch and upload prebuilt clang-format binaries from recent clang rolls

Recent clang rolls can be found via looking at the history of update.py. You can also use clang-format packages built in recent successful dry run attempts at updating clang as mentioned here.

The following will, for each supported host architecture,

  • Fetch the corresponding clang-format package from the specified clang roll
  • Extract and copy the clang-format binary to the proper directory
  • Upload the binary into a publicly accessible google storage bucket, also updating the corresponding .sha1 files in the local checkout of Chrome
cd $SRC/chromium/src

GS_PATH=gs://chromium-browser-clang-staging
CLANG_REV=llvmorg-15-init-234-g567890abc-2

echo Linux
gsutil cp $GS_PATH/Linux_x64/clang-format-$CLANG_REV.tgz /tmp
tar xf /tmp/clang-format-$CLANG_REV.tgz -C buildtools/linux64 --strip-component=1 bin/clang-format

echo Win
gsutil cp $GS_PATH/Win/clang-format-$CLANG_REV.tgz /tmp
tar xf /tmp/clang-format-$CLANG_REV.tgz -C buildtools/win --strip-component=1 bin/clang-format.exe

echo 'Mac x64'
gsutil cp $GS_PATH/Mac/clang-format-$CLANG_REV.tgz /tmp
tar xf /tmp/clang-format-$CLANG_REV.tgz -C buildtools/mac --strip-component=1 bin/clang-format
mv buildtools/mac/clang-format buildtools/mac/clang-format.x64

echo 'Mac arm64'
gsutil cp $GS_PATH/Mac_arm64/clang-format-$CLANG_REV.tgz /tmp
tar xf /tmp/clang-format-$CLANG_REV.tgz -C buildtools/mac --strip-component=1 bin/clang-format
mv buildtools/mac/clang-format buildtools/mac/clang-format.arm64

echo 'Uploading to GCS and creating sha1 files'
upload_to_google_storage.py --bucket=chromium-clang-format buildtools/linux64/clang-format
upload_to_google_storage.py --bucket=chromium-clang-format buildtools/win/clang-format.exe
upload_to_google_storage.py --bucket=chromium-clang-format buildtools/mac/clang-format.x64
upload_to_google_storage.py --bucket=chromium-clang-format buildtools/mac/clang-format.arm64

# Clean up
rm /tmp/clang-format-$CLANG_REV.tgz
# These aren't in .gitignore because these mac per-arch paths only exist when updating clang-format.
# gclient runhooks puts these binaries at buildtools/mac/clang-format.
rm buildtools/mac/clang-format.x64 buildtools/mac/clang-format.arm64

Upload a CL according to the following template

Update clang-format binaries and scripts for all platforms.

I followed these instructions:
https://chromium.googlesource.com/chromium/src/+/main/docs/updating_clang_format_binaries.md

The binaries were built at clang revision ####### on ##CRREV##.

Bug:

The change should always include new .sha1 files for each platform (we want to keep these in lockstep), should never include clang-format binaries directly. The change should always update README.chromium

clang-format binaries should weigh in at 1.5MB or less. Watch out for size regressions.