From ae88d4e21e072a5a4a15777ce2575b90a4689333 Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Thu, 6 Sep 2018 14:46:55 +0100 Subject: [PATCH] Ignore comment lines in hidden api lists It is sometimes useful to add comments at the top of a source file. This patch changes hidden API list generation to ignore lines beginning with a hash. Note that due to the sorting constraints on hidden API lists, comments can be only at the top of the files. Test: m appcompat Change-Id: I1bc6fd44d1b1f10a5adc45093d7f7ed5a0c5a54f --- config/hiddenapi-dark-greylist.txt | 4 ++++ tools/hiddenapi/generate_hiddenapi_lists.py | 4 +++- tools/hiddenapi/sort_api.sh | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config/hiddenapi-dark-greylist.txt b/config/hiddenapi-dark-greylist.txt index 87e315491ba71..71e1e293a1d64 100644 --- a/config/hiddenapi-dark-greylist.txt +++ b/config/hiddenapi-dark-greylist.txt @@ -1,3 +1,7 @@ +# +# DO NOT EDIT! +# This is an autogenerated file containing the dark greylist as present in P. +# Landroid/accessibilityservice/AccessibilityButtonController;->(Landroid/accessibilityservice/IAccessibilityServiceConnection;)V Landroid/accessibilityservice/AccessibilityButtonController;->dispatchAccessibilityButtonAvailabilityChanged(Z)V Landroid/accessibilityservice/AccessibilityButtonController;->dispatchAccessibilityButtonClicked()V diff --git a/tools/hiddenapi/generate_hiddenapi_lists.py b/tools/hiddenapi/generate_hiddenapi_lists.py index ec72ecee2a5c8..c5fcb63624c52 100755 --- a/tools/hiddenapi/generate_hiddenapi_lists.py +++ b/tools/hiddenapi/generate_hiddenapi_lists.py @@ -62,6 +62,8 @@ def get_args(): def read_lines(filename): """Reads entire file and return it as a list of lines. + Lines which begin with a hash are ignored. + Args: filename (string): Path to the file to read from. @@ -69,7 +71,7 @@ def read_lines(filename): list: Lines of the loaded file as a list of strings. """ with open(filename, 'r') as f: - return f.readlines() + return filter(lambda line: not line.startswith('#'), f.readlines()) def write_lines(filename, lines): """Writes list of lines into a file, overwriting the file it it exists. diff --git a/tools/hiddenapi/sort_api.sh b/tools/hiddenapi/sort_api.sh index 1c6eb1b286b18..bdcc8076dde1d 100755 --- a/tools/hiddenapi/sort_api.sh +++ b/tools/hiddenapi/sort_api.sh @@ -11,8 +11,14 @@ fi readarray A < "$source_list" # Sort IFS=$'\n' +# Stash away comments +C=( $(grep -E '^#' <<< "${A[*]}") ) +A=( $(grep -v -E '^#' <<< "${A[*]}") ) +# Sort entries A=( $(LC_COLLATE=C sort -f <<< "${A[*]}") ) A=( $(uniq <<< "${A[*]}") ) +# Concatenate comments and entries +A=( ${C[*]} ${A[*]} ) unset IFS # Dump array back into the file printf '%s\n' "${A[@]}" > "$dest_list"