Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 1 | #!/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 | """ |
| 17 | Verify that one set of hidden API flags is a subset of another. |
| 18 | """ |
| 19 | |
| 20 | import argparse |
| 21 | import csv |
| 22 | |
| 23 | args_parser = argparse.ArgumentParser(description='Verify that one set of hidden API flags is a subset of another.') |
| 24 | args_parser.add_argument('all', help='All the flags') |
| 25 | args_parser.add_argument('subsets', nargs=argparse.REMAINDER, help='Subsets of the flags') |
| 26 | args = args_parser.parse_args() |
| 27 | |
| 28 | |
| 29 | def 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 |
| 33 | allFlagsBySignature = {} |
| 34 | with 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 | |
| 40 | failed = False |
| 41 | for 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 Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 50 | mismatchingSignatures.append((signature, row.get(None, []), allFlags.get(None, []))) |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 51 | else: |
Paul Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 52 | mismatchingSignatures.append((signature, row.get(None, []), [])) |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 53 | |
| 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 Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 63 | if mismatch[2] != []: |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 64 | print("> " + mismatch[0] + "," + ",".join(mismatch[2])) |
| 65 | else: |
| 66 | print("> " + mismatch[0] + " - missing") |
| 67 | |
| 68 | if failed: |
| 69 | sys.exit(1) |