checksrc-all: rewrite in Perl

This commit is contained in:
Viktor Szakats 2025-07-10 10:33:40 +02:00
parent 1df2174ae2
commit 70bbd7b598
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
5 changed files with 41 additions and 26 deletions

View file

@ -22,7 +22,7 @@
#
###########################################################################
EXTRA_DIST = coverage.sh completion.pl firefox-db2pem.sh checksrc.pl checksrc-all.sh \
EXTRA_DIST = coverage.sh completion.pl firefox-db2pem.sh checksrc.pl checksrc-all.pl \
mk-ca-bundle.pl mk-unity.pl schemetable.c cd2nroff nroff2cd cdall cd2cd managen \
dmaketgz maketgz release-tools.sh verify-release cmakelint.sh mdlinkcheck \
CMakeLists.txt pythonlint.sh randdisable wcurl top-complexity extract-unit-protos

38
scripts/checksrc-all.pl Executable file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env perl
# Copyright (C) Viktor Szakats
#
# SPDX-License-Identifier: curl
use strict;
use warnings;
use File::Basename;
use File::Find;
use Cwd 'abs_path';
my @files;
if(system('git rev-parse --is-inside-work-tree >/dev/null 2>&1') == 0) {
@files = `git ls-files '*.[ch]'`;
}
else {
find(sub { if(/\.[ch]/) { push(@files, $File::Find::name) } }, ('.'));
}
if(@ARGV) {
find(sub { if(/\.[ch]/) { push(@files, $File::Find::name) } }, @ARGV);
}
@files = grep !/\/CMakeFiles\//, @files;
@files = map { dirname($_) } @files;
my @dirs = sort { $a cmp $b } keys %{{ map { $_ => 1 } @files }};
my $scripts_dir = dirname(abs_path($0));
my $anyfailed = 0;
for my $dir (@dirs) {
@files = glob("$dir/*.[ch]");
if(@files && system("$scripts_dir/checksrc.pl", @files) != 0) {
$anyfailed = 1;
}
}
exit $anyfailed;

View file

@ -1,23 +0,0 @@
#!/bin/sh
# Copyright (C) Viktor Szakats
#
# SPDX-License-Identifier: curl
set -eu
anyfailed=0
for dir in $({
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
git ls-files '*.[ch]'
else
find . -name '*.[ch]'
fi
[ -n "${1:-}" ] && find "$@" -name '*.[ch]'
} | grep -v -F '/CMakeFiles/' | sed -E 's|/[^/]+$||' | sort -u); do
if ! ./scripts/checksrc.pl "${dir}"/*.[ch]; then
anyfailed=1
fi
done
exit "${anyfailed}"