Skip to content

Commit 4a6710c

Browse files
committed
ci: add a includes-check workflow that runs include-what-you-use on the firmware sources
1 parent e9986d4 commit 4a6710c

7 files changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Check includes
2+
on: [push, pull_request]
3+
4+
jobs:
5+
includes-check:
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
board: ['HACKRF_ONE', 'JAWBREAKER', 'RAD1O', 'PRALINE']
10+
cmake: ['3.10.0', 'latest']
11+
12+
# Don't cancel all builds when one fails
13+
fail-fast: false
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
submodules: true
19+
20+
- name: Setup cmake
21+
uses: jwlawson/actions-setup-cmake@v2
22+
with:
23+
cmake-version: ${{ matrix.cmake }}
24+
25+
- name: Install Arm GNU Toolchain
26+
uses: carlosperate/arm-none-eabi-gcc-action@v1
27+
28+
- name: Install dependencies
29+
run: |
30+
python3 -m venv environment && source environment/bin/activate
31+
python3 -m pip install PyYAML
32+
sudo apt update
33+
sudo apt install iwyu
34+
35+
- name: Build libopencm3
36+
shell: bash
37+
working-directory: ${{github.workspace}}/firmware/libopencm3/
38+
run: |
39+
source ../../environment/bin/activate
40+
make
41+
42+
- name: Create Build Environment
43+
run: cmake -E make_directory ${{github.workspace}}/firmware/build
44+
45+
- name: Configure CMake
46+
shell: bash
47+
working-directory: ${{github.workspace}}/firmware/build
48+
run: cmake $GITHUB_WORKSPACE/firmware/ -DCMAKE_BUILD_TYPE=Release -DBOARD=${{ matrix.board }} -DCHECK_INCLUDES=1
49+
50+
- name: Build
51+
working-directory: ${{github.workspace}}/firmware/build
52+
shell: bash
53+
run: |
54+
source ../../environment/bin/activate
55+
output="$(cmake --build . --config Release 2>&1)"
56+
while IFS= read -r line
57+
do
58+
if [[ "${line}" == "Warning: include-what-you-use"* ]]; then
59+
exit_code=1
60+
dump=1
61+
elif [[ "${line}" == "---" ]]; then
62+
dump=0
63+
fi
64+
if [[ ${dump} == "1" ]]; then
65+
echo "${line}"
66+
fi
67+
done <<< ${output}
68+
if [[ ${exit_code} == "1" ]]; then
69+
echo "Includes check failed for board target: ${{ matrix.board }}"
70+
else
71+
echo "Includes check succeeded for board target: ${{ matrix.board }}"
72+
fi
73+
echo $(include-what-you-use --version)
74+
exit ${exit_code}

firmware/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@
2020

2121
# Top directory CMake project for HackRF firmware
2222

23+
option(CHECK_INCLUDES
24+
"Check firmware sources for unused includes and transitive dependencies. (Requires iwyu)" OFF)
25+
2326
cmake_minimum_required(VERSION 3.10.0)
2427
set(CMAKE_TOOLCHAIN_FILE toolchain-arm-cortex-m.cmake)
2528

2629
project (hackrf_firmware_all C)
2730

31+
if(CHECK_INCLUDES)
32+
include(include-what-you-use.cmake)
33+
endif()
34+
2835
add_subdirectory(blinky)
2936
add_subdirectory(hackrf_usb)

firmware/common/fpga.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "fpga.h"
2323

2424
#include <stdbool.h>
25+
#include <stddef.h> // TODO for testing the PR
2526

2627
#include "fpga_regs.def"
2728
#include "hackrf_core.h"

firmware/common/hackrf_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "delay.h"
3333
#include "gpio.h"
34+
#include "gpio_lpc.h"
3435
#include "hackrf_core.h"
3536
#include "hackrf_ui.h"
3637
#include "i2c_lpc.h"

firmware/common/rad1o/smallfonts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
/* Partially based on original code for the KS0108 by Stephane Rey */
4242
/* Current version by Kevin Townsend */
4343

44+
#include "rad1o/fonts.h"
45+
4446
extern const struct FONT_DEF Font_7x8;
4547

4648
#endif

firmware/common/rad1o/ubuntu18.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef __RAD1O_UBUNTU18_H__
22
#define __RAD1O_UBUNTU18_H__
33

4+
#include "rad1o/fonts.h"
5+
46
extern const struct FONT_DEF Font_Ubuntu18pt;
57

68
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2026 Great Scott Gadgets <info@greatscottgadgets.com>
2+
#
3+
# This file is part of HackRF.
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation; either version 2, or (at your option)
8+
# any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program; see the file COPYING. If not, write to
17+
# the Free Software Foundation, Inc., 51 Franklin Street,
18+
# Boston, MA 02110-1301, USA.
19+
#
20+
21+
cmake_minimum_required(VERSION 3.10.0)
22+
23+
find_program(IWYU_COMMAND NAMES include-what-you-use)
24+
if(NOT IWYU_COMMAND)
25+
message(FATAL_ERROR "Could not find the include-what-you-use executable.")
26+
endif()
27+
28+
# include-what-you-use arguments:
29+
#
30+
# --no_fwd_decls - Disable forward declaration suggestions.
31+
# --mapping_file - Specify mapping files for excluding suggestions.
32+
#
33+
list(APPEND IWYU_COMMAND
34+
-Xiwyu --no_fwd_decls
35+
-Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/libopencm3.imp)
36+
37+
set(CMAKE_C_INCLUDE_WHAT_YOU_USE ${IWYU_COMMAND})
38+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_COMMAND})

0 commit comments

Comments
 (0)