diff --git a/dev_scripts/codegen/codegen.py b/dev_scripts/codegen/codegen.py index 632f2163..8c9fbe5a 100644 --- a/dev_scripts/codegen/codegen.py +++ b/dev_scripts/codegen/codegen.py @@ -10,7 +10,7 @@ def _generate_sdk( meta_model_path: pathlib.Path, snippet_path: pathlib.Path, - sdk_path: pathlib.Path, + target_path: pathlib.Path, ) -> None: subprocess.run( [ @@ -20,7 +20,7 @@ def _generate_sdk( "--snippets_dir", str(snippet_path), "--output_dir", - str(sdk_path / "src"), + target_path, "--target", "cpp", ], @@ -39,7 +39,7 @@ def main() -> int: snippet_dir = this_dir / "snippets" - _generate_sdk(args.meta_model, snippet_dir, this_dir.parent.parent) + _generate_sdk(args.meta_model, snippet_dir, args.target) return 0 diff --git a/dev_scripts/update_to_aas_core_meta_codegen.py b/dev_scripts/update_to_aas_core_meta_codegen.py index e657ea73..1f889064 100644 --- a/dev_scripts/update_to_aas_core_meta_codegen.py +++ b/dev_scripts/update_to_aas_core_meta_codegen.py @@ -57,29 +57,45 @@ def _regenerate_code(our_repo: pathlib.Path) -> Optional[int]: meta_model_path = our_repo / "dev_scripts/codegen/meta_model.py" - target_dir = our_repo - print("Starting to run codegen script") - start = time.perf_counter() - - proc = subprocess.run( - [ - sys.executable, - "codegen.py", - "--meta_model", - str(meta_model_path), - "--target", - str(target_dir), - ], - check=True, - cwd=str(codegen_dir), - ) - if proc.returncode != 0: - return proc.returncode + with tempfile.TemporaryDirectory() as generate_dir_path: + start = time.perf_counter() + + generate_dir = pathlib.Path(generate_dir_path) + + proc = subprocess.run( + [ + sys.executable, + "codegen.py", + "--meta_model", + str(meta_model_path), + "--target", + str(generate_dir), + ], + check=True, + cwd=str(codegen_dir), + ) + + if proc.returncode != 0: + return proc.returncode + + duration = time.perf_counter() - start + print(f"Generating the code took: {duration:.2f} seconds.") + + for pth in generate_dir.glob("**/*.cpp"): + target_dir = our_repo / "src" + tgt_pth = target_dir / pth.relative_to(generate_dir) + + print(f"Copying the code: from {pth} to {tgt_pth} ...") + shutil.copy(pth, tgt_pth) + + for pth in generate_dir.glob("**/*.hpp"): + target_dir = our_repo / "include/aas_core/aas_3_0" + tgt_pth = target_dir / pth.relative_to(generate_dir) - duration = time.perf_counter() - start - print(f"Generating the code took: {duration:.2f} seconds.") + print(f"Copying the code: from {pth} to {tgt_pth} ...") + shutil.copy(pth, tgt_pth) return None