• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 metadata_helpers import *
23from metadata_parser_xml import *
24from os.path import relpath
25from os import getcwd
26
27if __name__ == "__main__":
28  if len(sys.argv) <= 4:
29    print("Usage: %s <filename.xml> <template_name> <output_directory> [<copyright_year>]"
30          % (sys.argv[0]), file=sys.stderr)
31    sys.exit(1)
32
33  file_name = sys.argv[1]
34  template_name = sys.argv[2]
35  output_dir = sys.argv[3]
36  copyright_year = sys.argv[4] if len(sys.argv) > 4 else "2022"
37
38  parser = MetadataParserXml.create_from_file(file_name)
39  metadata = parser.metadata
40
41  for sec in find_all_sections(metadata):
42    for entry in remove_hal_non_visible(find_unique_entries(sec)):
43      if entry.enum:
44        enum_name = entry.name.removeprefix("android.")
45        s = enum_name.split(".")
46        s = [x[0].capitalize() + x[1:] for x in s]
47        enum_name = ''.join(s)
48        output_name = output_dir + "/" + enum_name + ".aidl"
49        parser.render(template_name, output_name, entry.name, copyright_year)
50        print("OK: Generated " + relpath(output_name, getcwd()))
51
52  sys.exit(0)
53