blob: bb0917e535a1147874adbea771348df3bbe8e227 [file] [log] [blame]
Paul Duffindfa10832021-05-13 17:31:51 +01001#!/usr/bin/env python
2#
3# Copyright (C) 2018 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16"""
17Verify that one set of hidden API flags is a subset of another.
18"""
19
20import argparse
21import csv
22
23args_parser = argparse.ArgumentParser(description='Verify that one set of hidden API flags is a subset of another.')
24args_parser.add_argument('all', help='All the flags')
25args_parser.add_argument('subsets', nargs=argparse.REMAINDER, help='Subsets of the flags')
26args = args_parser.parse_args()
27
28
29def dict_reader(input):
30 return csv.DictReader(input, delimiter=',', quotechar='|', fieldnames=['signature'])
31
32# Read in all the flags into a dict indexed by signature
33allFlagsBySignature = {}
34with open(args.all, 'r') as allFlagsFile:
35 allFlagsReader = dict_reader(allFlagsFile)
36 for row in allFlagsReader:
37 signature = row['signature']
38 allFlagsBySignature[signature]=row
39
40failed = False
41for subsetPath in args.subsets:
42 mismatchingSignatures = []
43 with open(subsetPath, 'r') as subsetFlagsFile:
44 subsetReader = dict_reader(subsetFlagsFile)
45 for row in subsetReader:
46 signature = row['signature']
47 if signature in allFlagsBySignature:
48 allFlags = allFlagsBySignature.get(signature)
49 if allFlags != row:
Paul Duffin2e880972021-06-23 23:29:09 +010050 mismatchingSignatures.append((signature, row.get(None, []), allFlags.get(None, [])))
Paul Duffindfa10832021-05-13 17:31:51 +010051 else:
Paul Duffin2e880972021-06-23 23:29:09 +010052 mismatchingSignatures.append((signature, row.get(None, []), []))
Paul Duffindfa10832021-05-13 17:31:51 +010053
54
55 if mismatchingSignatures:
56 failed = True
57 print("ERROR: Hidden API flags are inconsistent:")
58 print("< " + subsetPath)
59 print("> " + args.all)
60 for mismatch in mismatchingSignatures:
61 print()
62 print("< " + mismatch[0] + "," + ",".join(mismatch[1]))
Paul Duffin2e880972021-06-23 23:29:09 +010063 if mismatch[2] != []:
Paul Duffindfa10832021-05-13 17:31:51 +010064 print("> " + mismatch[0] + "," + ",".join(mismatch[2]))
65 else:
66 print("> " + mismatch[0] + " - missing")
67
68if failed:
69 sys.exit(1)