File: check-headers.pl

package info (click to toggle)
gnome-vfs 1%3A2.24.4-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,120 kB
  • ctags: 10,397
  • sloc: ansic: 78,516; sh: 10,341; makefile: 902; perl: 99
file content (123 lines) | stat: -rwxr-xr-x 4,088 bytes parent folder | download | duplicates (7)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/perl -w
# -*- Mode: perl; indent-tabs-mode: nil -*-

use diagnostics;
use strict;

my $DEBUG = 0;

my %public_headers;
my %module_headers;
my %private_headers;

my $current_hash;
my $current_hash_name;

my $current_header;
my $included_header;

my $exit_code = 0;

open MAKEFILE_AM, "<./Makefile.am";

while (<MAKEFILE_AM>) {
    if (/libgnomevfsinclude_HEADERS/) {
        $current_hash = \%public_headers
    } elsif (/libgnomevfsmoduleinclude_HEADERS/) {
        $current_hash = \%module_headers
    } elsif (/noinst_HEADERS/) {
        $current_hash = \%private_headers
    } elsif (/\$\(NULL\)/ || ! /\\/) {
        $current_hash = 0;
    }

    if (/.*\.h[ \t]/) {
        chomp;
        $current_header = $_;
        $current_header =~ s/[ \t]*(.*\.h)[ \t]*.*/$1/;
        
        if ($current_hash) {
            $$current_hash{$current_header} = 1;
        }
    }
}

close MAKEFILE_AM;

for my $public_header (keys %public_headers) {
    open HEADER, "<${public_header}";
    while (<HEADER>) {
        if (/\#include[ \t]+<libgnomevfs\/.*\.h>.*/) {
            chomp;
            $included_header = $_;
            $included_header =~ s/\#include[ \t]+<libgnomevfs\/(.*\.h)>.*/$1/;

            if ($private_headers{$included_header}) {
                print "Public header \"$public_header\" includes private header \"$included_header\"\n";
                $exit_code = 1;
            } elsif ($module_headers{$included_header}) {
                print "Public header \"$public_header\" includes module API header \"$included_header\"\n";
                $exit_code = 1;
            } elsif ($public_headers{$included_header}) {
                print "Public header \"$public_header\" includes public header \"$included_header\"\n" if $DEBUG;
            } else {
                print "Public header \"$public_header\" includes unknown header \"$included_header\"\n";
                $exit_code = 1;
            }
        }
    }
    close HEADER;
}


for my $module_header (keys %module_headers) {
    open HEADER, "<${module_header}";

    while (<HEADER>) {
        if (/\#include[ \t]+<libgnomevfs\/.*\.h>.*/) {
            chomp;
            $included_header = $_;
            $included_header =~ s/\#include[ \t]+<libgnomevfs\/(.*\.h)>.*/$1/;

            if ($private_headers{$included_header}) {
                print "Module API header \"$module_header\" includes private header \"$included_header\"\n";
                $exit_code = 1;
            } elsif ($module_headers{$included_header}) {
                print "Module API header \"$module_header\" includes public header \"$included_header\"\n" if $DEBUG;
            } elsif ($public_headers{$included_header}) {
                print "Module API header \"$module_header\" includes public header \"$included_header\"\n" if $DEBUG;
            } else {
                print "Module API header \"$module_header\" includes unknown header \"$included_header\"\n";
                $exit_code = 1;
            }
        }
    }
    close HEADER;
}


for my $private_header (keys %private_headers) {
    open HEADER, "<${private_header}";

    while (<HEADER>) {
        if (/\#include[ \t]+<libgnomevfs\/.*\.h>.*/) {
            chomp;
            $included_header = $_;
            $included_header =~ s/\#include[ \t]+<libgnomevfs\/(.*\.h)>.*/$1/;

            if ($private_headers{$included_header}) {
                print "Private header \"$private_header\" includes private header \"$included_header\"\n" if $DEBUG;
            } elsif ($module_headers{$included_header}) {
                print "Private header \"$private_header\" includes module API header \"$included_header\"\n" if $DEBUG;
            } elsif ($public_headers{$included_header}) {
                print "Private header \"$private_header\" includes public header \"$included_header\"\n" if $DEBUG;
            } else {
                print "Private header \"$private_header\" includes unknown header \"$included_header\"\n";
                $exit_code = 1;
            }
        }
    }
    close HEADER;
}

exit $exit_code;