Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (C) 2021 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 | Generate a set of signature patterns from the modular flags generated by a |
| 18 | bootclasspath_fragment that can be used to select a subset of monolithic flags |
| 19 | against which the modular flags can be compared. |
| 20 | """ |
| 21 | |
| 22 | import argparse |
| 23 | import csv |
| 24 | |
| 25 | def dict_reader(input): |
| 26 | return csv.DictReader(input, delimiter=',', quotechar='|', fieldnames=['signature']) |
| 27 | |
| 28 | def produce_patterns_from_file(file): |
| 29 | with open(file, 'r') as f: |
| 30 | return produce_patterns_from_stream(f) |
| 31 | |
| 32 | def produce_patterns_from_stream(stream): |
Paul Duffin | 6ffdff8 | 2021-08-09 13:47:19 +0100 | [diff] [blame^] | 33 | # Read in all the signatures into a list and remove member names. |
| 34 | patterns = set() |
| 35 | for row in dict_reader(stream): |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 36 | signature = row['signature'] |
Paul Duffin | 6ffdff8 | 2021-08-09 13:47:19 +0100 | [diff] [blame^] | 37 | text = signature.removeprefix("L") |
| 38 | # Remove the class specific member signature |
| 39 | pieces = text.split(";->") |
| 40 | qualifiedClassName = pieces[0] |
| 41 | # Remove inner class names as they cannot be separated from the containing outer class. |
| 42 | pieces = qualifiedClassName.split("$", maxsplit=1) |
| 43 | pattern = pieces[0] |
| 44 | patterns.add(pattern) |
| 45 | |
| 46 | patterns = list(patterns) |
| 47 | patterns.sort() |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 48 | return patterns |
| 49 | |
| 50 | def main(args): |
| 51 | args_parser = argparse.ArgumentParser(description='Generate a set of signature patterns that select a subset of monolithic hidden API files.') |
| 52 | args_parser.add_argument('--flags', help='The stub flags file which contains an entry for every dex member') |
| 53 | args_parser.add_argument('--output', help='Generated signature prefixes') |
| 54 | args = args_parser.parse_args(args) |
| 55 | |
| 56 | # Read in all the patterns into a list. |
| 57 | patterns = produce_patterns_from_file(args.flags) |
| 58 | |
| 59 | # Write out all the patterns. |
| 60 | with open(args.output, 'w') as outputFile: |
| 61 | for pattern in patterns: |
| 62 | outputFile.write(pattern) |
| 63 | outputFile.write("\n") |
| 64 | |
| 65 | if __name__ == "__main__": |
| 66 | main(sys.argv[1:]) |