Merge "[WK2] Revert patch / set a limit of layer count and atlas size." into 2.0_beta
[framework/web/webkit-efl.git] / Tools / gtk / find-make-dist-errors
1 #!/usr/bin/python
2 # Copyright (C) 2011 Igalia S.L.
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17
18 import common
19 import os
20 import subprocess
21 import sys
22
23 def is_source_file_listing(line):
24     return line.strip().startswith('Source')
25
26 def get_listed_makefile_headers():
27     makefile_text = open(os.path.join(common.build_path('GNUmakefile'))).read()
28
29     # Automake often places separate includes on the same line.
30     makefile_text = makefile_text.replace(' ', '\n')
31
32     headers = []
33     for line in makefile_text.splitlines():
34         # $(srcdir)/ is the same as an empty string in a source file listing.
35         line = line.replace('$(srcdir)/', '')
36
37         # If the line doesn't start with 'Source' it isn't listing for
38         # a source file.
39         if not is_source_file_listing(line):
40             continue
41
42         # Most source listings end with \ indicating that the listing
43         # continues onto the next line.
44         line = line.replace('\\', '')
45
46         # We only care about header files. Source files result in build
47         # breakage, so we will detect them without this script.
48         line = line.strip()
49         if not line.endswith('.h'):
50             continue
51
52         # If the line contains a makefile variable we do not care about it.
53         if line.find('$') != -1:
54             continue
55
56         headers.append(line)
57
58     return headers
59
60 def scan_headers_from_dependency_files():
61     process = subprocess.Popen(['find . -name *.Plo | xargs cat | grep .h:$'],
62                                cwd=common.build_path(),
63                                stdout=subprocess.PIPE,
64                                shell=True)
65     sanitized_lines = set()
66     for line in process.communicate()[0].splitlines():
67         # Paths in Plo files are relative to the build directory so they might contain
68         # ../.. if the build directory is something like WebKitBuild/Release.
69         line = line.replace('../../', '')
70         if not is_source_file_listing(line):
71             continue
72
73         # The lines we care about end with ':'.
74         line = line.replace(':', '')
75         line = line.strip()
76         sanitized_lines.add(line)
77     return sanitized_lines
78
79 def get_unlisted_headers(listed_makefile_headers):
80     unlisted = set()
81     for header in scan_headers_from_dependency_files():
82         if not header in listed_makefile_headers:
83             unlisted.add(header)
84     return unlisted
85
86 def get_missing_headers(listed_makefile_headers):
87     missing = set()
88     for header in listed_makefile_headers:
89         if not os.path.exists(common.top_level_path(header)):
90             missing.add(header)
91     return missing
92
93 listed_makefile_headers = get_listed_makefile_headers()
94 unlisted_headers = get_unlisted_headers(listed_makefile_headers)
95 missing_headers = get_missing_headers(listed_makefile_headers)
96 if unlisted_headers:
97     print 'Headers not listed in the GNUmakefiles:'
98     for header in sorted(unlisted_headers):
99         print '\t%s' % header
100     print
101
102 if missing_headers:
103     print 'Headers listed in the GNUmakefiles that do not exist:'
104     for header in sorted(missing_headers):
105         print '\t%s' % header
106     print
107
108 sys.exit(len(unlisted_headers) + len(missing_headers))