summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-05-05 09:03:12 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-05-09 08:11:10 +0200
commitc4a090d60e09cd85a56ff91c46ca0f7b22dcd1a8 (patch)
treeb1d566df5cfc08e7fc74d40a7fea806c01d307e7 /tools
parent083e2ba44572a1681bf0b1b6543f13b1e8797532 (diff)
downloadsystemd-c4a090d60e09cd85a56ff91c46ca0f7b22dcd1a8.tar.gz
Rewrite check-includes.pl in python
Diffstat (limited to 'tools')
-rwxr-xr-xtools/check-includes.pl23
-rwxr-xr-xtools/check-includes.py23
2 files changed, 23 insertions, 23 deletions
diff --git a/tools/check-includes.pl b/tools/check-includes.pl
deleted file mode 100755
index c8bfcba8c0..0000000000
--- a/tools/check-includes.pl
+++ /dev/null
@@ -1,23 +0,0 @@
-# SPDX-License-Identifier: CC0-1.0
-#!/usr/bin/env perl
-#
-# checkincludes: Find files included more than once in (other) files.
-
-foreach $file (@ARGV) {
- open(FILE, $file) or die "Cannot open $file: $!.\n";
-
- my %includedfiles = ();
-
- while (<FILE>) {
- if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
- ++$includedfiles{$1};
- }
- }
- foreach $filename (keys %includedfiles) {
- if ($includedfiles{$filename} > 1) {
- print "$file: $filename is included more than once.\n";
- }
- }
-
- close(FILE);
-}
diff --git a/tools/check-includes.py b/tools/check-includes.py
new file mode 100755
index 0000000000..27d11b9d0a
--- /dev/null
+++ b/tools/check-includes.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# pylint: disable=missing-docstring,invalid-name,unspecified-encoding,consider-using-with
+
+import re
+import sys
+
+def check_file(filename):
+ seen = set()
+ good = True
+ for n, line in enumerate(open(filename)):
+ if m := re.match(r'^\s*#\s*include\s*[<"](\S*)[>"]', line):
+ include = m.group(1)
+ if include in seen:
+ print(f'{filename}:{n}: {line.strip()}')
+ good = False
+ seen.add(include)
+ return good
+
+if __name__ == '__main__':
+ good = all(check_file(name) for name in sys.argv[1:])
+ sys.exit(0 if good else 1)