Andrew Grieve | 1f1f380 | 2022-08-25 20:52:46 | [diff] [blame] | 1 | #!/bin/bash |
Avi Drissman | 3f1ea44 | 2022-09-08 15:42:01 | [diff] [blame] | 2 | # Copyright 2022 The Chromium Authors |
Andrew Grieve | 1f1f380 | 2022-08-25 20:52:46 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | ####################################################################### |
| 7 | # See go/clank-autoroll#androidx-bisect for instructions. |
| 8 | ####################################################################### |
| 9 | |
| 10 | function abort() { |
| 11 | echo "$1" >&2 |
| 12 | # 255 will abort the bisect. 125 marks commit as "unknown". |
| 13 | exit ${2-255} |
| 14 | } |
| 15 | |
| 16 | if [[ -z "$PERF_BENCHMARK" || -z "$PERF_BOT" || -z "$PERF_STORY" || -z "$PERF_METRIC" ]]; then |
| 17 | abort 'Example Usage: |
| 18 | PERF_BENCHMARK="startup.mobile" \ |
| 19 | PERF_BOT="android-pixel4-perf" \ |
| 20 | PERF_STORY="cct_coldish_bbc" \ |
Andrew Grieve | 7fed47f | 2022-08-29 16:07:34 | [diff] [blame] | 21 | PERF_METRIC="messageloop_start_time" $0 "$@" |
Andrew Grieve | 1f1f380 | 2022-08-25 20:52:46 | [diff] [blame] | 22 | fi |
| 23 | |
| 24 | # Determine Chromium src path based on script location. |
| 25 | CHROMIUM_SRC="$(dirname $0)/../.." |
| 26 | # Determine Android src path based on current directory (git bisect must be run from it). |
| 27 | # Allow running from superproject root, or from within frameworks/support. |
| 28 | if [[ -d frameworks/support ]]; then |
| 29 | SUPERPROJECT_DIR="$(pwd)" |
| 30 | elif [[ -d ../../frameworks/support ]]; then |
| 31 | SUPERPROJECT_DIR="$(pwd)/../.." |
| 32 | else |
| 33 | abort "Expected to have been run from androidx checkout." |
| 34 | fi |
| 35 | FRAMEWORKS_SUPPORT_DIR="$SUPERPROJECT_DIR/frameworks/support" |
| 36 | |
| 37 | set -x |
| 38 | set -o pipefail |
| 39 | |
| 40 | cd "$CHROMIUM_SRC" |
| 41 | # Sanity checks: |
| 42 | pinpoint auth-info >/dev/null || abort "First run: pinpoint auth-login" |
| 43 | cipd auth-info >/dev/null || abort "First run: cipd auth-login" |
| 44 | # Needed for androidx sync. |
| 45 | gcertstatus -check_ssh=false || abort "First run: gcert" |
| 46 | |
| 47 | # Allow //third_party/androidx/cipd.yaml to be listed. |
| 48 | local changes=$(git status --porcelain | grep -v cipd.yaml) |
| 49 | [[ -n "$changes" ]] && abort "git status reports changes present." |
| 50 | |
| 51 | # Ensure we're on a non-main branch. |
| 52 | git_branch=$(git rev-parse --abbrev-ref HEAD) |
| 53 | [[ "$git_branch" = HEAD ]] && abort "Need to be on a branch" |
| 54 | [[ "$git_branch" = main ]] && abort "Need to be on a non-main branch" |
| 55 | |
| 56 | # Use the most recent non-local commit as the diffbase. |
| 57 | git_base_rev=$(git merge-base origin/main HEAD) |
| 58 | |
| 59 | cd "$SUPERPROJECT_DIR" |
| 60 | git submodule update --recursive --init || abort "AndroidX sync Failed" |
| 61 | cd "$FRAMEWORKS_SUPPORT_DIR" |
| 62 | # Creates a local maven repo in: out/dist/repository. Aborts bisect upon failure. |
| 63 | |
| 64 | SNAPSHOT=true ./gradlew createArchive || abort "AndroidX Build Failed" 125 |
| 65 | cd $CHROMIUM_SRC |
| 66 | third_party/androidx/fetch_all_androidx.py \ |
| 67 | --local-repo "$SUPERPROJECT_DIR/out/dist/repository" || abort "fetch_all_androidx.py failure" |
| 68 | |
| 69 | super_rev=$(git -C "$SUPERPROJECT_DIR" rev-parse HEAD) |
| 70 | support_rev=$(git -C "$FRAMEWORKS_SUPPORT_DIR" rev-parse HEAD) |
| 71 | cipd_output=$(cipd create -pkg-def third_party/androidx/cipd.yaml \ |
| 72 | -tag super_rev:$super_rev \ |
| 73 | -tag support_rev:$support_rev | grep Instance:) || abort "cipd failure" |
| 74 | # E.g.: Instance: experimental/google.com/agrieve/androidx:3iiAIwUqY5nB5O9ArpioN... |
| 75 | cipd_output=${cipd_output#*Instance: } |
| 76 | cipd_package=${cipd_output%:*} # Strip after colon. |
| 77 | cipd_package_escaped=${cipd_package//\//\\/} |
| 78 | cipd_instance=${cipd_output#*:} # Strip before colon. |
| 79 | # This needs to be run only once per package, but it's simpler to run it every time. |
| 80 | cipd acl-edit "$cipd_package" -reader group:all || abort "cipd acl failure" |
| 81 | # gclient setdep does not allow changing CIPD package, so perl it is. |
| 82 | perl -0777 -i -pe "s/(.*src\/third_party\/androidx.*?packages.*?package': ')(.*?)('.*?version': ')(.*?)('.*)/\${1}${cipd_package_escaped}\${3}${cipd_instance}\$5/s" DEPS |
| 83 | |
| 84 | git add DEPS || abort "git add failed" |
| 85 | git commit -m "androidx bisect super_rev=${super_rev::9} support_rev=${support_rev::9}" |
| 86 | EDITOR=true git cl upload --bypass-hooks --bypass-watchlists --no-autocc --message "androidx bisect review" \ |
| 87 | --title "super_rev=${super_rev::9} support_rev=${support_rev::9}" || abort "Upload CL failed" |
| 88 | review_number=$(git cl issue | grep -P --only-matching '(?<=Issue number: )(\d+)') || abort "parsing issue failed" |
| 89 | |
| 90 | review_url="https://chromium-review.googlesource.com/c/chromium/src/+/$review_number" |
| 91 | # Returns non-zero if metric changed or if command fails. |
| 92 | pinpoint_job=$(pinpoint experiment-telemetry-start \ |
| 93 | -base-commit $git_base_rev -exp-commit $git_base_rev \ |
| 94 | -benchmark $PERF_BENCHMARK -cfg $PERF_BOT \ |
| 95 | -story $PERF_STORY -measurement $PERF_METRIC \ |
| 96 | -check-experiment -wait -quiet \ |
| 97 | -exp-patch-url "$review_url" \ |
| 98 | | tee /dev/stderr \ |
| 99 | | grep -P --only-matching '(?<=/job/)\S+') |
| 100 | # E.g.: Pinpoint job scheduled: https://pinpoint-dot-chromeperf.appspot.com/job/13af94f2ea0000 |
| 101 | retcode=$? |
| 102 | |
| 103 | if [[ -z "$pinpoint_job" ]]; then |
| 104 | abort "Failed to parse pinpoint job" |
| 105 | fi |
| 106 | # E.g.: state: SUCCEEDED |
| 107 | if ! pinpoint get-job -name $pinpoint_job | grep -q "state.*SUCCEEDED"; then |
| 108 | abort "Pinpoint did not finish successfully." |
| 109 | fi |
| 110 | |
| 111 | # Expect a significant difference for good changes. |
| 112 | if [[ $retcode = 0 ]]; then |
| 113 | exit 1 |
| 114 | fi |
| 115 | exit 0 |