Skip to content

Commit c8337ab

Browse files
committed
feature: add cmake support flag on Board dataclass
1 parent af6cdf3 commit c8337ab

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

ntxbuild/nuttx.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Board:
5151
name: str = None
5252
arch: str = None
5353
soc: str = None
54+
cmake: bool = False
5455
defconfigs: list[Defconfig] = field(default_factory=list)
5556
"""Representation of a NuttX board directory.
5657
@@ -66,6 +67,7 @@ class Board:
6667
provided).
6768
soc: SoC/chip name (inferred from path.parents[0].stem if not
6869
provided).
70+
cmake: Whether the board supports CMake.
6971
defconfigs: List of `Defconfig` objects found under the
7072
`configs/` subdirectory.
7173
"""
@@ -77,6 +79,11 @@ def __post_init__(self):
7779
self.arch = self.path.parents[1].stem
7880
if not self.soc:
7981
self.soc = self.path.parents[0].stem
82+
if not self.cmake:
83+
files = [
84+
f.name == "CMakeLists.txt" for f in self.path.iterdir() if f.is_file()
85+
]
86+
self.cmake = any(files)
8087
self._parse_defconfigs()
8188

8289
def _parse_defconfigs(self):

tests/test_nuttx.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,27 @@ def test_board_get_defconfig(nuttxspace_path: Path):
111111
# Test getting a non-existent defconfig
112112
non_existent = board.get_defconfig("nonexistent_defconfig_xyz")
113113
assert non_existent is None
114+
115+
116+
@pytest.mark.parametrize("board_name", ["nucleo-f746zg", "a2g-tc397-5v-tft", "sim"])
117+
def test_board_supports_cmake(nuttxspace_path: Path, board_name: str):
118+
"""Test Board.cmake property to check CMake support."""
119+
nuttx_repo = nuttxspace_path / "nuttx"
120+
nbe = NuttxBoardExplorer(nuttx_path=nuttx_repo)
121+
nbe.set_board(board_name)
122+
board = nbe.boards[0]
123+
124+
assert board.cmake is True, f"Board {board.path} should support CMake"
125+
126+
127+
@pytest.mark.parametrize(
128+
"board_name", ["arduino-mega2560", "pic32mx7mmb", "esp32-devkitc"]
129+
)
130+
def test_board_does_not_support_cmake(nuttxspace_path: Path, board_name: str):
131+
"""Test Board.cmake property to check CMake support."""
132+
nuttx_repo = nuttxspace_path / "nuttx"
133+
nbe = NuttxBoardExplorer(nuttx_path=nuttx_repo)
134+
nbe.set_board(board_name)
135+
board = nbe.boards[0]
136+
137+
assert board.cmake is False, f"Board {board.path} should not support CMake"

0 commit comments

Comments
 (0)