| Anton Hansson | 8caea0d | 2021-03-24 14:54:49 +0000 | [diff] [blame] | 1 | #!/bin/bash -e | 
|  | 2 | # This script dumps the git SHAs of all commits inside api tracking directories. | 
|  | 3 | # It can used by tools wanting to track API changes, and the primary original | 
|  | 4 | # purpose is to verify verify all API change SHAs have been tracked by the | 
|  | 5 | # server-side API-council tools. | 
|  | 6 | # | 
|  | 7 | # The only argument is used to specify a git commit range to filter by. | 
|  | 8 | # | 
|  | 9 | # Example invocation (API changes between O and P): | 
|  | 10 | # frameworks/base/api/dump_api_shas.sh origin/oreo-dev..origin/pie-dev | 
|  | 11 |  | 
|  | 12 | set -o pipefail | 
|  | 13 |  | 
|  | 14 | eecho() { echo $@ >&2 ; } | 
|  | 15 |  | 
|  | 16 | if [[ $1 == *..* ]]; then | 
|  | 17 | exclude=${1/..*} | 
|  | 18 | include=${1/*..} | 
|  | 19 | else | 
|  | 20 | eecho No range or invalid range specified, defaulting to all commits from HEAD. | 
|  | 21 | exclude= | 
|  | 22 | include=HEAD | 
|  | 23 | fi | 
|  | 24 |  | 
|  | 25 | eecho -n building queryview... | 
|  | 26 | { source build/envsetup.sh && lunch aosp_arm && m queryview; } >/dev/null 2>&1 \ | 
|  | 27 | || { eecho failed; exit 1; } | 
|  | 28 | eecho "done" | 
|  | 29 |  | 
|  | 30 | # This finds the directories where the dependant java_sdk_libs are defined | 
|  | 31 | bpdirs=$( | 
|  | 32 | bazel query --config=queryview --output=package \ | 
|  | 33 | 'kind(java_sdk_library, deps(//frameworks/base/api/..., 1))' 2>/dev/null | 
|  | 34 | echo frameworks/base/core/api # Not a java_sdk_library. | 
|  | 35 | echo frameworks/base/services/api # Not a java_sdk_library. | 
|  | 36 | ) | 
|  | 37 |  | 
|  | 38 | # Find relevant api subdirectories | 
|  | 39 | apidirs=$( | 
|  | 40 | find $bpdirs -type f -name '*current.txt' -path '*/api/*' \ | 
|  | 41 | | xargs realpath --relative-to=$(pwd) | xargs dirname | sort | uniq | 
|  | 42 | ) | 
|  | 43 |  | 
|  | 44 | # Dump sorted SHAs of commits in these directories | 
|  | 45 | { for d in $apidirs; do | 
|  | 46 | ( cd $d | 
|  | 47 | eecho inspecting $d | 
|  | 48 | exclude_arg=$(test -n "$exclude" && { | 
|  | 49 | git rev-parse -q --verify $exclude > /dev/null && echo "--not $exclude" \ | 
|  | 50 | || eecho "$d has no revision $exclude, including all commits"; } || true) | 
|  | 51 | for f in $(find . -name '*current.txt'); do | 
|  | 52 | git --no-pager log --pretty=format:%H --no-merges --follow $include $exclude_arg -- $f | 
|  | 53 | echo # No trailing newline with --no-pager | 
|  | 54 | done | 
|  | 55 | ) | 
|  | 56 | done; } | sort | uniq |