Remove member signature and inner classes from signature-patterns.csv

Previously, the signature-patterns.csv file included a lot of
implementation details, e.g. the signatures of dex members or inner
classes that are not part of any API, including the hidden API.

This change will remove all member signatures and inner class names
from the file and replace them with just the outermost qualified class
name.

That will still leave some implementation details, e.g. the names of
implementation only classes and packages.

Bug: 194063708
Test: atest --host verify_overlaps_test signature_patterns_test
      m out/soong/hiddenapi/hiddenapi-flags.csv
      - manually change files to cause difference in flags to check
        that it detects the differences.
Change-Id: I9de6a2a6129e875e19f7ded5fae578cbdb584660
This commit is contained in:
Paul Duffin
2021-08-09 13:47:19 +01:00
parent 8f34b0e19d
commit 6ffdff853c
2 changed files with 19 additions and 6 deletions

View File

@@ -30,11 +30,21 @@ def produce_patterns_from_file(file):
return produce_patterns_from_stream(f)
def produce_patterns_from_stream(stream):
patterns = []
allFlagsReader = dict_reader(stream)
for row in allFlagsReader:
# Read in all the signatures into a list and remove member names.
patterns = set()
for row in dict_reader(stream):
signature = row['signature']
patterns.append(signature)
text = signature.removeprefix("L")
# Remove the class specific member signature
pieces = text.split(";->")
qualifiedClassName = pieces[0]
# Remove inner class names as they cannot be separated from the containing outer class.
pieces = qualifiedClassName.split("$", maxsplit=1)
pattern = pieces[0]
patterns.add(pattern)
patterns = list(patterns)
patterns.sort()
return patterns
def main(args):