blob: f4ab00da06fad96cb50c3987ccb8437844d8cb8e [file] [log] [blame]
Keith Mok57baaaf2023-06-13 22:33:10 +00001#!/usr/bin/python3
Yu Shan63e24d72022-06-24 17:53:32 +00002
3# Copyright (C) 2022 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"""A script to generate Java files and CPP header files based on annotations in VehicleProperty.aidl
18
19 Need ANDROID_BUILD_TOP environmental variable to be set. This script will update
Yu Shan72594ce2024-04-26 14:49:04 -070020 ChangeModeForVehicleProperty.h and AccessForVehicleProperty.h under generated_lib/version/cpp and
Tyler Trephanc8a50de2024-01-19 22:50:03 +000021 ChangeModeForVehicleProperty.java, AccessForVehicleProperty.java, EnumForVehicleProperty.java
Yu Shan72594ce2024-04-26 14:49:04 -070022 UnitsForVehicleProperty.java under generated_lib/version/java.
Yu Shan63e24d72022-06-24 17:53:32 +000023
24 Usage:
25 $ python generate_annotation_enums.py
26"""
Yu Shan41dd7f12023-06-07 13:25:43 -070027import argparse
28import filecmp
Yu Shan63e24d72022-06-24 17:53:32 +000029import os
30import re
31import sys
Yu Shan41dd7f12023-06-07 13:25:43 -070032import tempfile
Yu Shan63e24d72022-06-24 17:53:32 +000033
Yu Shan72594ce2024-04-26 14:49:04 -070034# Keep this updated with the latest in-development property version.
Yu Shanc746fc82024-04-26 15:47:26 -070035PROPERTY_VERSION = '4'
Yu Shan72594ce2024-04-26 14:49:04 -070036
Yu Shan41dd7f12023-06-07 13:25:43 -070037PROP_AIDL_FILE_PATH = ('hardware/interfaces/automotive/vehicle/aidl_property/android/hardware/' +
38 'automotive/vehicle/VehicleProperty.aidl')
Yu Shan72594ce2024-04-26 14:49:04 -070039GENERATED_LIB = ('hardware/interfaces/automotive/vehicle/aidl/generated_lib/' + PROPERTY_VERSION +
40 '/')
41CHANGE_MODE_CPP_FILE_PATH = GENERATED_LIB + '/cpp/ChangeModeForVehicleProperty.h'
42ACCESS_CPP_FILE_PATH = GENERATED_LIB + '/cpp/AccessForVehicleProperty.h'
43CHANGE_MODE_JAVA_FILE_PATH = GENERATED_LIB + '/java/ChangeModeForVehicleProperty.java'
44ACCESS_JAVA_FILE_PATH = GENERATED_LIB + '/java/AccessForVehicleProperty.java'
45ENUM_JAVA_FILE_PATH = GENERATED_LIB + '/java/EnumForVehicleProperty.java'
46UNITS_JAVA_FILE_PATH = GENERATED_LIB + '/java/UnitsForVehicleProperty.java'
47VERSION_CPP_FILE_PATH = GENERATED_LIB + '/cpp/VersionForVehicleProperty.h'
Yu Shan41dd7f12023-06-07 13:25:43 -070048SCRIPT_PATH = 'hardware/interfaces/automotive/vehicle/tools/generate_annotation_enums.py'
Yu Shan63e24d72022-06-24 17:53:32 +000049
Yu Shan41dd7f12023-06-07 13:25:43 -070050TAB = ' '
51RE_ENUM_START = re.compile('\s*enum VehicleProperty \{')
52RE_ENUM_END = re.compile('\s*\}\;')
53RE_COMMENT_BEGIN = re.compile('\s*\/\*\*?')
54RE_COMMENT_END = re.compile('\s*\*\/')
55RE_CHANGE_MODE = re.compile('\s*\* @change_mode (\S+)\s*')
Yu Shan7881e822023-12-15 13:12:01 -080056RE_VERSION = re.compile('\s*\* @version (\S+)\s*')
Yu Shan41dd7f12023-06-07 13:25:43 -070057RE_ACCESS = re.compile('\s*\* @access (\S+)\s*')
Yu Shan8ddd65d2023-06-28 17:02:29 -070058RE_DATA_ENUM = re.compile('\s*\* @data_enum (\S+)\s*')
59RE_UNIT = re.compile('\s*\* @unit (\S+)\s+')
Yu Shan41dd7f12023-06-07 13:25:43 -070060RE_VALUE = re.compile('\s*(\w+)\s*=(.*)')
Yu Shan70447692025-01-08 16:56:21 -080061RE_ANNOTATION = re.compile('\s*\* @(\S+)\s*')
62
63SUPPORTED_ANNOTATIONS = ['change_mode', 'access', 'unit', 'data_enum', 'data_enum_bit_flags',
64 'version', 'require_min_max_supported_value', 'require_supported_values_list',
65 'legacy_supported_values_in_config']
66
67# Non static data_enum properties that do not require supported values list.
68# These properties are either deprecated or for internal use only.
69ENUM_PROPERTIES_WITHOUT_SUPPORTED_VALUES = [
70 # deprecated
71 'TURN_SIGNAL_STATE',
72 # The supported values are exposed through HVAC_FAN_DIRECTION_AVAILABLE
73 'HVAC_FAN_DIRECTION',
74 # Internal use only
75 'HW_ROTARY_INPUT',
76 # Internal use only
77 'HW_CUSTOM_INPUT',
78 # Internal use only
79 'SHUTDOWN_REQUEST',
80 # Internal use only
81 'CAMERA_SERVICE_CURRENT_STATE'
82]
Yu Shan63e24d72022-06-24 17:53:32 +000083
84LICENSE = """/*
Tyler Trephana1828f92023-10-06 02:39:13 +000085 * Copyright (C) 2023 The Android Open Source Project
Yu Shan63e24d72022-06-24 17:53:32 +000086 *
87 * Licensed under the Apache License, Version 2.0 (the "License");
88 * you may not use this file except in compliance with the License.
89 * You may obtain a copy of the License at
90 *
91 * http://www.apache.org/licenses/LICENSE-2.0
92 *
93 * Unless required by applicable law or agreed to in writing, software
94 * distributed under the License is distributed on an "AS IS" BASIS,
95 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96 * See the License for the specific language governing permissions and
97 * limitations under the License.
98 */
99
100/**
101 * DO NOT EDIT MANUALLY!!!
102 *
103 * Generated by tools/generate_annotation_enums.py.
104 */
105
Aaqib Ismail2e8915d2023-01-30 13:04:05 -0800106// clang-format off
107
Yu Shan63e24d72022-06-24 17:53:32 +0000108"""
109
Yu Shan7881e822023-12-15 13:12:01 -0800110CHANGE_MODE_CPP_HEADER = """#pragma once
Yu Shan63e24d72022-06-24 17:53:32 +0000111
112#include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h>
113#include <aidl/android/hardware/automotive/vehicle/VehiclePropertyChangeMode.h>
114
115#include <unordered_map>
116
117namespace aidl {
118namespace android {
119namespace hardware {
120namespace automotive {
121namespace vehicle {
122
123std::unordered_map<VehicleProperty, VehiclePropertyChangeMode> ChangeModeForVehicleProperty = {
124"""
125
Yu Shan7881e822023-12-15 13:12:01 -0800126CPP_FOOTER = """
Yu Shan63e24d72022-06-24 17:53:32 +0000127};
128
129} // namespace vehicle
130} // namespace automotive
131} // namespace hardware
132} // namespace android
133} // aidl
Yu Shan63e24d72022-06-24 17:53:32 +0000134"""
135
Yu Shan7881e822023-12-15 13:12:01 -0800136ACCESS_CPP_HEADER = """#pragma once
Yu Shan63e24d72022-06-24 17:53:32 +0000137
138#include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h>
139#include <aidl/android/hardware/automotive/vehicle/VehiclePropertyAccess.h>
140
141#include <unordered_map>
142
143namespace aidl {
144namespace android {
145namespace hardware {
146namespace automotive {
147namespace vehicle {
148
149std::unordered_map<VehicleProperty, VehiclePropertyAccess> AccessForVehicleProperty = {
150"""
151
Yu Shan7881e822023-12-15 13:12:01 -0800152VERSION_CPP_HEADER = """#pragma once
Yu Shan63e24d72022-06-24 17:53:32 +0000153
Yu Shan7881e822023-12-15 13:12:01 -0800154#include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h>
Yu Shan63e24d72022-06-24 17:53:32 +0000155
Yu Shan7881e822023-12-15 13:12:01 -0800156#include <unordered_map>
157
158namespace aidl {
159namespace android {
160namespace hardware {
161namespace automotive {
162namespace vehicle {
163
164std::unordered_map<VehicleProperty, int32_t> VersionForVehicleProperty = {
Yu Shan63e24d72022-06-24 17:53:32 +0000165"""
166
167CHANGE_MODE_JAVA_HEADER = """package android.hardware.automotive.vehicle;
168
169import java.util.Map;
170
171public final class ChangeModeForVehicleProperty {
172
173 public static final Map<Integer, Integer> values = Map.ofEntries(
174"""
175
Yu Shan7881e822023-12-15 13:12:01 -0800176JAVA_FOOTER = """
Yu Shan63e24d72022-06-24 17:53:32 +0000177 );
178
179}
180"""
181
182ACCESS_JAVA_HEADER = """package android.hardware.automotive.vehicle;
183
184import java.util.Map;
185
186public final class AccessForVehicleProperty {
187
188 public static final Map<Integer, Integer> values = Map.ofEntries(
189"""
190
Tyler Trephana1828f92023-10-06 02:39:13 +0000191ENUM_JAVA_HEADER = """package android.hardware.automotive.vehicle;
192
193import java.util.List;
194import java.util.Map;
195
196public final class EnumForVehicleProperty {
197
198 public static final Map<Integer, List<Class<?>>> values = Map.ofEntries(
199"""
200
Tyler Trephanc8a50de2024-01-19 22:50:03 +0000201UNITS_JAVA_HEADER = """package android.hardware.automotive.vehicle;
202
203import java.util.Map;
204
205public final class UnitsForVehicleProperty {
206
207 public static final Map<Integer, Integer> values = Map.ofEntries(
208"""
209
Yu Shan63e24d72022-06-24 17:53:32 +0000210
Yu Shan8ddd65d2023-06-28 17:02:29 -0700211class PropertyConfig:
212 """Represents one VHAL property definition in VehicleProperty.aidl."""
Yu Shan63e24d72022-06-24 17:53:32 +0000213
Yu Shan8ddd65d2023-06-28 17:02:29 -0700214 def __init__(self):
215 self.name = None
216 self.description = None
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800217 self.comment = None
Yu Shan8ddd65d2023-06-28 17:02:29 -0700218 self.change_mode = None
219 self.access_modes = []
220 self.enum_types = []
221 self.unit_type = None
Yu Shan7881e822023-12-15 13:12:01 -0800222 self.version = None
Yu Shan70447692025-01-08 16:56:21 -0800223 self.annotations = []
Yu Shan63e24d72022-06-24 17:53:32 +0000224
Yu Shan8ddd65d2023-06-28 17:02:29 -0700225 def __repr__(self):
226 return self.__str__()
227
228 def __str__(self):
229 return ('PropertyConfig{{' +
230 'name: {}, description: {}, change_mode: {}, access_modes: {}, enum_types: {}' +
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800231 ', unit_type: {}, version: {}, comment: {}}}').format(self.name, self.description,
232 self.change_mode, self.access_modes, self.enum_types, self.unit_type,
233 self.version, self.comment)
Yu Shan8ddd65d2023-06-28 17:02:29 -0700234
235
236class FileParser:
237
238 def __init__(self):
239 self.configs = None
240
241 def parseFile(self, input_file):
242 """Parses the input VehicleProperty.aidl file into a list of property configs."""
Yu Shan63e24d72022-06-24 17:53:32 +0000243 processing = False
244 in_comment = False
Yu Shan8ddd65d2023-06-28 17:02:29 -0700245 configs = []
246 config = None
247 with open(input_file, 'r') as f:
Yu Shan63e24d72022-06-24 17:53:32 +0000248 for line in f.readlines():
249 if RE_ENUM_START.match(line):
250 processing = True
Yu Shan63e24d72022-06-24 17:53:32 +0000251 elif RE_ENUM_END.match(line):
252 processing = False
253 if not processing:
254 continue
255 if RE_COMMENT_BEGIN.match(line):
256 in_comment = True
Yu Shan8ddd65d2023-06-28 17:02:29 -0700257 config = PropertyConfig()
Yu Shan70447692025-01-08 16:56:21 -0800258 # Use an array so that we could modify the string in parseComment.
259 description = ['']
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800260 continue
261
Yu Shan63e24d72022-06-24 17:53:32 +0000262 if RE_COMMENT_END.match(line):
263 in_comment = False
264 if in_comment:
Yu Shan70447692025-01-08 16:56:21 -0800265 # We will update the string in description in this function.
266 self.parseComment(line, config, description)
Yu Shan63e24d72022-06-24 17:53:32 +0000267 else:
268 match = RE_VALUE.match(line)
269 if match:
270 prop_name = match.group(1)
Yu Shan41dd7f12023-06-07 13:25:43 -0700271 if prop_name == 'INVALID':
Yu Shan63e24d72022-06-24 17:53:32 +0000272 continue
Yu Shan8ddd65d2023-06-28 17:02:29 -0700273 if not config.change_mode:
Yu Shan41dd7f12023-06-07 13:25:43 -0700274 raise Exception(
Yu Shan8ddd65d2023-06-28 17:02:29 -0700275 'No change_mode annotation for property: ' + prop_name)
276 if not config.access_modes:
277 raise Exception(
278 'No access_mode annotation for property: ' + prop_name)
Yu Shan7881e822023-12-15 13:12:01 -0800279 if not config.version:
280 raise Exception(
Yu Shan70447692025-01-08 16:56:21 -0800281 'No version annotation for property: ' + prop_name)
282 if ('data_enum' in config.annotations and
283 'require_supported_values_list' not in config.annotations and
284 config.change_mode != 'STATIC' and
285 prop_name not in ENUM_PROPERTIES_WITHOUT_SUPPORTED_VALUES):
286 raise Exception(
287 'The property: ' + prop_name + ' has @data_enum '
288 'annotation but does not have @require_supported_values_list'
289 ', either add the annotation or add the property name to '
290 'ENUM_PROPERTIES_WITHOUT_SUPPORTED_VALUES in '
291 'generate_annotation_enums.py')
292
Yu Shan8ddd65d2023-06-28 17:02:29 -0700293 config.name = prop_name
294 configs.append(config)
295
296 self.configs = configs
297
Yu Shan70447692025-01-08 16:56:21 -0800298 def parseComment(self, line, config, description):
299 match_annotation = RE_ANNOTATION.match(line)
300 if match_annotation:
301 annotation = match_annotation.group(1)
302 if annotation not in SUPPORTED_ANNOTATIONS:
303 raise Exception('Annotation: @' + annotation + " is not supported, typo?")
304 config.annotations.append(annotation)
305 match = RE_CHANGE_MODE.match(line)
306 if match:
307 config.change_mode = match.group(1).replace('VehiclePropertyChangeMode.', '')
308 return
309 match = RE_ACCESS.match(line)
310 if match:
311 config.access_modes.append(match.group(1).replace('VehiclePropertyAccess.', ''))
312 return
313 match = RE_UNIT.match(line)
314 if match:
315 config.unit_type = match.group(1)
316 return
317 match = RE_DATA_ENUM.match(line)
318 if match:
319 config.enum_types.append(match.group(1))
320 return
321 match = RE_VERSION.match(line)
322 if match:
323 if config.version != None:
324 raise Exception('Duplicate version annotation for property: ' + prop_name)
325 config.version = match.group(1)
326 return
327
328 sline = line.strip()
329 if sline.startswith('*'):
330 # Remove the '*'.
331 sline = sline[1:].strip()
332
333 if not config.description:
334 # We reach an empty line of comment, the description part is ending.
335 if sline == '':
336 config.description = description[0]
337 else:
338 if description[0] != '':
339 description[0] += ' '
340 description[0] += sline
341 else:
342 if not config.comment:
343 if sline != '':
344 # This is the first line for comment.
345 config.comment = sline
346 else:
347 if sline != '':
348 # Concat this line with the previous line's comment with a space.
349 config.comment += ' ' + sline
350 else:
351 # Treat empty line comment as a new line.
352 config.comment += '\n'
353
Yu Shan8ddd65d2023-06-28 17:02:29 -0700354 def convert(self, output, header, footer, cpp, field):
355 """Converts the property config file to C++/Java output file."""
356 counter = 0
357 content = LICENSE + header
358 for config in self.configs:
359 if field == 'change_mode':
360 if cpp:
361 annotation = "VehiclePropertyChangeMode::" + config.change_mode
362 else:
363 annotation = "VehiclePropertyChangeMode." + config.change_mode
364 elif field == 'access_mode':
365 if cpp:
366 annotation = "VehiclePropertyAccess::" + config.access_modes[0]
367 else:
368 annotation = "VehiclePropertyAccess." + config.access_modes[0]
Tyler Trephana1828f92023-10-06 02:39:13 +0000369 elif field == 'enum_types':
370 if len(config.enum_types) < 1:
371 continue;
372 if not cpp:
373 annotation = "List.of(" + ', '.join([class_name + ".class" for class_name in config.enum_types]) + ")"
Tyler Trephanc8a50de2024-01-19 22:50:03 +0000374 elif field == 'unit_type':
375 if not config.unit_type:
376 continue
377 if not cpp:
378 annotation = config.unit_type
379
Yu Shan7881e822023-12-15 13:12:01 -0800380 elif field == 'version':
381 if cpp:
382 annotation = config.version
Yu Shan8ddd65d2023-06-28 17:02:29 -0700383 else:
384 raise Exception('Unknown field: ' + field)
385 if counter != 0:
386 content += '\n'
387 if cpp:
388 content += (TAB + TAB + '{VehicleProperty::' + config.name + ', ' +
389 annotation + '},')
390 else:
391 content += (TAB + TAB + 'Map.entry(VehicleProperty.' + config.name + ', ' +
392 annotation + '),')
393 counter += 1
Yu Shan63e24d72022-06-24 17:53:32 +0000394
Yu Shan41dd7f12023-06-07 13:25:43 -0700395 # Remove the additional ',' at the end for the Java file.
Yu Shan63e24d72022-06-24 17:53:32 +0000396 if not cpp:
397 content = content[:-1]
398
399 content += footer
400
401 with open(output, 'w') as f:
402 f.write(content)
403
Yu Shan8ddd65d2023-06-28 17:02:29 -0700404 def outputAsCsv(self, output):
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800405 content = 'name,description,change mode,access mode,enum type,unit type,comment\n'
Yu Shan8ddd65d2023-06-28 17:02:29 -0700406 for config in self.configs:
407 enum_types = None
408 if not config.enum_types:
409 enum_types = '/'
410 else:
411 enum_types = '/'.join(config.enum_types)
412 unit_type = config.unit_type
413 if not unit_type:
414 unit_type = '/'
415 access_modes = ''
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800416 comment = config.comment
417 if not comment:
418 comment = ''
419 content += '"{}","{}","{}","{}","{}","{}", "{}"\n'.format(
Yu Shan8ddd65d2023-06-28 17:02:29 -0700420 config.name,
421 # Need to escape quote as double quote.
422 config.description.replace('"', '""'),
423 config.change_mode,
424 '/'.join(config.access_modes),
425 enum_types,
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800426 unit_type,
427 comment.replace('"', '""'))
Yu Shan8ddd65d2023-06-28 17:02:29 -0700428
429 with open(output, 'w+') as f:
430 f.write(content)
431
Yu Shan63e24d72022-06-24 17:53:32 +0000432
Yu Shan41dd7f12023-06-07 13:25:43 -0700433def createTempFile():
434 f = tempfile.NamedTemporaryFile(delete=False);
435 f.close();
436 return f.name
437
438
Yu Shan7881e822023-12-15 13:12:01 -0800439class GeneratedFile:
440
441 def __init__(self, type):
442 self.type = type
443 self.cpp_file_path = None
444 self.java_file_path = None
445 self.cpp_header = None
446 self.java_header = None
447 self.cpp_footer = None
448 self.java_footer = None
449 self.cpp_output_file = None
450 self.java_output_file = None
451
452 def setCppFilePath(self, cpp_file_path):
453 self.cpp_file_path = cpp_file_path
454
455 def setJavaFilePath(self, java_file_path):
456 self.java_file_path = java_file_path
457
458 def setCppHeader(self, cpp_header):
459 self.cpp_header = cpp_header
460
461 def setCppFooter(self, cpp_footer):
462 self.cpp_footer = cpp_footer
463
464 def setJavaHeader(self, java_header):
465 self.java_header = java_header
466
467 def setJavaFooter(self, java_footer):
468 self.java_footer = java_footer
469
470 def convert(self, file_parser, check_only, temp_files):
471 if self.cpp_file_path:
472 output_file = GeneratedFile._getOutputFile(self.cpp_file_path, check_only, temp_files)
473 file_parser.convert(output_file, self.cpp_header, self.cpp_footer, True, self.type)
474 self.cpp_output_file = output_file
475
476 if self.java_file_path:
477 output_file = GeneratedFile._getOutputFile(self.java_file_path, check_only, temp_files)
478 file_parser.convert(output_file, self.java_header, self.java_footer, False, self.type)
479 self.java_output_file = output_file
480
481 def cmp(self):
482 if self.cpp_file_path:
483 if not filecmp.cmp(self.cpp_output_file, self.cpp_file_path):
484 return False
485
486 if self.java_file_path:
487 if not filecmp.cmp(self.java_output_file, self.java_file_path):
488 return False
489
490 return True
491
492 @staticmethod
493 def _getOutputFile(file_path, check_only, temp_files):
494 if not check_only:
495 return file_path
496
497 temp_file = createTempFile()
498 temp_files.append(temp_file)
499 return temp_file
500
501
Yu Shan63e24d72022-06-24 17:53:32 +0000502def main():
Yu Shan41dd7f12023-06-07 13:25:43 -0700503 parser = argparse.ArgumentParser(
504 description='Generate Java and C++ enums based on annotations in VehicleProperty.aidl')
505 parser.add_argument('--android_build_top', required=False, help='Path to ANDROID_BUILD_TOP')
Yu Shanb1fc8c92023-08-30 11:51:04 -0700506 parser.add_argument('--preupload_files', nargs='*', required=False, help='modified files')
Yu Shan41dd7f12023-06-07 13:25:43 -0700507 parser.add_argument('--check_only', required=False, action='store_true',
508 help='only check whether the generated files need update')
Yu Shan8ddd65d2023-06-28 17:02:29 -0700509 parser.add_argument('--output_csv', required=False,
510 help='Path to the parsing result in CSV style, useful for doc generation')
Yu Shan41dd7f12023-06-07 13:25:43 -0700511 args = parser.parse_args();
512 android_top = None
513 output_folder = None
514 if args.android_build_top:
515 android_top = args.android_build_top
516 vehiclePropertyUpdated = False
517 for preuload_file in args.preupload_files:
518 if preuload_file.endswith('VehicleProperty.aidl'):
519 vehiclePropertyUpdated = True
520 break
521 if not vehiclePropertyUpdated:
522 return
523 else:
524 android_top = os.environ['ANDROID_BUILD_TOP']
Yu Shan63e24d72022-06-24 17:53:32 +0000525 if not android_top:
Tyler Trephana1828f92023-10-06 02:39:13 +0000526 print('ANDROID_BUILD_TOP is not in environmental variable, please run source and lunch ' +
Yu Shan41dd7f12023-06-07 13:25:43 -0700527 'at the android root')
Yu Shan63e24d72022-06-24 17:53:32 +0000528
529 aidl_file = os.path.join(android_top, PROP_AIDL_FILE_PATH)
Yu Shan8ddd65d2023-06-28 17:02:29 -0700530 f = FileParser();
531 f.parseFile(aidl_file)
532
533 if args.output_csv:
534 f.outputAsCsv(args.output_csv)
535 return
Yu Shan63e24d72022-06-24 17:53:32 +0000536
Yu Shan7881e822023-12-15 13:12:01 -0800537 generated_files = []
538
539 change_mode = GeneratedFile('change_mode')
540 change_mode.setCppFilePath(os.path.join(android_top, CHANGE_MODE_CPP_FILE_PATH))
541 change_mode.setJavaFilePath(os.path.join(android_top, CHANGE_MODE_JAVA_FILE_PATH))
542 change_mode.setCppHeader(CHANGE_MODE_CPP_HEADER)
543 change_mode.setCppFooter(CPP_FOOTER)
544 change_mode.setJavaHeader(CHANGE_MODE_JAVA_HEADER)
545 change_mode.setJavaFooter(JAVA_FOOTER)
546 generated_files.append(change_mode)
547
548 access_mode = GeneratedFile('access_mode')
549 access_mode.setCppFilePath(os.path.join(android_top, ACCESS_CPP_FILE_PATH))
550 access_mode.setJavaFilePath(os.path.join(android_top, ACCESS_JAVA_FILE_PATH))
551 access_mode.setCppHeader(ACCESS_CPP_HEADER)
552 access_mode.setCppFooter(CPP_FOOTER)
553 access_mode.setJavaHeader(ACCESS_JAVA_HEADER)
554 access_mode.setJavaFooter(JAVA_FOOTER)
555 generated_files.append(access_mode)
556
557 enum_types = GeneratedFile('enum_types')
558 enum_types.setJavaFilePath(os.path.join(android_top, ENUM_JAVA_FILE_PATH))
559 enum_types.setJavaHeader(ENUM_JAVA_HEADER)
560 enum_types.setJavaFooter(JAVA_FOOTER)
561 generated_files.append(enum_types)
562
Tyler Trephanc8a50de2024-01-19 22:50:03 +0000563 unit_type = GeneratedFile('unit_type')
564 unit_type.setJavaFilePath(os.path.join(android_top, UNITS_JAVA_FILE_PATH))
565 unit_type.setJavaHeader(UNITS_JAVA_HEADER)
566 unit_type.setJavaFooter(JAVA_FOOTER)
567 generated_files.append(unit_type)
568
Yu Shan7881e822023-12-15 13:12:01 -0800569 version = GeneratedFile('version')
570 version.setCppFilePath(os.path.join(android_top, VERSION_CPP_FILE_PATH))
571 version.setCppHeader(VERSION_CPP_HEADER)
572 version.setCppFooter(CPP_FOOTER)
573 generated_files.append(version)
574
Yu Shan41dd7f12023-06-07 13:25:43 -0700575 temp_files = []
576
Yu Shan41dd7f12023-06-07 13:25:43 -0700577 try:
Yu Shan7881e822023-12-15 13:12:01 -0800578 for generated_file in generated_files:
579 generated_file.convert(f, args.check_only, temp_files)
Yu Shan41dd7f12023-06-07 13:25:43 -0700580
581 if not args.check_only:
582 return
583
Yu Shan7881e822023-12-15 13:12:01 -0800584 for generated_file in generated_files:
585 if not generated_file.cmp():
586 print('The generated enum files for VehicleProperty.aidl requires update, ')
587 print('Run \npython ' + android_top + '/' + SCRIPT_PATH)
588 sys.exit(1)
Yu Shan41dd7f12023-06-07 13:25:43 -0700589 except Exception as e:
590 print('Error parsing VehicleProperty.aidl')
591 print(e)
592 sys.exit(1)
593 finally:
594 for file in temp_files:
595 os.remove(file)
Yu Shan63e24d72022-06-24 17:53:32 +0000596
597
Yu Shan41dd7f12023-06-07 13:25:43 -0700598if __name__ == '__main__':
Yu Shan63e24d72022-06-24 17:53:32 +0000599 main()