blob: c023b312b4716eb9365a0b9aa92f0a0cb195eae5 [file] [log] [blame]
Anton Hansson8caea0d2021-03-24 14:54:49 +00001#!/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
12set -o pipefail
13
14eecho() { echo $@ >&2 ; }
15
16if [[ $1 == *..* ]]; then
17 exclude=${1/..*}
18 include=${1/*..}
19else
20 eecho No range or invalid range specified, defaulting to all commits from HEAD.
21 exclude=
22 include=HEAD
23fi
24
25eecho -n building queryview...
26{ source build/envsetup.sh && lunch aosp_arm && m queryview; } >/dev/null 2>&1 \
27 || { eecho failed; exit 1; }
28eecho "done"
29
30# This finds the directories where the dependant java_sdk_libs are defined
31bpdirs=$(
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
39apidirs=$(
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 )
56done; } | sort | uniq