blob: 91328e60fd406d5e2fca36bb01fe6fbc4c08d5b1 [file] [log] [blame]
Paul Duffin67b9d612021-07-21 17:38:47 +01001#!/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"""
17Generate a set of signature patterns from the modular flags generated by a
18bootclasspath_fragment that can be used to select a subset of monolithic flags
19against which the modular flags can be compared.
20"""
21
22import argparse
23import csv
24
25def dict_reader(input):
26 return csv.DictReader(input, delimiter=',', quotechar='|', fieldnames=['signature'])
27
28def produce_patterns_from_file(file):
29 with open(file, 'r') as f:
30 return produce_patterns_from_stream(f)
31
32def produce_patterns_from_stream(stream):
33 patterns = []
34 allFlagsReader = dict_reader(stream)
35 for row in allFlagsReader:
36 signature = row['signature']
37 patterns.append(signature)
38 return patterns
39
40def main(args):
41 args_parser = argparse.ArgumentParser(description='Generate a set of signature patterns that select a subset of monolithic hidden API files.')
42 args_parser.add_argument('--flags', help='The stub flags file which contains an entry for every dex member')
43 args_parser.add_argument('--output', help='Generated signature prefixes')
44 args = args_parser.parse_args(args)
45
46 # Read in all the patterns into a list.
47 patterns = produce_patterns_from_file(args.flags)
48
49 # Write out all the patterns.
50 with open(args.output, 'w') as outputFile:
51 for pattern in patterns:
52 outputFile.write(pattern)
53 outputFile.write("\n")
54
55if __name__ == "__main__":
56 main(sys.argv[1:])