Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement impl with fpp-to-cpp #171

Merged
merged 17 commits into from
Oct 26, 2023
9 changes: 9 additions & 0 deletions src/fprime/fbuild/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ def is_project_root(self, context: Path) -> bool:
except CMakeException:
return False

def is_submodule_build_structure(self) -> bool:
"""Returns whether the F´ source code is a parent of the build.

Returns:
bool: True if the F´ code is a externally linked directory (e.g. a submodule)
False if the build is self-contained within the F´ code (e.g. the Ref app)
"""
return self.get_settings("framework_path", "") not in self.cmake_root.parents

def find_toolchain(self):
"""Locates a toolchain file in know locations

Expand Down
3 changes: 2 additions & 1 deletion src/fprime/fpp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def execute(
]
else:
input_args.extend(["-i", ",".join(map(str, imports))] if imports else [])
input_args.extend(sources)
input_args.extend([str(source) for source in sources])
input_args.append(str(locations))
thomas-bc marked this conversation as resolved.
Show resolved Hide resolved

user_args = args[1]
app_args = [self.utility] + user_args + input_args
Expand Down
20 changes: 9 additions & 11 deletions src/fprime/fpp/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def fpp_generate_implementation(
output_dir: Path,
context: Path,
apply_formatting: bool,
ut: bool,
generate_ut: bool,
auto_test_helpers: bool = False,
) -> int:
"""
Expand All @@ -42,18 +42,16 @@ def fpp_generate_implementation(
prefixes = [
build.get_settings("framework_path", ""),
*build.get_settings("library_locations", []),
build.cmake_root,
build.build_dir / "F-Prime",
build.build_dir,
]
if build.is_submodule_build_structure():
Copy link
Collaborator

@LeStarch LeStarch Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Also, this should not use "cmake root", but build.get_settings("project_path") should it not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes absolutely, my mistake. By using project_root, we don't need to check whether the build structure is old or new, as project_root and framework_path will simply be the same. Note, both of these values are guaranteed to exist as per the following:
https://github.com/fprime-community/fprime-tools/blob/4fc88dc0a20fcadd5b09bb5a188bc41373237d5d/src/fprime/fbuild/settings.py#L52-L53

since find_fprime will error out if it can't find framework_location

prefixes.append(build.cmake_root)

# Holds the list of generated files to be passed to clang-format
gen_files = tempfile.NamedTemporaryFile(prefix="fprime-impl-")

output_path = Path(output_dir)
if ut:
output_path = output_path / "test/ut"
output_path.mkdir(parents=True, exist_ok=True)
output_dir.mkdir(parents=True, exist_ok=True)

# Run fpp-to-cpp --template
FppUtility("fpp-to-cpp", imports_as_sources=False).execute(
Expand All @@ -63,12 +61,12 @@ def fpp_generate_implementation(
{},
[
"--template",
*(["--unit-test"] if ut else []),
*(["--unit-test"] if generate_ut else []),
*(["--auto-test-helpers"] if auto_test_helpers else []),
"--names",
gen_files.name,
"--directory",
output_path,
output_dir,
"--path-prefixes",
",".join(map(str, prefixes)),
],
Expand All @@ -88,7 +86,7 @@ def fpp_generate_implementation(
for line in gen_files.readlines():
# FPP --names outputs a list of file names. output_dir is added to get relative path
filename = Path(line.decode("utf-8").strip())
clang_formatter.stage_file(output_path / filename)
clang_formatter.stage_file(output_dir / filename)
clang_formatter.execute(None, None, ({}, []))

return 0
Expand All @@ -113,8 +111,8 @@ def run_fpp_impl(

return fpp_generate_implementation(
build,
parsed.output_dir,
parsed.path,
Path(parsed.output_dir),
Path(parsed.path),
not parsed.no_format,
parsed.ut,
parsed.auto_test_helpers,
Expand Down