Extract a subset of the monolithic flags for comparison
Previously, the compare_signature_flags compared the full set of
monolithic flags against the modular flags and just ignored any
monolithic flags for a signature that was not present in the modular
flags. It essentially performed two tasks, identifying the subset of
the monolithic flags against which the modular flags should be compared
and then doing the actual comparison.
This change separates those two tasks, by first creating a dict that is
the subset of the monolithic flags against which the modular flags will
be compared and then do the comparison.
At the moment the subset is simply the set of monolithic flags
associated with the signatures that are present in the modular flags.
Follow up changes will provide other ways to select the subset.
Bug: 194063708
Test: atest --host verify_overlaps_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: Icb547f071b814dd955f31255b0d35597f7ba4aa1
diff --git a/scripts/hiddenapi/verify_overlaps.py b/scripts/hiddenapi/verify_overlaps.py
index b5ca30c..fe4e359 100755
--- a/scripts/hiddenapi/verify_overlaps.py
+++ b/scripts/hiddenapi/verify_overlaps.py
@@ -19,10 +19,24 @@
import argparse
import csv
+from itertools import chain
def dict_reader(input):
return csv.DictReader(input, delimiter=',', quotechar='|', fieldnames=['signature'])
+def extract_subset_from_monolithic_flags_as_dict(monolithicFlagsDict, signatures):
+ """
+ Extract a subset of flags from the dict containing all the monolithic flags.
+
+ :param monolithicFlagsDict: the dict containing all the monolithic flags.
+ :param signatures: a list of signature that define the subset.
+ :return: the dict from signature to row.
+ """
+ dict = {}
+ for signature in signatures:
+ dict[signature] = monolithicFlagsDict.get(signature, {})
+ return dict
+
def read_signature_csv_from_stream_as_dict(stream):
"""
Read the csv contents from the stream into a dict. The first column is assumed to be the
@@ -62,10 +76,14 @@
modular dict, and monolithic dict respectively.
"""
mismatchingSignatures = []
- for signature, modularRow in modularFlagsDict.items():
- modularFlags = modularRow.get(None, [])
+ # Create a sorted set of all the signatures from both the monolithic and
+ # modular dicts.
+ allSignatures = sorted(set(chain(monolithicFlagsDict.keys(), modularFlagsDict.keys())))
+ for signature in allSignatures:
monolithicRow = monolithicFlagsDict.get(signature, {})
monolithicFlags = monolithicRow.get(None, [])
+ modularRow = modularFlagsDict.get(signature, {})
+ modularFlags = modularRow.get(None, [])
if monolithicFlags != modularFlags:
mismatchingSignatures.append((signature, modularFlags, monolithicFlags))
return mismatchingSignatures
@@ -80,10 +98,14 @@
monolithicFlagsPath = args.monolithicFlags
monolithicFlagsDict = read_signature_csv_from_file_as_dict(monolithicFlagsPath)
+ # For each subset specified on the command line, create dicts for the flags
+ # provided by the subset and the corresponding flags from the complete set of
+ # flags and compare them.
failed = False
for modularFlagsPath in args.modularFlags:
modularFlagsDict = read_signature_csv_from_file_as_dict(modularFlagsPath)
- mismatchingSignatures = compare_signature_flags(monolithicFlagsDict, modularFlagsDict)
+ monolithicFlagsSubsetDict = extract_subset_from_monolithic_flags_as_dict(monolithicFlagsDict, modularFlagsDict.keys())
+ mismatchingSignatures = compare_signature_flags(monolithicFlagsSubsetDict, modularFlagsDict)
if mismatchingSignatures:
failed = True
print("ERROR: Hidden API flags are inconsistent:")