summaryrefslogtreecommitdiff
path: root/tools/hiddenapi/generate_hiddenapi_lists.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/hiddenapi/generate_hiddenapi_lists.py')
-rwxr-xr-xtools/hiddenapi/generate_hiddenapi_lists.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/tools/hiddenapi/generate_hiddenapi_lists.py b/tools/hiddenapi/generate_hiddenapi_lists.py
index 6781eba05534..c856cc36d6f6 100755
--- a/tools/hiddenapi/generate_hiddenapi_lists.py
+++ b/tools/hiddenapi/generate_hiddenapi_lists.py
@@ -21,6 +21,7 @@ from collections import defaultdict
import os
import sys
import re
+import functools
# Names of flags recognized by the `hiddenapi` tool.
FLAG_WHITELIST = "whitelist"
@@ -58,6 +59,10 @@ ALL_FLAGS_SET = set(ALL_FLAGS)
# script to skip any entries which do not exist any more.
FLAG_IGNORE_CONFLICTS_SUFFIX = "-ignore-conflicts"
+# Suffix used in command line args to express that all apis within a given set
+# of packages should be assign the given flag.
+FLAG_PACKAGES_SUFFIX = "-packages"
+
# Regex patterns of fields/methods used in serialization. These are
# considered public API despite being hidden.
SERIALIZATION_PATTERNS = [
@@ -91,12 +96,16 @@ def get_args():
for flag in ALL_FLAGS:
ignore_conflicts_flag = flag + FLAG_IGNORE_CONFLICTS_SUFFIX
+ packages_flag = flag + FLAG_PACKAGES_SUFFIX
parser.add_argument('--' + flag, dest=flag, nargs='*', default=[], metavar='TXT_FILE',
help='lists of entries with flag "' + flag + '"')
parser.add_argument('--' + ignore_conflicts_flag, dest=ignore_conflicts_flag, nargs='*',
default=[], metavar='TXT_FILE',
help='lists of entries with flag "' + flag +
'". skip entry if missing or flag conflict.')
+ parser.add_argument('--' + packages_flag, dest=packages_flag, nargs='*',
+ default=[], metavar='TXT_FILE',
+ help='lists of packages to be added to ' + flag + ' list')
return parser.parse_args()
@@ -128,6 +137,19 @@ def write_lines(filename, lines):
with open(filename, 'w') as f:
f.writelines(lines)
+def extract_package(signature):
+ """Extracts the package from a signature.
+
+ Args:
+ signature (string): JNI signature of a method or field.
+
+ Returns:
+ The package name of the class containing the field/method.
+ """
+ full_class_name = signature.split(";->")[0]
+ package_name = full_class_name[1:full_class_name.rindex("/")]
+ return package_name.replace('/', '.')
+
class FlagsDict:
def __init__(self):
self._dict_keyset = set()
@@ -206,7 +228,10 @@ class FlagsDict:
self._dict_keyset.update([ csv[0] for csv in csv_values ])
# Check that all flags are known.
- csv_flags = set(reduce(lambda x, y: set(x).union(y), [ csv[1:] for csv in csv_values ], []))
+ csv_flags = set(functools.reduce(
+ lambda x, y: set(x).union(y),
+ [ csv[1:] for csv in csv_values ],
+ []))
self._check_flags_set(csv_flags, source)
# Iterate over all CSV lines, find entry in dict and append flags to it.
@@ -273,6 +298,15 @@ def main(argv):
valid_entries = flags.get_valid_subset_of_unassigned_apis(read_lines(filename))
flags.assign_flag(flag, valid_entries, filename)
+ # All members in the specified packages will be assigned the appropriate flag.
+ for flag in ALL_FLAGS:
+ for filename in args[flag + FLAG_PACKAGES_SUFFIX]:
+ packages_needing_list = set(read_lines(filename))
+ should_add_signature_to_list = lambda sig,lists: extract_package(
+ sig) in packages_needing_list and not lists
+ valid_entries = flags.filter_apis(should_add_signature_to_list)
+ flags.assign_flag(flag, valid_entries)
+
# Assign all remaining entries to the blacklist.
flags.assign_flag(FLAG_BLACKLIST, flags.filter_apis(HAS_NO_API_LIST_ASSIGNED))