nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 1 | # Updating Clang format binaries |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 3 | Instructions on how to update the [clang-format binaries](clang_format.md) that |
| 4 | come with a checkout of Chromium. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 5 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 6 | ## Prerequisites |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 7 | |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 8 | You'll also need permissions to upload to the appropriate google storage |
| 9 | bucket. Chromium infrastructure team members have this, and others can be |
| 10 | granted the permission based on need. If you need this permission, mention this |
| 11 | in the tracking bug. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 12 | |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 13 | ## Fetch and upload prebuilt clang-format binaries from recent clang rolls |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 14 | |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 15 | Recent clang rolls can be found via looking at the history of |
| 16 | [update.py](https://crsrc.org/c/tools/clang/scripts/update.py). You can also |
| 17 | use clang-format packages built in recent successful dry run attempts at |
| 18 | updating clang as mentioned [here](clang_sheriffing.md). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 19 | |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 20 | The following will, for each supported host architecture, |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 21 | |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 22 | * Fetch the corresponding clang-format package from the specified clang roll |
| 23 | * Extract and copy the clang-format binary to the proper directory |
| 24 | * Upload the binary into a publicly accessible google storage bucket, also |
Stephanie Kim | 29ae3165 | 2024-05-09 17:57:39 | [diff] [blame] | 25 | updating the deps entries in DEPS files in the local checkout of Chrome |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 26 | |
| 27 | ```shell |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 28 | cd $SRC/chromium/src |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 29 | |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 30 | GS_PATH=gs://chromium-browser-clang-staging |
| 31 | CLANG_REV=llvmorg-15-init-234-g567890abc-2 |
| 32 | |
| 33 | echo Linux |
Alan Zhao | c98914a | 2025-02-04 20:26:16 | [diff] [blame] | 34 | gsutil cp $GS_PATH/Linux_x64/clang-format-$CLANG_REV.tar.xz /tmp |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 35 | tar xf /tmp/clang-format-$CLANG_REV.tgz -C buildtools/linux64 --strip-component=1 bin/clang-format |
| 36 | |
| 37 | echo Win |
Alan Zhao | c98914a | 2025-02-04 20:26:16 | [diff] [blame] | 38 | gsutil cp $GS_PATH/Win/clang-format-$CLANG_REV.tar.xz /tmp |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 39 | tar xf /tmp/clang-format-$CLANG_REV.tgz -C buildtools/win --strip-component=1 bin/clang-format.exe |
| 40 | |
| 41 | echo 'Mac x64' |
Alan Zhao | c98914a | 2025-02-04 20:26:16 | [diff] [blame] | 42 | gsutil cp $GS_PATH/Mac/clang-format-$CLANG_REV.tar.xz /tmp |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 43 | tar xf /tmp/clang-format-$CLANG_REV.tgz -C buildtools/mac --strip-component=1 bin/clang-format |
| 44 | mv buildtools/mac/clang-format buildtools/mac/clang-format.x64 |
| 45 | |
| 46 | echo 'Mac arm64' |
| 47 | gsutil cp $GS_PATH/Mac_arm64/clang-format-$CLANG_REV.tgz /tmp |
| 48 | tar xf /tmp/clang-format-$CLANG_REV.tgz -C buildtools/mac --strip-component=1 bin/clang-format |
| 49 | mv buildtools/mac/clang-format buildtools/mac/clang-format.arm64 |
| 50 | |
Stephanie Kim | 29ae3165 | 2024-05-09 17:57:39 | [diff] [blame] | 51 | # TODO(crbug.com/339490714): Remove sha1 file creation once all downstream repos that |
| 52 | # use clang-format are migrated over to recursedeps into buildtools. |
| 53 | echo '(Legacy) Uploading to GCS and creating sha1 files' |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 54 | upload_to_google_storage.py --bucket=chromium-clang-format buildtools/linux64/clang-format |
| 55 | upload_to_google_storage.py --bucket=chromium-clang-format buildtools/win/clang-format.exe |
| 56 | upload_to_google_storage.py --bucket=chromium-clang-format buildtools/mac/clang-format.x64 |
| 57 | upload_to_google_storage.py --bucket=chromium-clang-format buildtools/mac/clang-format.arm64 |
| 58 | |
Stephanie Kim | 29ae3165 | 2024-05-09 17:57:39 | [diff] [blame] | 59 | echo 'Uploading to GCS and updating DEPS files' |
| 60 | # helper function to set deps entries in DEPS file using `gclient setdep` |
| 61 | # first argument relative DEPS path. |
| 62 | # second argument object_info |
| 63 | function set_deps { |
| 64 | gclient setdep -r src/buildtools/$1@$2 |
| 65 | gclient setdep -r $1@$2 --deps-file=buildtools/DEPS |
| 66 | } |
| 67 | # helper function to upload content to GCS and set DEPS |
| 68 | # first argument: google storage path |
| 69 | # second argument: relative DEPS path |
| 70 | # This function parses out the object info outputted by upload_to_google_storage_first_class.py |
| 71 | # and formats it into a format that gclient setdep understands |
| 72 | function upload_and_set { |
| 73 | object_info=$(upload_to_google_storage_first_class.py --bucket=chromium-clang-format $1 | jq -r .path.objects[0][] | sed -z 's/\n/,/g;s/,$/\n/')',clang-format' |
| 74 | if [[ $2 == 'win/format' ]]; then |
| 75 | object_info+='.exe' |
| 76 | fi; |
| 77 | set_deps $2 $object_info |
| 78 | } |
| 79 | |
Josip Sokcevic | cc85a77 | 2024-06-04 23:07:34 | [diff] [blame] | 80 | upload_and_set buildtools/linux64/clang-format linux64-format |
| 81 | upload_and_set buildtools/win/clang-format.exe win-format |
| 82 | upload_and_set buildtools/mac/clang-format.x64 mac-format |
| 83 | upload_and_set buildtools/mac/clang-format.arm64 mac_arm64-format |
Stephanie Kim | 29ae3165 | 2024-05-09 17:57:39 | [diff] [blame] | 84 | |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 85 | # Clean up |
| 86 | rm /tmp/clang-format-$CLANG_REV.tgz |
| 87 | # These aren't in .gitignore because these mac per-arch paths only exist when updating clang-format. |
| 88 | # gclient runhooks puts these binaries at buildtools/mac/clang-format. |
| 89 | rm buildtools/mac/clang-format.x64 buildtools/mac/clang-format.arm64 |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 90 | ``` |
| 91 | |
Arthur Eubanks | 3e614375 | 2022-04-19 19:48:28 | [diff] [blame] | 92 | ## Check that the new clang-format works as expected |
| 93 | |
| 94 | Compare the diffs created by running the old and new clang-format versions to |
| 95 | see if the new version does anything unexpected. Running them on some |
| 96 | substantial directory like `third_party/blink` or `base` should be sufficient. |
| 97 | Upload the diffs as two patchsets in a CL for easy inspection of the |
| 98 | clang-format differences by choosing patchset 1 as the base for the gerrit diff. |
| 99 | |
| 100 | ```shell |
| 101 | ## New gerrit CL with results of old clang-format. |
Alan Zhao | c98914a | 2025-02-04 20:26:16 | [diff] [blame] | 102 | |
| 103 | # For mac, use: |
| 104 | # export NPROC=$(sysctl -n hw.logicalcpu) |
| 105 | export NPROC=$(nproc --all) |
| 106 | |
Arthur Eubanks | 3e614375 | 2022-04-19 19:48:28 | [diff] [blame] | 107 | # use old clang-format |
Alan Zhao | c98914a | 2025-02-04 20:26:16 | [diff] [blame] | 108 | find base -name '*.cc' -o -name '*.c' -o -name '*.h' -o -name '*.mm' | xargs -P $NPROC -n1 ./buildtools/linux64-format/clang-format -i |
Arthur Eubanks | 3e614375 | 2022-04-19 19:48:28 | [diff] [blame] | 109 | git commit -a |
Arthur Eubanks | 9e9f060 | 2023-08-21 08:28:29 | [diff] [blame] | 110 | git cl upload --bypass-hooks |
Arthur Eubanks | 3e614375 | 2022-04-19 19:48:28 | [diff] [blame] | 111 | ## New patchset on gerrit CL with results of new clang-format. |
| 112 | # update to new clang-format |
Alan Zhao | c98914a | 2025-02-04 20:26:16 | [diff] [blame] | 113 | find base -name '*.cc' -o -name '*.c' -o -name '*.h' -o -name '*.mm' | xargs -P $NPROC -n1 ./buildtools/linux64/clang-format -i |
Arthur Eubanks | 3e614375 | 2022-04-19 19:48:28 | [diff] [blame] | 114 | git commit -a --amend --no-edit |
Arthur Eubanks | 9e9f060 | 2023-08-21 08:28:29 | [diff] [blame] | 115 | git cl upload --bypass-hooks |
Arthur Eubanks | 3e614375 | 2022-04-19 19:48:28 | [diff] [blame] | 116 | ``` |
| 117 | |
| 118 | If there are any unexpected diffs, file a bug upstream (and fix it if you can :)). |
| 119 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 120 | ## Upload a CL according to the following template |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 121 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 122 | Update clang-format binaries and scripts for all platforms. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 123 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 124 | I followed these instructions: |
John Palmer | 046f987 | 2021-05-24 01:24:56 | [diff] [blame] | 125 | https://chromium.googlesource.com/chromium/src/+/main/docs/updating_clang_format_binaries.md |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 126 | |
Arthur Eubanks | 32c470c | 2022-03-22 00:22:42 | [diff] [blame] | 127 | The binaries were built at clang revision ####### on ##CRREV##. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 128 | |
Arthur Eubanks | 3e614375 | 2022-04-19 19:48:28 | [diff] [blame] | 129 | Diff on base/ from previous revision of clang-format to this version: |
| 130 | https://crrev.com/c/123123123/1..2 |
| 131 | |
| 132 | Bug: ####### |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 133 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 134 | The change should **always** include new `.sha1` files for each platform (we |
| 135 | want to keep these in lockstep), should **never** include `clang-format` |
| 136 | binaries directly. The change should **always** update `README.chromium` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 137 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 138 | clang-format binaries should weigh in at 1.5MB or less. Watch out for size |
| 139 | regressions. |
Stephanie Kim | 29ae3165 | 2024-05-09 17:57:39 | [diff] [blame] | 140 | |
| 141 | ## Clean up downloaded binaries |
| 142 | Delete the binaries that were just extracted. To use the new binaries that were |
| 143 | updated in the DEPS files, run gclient sync. |
| 144 | ```shell |
| 145 | rm buildtools/linux64/clang-format |
| 146 | rm buildtools/win/clang-format.exe |
| 147 | rm buildtools/mac/clang-format.x64 |
| 148 | rm buildtools/mac/clang-format.arm64 |
| 149 | ``` |