Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dist tools: header guard checker #6438

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions boards/nucleo32-f303/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*/

#ifndef BOARD_H_
#define BOARD_H_
#ifndef BOARD_H
#define BOARD_H

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -47,5 +47,5 @@ void board_init(void);
}
#endif

#endif /* BOARD_H_ */
#endif /* BOARD_H */
/** @} */
6 changes: 3 additions & 3 deletions boards/nucleo32-f303/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*/

#ifndef PERIPH_CONF_H_
#define PERIPH_CONF_H_
#ifndef PERIPH_CONF_H
#define PERIPH_CONF_H

#include "periph_cpu.h"

Expand Down Expand Up @@ -152,5 +152,5 @@ static const pwm_conf_t pwm_config[] = {
}
#endif

#endif /* PERIPH_CONF_H_ */
#endif /* PERIPH_CONF_H */
/** @} */
6 changes: 3 additions & 3 deletions cpu/native/include/netdev2_tap_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*
* @author Martine Lenders <m.lenders@fu-berlin.de>
*/
#ifndef NETDEV2_TAP_PARAMS_H_
#define NETDEV2_TAP_PARAMS_H_
#ifndef NETDEV2_TAP_PARAMS_H
#define NETDEV2_TAP_PARAMS_H

#include "netdev2_tap.h"

Expand Down Expand Up @@ -46,5 +46,5 @@ extern netdev2_tap_params_t netdev2_tap_params[NETDEV2_TAP_MAX];
}
#endif

#endif /* NETDEV2_TAP_PARAMS_H_ */
#endif /* NETDEV2_TAP_PARAMS_H */
/** @} */
1 change: 1 addition & 0 deletions dist/tools/ci/build_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ then
run ./dist/tools/licenses/check.sh ${CI_BASE_BRANCH} --diff-filter=AC
run ./dist/tools/doccheck/check.sh ${CI_BASE_BRANCH}
run ./dist/tools/externc/check.sh ${CI_BASE_BRANCH}
run ./dist/tools/headerguards/check.sh

# TODO:
# Remove all but `${CI_BASE_BRANCH}` parameters to cppcheck (and remove second
Expand Down
25 changes: 25 additions & 0 deletions dist/tools/headerguards/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

# Copyright 2017 Oliver Hahm <oliver.hahm@inria.fr>
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.

# customizable
DIRS="core drivers pkg sys"
Copy link
Member

Choose a reason for hiding this comment

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

why not boards? If we do the proposed vendor/ include structure, we might also be able to add cpu.

Copy link
Member Author

Choose a reason for hiding this comment

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

True. I saw some warnings and thought they were vendor specific, but actually they can and should be fixed. Will update.


# prepare
EXIT_CODE=0

# check files
if FILES=$(git grep -lE 'ifndef\ +(_.*_H$|.*_H_$)' ${DIRS})
Copy link
Member

Choose a reason for hiding this comment

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

Why not ^# *ifndef? Why not -n instead of -l (I think it's actually beneficial to see line number and the offending #ifndef as well)

Copy link
Member Author

Choose a reason for hiding this comment

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

Why not ^# *ifndef?

What's the advantage?

Why not -n instead of -l (I think it's actually beneficial to see line number and the offending #ifndef as well)

My assessment was exactly the opposite. Too much cluttered information for my taste.

Copy link
Member

Choose a reason for hiding this comment

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

What's the advantage?

Avoiding weird false-positives like e.g.

const struct someweirdtypenameifndef _MY_PRIVATE_CONSTANT_FOR_HEIGHT_H

My assessment was exactly the opposite. Too much cluttered information for my taste.

I'm already annoyed about the doc-checker, that tells me there is a problem in file x, but not what the problem is ;-)

then
EXIT_CODE=1
for LINE in ${FILES}
do
echo "files with invalid header guard (leading or trailing underscore): ${LINE}"
done
fi

exit ${EXIT_CODE}
4 changes: 2 additions & 2 deletions pkg/oonf_api/patches/0001-add-RIOT-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ index 0000000..9bf6622
+ *
+ */
+
+#ifndef RFC5444_API_CONFIG_H_
+#define RFC5444_API_CONFIG_H_
+#ifndef RFC5444_API_CONFIG_H
+#define RFC5444_API_CONFIG_H
+
+#define DISALLOW_CONSUMER_CONTEXT_DROP false
+#define WRITER_STATE_MACHINE true
Expand Down
4 changes: 2 additions & 2 deletions pkg/tlsf/patch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ index 0000000..2d8bb4d
--- /dev/null
+++ tlsf-malloc.h
@@ -0,0 +1,26 @@
+#ifndef __TLSF_MALLOC_H
+#define __TLSF_MALLOC_H
+#ifndef TLSF_MALLOC_H
+#define TLSF_MALLOC_H
+
+#include <stdbool.h>
+#include <stddef.h>
Expand Down
6 changes: 3 additions & 3 deletions sys/include/bloom.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
*/

#ifndef _BLOOM_FILTER_H
#define _BLOOM_FILTER_H
#ifndef BLOOM_FILTER_H
#define BLOOM_FILTER_H

#include <stdlib.h>
#include <stdbool.h>
Expand Down Expand Up @@ -233,4 +233,4 @@ bool bloom_check(bloom_t *bloom, const uint8_t *buf, size_t len);
#endif

/** @} */
#endif /* _BLOOM_FILTER_H */
#endif /* BLOOM_FILTER_H */
4 changes: 2 additions & 2 deletions sys/include/ecc/hamming256.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* @author Lucas Jenß <lucas@x3ro.de>
*/

#ifndef _HAMMING256_H
#define _HAMMING256_H
#ifndef HAMMING256_H
#define HAMMING256_H

#include <stdint.h>

Expand Down
6 changes: 3 additions & 3 deletions sys/include/hashes/sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
/* This code is public-domain - it is based on libcrypt
* placed in the public domain by Wei Dai and other contributors. */

#ifndef _SHA1_H
#define _SHA1_H
#ifndef SHA1_H
#define SHA1_H

#include <stdint.h>

Expand Down Expand Up @@ -118,5 +118,5 @@ void sha1_final_hmac(sha1_context *ctx, void *digest);
}
#endif

#endif /* _SHA1_H */
#endif /* SHA1_H */
/** @} */
6 changes: 3 additions & 3 deletions sys/include/hashes/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
* @author Rene Kijewski
*/

#ifndef _SHA256_H
#define _SHA256_H
#ifndef SHA256_H
#define SHA256_H

#include <inttypes.h>

Expand Down Expand Up @@ -203,4 +203,4 @@ int sha256_chain_verify_element(void *element,
#endif

/** @} */
#endif /* _SHA256_H */
#endif /* SHA256_H */
6 changes: 3 additions & 3 deletions sys/include/uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/

#ifndef UUID_H_
#define UUID_H_
#ifndef UUID_H
#define UUID_H

#include <stddef.h>

Expand Down Expand Up @@ -115,5 +115,5 @@ void uuid_base(void *buf, size_t len);
}
#endif

#endif /* UUID_H_ */
#endif /* UUID_H */
/** @} */
6 changes: 3 additions & 3 deletions sys/posix/include/netinet/in.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef _NETINET_IN_H
#define _NETINET_IN_H
#ifndef NETINET_IN_H
#define NETINET_IN_H

#include <inttypes.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -271,4 +271,4 @@ extern const struct in6_addr in6addr_loopback;
/**
* @}
*/
#endif /* _NETINET_IN_H */
#endif /* NETINET_IN_H */
4 changes: 2 additions & 2 deletions sys/posix/include/sys/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef _SYS_SOCKET_H
#define _SYS_SOCKET_H
#ifndef SYS_SOCKET_H
#define SYS_SOCKET_H

#ifdef CPU_NATIVE
/* Ignore Linux definitions in native */
Expand Down