mirror of
https://github.com/systemd/systemd.git
synced 2025-01-05 13:18:06 +03:00
Rewrite check-includes.pl in python
This commit is contained in:
parent
083e2ba445
commit
c4a090d60e
@ -45,7 +45,6 @@ The following exceptions apply:
|
|||||||
* the following sources are licensed under the **CC0-1.0** license:
|
* the following sources are licensed under the **CC0-1.0** license:
|
||||||
- src/basic/siphash24.c
|
- src/basic/siphash24.c
|
||||||
- src/basic/siphash24.h
|
- src/basic/siphash24.h
|
||||||
- tools/check-includes.pl
|
|
||||||
* the following sources are licensed under the **MIT-0** license:
|
* the following sources are licensed under the **MIT-0** license:
|
||||||
- all examples under man/
|
- all examples under man/
|
||||||
- src/systemctl/systemd-sysv-install.SKELETON
|
- src/systemctl/systemd-sysv-install.SKELETON
|
||||||
|
@ -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);
|
|
||||||
}
|
|
23
tools/check-includes.py
Executable file
23
tools/check-includes.py
Executable file
@ -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)
|
Loading…
Reference in New Issue
Block a user