Skip to content

dist/tools/headerguards: use regex to check include guard name - #22537

Merged
Enoch247 merged 1 commit into
RIOT-OS:masterfrom
crasbe:pr/fix_headerguard_check
Aug 1, 2026
Merged

dist/tools/headerguards: use regex to check include guard name#22537
Enoch247 merged 1 commit into
RIOT-OS:masterfrom
crasbe:pr/fix_headerguard_check

Conversation

@crasbe

@crasbe crasbe commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Contribution description

The headerguard check tried to find if classic header guards were used by matching the beginning of the line with #ifndef $(filename_with_underscores). So for drivers/abp2/include/abp2_params.h it would try to find #ifndef ABP2_PARAMS_H*.

The issue arises when you have a parameter that has a word starting with H, for example #ifndef ABP2_PARAMS_HWTIMER, creating a false positive.

Instead of matching the line start, I changed it to a RegEx to match either #ifndef ABP2_PARAMS_H or #ifndef ABP2_PARAMS_H_, but nothing else.

Testing procedure

Test for Bug Fixed

Add #ifndef ABP2_PARAMS_HWTIMER to drivers/abp2/include/abp2_params.h and it should not still complain.

Behavior on master, it complains:

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ git diff
diff --git a/drivers/abp2/include/abp2_params.h b/drivers/abp2/include/abp2_params.h
index b5def22f3b..84ea69d97b 100644
--- a/drivers/abp2/include/abp2_params.h
+++ b/drivers/abp2/include/abp2_params.h
@@ -20,6 +20,10 @@
 #include "saul_reg.h"
 #include "abp2.h"

+#ifndef ABP2_PARAMS_HWTIMER
+#  define ABP2_PARAMS_HWTIMER
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ ./dist/tools/headerguards/check.sh
drivers/abp2/include/abp2_params.h: #pragma once and classic header guards used in the same file

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ echo $?
1

Behavior with this PR, it does not complain:

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ git diff
diff --git a/drivers/abp2/include/abp2_params.h b/drivers/abp2/include/abp2_params.h
index b5def22f3b..84ea69d97b 100644
--- a/drivers/abp2/include/abp2_params.h
+++ b/drivers/abp2/include/abp2_params.h
@@ -20,6 +20,10 @@
 #include "saul_reg.h"
 #include "abp2.h"

+#ifndef ABP2_PARAMS_HWTIMER
+#  define ABP2_PARAMS_HWTIMER
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ ./dist/tools/headerguards/check.sh

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ echo $?
0

Test for Regression

  1. Add #ifndef ABP2_PARAMS_H to drivers/abp2/include/abp2_params.h and it should still complain:
cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ git diff
diff --git a/drivers/abp2/include/abp2_params.h b/drivers/abp2/include/abp2_params.h
index b5def22f3b..9e32af8eee 100644
--- a/drivers/abp2/include/abp2_params.h
+++ b/drivers/abp2/include/abp2_params.h
@@ -20,6 +20,10 @@
 #include "saul_reg.h"
 #include "abp2.h"

+#ifndef ABP2_PARAMS_H
+#  define ABP2_PARAMS_H
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ ./dist/tools/headerguards/check.sh
drivers/abp2/include/abp2_params.h: #pragma once and classic header guards used in the same file
  1. Add #ifndef ABP2_PARAMS_H_ to drivers/abp2/include/abp2_params.h and it should still complain:
cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ git diff
diff --git a/drivers/abp2/include/abp2_params.h b/drivers/abp2/include/abp2_params.h
index b5def22f3b..694ab39b57 100644
--- a/drivers/abp2/include/abp2_params.h
+++ b/drivers/abp2/include/abp2_params.h
@@ -20,6 +20,10 @@
 #include "saul_reg.h"
 #include "abp2.h"

+#ifndef ABP2_PARAMS_H_
+#  define ABP2_PARAMS_H_
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif

cbuec@W11nMate:~/RIOTstuff/riot-vanillaice/RIOT$ ./dist/tools/headerguards/check.sh
drivers/abp2/include/abp2_params.h: #pragma once and classic header guards used in the same file

Issues/PRs references

Found in #19848.

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

  • none

@crasbe
crasbe requested a review from Enoch247 August 1, 2026 13:38
@crasbe crasbe added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs AI: Not Used AI was stated to not be used in this PR/Issue labels Aug 1, 2026
@github-actions github-actions Bot added the Area: tools Area: Supplementary tools label Aug 1, 2026
@riot-ci

riot-ci commented Aug 1, 2026

Copy link
Copy Markdown

Murdock results

✔️ PASSED

3ccd898 dist/tools/headerguards: use regex to check include guard name

Success Failures Total Runtime
1 0 1 01m:17s

Artifacts

@Enoch247 Enoch247 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I trust the test cases you already checked, and did not re-run them. I did run a few of my own though:

This should pass, and does:

josh@dragonkite:fix_headerguard_check$ git diff
diff --git a/drivers/abp2/include/abp2_params.h b/drivers/abp2/include/abp2_params.h
index b5def22f3b..652eed3fd4 100644
--- a/drivers/abp2/include/abp2_params.h
+++ b/drivers/abp2/include/abp2_params.h
@@ -3,7 +3,8 @@
  * SPDX-License-Identifier: LGPL-2.1-only
  */
 
-#pragma once
+#ifndef ABP2_PARAMS_H
+#define ABP2_PARAMS_H
 
 /**
  * @ingroup     drivers_abp2
@@ -112,3 +113,5 @@ static const saul_reg_info_t abp2_saul_info[][2] =
 #endif
 
 /** @} */
+
+#endif /* ABP2_PARAMS_H */
josh@dragonkite:fix_headerguard_check$ ./dist/tools/headerguards/check.sh
josh@dragonkite:fix_headerguard_check$

This should fail, and does:

josh@dragonkite:fix_headerguard_check$ git diff
diff --git a/drivers/abp2/include/abp2_params.h b/drivers/abp2/include/abp2_params.h
index b5def22f3b..252b86809d 100644
--- a/drivers/abp2/include/abp2_params.h
+++ b/drivers/abp2/include/abp2_params.h
@@ -5,6 +5,9 @@
 
 #pragma once
 
+#ifndef ABP2_PARAMS_H
+#define ABP2_PARAMS_H
+
 /**
  * @ingroup     drivers_abp2
  * @{
@@ -112,3 +115,5 @@ static const saul_reg_info_t abp2_saul_info[][2] =
 #endif
 
 /** @} */
+
+#endif /* ABP2_PARAMS_H */
josh@dragonkite:fix_headerguard_check$ ./dist/tools/headerguards/check.sh
drivers/abp2/include/abp2_params.h: #pragma once and classic header guards used in the same file

@Enoch247

Enoch247 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

I should learn to read more carefully. You already provided tests for regression.

@Enoch247
Enoch247 added this pull request to the merge queue Aug 1, 2026
Merged via the queue into RIOT-OS:master with commit 4dbadb0 Aug 1, 2026
33 checks passed
@crasbe
crasbe deleted the pr/fix_headerguard_check branch August 1, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Not Used AI was stated to not be used in this PR/Issue Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants