Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(793)

Side by Side Diff: ppapi/generate_ppapi_include_tests.py

Issue 5190004: This accomplishes a few things:... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ppapi/ppapi.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/python
2
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 # This script should be run manually on occasion to make sure the gyp file and
8 # the includes tests are up to date.
9 # It does the following:
10 # - Verifies that all source code is in ppapi.gyp
11 # - Verifies that all sources in ppapi.gyp really do exist
12 # - Generates tests/test_c_includes.c
13 # - Generates tests/test_cc_includes.cc
14 # These tests are checked in to SVN.
15 # TODO(dmichael): Make this script execute as a gyp action, move the include
16 # tests to some 'generated' area, and remove them from version
17 # control.
18
19 import re
20 import os
21 import sys
22 import posixpath
23
24 # A simple regular expression that should match source files for C++ and C.
25 SOURCE_FILE_RE = re.compile('.+\.(cc|c|h)$')
26
27 # IGNORE_RE is a regular expression that matches directories which contain
28 # source that we don't (currently) expect to be in ppapi.gyp. This script will
29 # not check whether source files under these directories are in the gyp file.
30 # TODO(dmichael): Put examples back in the build.
31 # TODO(brettw): Put proxy in the build when it's ready.
32 IGNORE_RE = re.compile('^(examples|GLES2|proxy).*')
33
34 GYP_TARGETS_KEY = 'targets'
35 GYP_SOURCES_KEY = 'sources'
36 GYP_TARGET_NAME_KEY = 'target_name'
37
38
39 # Return a set containing all source files found given an object read from a gyp
40 # file.
41 def GetAllGypSources(gyp_file_data):
42 sources = set([])
43 for target in gyp_file_data[GYP_TARGETS_KEY]:
44 # Get a list of sources in the target that are not ignored, and 'normalize'
45 # them. The main reason for this is to turn the forward slashes in the gyp
46 # file in to backslashes when the script is run on Windows.
47 source_list = [posixpath.normpath(src) for src in target[GYP_SOURCES_KEY]
48 if not IGNORE_RE.match(src)]
49 sources |= set(source_list)
50 return sources
51
52
53 # Search the directory named start_root and all its subdirectories for source
54 # files.
55 # Return a set containing the string names of all the source files found,
56 # relative to start_root.
57 def GetFileSources(start_root):
58 file_set = set([])
59 for root, dirs, files in os.walk(start_root):
60 relative_root = os.path.relpath(root, start_root)
61 if not IGNORE_RE.match(relative_root):
62 for source in files:
63 if SOURCE_FILE_RE.match(source):
64 file_set |= set([os.path.join(relative_root, source)])
65 return file_set
66
67
68 # Make sure all source files are in the given gyp object (evaluated from a gyp
69 # file), and that all source files listed in the gyp object exist in the
70 # directory.
71 def VerifyGypFile(gyp_file_data):
72 gyp_sources = GetAllGypSources(gyp_file_data)
73 file_sources = GetFileSources('.')
74 in_gyp_not_file = gyp_sources - file_sources
75 in_file_not_gyp = file_sources - gyp_sources
76 if len(in_gyp_not_file):
77 print 'Found source file(s) in ppapi.gyp but not in the directory:', \
78 in_gyp_not_file
79 if len(in_file_not_gyp):
80 print 'Found source file(s) in the directory but not in ppapi.gyp:', \
81 in_file_not_gyp
82 error_count = len(in_gyp_not_file) + len(in_file_not_gyp)
83 if error_count:
84 sys.exit(error_count)
85
86
87 def WriteLines(filename, lines):
88 outfile = open(filename, 'w')
89 for line in lines:
90 outfile.write(line)
91 outfile.write('\n')
92
93
94 COPYRIGHT_STRING_C = \
95 """
96 /* Copyright (c) 2010 The Chromium Authors. All rights reserved.
97 * Use of this source code is governed by a BSD-style license that can be
98 * found in the LICENSE file.
99 *
100 * This test simply includes all the C headers to ensure they compile with a C
101 * compiler. If it compiles, it passes.
102 */
103 """
104
105 COPYRIGHT_STRING_CC = \
106 """
107 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
108 // Use of this source code is governed by a BSD-style license that can be
109 // found in the LICENSE file.
110 //
111 // This test simply includes all the C++ headers to ensure they compile with a
112 // C++ compiler. If it compiles, it passes.
113 //
114 """
115
116
117 # Get the source file names out of the given gyp file data object (as evaluated
118 # from a gyp file) for the given target name. Return the string names in
119 # sorted order.
120 def GetSourcesForTarget(target_name, gyp_file_data):
121 for target in gyp_file_data[GYP_TARGETS_KEY]:
122 if target[GYP_TARGET_NAME_KEY] == target_name:
123 sources = target[GYP_SOURCES_KEY]
124 sources.sort()
125 return sources
126 print 'Warning: no target named ', target, ' found.'
127 return []
128
129
130 # Generate test_c_includes.c, which is a test to ensure that all the headers in
131 # ppapi/c can be compiled with a C compiler.
132 def GenerateCIncludeTest(gyp_file_data):
133 c_sources = GetSourcesForTarget('ppapi_c', gyp_file_data)
134 lines = [COPYRIGHT_STRING_C]
135 for source in c_sources:
136 lines.append('#include "ppapi/' + source + '"\n')
137 WriteLines('tests/test_c_includes.c', lines)
138
139
140 # Generate test_cc_includes.cc, which is a test to ensure that all the headers
141 # in ppapi/cpp can be compiled with a C++ compiler.
142 def GenerateCCIncludeTest(gyp_file_data):
143 cc_sources = GetSourcesForTarget('ppapi_cpp_objects', gyp_file_data)
144 header_re = re.compile('.+\.h$')
145 lines = [COPYRIGHT_STRING_CC]
146 for source in cc_sources:
147 if header_re.match(source):
148 lines.append('#include "ppapi/' + source + '"\n')
149 WriteLines('tests/test_cc_includes.cc', lines)
150
151
152 def main():
153 ppapi_gyp_file_name = 'ppapi.gyp'
David Springer 2010/11/19 20:48:19 Nit: maybe make this a global const at the top fo
154 gyp_file_contents = open(ppapi_gyp_file_name).read()
155 gyp_file_data = eval(gyp_file_contents)
156 VerifyGypFile(gyp_file_data)
157 GenerateCIncludeTest(gyp_file_data)
158 GenerateCCIncludeTest(gyp_file_data)
159 return 0
160
161
162 if __name__ == '__main__':
163 sys.exit(main())
David Springer 2010/11/19 20:48:19 Nit: 2-space indent.
164
OLDNEW
« no previous file with comments | « no previous file | ppapi/ppapi.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698