]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add unused headers check to CI
authorMichal Nowak <mnowak@isc.org>
Fri, 6 Nov 2020 11:28:26 +0000 (12:28 +0100)
committerMichal Nowak <mnowak@isc.org>
Wed, 11 Nov 2020 09:08:12 +0000 (10:08 +0100)
.gitlab-ci.yml
util/copyrights
util/unused-headers.sh [new file with mode: 0755]

index 3e939721b877abb773ae28befad5c4e020a3c924..6c5dee8ac2652d5f9c48670115a0c88f96d078e3 100644 (file)
@@ -466,6 +466,7 @@ misc:
     - sh util/check-win32util-configure
     - sh util/check-categories.sh
     - if git grep SYSTEMTESTTOP -- ':!.gitlab-ci.yml'; then echo 'Please use relative paths instead of $SYSTEMTESTTOP.'; exit 1; fi
+    - bash util/unused-headers.sh
   needs: []
   artifacts:
     paths:
index 1b29c20edf93a6133f52ca15c55305a5a9471d13..161226d4de291cdac326e6ff140ed3b946055d2f 100644 (file)
 ./util/run-clang-tidy                          X       2020
 ./util/spacewhack.pl                           PERL    2000,2001,2004,2007,2012,2016,2018,2019,2020
 ./util/tabify-changes                          SH      2004,2007,2012,2016,2018,2019,2020
+./util/unused-headers.sh                       SH      2020
 ./util/update-drafts.pl                                PERL    2000,2001,2004,2007,2012,2016,2018,2019,2020
 ./util/update_branches                         PERL    2005,2007,2012,2016,2018,2019,2020
 ./util/update_copyrights                       PERL    1998,1999,2000,2001,2004,2005,2006,2007,2008,2009,2010,2012,2013,2014,2015,2016,2017,2018,2019,2020
diff --git a/util/unused-headers.sh b/util/unused-headers.sh
new file mode 100755 (executable)
index 0000000..35af0f6
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+unused_headers=$(
+       git ls-files -- '*.h' ':!:*include*' ':!:*rdata*' ':!:*win32*' |
+       sed 's|.*/\(.*\.h\)|\1|' |
+       while read -r header; do
+               git grep -q "#include \".*${header}\"" || echo "${header}"
+       done
+
+       git ls-files -- '*include/*.h' |
+       sed 's|.*/include\/\(.*\.h\)|\1|' |
+       while read -r header; do
+               git grep -q "#include <${header}>" || echo "${header}"
+       done
+)
+
+if [ -n "${unused_headers}" ]; then
+       echo -e "Following headers are unused:\n${unused_headers}"
+       exit 1
+fi