summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Brazdil <dbrazdil@google.com>2018-05-05 12:07:38 +0100
committerDavid Brazdil <dbrazdil@google.com>2018-05-08 10:29:50 +0100
commit2200a1b83bf94456711b61b518b0daa38b0e18ae (patch)
tree9552a7789218e724afa7d6867a025d31cc11657c
parent40f67c52bb0553e81a1537369abe2878641a6aaa (diff)
Add presubmit hook for hidden API lists.
Check that they're sorted as expected and contain no duplicates. The sort order now uses: $ LC_COLLATE=C sort -f So that non-alphanumeric characters are not ignored, giving a more intuitive sort order. the '-f' means ignore case. Also sort the existing lists accordingly. Test: repo upload Bug: 64382372 Merged-In: I52b884da33a9a46455df6747a215683d9d3c3218 Change-Id: Icc124fd8ceb3f001a9c11bbf40e0a111910c6b39 (cherry picked from commit e5dc64d4281dd9f38c2b585202e26ae4278fcfc5)
-rw-r--r--PREUPLOAD.cfg1
-rwxr-xr-xtools/hiddenapi/checksorted_sha.sh10
-rwxr-xr-xtools/hiddenapi/sort_api.sh18
3 files changed, 29 insertions, 0 deletions
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index 75b74913870f..a632771956ef 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -8,3 +8,4 @@ checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPL
services/usb/
telephony/
+hidden_api_txt_hook = ${REPO_ROOT}/frameworks/base/tools/hiddenapi/checksorted_sha.sh ${PREUPLOAD_COMMIT} ${REPO_ROOT}
diff --git a/tools/hiddenapi/checksorted_sha.sh b/tools/hiddenapi/checksorted_sha.sh
new file mode 100755
index 000000000000..ceb705f4e42a
--- /dev/null
+++ b/tools/hiddenapi/checksorted_sha.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -e
+LOCAL_DIR="$( dirname ${BASH_SOURCE} )"
+git show --name-only --pretty=format: $1 | grep "config/hiddenapi-.*txt" | while read file; do
+ diff <(git show $1:$file) <(git show $1:$file | $LOCAL_DIR/sort_api.sh ) || {
+ echo -e "\e[1m\e[31m$file $1 is not sorted or contains duplicates. To sort it correctly:\e[0m"
+ echo -e "\e[33m${LOCAL_DIR}/sort_api.sh $2/frameworks/base/$file\e[0m"
+ exit 1
+ }
+done
diff --git a/tools/hiddenapi/sort_api.sh b/tools/hiddenapi/sort_api.sh
new file mode 100755
index 000000000000..1c6eb1b286b1
--- /dev/null
+++ b/tools/hiddenapi/sort_api.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+set -e
+if [ -z "$1" ]; then
+ source_list=/dev/stdin
+ dest_list=/dev/stdout
+else
+ source_list="$1"
+ dest_list="$1"
+fi
+# Load the file
+readarray A < "$source_list"
+# Sort
+IFS=$'\n'
+A=( $(LC_COLLATE=C sort -f <<< "${A[*]}") )
+A=( $(uniq <<< "${A[*]}") )
+unset IFS
+# Dump array back into the file
+printf '%s\n' "${A[@]}" > "$dest_list"