-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoccicheck
executable file
·49 lines (44 loc) · 1.24 KB
/
coccicheck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl -w
#
# coccicheck
# A more generic coccinelle wrapper but following the same idea from the Linux version.
use strict;
use Getopt::Long qw(:config pass_through);
my $nrproc = `getconf _NPROCESSORS_ONLN`;
chomp($nrproc);
my $macros = $0;
$macros =~ s,/[^/]+$,/macros,;
my $report = 0;
my $timeout = undef;
my $tryreport = 0;
GetOptions(
"report" => \$report,
"timeout=s" => \$timeout,
"try-report" => \$tryreport,
);
my $srcdir;
if ($ARGV[0] !~ /\.cocci$/) {
$srcdir = $ARGV[0];
} else {
$srcdir = $ARGV[1];
}
$srcdir =~ s,/\K[^/]+$,, if (! -d $srcdir);
$srcdir = `cd '$srcdir' && git rev-parse --show-toplevel`;
chomp($srcdir);
my @cocci = grep(/\.cocci$/, @ARGV);
if ($tryreport) {
system('grep', '-q', '^virtual report', $cocci[0]);
$report = 1 if ($? >> 8 == 0);
}
my $optstr = `grep -P '^\\s*//\\s*Options:' '$cocci[0]' | cut -d: -f2`;
$optstr =~ s/^\s+//;
$optstr =~ s/\s+$//;
my @opts = split(/\s+/, $optstr);
if (defined($timeout)) {
push(@opts, '--timeout', $timeout);
}
if ($report) {
push(@opts, '--no-show-diff', '-D', 'report');
}
system('spatch', '--macro-file-builtins', $macros, '-j', $nrproc, '--patch', $srcdir, '--indent', 4,
'--max-width', 100, '--quiet', @opts, @ARGV);