Skip to content

Commit 6e1ace0

Browse files
Fix fprime-util purge error on broken directory (nasa#247)
* Fixes fprime-util purge error on broken directory * Fixed file creation and formatting * Refactored nested conditional * Fixed formatting * Remove empty directory check * Update src/fprime/fbuild/cmake.py Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com> * Update src/fprime/fbuild/builder.py Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com> * Updated tests --------- Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com>
1 parent 25c133f commit 6e1ace0

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

src/fprime/fbuild/builder.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,27 +110,32 @@ def load(self, platform: str = None, build_dir: Path = None, skip_validation=Fal
110110
InvalidBuildCacheException: the build cache does not exist as it must
111111
"""
112112
self.__setup_default(platform, build_dir)
113-
if not skip_validation and (
114-
not self.build_dir.exists()
115-
or not (self.build_dir / "CMakeCache.txt").exists()
113+
114+
if skip_validation:
115+
return
116+
if (
117+
self.build_dir is not None
118+
and (self.build_dir / ".fprime-build-dir").exists()
116119
):
117-
# Message for hard-supplied --build-cache message
118-
if build_dir is not None:
119-
gen_args = f" --build-cache {build_dir}"
120-
else:
121-
gen_args = " --ut" if self.build_type == BuildType.BUILD_TESTING else ""
122-
gen_args += (
123-
" " + platform
124-
if platform is not None
125-
and platform != "native"
126-
and platform != "default"
127-
else ""
128-
)
129-
msg = f"'{self.build_dir}' is not a valid build cache. Generate this build cache with 'fprime-util generate{gen_args} ...'"
130-
raise InvalidBuildCacheException(
131-
msg,
132-
self.build_dir,
120+
return
121+
122+
# Message for hard-supplied --build-cache message
123+
if build_dir is not None:
124+
gen_args = f" --build-cache {build_dir}"
125+
else:
126+
gen_args = " --ut" if self.build_type == BuildType.BUILD_TESTING else ""
127+
gen_args += (
128+
" " + platform
129+
if platform is not None
130+
and platform != "native"
131+
and platform != "default"
132+
else ""
133133
)
134+
msg = f"'{self.build_dir}' is not a valid build cache. Generate this build cache with 'fprime-util generate{gen_args} ...'"
135+
raise InvalidBuildCacheException(
136+
msg,
137+
self.build_dir,
138+
)
134139

135140
def get_settings(
136141
self,

src/fprime/fbuild/cmake.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import functools
1515
import itertools
1616
import os
17+
from pathlib import Path
1718
import pty
1819
import re
1920
import selectors
@@ -280,6 +281,8 @@ def generate_build(
280281
),
281282
args.keys(),
282283
)
284+
# Creating a file to mark the directory as a F Prime directory
285+
(Path(build_dir) / ".fprime-build-dir").touch()
283286
self.cmake_validate_source_dir(source_dir)
284287
self._run_cmake(
285288
["-S", source_dir] + list(fleshed_args),

test/fprime/fbuild/test_build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def test_hash_finder():
4646
builder = fprime.fbuild.builder.Build(
4747
fprime.fbuild.builder.BuildType.BUILD_NORMAL, dep_dir
4848
)
49-
builder.load(local, build_dir=dep_dir / "build-fprime-automatic-native")
49+
builder.load(
50+
local, build_dir=dep_dir / "build-fprime-automatic-native", skip_validation=True
51+
)
5052

5153
assert builder.find_hashed_file(0xDEADBEEF) == ["Abc: 0xdeadbeef\n"]
5254
assert builder.find_hashed_file(0xC0DEC0DE) == ["HJK: 0xc0dec0de\n"]

test/fprime/fbuild/test_cmake.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
""" Test CMake interaction
1+
"""Test CMake interaction
22
33
This file contains a set of tests for validating CMake interaction on the back-end of fprime-util. These tests poke at
44
the CMakeHandler component.
55
"""
6+
67
import json
78
import os
89
import shutil
@@ -460,6 +461,7 @@ def test_refresh_cache_noop_with_environment(cmake_handler):
460461

461462
@patch("os.makedirs")
462463
@patch("os.path.exists")
464+
@patch("pathlib.Path.touch")
463465
@patch("fprime.fbuild.cmake.CMakeHandler.cmake_validate_source_dir")
464466
@patch("fprime.fbuild.cmake.CMakeHandler._run_cmake")
465467
def generate_build(
@@ -468,6 +470,7 @@ def generate_build(
468470
cmake_handler,
469471
mock_run_cmake,
470472
mock_validate_source_dir,
473+
mock_touch,
471474
mock_path_exists,
472475
mock_makedirs,
473476
**kwargs,
@@ -493,6 +496,9 @@ def generate_build(
493496
# Call the generate_build function
494497
cmake_handler.generate_build(source_dir, build_dir, **kwargs)
495498

499+
# Asset that the touch method was called once
500+
mock_touch.assert_called_once()
501+
496502
# Assert that cmake_validate_source_dir was called with the correct source_dir
497503
mock_validate_source_dir.assert_called_once_with(source_dir)
498504

0 commit comments

Comments
 (0)