mirror of
https://github.com/nasa/fprime-tools.git
synced 2025-12-10 00:06:11 -06:00
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:
parent
13988d6fdd
commit
1be03f434d
@ -6,6 +6,7 @@ Processing and CLI entry points for `fprime-util impl` command line tool.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import glob
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
@ -79,6 +80,7 @@ def fpp_generate_implementation(
|
||||
apply_formatting: bool,
|
||||
generate_ut: bool,
|
||||
generate_test_helpers: bool = False,
|
||||
overwrite: bool = False,
|
||||
) -> int:
|
||||
"""
|
||||
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
|
||||
generate_ut: Generates UT files 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 = [
|
||||
@ -137,6 +140,12 @@ def fpp_generate_implementation(
|
||||
if generate_ut:
|
||||
_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
|
||||
|
||||
|
||||
@ -164,6 +173,7 @@ def run_fpp_impl(
|
||||
not parsed.no_format,
|
||||
parsed.ut,
|
||||
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.",
|
||||
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}
|
||||
|
||||
@ -28,13 +28,14 @@ def run_impl(build: Build, source_path: Path):
|
||||
print("Refreshing cache and generating implementation files...")
|
||||
|
||||
with suppress_stdout():
|
||||
fpp_generate_implementation(build, source_path, source_path, True, False)
|
||||
|
||||
# Path(source_path).
|
||||
file_list = glob.glob(f"{source_path}/*.template.*pp", recursive=False)
|
||||
for filename in file_list:
|
||||
new_filename = filename.replace(".template", "")
|
||||
os.rename(filename, new_filename)
|
||||
fpp_generate_implementation(
|
||||
build,
|
||||
source_path,
|
||||
source_path,
|
||||
apply_formatting=True,
|
||||
generate_ut=False,
|
||||
overwrite=True,
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user