|
13 | 13 | import sys |
14 | 14 | from concurrent.futures import ProcessPoolExecutor, wait, FIRST_COMPLETED, ALL_COMPLETED |
15 | 15 | from subprocess import list2cmdline, run |
16 | | -from tempfile import NamedTemporaryFile |
17 | 16 |
|
| 17 | +from codegen.format_util import format_directories |
18 | 18 | from codegen.legacy_c2j_cpp_gen import LegacyC2jCppGen |
19 | 19 | from codegen.model_utils import SERVICE_MODEL_FILENAME_PATTERN, ServiceModel, ModelUtils |
20 | 20 |
|
|
31 | 31 | UNSUPPORTED_CLIENTS = {} |
32 | 32 | UNSUPPORTED_TESTS = {} |
33 | 33 |
|
34 | | -CLANG_FORMAT_VERSION = '18.1.6' |
35 | | -CLANG_FORMAT_INCLUDE_REGEX = re.compile(r'^.*\.(cpp|h)$') |
36 | | - |
37 | 34 | # Regexp to parse C2J model filename to extract service name and date version |
38 | 35 | TEST_DEFINITION_FILENAME_PATTERN = re.compile( |
39 | 36 | "^" |
@@ -93,7 +90,7 @@ def generate(self, executor: ProcessPoolExecutor, max_workers: int): |
93 | 90 | if self._generate_test_clients(executor, max_workers) == 0: |
94 | 91 | result = self._generate_tests(executor, max_workers) |
95 | 92 | if result == 0: |
96 | | - self._format_generated_files() |
| 93 | + format_directories([self.generated_test_clients_dir, self.generated_tests_dir]) |
97 | 94 | return result |
98 | 95 | return -1 |
99 | 96 |
|
@@ -316,22 +313,3 @@ def _generate_single_protocol_test(self, models: ProtocolTestModel): |
316 | 313 | dir_to_extract, dir_to_delete) |
317 | 314 |
|
318 | 315 | return name_for_logging, status |
319 | | - |
320 | | - def _format_generated_files(self): |
321 | | - """Format generated C++ files using clang-format""" |
322 | | - filepaths_file = NamedTemporaryFile(delete=False) |
323 | | - |
324 | | - for root_dir in [self.generated_test_clients_dir, self.generated_tests_dir]: |
325 | | - for dirpath, dirnames, filenames in os.walk(root_dir): |
326 | | - for filename in filenames: |
327 | | - filepath = pathlib.Path(dirpath, filename).as_posix() |
328 | | - if CLANG_FORMAT_INCLUDE_REGEX.match(filename): |
329 | | - filepaths_file.write(f"{filepath}\n".encode()) |
330 | | - |
331 | | - filepaths_file.close() |
332 | | - |
333 | | - cmd = ['pipx', 'run', f'clang-format=={CLANG_FORMAT_VERSION}', |
334 | | - f'--files={filepaths_file.name}', '-i', '-style=file:.clang-format'] |
335 | | - |
336 | | - print(f"Formatting generated files: {list2cmdline(cmd)}") |
337 | | - run(cmd) |
0 commit comments