syntax check: update header guard check

Internal headers should use #pragma once instead of the standard #ifndef
guard. Public headers still require the existing header guard.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Jonathon Jongsma 2019-06-19 14:48:36 -05:00 committed by Ján Tomko
parent 63acb7bfd5
commit 34c9a5fc06

View File

@ -6,18 +6,26 @@
# ...copyright header... # ...copyright header...
# */ # */
# <one blank line> # <one blank line>
# #ifndef SYMBOL # #pragma once
# # define SYMBOL
# ....content.... # ....content....
# #endif /* SYMBOL */
# #
# For any file ending priv.h, before the #ifndef #---
#
# For any file ending priv.h, before the #pragma once
# We will have a further section # We will have a further section
# #
# #ifndef SYMBOL_ALLOW # #ifndef SYMBOL_ALLOW
# # error .... # # error ....
# #endif /* SYMBOL_ALLOW */ # #endif /* SYMBOL_ALLOW */
# <one blank line> # <one blank line>
#
#---
#
# For public headers (files in include/), use the standard header guard instead of #pragma once:
# #ifndef SYMBOL
# # define SYMBOL
# ....content....
# #endif /* SYMBOL */
use strict; use strict;
use warnings; use warnings;
@ -38,6 +46,7 @@ my $file = " ";
my $ret = 0; my $ret = 0;
my $ifdef = ""; my $ifdef = "";
my $ifdefpriv = ""; my $ifdefpriv = "";
my $publicheader = 0;
my $state = $STATE_EOF; my $state = $STATE_EOF;
my $mistake = 0; my $mistake = 0;
@ -64,7 +73,11 @@ while (<>) {
} elsif ($state == $STATE_PRIV_BLANK) { } elsif ($state == $STATE_PRIV_BLANK) {
&mistake("$file: missing blank line after priv header check"); &mistake("$file: missing blank line after priv header check");
} elsif ($state == $STATE_GUARD_START) { } elsif ($state == $STATE_GUARD_START) {
&mistake("$file: missing '#ifndef $ifdef'"); if ($publicheader) {
&mistake("$file: missing '#ifndef $ifdef'");
} else {
&mistake("$file: missing '#pragma once' header guard");
}
} elsif ($state == $STATE_GUARD_DEFINE) { } elsif ($state == $STATE_GUARD_DEFINE) {
&mistake("$file: missing '# define $ifdef'"); &mistake("$file: missing '# define $ifdef'");
} elsif ($state == $STATE_GUARD_END) { } elsif ($state == $STATE_GUARD_END) {
@ -83,6 +96,7 @@ while (<>) {
$file = $ARGV; $file = $ARGV;
$state = $STATE_COPYRIGHT_COMMENT; $state = $STATE_COPYRIGHT_COMMENT;
$mistake = 0; $mistake = 0;
$publicheader = ($ARGV =~ /include\//);
} }
if ($mistake || if ($mistake ||
@ -133,12 +147,19 @@ while (<>) {
} elsif ($state == $STATE_GUARD_START) { } elsif ($state == $STATE_GUARD_START) {
if (/^$/) { if (/^$/) {
&mistake("$file: too many blank lines after copyright header"); &mistake("$file: too many blank lines after copyright header");
} elsif(/#pragma once/) { }
$state = $STATE_PRAGMA; if ($publicheader) {
} elsif (/#ifndef $ifdef$/) { if (/#ifndef $ifdef$/) {
$state = $STATE_GUARD_DEFINE; $state = $STATE_GUARD_DEFINE;
} else {
&mistake("$file: missing '#ifndef $ifdef'");
}
} else { } else {
&mistake("$file: missing '#ifndef $ifdef'"); if (/#pragma once/) {
$state = $STATE_PRAGMA;
} else {
&mistake("$file: missing '#pragma once' header guard");
}
} }
} elsif ($state == $STATE_GUARD_DEFINE) { } elsif ($state == $STATE_GUARD_DEFINE) {
if (/# define $ifdef$/) { if (/# define $ifdef$/) {