blob: f2797678ab4f17cdb06b46b7fef910d710f172ef [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
20 ChangeModeForVehicleProperty.h and AccessForVehicleProperty.h under generated_lib/cpp and
Tyler Trephanc8a50de2024-01-19 22:50:03 +000021 ChangeModeForVehicleProperty.java, AccessForVehicleProperty.java, EnumForVehicleProperty.java
22 UnitsForVehicleProperty.java under generated_lib/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 Shan41dd7f12023-06-07 13:25:43 -070034PROP_AIDL_FILE_PATH = ('hardware/interfaces/automotive/vehicle/aidl_property/android/hardware/' +
35 'automotive/vehicle/VehicleProperty.aidl')
36CHANGE_MODE_CPP_FILE_PATH = ('hardware/interfaces/automotive/vehicle/aidl/generated_lib/cpp/' +
37 'ChangeModeForVehicleProperty.h')
38ACCESS_CPP_FILE_PATH = ('hardware/interfaces/automotive/vehicle/aidl/generated_lib/cpp/' +
39 'AccessForVehicleProperty.h')
40CHANGE_MODE_JAVA_FILE_PATH = ('hardware/interfaces/automotive/vehicle/aidl/generated_lib/java/' +
41 'ChangeModeForVehicleProperty.java')
42ACCESS_JAVA_FILE_PATH = ('hardware/interfaces/automotive/vehicle/aidl/generated_lib/java/' +
43 'AccessForVehicleProperty.java')
Tyler Trephana1828f92023-10-06 02:39:13 +000044ENUM_JAVA_FILE_PATH = ('hardware/interfaces/automotive/vehicle/aidl/generated_lib/java/' +
45 'EnumForVehicleProperty.java')
Tyler Trephanc8a50de2024-01-19 22:50:03 +000046UNITS_JAVA_FILE_PATH = ('hardware/interfaces/automotive/vehicle/aidl/generated_lib/java/' +
47 'UnitsForVehicleProperty.java')
Yu Shan7881e822023-12-15 13:12:01 -080048VERSION_CPP_FILE_PATH = ('hardware/interfaces/automotive/vehicle/aidl/generated_lib/cpp/' +
49 'VersionForVehicleProperty.h')
Yu Shan41dd7f12023-06-07 13:25:43 -070050SCRIPT_PATH = 'hardware/interfaces/automotive/vehicle/tools/generate_annotation_enums.py'
Yu Shan63e24d72022-06-24 17:53:32 +000051
Yu Shan41dd7f12023-06-07 13:25:43 -070052TAB = ' '
53RE_ENUM_START = re.compile('\s*enum VehicleProperty \{')
54RE_ENUM_END = re.compile('\s*\}\;')
55RE_COMMENT_BEGIN = re.compile('\s*\/\*\*?')
56RE_COMMENT_END = re.compile('\s*\*\/')
57RE_CHANGE_MODE = re.compile('\s*\* @change_mode (\S+)\s*')
Yu Shan7881e822023-12-15 13:12:01 -080058RE_VERSION = re.compile('\s*\* @version (\S+)\s*')
Yu Shan41dd7f12023-06-07 13:25:43 -070059RE_ACCESS = re.compile('\s*\* @access (\S+)\s*')
Yu Shan8ddd65d2023-06-28 17:02:29 -070060RE_DATA_ENUM = re.compile('\s*\* @data_enum (\S+)\s*')
61RE_UNIT = re.compile('\s*\* @unit (\S+)\s+')
Yu Shan41dd7f12023-06-07 13:25:43 -070062RE_VALUE = re.compile('\s*(\w+)\s*=(.*)')
Yu Shan63e24d72022-06-24 17:53:32 +000063
64LICENSE = """/*
Tyler Trephana1828f92023-10-06 02:39:13 +000065 * Copyright (C) 2023 The Android Open Source Project
Yu Shan63e24d72022-06-24 17:53:32 +000066 *
67 * Licensed under the Apache License, Version 2.0 (the "License");
68 * you may not use this file except in compliance with the License.
69 * You may obtain a copy of the License at
70 *
71 * http://www.apache.org/licenses/LICENSE-2.0
72 *
73 * Unless required by applicable law or agreed to in writing, software
74 * distributed under the License is distributed on an "AS IS" BASIS,
75 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
76 * See the License for the specific language governing permissions and
77 * limitations under the License.
78 */
79
80/**
81 * DO NOT EDIT MANUALLY!!!
82 *
83 * Generated by tools/generate_annotation_enums.py.
84 */
85
Aaqib Ismail2e8915d2023-01-30 13:04:05 -080086// clang-format off
87
Yu Shan63e24d72022-06-24 17:53:32 +000088"""
89
Yu Shan7881e822023-12-15 13:12:01 -080090CHANGE_MODE_CPP_HEADER = """#pragma once
Yu Shan63e24d72022-06-24 17:53:32 +000091
92#include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h>
93#include <aidl/android/hardware/automotive/vehicle/VehiclePropertyChangeMode.h>
94
95#include <unordered_map>
96
97namespace aidl {
98namespace android {
99namespace hardware {
100namespace automotive {
101namespace vehicle {
102
103std::unordered_map<VehicleProperty, VehiclePropertyChangeMode> ChangeModeForVehicleProperty = {
104"""
105
Yu Shan7881e822023-12-15 13:12:01 -0800106CPP_FOOTER = """
Yu Shan63e24d72022-06-24 17:53:32 +0000107};
108
109} // namespace vehicle
110} // namespace automotive
111} // namespace hardware
112} // namespace android
113} // aidl
Yu Shan63e24d72022-06-24 17:53:32 +0000114"""
115
Yu Shan7881e822023-12-15 13:12:01 -0800116ACCESS_CPP_HEADER = """#pragma once
Yu Shan63e24d72022-06-24 17:53:32 +0000117
118#include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h>
119#include <aidl/android/hardware/automotive/vehicle/VehiclePropertyAccess.h>
120
121#include <unordered_map>
122
123namespace aidl {
124namespace android {
125namespace hardware {
126namespace automotive {
127namespace vehicle {
128
129std::unordered_map<VehicleProperty, VehiclePropertyAccess> AccessForVehicleProperty = {
130"""
131
Yu Shan7881e822023-12-15 13:12:01 -0800132VERSION_CPP_HEADER = """#pragma once
Yu Shan63e24d72022-06-24 17:53:32 +0000133
Yu Shan7881e822023-12-15 13:12:01 -0800134#include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h>
Yu Shan63e24d72022-06-24 17:53:32 +0000135
Yu Shan7881e822023-12-15 13:12:01 -0800136#include <unordered_map>
137
138namespace aidl {
139namespace android {
140namespace hardware {
141namespace automotive {
142namespace vehicle {
143
144std::unordered_map<VehicleProperty, int32_t> VersionForVehicleProperty = {
Yu Shan63e24d72022-06-24 17:53:32 +0000145"""
146
147CHANGE_MODE_JAVA_HEADER = """package android.hardware.automotive.vehicle;
148
149import java.util.Map;
150
151public final class ChangeModeForVehicleProperty {
152
153 public static final Map<Integer, Integer> values = Map.ofEntries(
154"""
155
Yu Shan7881e822023-12-15 13:12:01 -0800156JAVA_FOOTER = """
Yu Shan63e24d72022-06-24 17:53:32 +0000157 );
158
159}
160"""
161
162ACCESS_JAVA_HEADER = """package android.hardware.automotive.vehicle;
163
164import java.util.Map;
165
166public final class AccessForVehicleProperty {
167
168 public static final Map<Integer, Integer> values = Map.ofEntries(
169"""
170
Tyler Trephana1828f92023-10-06 02:39:13 +0000171ENUM_JAVA_HEADER = """package android.hardware.automotive.vehicle;
172
173import java.util.List;
174import java.util.Map;
175
176public final class EnumForVehicleProperty {
177
178 public static final Map<Integer, List<Class<?>>> values = Map.ofEntries(
179"""
180
Tyler Trephanc8a50de2024-01-19 22:50:03 +0000181UNITS_JAVA_HEADER = """package android.hardware.automotive.vehicle;
182
183import java.util.Map;
184
185public final class UnitsForVehicleProperty {
186
187 public static final Map<Integer, Integer> values = Map.ofEntries(
188"""
189
Yu Shan63e24d72022-06-24 17:53:32 +0000190
Yu Shan8ddd65d2023-06-28 17:02:29 -0700191class PropertyConfig:
192 """Represents one VHAL property definition in VehicleProperty.aidl."""
Yu Shan63e24d72022-06-24 17:53:32 +0000193
Yu Shan8ddd65d2023-06-28 17:02:29 -0700194 def __init__(self):
195 self.name = None
196 self.description = None
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800197 self.comment = None
Yu Shan8ddd65d2023-06-28 17:02:29 -0700198 self.change_mode = None
199 self.access_modes = []
200 self.enum_types = []
201 self.unit_type = None
Yu Shan7881e822023-12-15 13:12:01 -0800202 self.version = None
Yu Shan63e24d72022-06-24 17:53:32 +0000203
Yu Shan8ddd65d2023-06-28 17:02:29 -0700204 def __repr__(self):
205 return self.__str__()
206
207 def __str__(self):
208 return ('PropertyConfig{{' +
209 'name: {}, description: {}, change_mode: {}, access_modes: {}, enum_types: {}' +
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800210 ', unit_type: {}, version: {}, comment: {}}}').format(self.name, self.description,
211 self.change_mode, self.access_modes, self.enum_types, self.unit_type,
212 self.version, self.comment)
Yu Shan8ddd65d2023-06-28 17:02:29 -0700213
214
215class FileParser:
216
217 def __init__(self):
218 self.configs = None
219
220 def parseFile(self, input_file):
221 """Parses the input VehicleProperty.aidl file into a list of property configs."""
Yu Shan63e24d72022-06-24 17:53:32 +0000222 processing = False
223 in_comment = False
Yu Shan8ddd65d2023-06-28 17:02:29 -0700224 configs = []
225 config = None
226 with open(input_file, 'r') as f:
Yu Shan63e24d72022-06-24 17:53:32 +0000227 for line in f.readlines():
228 if RE_ENUM_START.match(line):
229 processing = True
Yu Shan63e24d72022-06-24 17:53:32 +0000230 elif RE_ENUM_END.match(line):
231 processing = False
232 if not processing:
233 continue
234 if RE_COMMENT_BEGIN.match(line):
235 in_comment = True
Yu Shan8ddd65d2023-06-28 17:02:29 -0700236 config = PropertyConfig()
237 description = ''
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800238 continue
239
Yu Shan63e24d72022-06-24 17:53:32 +0000240 if RE_COMMENT_END.match(line):
241 in_comment = False
242 if in_comment:
Yu Shan8ddd65d2023-06-28 17:02:29 -0700243 match = RE_CHANGE_MODE.match(line)
244 if match:
245 config.change_mode = match.group(1).replace('VehiclePropertyChangeMode.', '')
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800246 continue
Yu Shan8ddd65d2023-06-28 17:02:29 -0700247 match = RE_ACCESS.match(line)
248 if match:
249 config.access_modes.append(match.group(1).replace('VehiclePropertyAccess.', ''))
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800250 continue
Yu Shan8ddd65d2023-06-28 17:02:29 -0700251 match = RE_UNIT.match(line)
252 if match:
253 config.unit_type = match.group(1)
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800254 continue
Yu Shan8ddd65d2023-06-28 17:02:29 -0700255 match = RE_DATA_ENUM.match(line)
256 if match:
257 config.enum_types.append(match.group(1))
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800258 continue
Yu Shan7881e822023-12-15 13:12:01 -0800259 match = RE_VERSION.match(line)
260 if match:
261 if config.version != None:
262 raise Exception('Duplicate version annotation for property: ' + prop_name)
263 config.version = match.group(1)
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800264 continue
265
266 sline = line.strip()
267 if sline.startswith('*'):
268 # Remove the '*'.
269 sline = sline[1:].strip()
270
271 if not config.description:
272 # We reach an empty line of comment, the description part is ending.
273 if sline == '':
274 config.description = description
275 else:
276 if description != '':
277 description += ' '
278 description += sline
279 else:
280 if not config.comment:
281 if sline != '':
282 # This is the first line for comment.
283 config.comment = sline
284 else:
285 if sline != '':
286 # Concat this line with the previous line's comment with a space.
287 config.comment += ' ' + sline
288 else:
289 # Treat empty line comment as a new line.
290 config.comment += '\n'
Yu Shan63e24d72022-06-24 17:53:32 +0000291 else:
292 match = RE_VALUE.match(line)
293 if match:
294 prop_name = match.group(1)
Yu Shan41dd7f12023-06-07 13:25:43 -0700295 if prop_name == 'INVALID':
Yu Shan63e24d72022-06-24 17:53:32 +0000296 continue
Yu Shan8ddd65d2023-06-28 17:02:29 -0700297 if not config.change_mode:
Yu Shan41dd7f12023-06-07 13:25:43 -0700298 raise Exception(
Yu Shan8ddd65d2023-06-28 17:02:29 -0700299 'No change_mode annotation for property: ' + prop_name)
300 if not config.access_modes:
301 raise Exception(
302 'No access_mode annotation for property: ' + prop_name)
Yu Shan7881e822023-12-15 13:12:01 -0800303 if not config.version:
304 raise Exception(
305 'no version annotation for property: ' + prop_name)
Yu Shan8ddd65d2023-06-28 17:02:29 -0700306 config.name = prop_name
307 configs.append(config)
308
309 self.configs = configs
310
311 def convert(self, output, header, footer, cpp, field):
312 """Converts the property config file to C++/Java output file."""
313 counter = 0
314 content = LICENSE + header
315 for config in self.configs:
316 if field == 'change_mode':
317 if cpp:
318 annotation = "VehiclePropertyChangeMode::" + config.change_mode
319 else:
320 annotation = "VehiclePropertyChangeMode." + config.change_mode
321 elif field == 'access_mode':
322 if cpp:
323 annotation = "VehiclePropertyAccess::" + config.access_modes[0]
324 else:
325 annotation = "VehiclePropertyAccess." + config.access_modes[0]
Tyler Trephana1828f92023-10-06 02:39:13 +0000326 elif field == 'enum_types':
327 if len(config.enum_types) < 1:
328 continue;
329 if not cpp:
330 annotation = "List.of(" + ', '.join([class_name + ".class" for class_name in config.enum_types]) + ")"
Tyler Trephanc8a50de2024-01-19 22:50:03 +0000331 elif field == 'unit_type':
332 if not config.unit_type:
333 continue
334 if not cpp:
335 annotation = config.unit_type
336
Yu Shan7881e822023-12-15 13:12:01 -0800337 elif field == 'version':
338 if cpp:
339 annotation = config.version
Yu Shan8ddd65d2023-06-28 17:02:29 -0700340 else:
341 raise Exception('Unknown field: ' + field)
342 if counter != 0:
343 content += '\n'
344 if cpp:
345 content += (TAB + TAB + '{VehicleProperty::' + config.name + ', ' +
346 annotation + '},')
347 else:
348 content += (TAB + TAB + 'Map.entry(VehicleProperty.' + config.name + ', ' +
349 annotation + '),')
350 counter += 1
Yu Shan63e24d72022-06-24 17:53:32 +0000351
Yu Shan41dd7f12023-06-07 13:25:43 -0700352 # Remove the additional ',' at the end for the Java file.
Yu Shan63e24d72022-06-24 17:53:32 +0000353 if not cpp:
354 content = content[:-1]
355
356 content += footer
357
358 with open(output, 'w') as f:
359 f.write(content)
360
Yu Shan8ddd65d2023-06-28 17:02:29 -0700361 def outputAsCsv(self, output):
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800362 content = 'name,description,change mode,access mode,enum type,unit type,comment\n'
Yu Shan8ddd65d2023-06-28 17:02:29 -0700363 for config in self.configs:
364 enum_types = None
365 if not config.enum_types:
366 enum_types = '/'
367 else:
368 enum_types = '/'.join(config.enum_types)
369 unit_type = config.unit_type
370 if not unit_type:
371 unit_type = '/'
372 access_modes = ''
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800373 comment = config.comment
374 if not comment:
375 comment = ''
376 content += '"{}","{}","{}","{}","{}","{}", "{}"\n'.format(
Yu Shan8ddd65d2023-06-28 17:02:29 -0700377 config.name,
378 # Need to escape quote as double quote.
379 config.description.replace('"', '""'),
380 config.change_mode,
381 '/'.join(config.access_modes),
382 enum_types,
Yu Shan0ebf5bb2023-12-18 15:42:43 -0800383 unit_type,
384 comment.replace('"', '""'))
Yu Shan8ddd65d2023-06-28 17:02:29 -0700385
386 with open(output, 'w+') as f:
387 f.write(content)
388
Yu Shan63e24d72022-06-24 17:53:32 +0000389
Yu Shan41dd7f12023-06-07 13:25:43 -0700390def createTempFile():
391 f = tempfile.NamedTemporaryFile(delete=False);
392 f.close();
393 return f.name
394
395
Yu Shan7881e822023-12-15 13:12:01 -0800396class GeneratedFile:
397
398 def __init__(self, type):
399 self.type = type
400 self.cpp_file_path = None
401 self.java_file_path = None
402 self.cpp_header = None
403 self.java_header = None
404 self.cpp_footer = None
405 self.java_footer = None
406 self.cpp_output_file = None
407 self.java_output_file = None
408
409 def setCppFilePath(self, cpp_file_path):
410 self.cpp_file_path = cpp_file_path
411
412 def setJavaFilePath(self, java_file_path):
413 self.java_file_path = java_file_path
414
415 def setCppHeader(self, cpp_header):
416 self.cpp_header = cpp_header
417
418 def setCppFooter(self, cpp_footer):
419 self.cpp_footer = cpp_footer
420
421 def setJavaHeader(self, java_header):
422 self.java_header = java_header
423
424 def setJavaFooter(self, java_footer):
425 self.java_footer = java_footer
426
427 def convert(self, file_parser, check_only, temp_files):
428 if self.cpp_file_path:
429 output_file = GeneratedFile._getOutputFile(self.cpp_file_path, check_only, temp_files)
430 file_parser.convert(output_file, self.cpp_header, self.cpp_footer, True, self.type)
431 self.cpp_output_file = output_file
432
433 if self.java_file_path:
434 output_file = GeneratedFile._getOutputFile(self.java_file_path, check_only, temp_files)
435 file_parser.convert(output_file, self.java_header, self.java_footer, False, self.type)
436 self.java_output_file = output_file
437
438 def cmp(self):
439 if self.cpp_file_path:
440 if not filecmp.cmp(self.cpp_output_file, self.cpp_file_path):
441 return False
442
443 if self.java_file_path:
444 if not filecmp.cmp(self.java_output_file, self.java_file_path):
445 return False
446
447 return True
448
449 @staticmethod
450 def _getOutputFile(file_path, check_only, temp_files):
451 if not check_only:
452 return file_path
453
454 temp_file = createTempFile()
455 temp_files.append(temp_file)
456 return temp_file
457
458
Yu Shan63e24d72022-06-24 17:53:32 +0000459def main():
Yu Shan41dd7f12023-06-07 13:25:43 -0700460 parser = argparse.ArgumentParser(
461 description='Generate Java and C++ enums based on annotations in VehicleProperty.aidl')
462 parser.add_argument('--android_build_top', required=False, help='Path to ANDROID_BUILD_TOP')
Yu Shanb1fc8c92023-08-30 11:51:04 -0700463 parser.add_argument('--preupload_files', nargs='*', required=False, help='modified files')
Yu Shan41dd7f12023-06-07 13:25:43 -0700464 parser.add_argument('--check_only', required=False, action='store_true',
465 help='only check whether the generated files need update')
Yu Shan8ddd65d2023-06-28 17:02:29 -0700466 parser.add_argument('--output_csv', required=False,
467 help='Path to the parsing result in CSV style, useful for doc generation')
Yu Shan41dd7f12023-06-07 13:25:43 -0700468 args = parser.parse_args();
469 android_top = None
470 output_folder = None
471 if args.android_build_top:
472 android_top = args.android_build_top
473 vehiclePropertyUpdated = False
474 for preuload_file in args.preupload_files:
475 if preuload_file.endswith('VehicleProperty.aidl'):
476 vehiclePropertyUpdated = True
477 break
478 if not vehiclePropertyUpdated:
479 return
480 else:
481 android_top = os.environ['ANDROID_BUILD_TOP']
Yu Shan63e24d72022-06-24 17:53:32 +0000482 if not android_top:
Tyler Trephana1828f92023-10-06 02:39:13 +0000483 print('ANDROID_BUILD_TOP is not in environmental variable, please run source and lunch ' +
Yu Shan41dd7f12023-06-07 13:25:43 -0700484 'at the android root')
Yu Shan63e24d72022-06-24 17:53:32 +0000485
486 aidl_file = os.path.join(android_top, PROP_AIDL_FILE_PATH)
Yu Shan8ddd65d2023-06-28 17:02:29 -0700487 f = FileParser();
488 f.parseFile(aidl_file)
489
490 if args.output_csv:
491 f.outputAsCsv(args.output_csv)
492 return
Yu Shan63e24d72022-06-24 17:53:32 +0000493
Yu Shan7881e822023-12-15 13:12:01 -0800494 generated_files = []
495
496 change_mode = GeneratedFile('change_mode')
497 change_mode.setCppFilePath(os.path.join(android_top, CHANGE_MODE_CPP_FILE_PATH))
498 change_mode.setJavaFilePath(os.path.join(android_top, CHANGE_MODE_JAVA_FILE_PATH))
499 change_mode.setCppHeader(CHANGE_MODE_CPP_HEADER)
500 change_mode.setCppFooter(CPP_FOOTER)
501 change_mode.setJavaHeader(CHANGE_MODE_JAVA_HEADER)
502 change_mode.setJavaFooter(JAVA_FOOTER)
503 generated_files.append(change_mode)
504
505 access_mode = GeneratedFile('access_mode')
506 access_mode.setCppFilePath(os.path.join(android_top, ACCESS_CPP_FILE_PATH))
507 access_mode.setJavaFilePath(os.path.join(android_top, ACCESS_JAVA_FILE_PATH))
508 access_mode.setCppHeader(ACCESS_CPP_HEADER)
509 access_mode.setCppFooter(CPP_FOOTER)
510 access_mode.setJavaHeader(ACCESS_JAVA_HEADER)
511 access_mode.setJavaFooter(JAVA_FOOTER)
512 generated_files.append(access_mode)
513
514 enum_types = GeneratedFile('enum_types')
515 enum_types.setJavaFilePath(os.path.join(android_top, ENUM_JAVA_FILE_PATH))
516 enum_types.setJavaHeader(ENUM_JAVA_HEADER)
517 enum_types.setJavaFooter(JAVA_FOOTER)
518 generated_files.append(enum_types)
519
Tyler Trephanc8a50de2024-01-19 22:50:03 +0000520 unit_type = GeneratedFile('unit_type')
521 unit_type.setJavaFilePath(os.path.join(android_top, UNITS_JAVA_FILE_PATH))
522 unit_type.setJavaHeader(UNITS_JAVA_HEADER)
523 unit_type.setJavaFooter(JAVA_FOOTER)
524 generated_files.append(unit_type)
525
Yu Shan7881e822023-12-15 13:12:01 -0800526 version = GeneratedFile('version')
527 version.setCppFilePath(os.path.join(android_top, VERSION_CPP_FILE_PATH))
528 version.setCppHeader(VERSION_CPP_HEADER)
529 version.setCppFooter(CPP_FOOTER)
530 generated_files.append(version)
531
Yu Shan41dd7f12023-06-07 13:25:43 -0700532 temp_files = []
533
Yu Shan41dd7f12023-06-07 13:25:43 -0700534 try:
Yu Shan7881e822023-12-15 13:12:01 -0800535 for generated_file in generated_files:
536 generated_file.convert(f, args.check_only, temp_files)
Yu Shan41dd7f12023-06-07 13:25:43 -0700537
538 if not args.check_only:
539 return
540
Yu Shan7881e822023-12-15 13:12:01 -0800541 for generated_file in generated_files:
542 if not generated_file.cmp():
543 print('The generated enum files for VehicleProperty.aidl requires update, ')
544 print('Run \npython ' + android_top + '/' + SCRIPT_PATH)
545 sys.exit(1)
Yu Shan41dd7f12023-06-07 13:25:43 -0700546 except Exception as e:
547 print('Error parsing VehicleProperty.aidl')
548 print(e)
549 sys.exit(1)
550 finally:
551 for file in temp_files:
552 os.remove(file)
Yu Shan63e24d72022-06-24 17:53:32 +0000553
554
Yu Shan41dd7f12023-06-07 13:25:43 -0700555if __name__ == '__main__':
Yu Shan63e24d72022-06-24 17:53:32 +0000556 main()