File: t_dist_tabs.pl

package info (click to toggle)
verilator 4.038-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 29,596 kB
  • sloc: cpp: 90,585; perl: 15,101; ansic: 8,573; yacc: 3,626; lex: 1,616; makefile: 1,101; sh: 175; python: 145
file content (104 lines) | stat: -rwxr-xr-x 3,662 bytes parent folder | download
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0

scenarios(dist => 1);

my $root = "..";

my $Tabs_Exempt_Re = qr!(\.out$)|(/gtkwave)|(Makefile)|(\.mk$)|(nodist/fastcov.py)!;
my $Wide_Exempt_Re = qr!(\.l$)|(\.y$)!;

if (!-r "$root/.git") {
    skip("Not in a git repository");
} else {
    ### Must trim output before and after our file list
    my %warns;
    my $prefix;
    my $summary = "";
    {
        my $diff = `cd $root && git diff HEAD`;
        #print "DS $diff\n" if $Debug;
        my $file;
        my $atab;
        my $btab;
        my $lineno = 0;
        foreach my $line ((split /\n/, $diff), "+++ b/_the_end") {
            if ($line =~ m!^\+\+\+ b/(.*)!) {
                if ($file && !$atab && $btab
                    && $file !~ $Tabs_Exempt_Re) {
                    $summary = "File modifications adds new tabs (please untabify the patch):";
                    $warns{$file} = "File modification adds new tabs (please untabify the patch): $file";
                }
                # Next
                $file = $1;
                $atab = 0;
                $btab = 0;
                print " File $file\n" if $Self->{verbose};
            }
            elsif ($line  =~ m!^@@ -?[0-9]+,?[0-9]* \+?([0-9]+)!) {
                $lineno = $1 - 1;
            }
            elsif ($line  =~ m!^ !) {
                ++$lineno;
                if ($line =~ m!^[- ].*\t!) {
                    print "  Had tabs\n" if $Self->{verbose} && !$atab;
                    $atab = 1;
                }
            }
            elsif ($line =~ m!^-.*\t!) {
                print "  Had tabs\n" if $Self->{verbose} && !$atab;
                $atab = 1;
            }
            elsif ($line =~ m!^\+.*\t!) {
                ++$lineno;
                print "  Inserts tabs\n" if $Self->{verbose} && !$btab;
                $btab = 1;
            }
            elsif ($line =~ m!^\+(.*)!) {
                ++$lineno;
                if ($line =~ /\r/) {
                    $summary = "File modification adds carriage return (remove them):" if !$summary;
                    $warns{$file} = "File modification adds carriage return (remove them): $file:$lineno";
                }
                my $len = length($1);
                if ($len >= 100
                    && $file !~ $Tabs_Exempt_Re
                    && $file !~ $Wide_Exempt_Re) {
                    print"  Wide $line\n" if $Self->{verbose};
                    $summary = "File modification adds a new >100 column line:" if !$summary;
                    $warns{$file} = "File modification adds a new >100 column line: $file:$lineno";
                }
            }
        }
    }
    if (keys %warns) {
        # First warning lists everything as that's shown in the driver summary
        error($summary." ",join(' ',sort keys %warns));
        foreach my $file (sort keys %warns) {
            error($warns{$file});
        }
    }
}

sub _has_tabs {
    my $filename = shift;
    my $contents = file_contents($filename);
    if ($filename =~ /\.out$/) {
        # Ignore golden files
    } elsif ($contents =~ /[\001\002\003\004\005\006]/) {
        # Ignore binrary files
    } elsif ($contents =~ /\t/) {
        return 1;
    }
    return 0;
}

ok(1);
1;