Add --overwrite flag to impl command (#259)

* Update impl.py

* Update src/fprime/fpp/impl.py

Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com>

* Update impl.py

* Update impl.py

* Fix code and re-apply commit without rebase

---------

Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com>
Co-authored-by: thomas-bc <thomas.boyerchammard@gmail.com>
This commit is contained in:
Tanuj Rai 2025-08-21 06:13:57 +05:30 committed by GitHub
parent 13988d6fdd
commit 1be03f434d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 7 deletions

View File

@ -6,6 +6,7 @@ Processing and CLI entry points for `fprime-util impl` command line tool.
""" """
import argparse import argparse
import glob
import os import os
import tempfile import tempfile
from pathlib import Path from pathlib import Path
@ -79,6 +80,7 @@ def fpp_generate_implementation(
apply_formatting: bool, apply_formatting: bool,
generate_ut: bool, generate_ut: bool,
generate_test_helpers: bool = False, generate_test_helpers: bool = False,
overwrite: bool = False,
) -> int: ) -> int:
""" """
Generate implementation files from FPP templates. Generate implementation files from FPP templates.
@ -90,6 +92,7 @@ def fpp_generate_implementation(
apply_formatting: Whether to format the generated files using clang-format apply_formatting: Whether to format the generated files using clang-format
generate_ut: Generates UT files if set to True generate_ut: Generates UT files if set to True
generate_test_helpers: Generate of test helper code if set to True generate_test_helpers: Generate of test helper code if set to True
overwrite: Overwrite existing implementation files if set to True
""" """
prefixes = [ prefixes = [
@ -137,6 +140,12 @@ def fpp_generate_implementation(
if generate_ut: if generate_ut:
_move_ut_templates(output_dir, generated_file_names) _move_ut_templates(output_dir, generated_file_names)
if overwrite:
file_list = glob.glob(f"{output_dir}/*.template.*pp", recursive=False)
for filename in file_list:
new_filename = filename.replace(".template", "")
os.rename(filename, new_filename)
return 0 return 0
@ -164,6 +173,7 @@ def run_fpp_impl(
not parsed.no_format, not parsed.no_format,
parsed.ut, parsed.ut,
parsed.generate_test_helpers, parsed.generate_test_helpers,
parsed.overwrite,
) )
@ -207,4 +217,11 @@ def add_fpp_impl_parsers(
help="Generate test helper code for hand-coding. Default to False, leveraging the test helpers autocoded by FPP.", help="Generate test helper code for hand-coding. Default to False, leveraging the test helpers autocoded by FPP.",
required=False, required=False,
) )
impl_parser.add_argument(
"--overwrite",
action="store_true",
default=False,
help="Overwrite contents of current CPP and HPP files. Use with caution.",
required=False,
)
return {"impl": run_fpp_impl}, {"impl": impl_parser} return {"impl": run_fpp_impl}, {"impl": impl_parser}

View File

@ -28,13 +28,14 @@ def run_impl(build: Build, source_path: Path):
print("Refreshing cache and generating implementation files...") print("Refreshing cache and generating implementation files...")
with suppress_stdout(): with suppress_stdout():
fpp_generate_implementation(build, source_path, source_path, True, False) fpp_generate_implementation(
build,
# Path(source_path). source_path,
file_list = glob.glob(f"{source_path}/*.template.*pp", recursive=False) source_path,
for filename in file_list: apply_formatting=True,
new_filename = filename.replace(".template", "") generate_ut=False,
os.rename(filename, new_filename) overwrite=True,
)
return True return True