2 # Copyright (C) 2011 Igalia S.L.
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.
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.
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
23 def is_source_file_listing(line):
24 return line.strip().startswith('Source')
26 def get_listed_makefile_headers():
27 makefile_text = open(os.path.join(common.build_path('GNUmakefile'))).read()
29 # Automake often places separate includes on the same line.
30 makefile_text = makefile_text.replace(' ', '\n')
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)/', '')
37 # If the line doesn't start with 'Source' it isn't listing for
39 if not is_source_file_listing(line):
42 # Most source listings end with \ indicating that the listing
43 # continues onto the next line.
44 line = line.replace('\\', '')
46 # We only care about header files. Source files result in build
47 # breakage, so we will detect them without this script.
49 if not line.endswith('.h'):
52 # If the line contains a makefile variable we do not care about it.
53 if line.find('$') != -1:
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,
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):
73 # The lines we care about end with ':'.
74 line = line.replace(':', '')
76 sanitized_lines.add(line)
77 return sanitized_lines
79 def get_unlisted_headers(listed_makefile_headers):
81 for header in scan_headers_from_dependency_files():
82 if not header in listed_makefile_headers:
86 def get_missing_headers(listed_makefile_headers):
88 for header in listed_makefile_headers:
89 if not os.path.exists(common.top_level_path(header)):
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)
97 print 'Headers not listed in the GNUmakefiles:'
98 for header in sorted(unlisted_headers):
103 print 'Headers listed in the GNUmakefiles that do not exist:'
104 for header in sorted(missing_headers):
105 print '\t%s' % header
108 sys.exit(len(unlisted_headers) + len(missing_headers))