blob: a7c5bb4f3f5a06488252b6c7ae19b079455557d0 [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):
Paul Duffin6ffdff82021-08-09 13:47:19 +010033 # Read in all the signatures into a list and remove member names.
34 patterns = set()
35 for row in dict_reader(stream):
Paul Duffin67b9d612021-07-21 17:38:47 +010036 signature = row['signature']
Paul Duffin6ffdff82021-08-09 13:47:19 +010037 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 Duffin67b9d612021-07-21 17:38:47 +010048 return patterns
49
50def 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
65if __name__ == "__main__":
66 main(sys.argv[1:])