1# 2# Copyright (C) 2022 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17""" 18Generates aidl files for enums needed by camera metadata keys 19""" 20 21import sys 22from datetime import datetime 23from metadata_helpers import * 24from metadata_parser_xml import * 25from os.path import relpath 26from os import getcwd 27 28if __name__ == "__main__": 29 if len(sys.argv) <= 4: 30 print("Usage: %s <filename.xml> <template_name> <output_directory> [<copyright_year>]" 31 % (sys.argv[0]), file=sys.stderr) 32 sys.exit(1) 33 34 file_name = sys.argv[1] 35 template_name = sys.argv[2] 36 output_dir = sys.argv[3] 37 copyright_year = sys.argv[4] if len(sys.argv) > 4 else str(datetime.now().year) 38 39 parser = MetadataParserXml.create_from_file(file_name) 40 metadata = parser.metadata 41 42 for sec in find_all_sections(metadata): 43 for entry in remove_hal_non_visible(find_unique_entries(sec)): 44 if entry.enum: 45 enum_name = entry.name.removeprefix("android.") 46 s = enum_name.split(".") 47 s = [x[0].capitalize() + x[1:] for x in s] 48 enum_name = ''.join(s) 49 output_name = output_dir + "/" + enum_name + ".aidl" 50 parser.render(template_name, output_name, entry.name, copyright_year) 51 print("OK: Generated " + relpath(output_name, getcwd())) 52 53 sys.exit(0) 54