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

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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/python
dmichael(do not use this one) 2010/11/19 18:53:27 Regarding style: Figures, I picked the wrongest of
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 source_file_re = re.compile('.+\.(cc|c|h)$')
25
26 # TODO(dmichael): Put examples back in the build.
27 # TODO(brettw): Put proxy in the build when it's ready.
David Springer 2010/11/19 00:14:21 Are these comments relevant in this file?
dmichael(do not use this one) 2010/11/19 18:53:27 Yes. I added another comment to try to clear it u
28 ignore_re = re.compile('.*(examples|GLES|proxy).*')
29
30 # Open ppapi.gyp. Return a set containing all source files found.
31 def get_gyp_sources(gyp_file_data):
32 sources = set([])
33 for target in gyp_file_data['targets']:
David Springer 2010/11/19 00:14:21 Consider using globals for these strings (e.g. TAR
dmichael(do not use this one) 2010/11/19 18:53:27 Done.
34 source_list = [source for source in target['sources']
35 if not ignore_re.match(source)]
36 sources |= set(source_list)
37 return sources
38
39 # Search the local directory and all its subdirectories for source files.
40 # Return a set containing all the source files found.
41 def get_file_sources():
42 file_set = set([])
43 for root, dirs, files in os.walk('.'):
44 if not ignore_re.match(root):
45 adjusted_root = root[2:]
David Springer 2010/11/19 00:16:40 This is a little magical - can you explain why you
dmichael(do not use this one) 2010/11/19 18:53:27 I reworked it to be a little more general & self-d
46 sources = [posixpath.join(adjusted_root, src)
47 for src in files if source_file_re.match(src)]
48 file_set |= set(sources)
49 return file_set
50
51
52 # Make sure all source files are in ppapi.gyp, and all files in ppapi.gyp exist.
53 def verify_gyp_file(gyp_file_data):
54 gyp_sources = get_gyp_sources(gyp_file_data)
55 file_sources = get_file_sources()
56 in_gyp_not_file = gyp_sources - file_sources
57 in_file_not_gyp = file_sources - gyp_sources
58 if len(in_gyp_not_file):
59 print "Found source file(s) in ppapi.gyp but not in the directory:", \
60 in_gyp_not_file
61 if len(in_file_not_gyp):
62 print "Found source file(s) in the directory but not in ppapi.gyp:", \
63 in_file_not_gyp
64 error_count = len(in_gyp_not_file) + len(in_file_not_gyp)
65 if error_count:
66 sys.exit(error_count)
67
68 def writelines(filename, lines):
69 outfile = open(filename, 'w')
70 for line in lines:
71 outfile.write(line)
72 outfile.write("\n")
73
74 COPYRIGHT_STRING_C = \
75 "/* Copyright (c) 2010 The Chromium Authors. All rights reserved.\n\
76 * Use of this source code is governed by a BSD-style license that can be\n\
77 * found in the LICENSE file.\n\
78 *\n\
79 * This test simply includes all the C headers to ensure they compile with a\n\
80 * C compiler. If it compiles, it passes.\n\
81 */\n"
82
83 COPYRIGHT_STRING_CC = \
84 "// Copyright (c) 2010 The Chromium Authors. All rights reserved.\n\
85 // Use of this source code is governed by a BSD-style license that can be\n\
86 // found in the LICENSE file.\n\
87 //\n\
88 // This test simply includes all the C++ headers to ensure they compile with\n\
89 // a C++ compiler. If it compiles, it passes.\n\
90 //\n"
91
92 def get_sources_for_target(target_name, gyp_file_data):
93 for target in gyp_file_data['targets']:
94 if target['target_name'] == target_name:
95 sources = target['sources']
96 sources.sort()
97 return sources
98 print "Warning: no target named ", target, " found."
99 return []
100
101 # Generate test_c_includes.c, which is a test to ensure that all the headers in
102 # ppapi/c can be compiled with a C compiler.
103 def generate_test_c_includes(gyp_file_data):
104 c_sources = get_sources_for_target('ppapi_c', gyp_file_data)
105 lines = [COPYRIGHT_STRING_C]
106 for source in c_sources:
107 lines.append("#include \"ppapi/" + source + "\"\n")
108 writelines('tests/test_c_includes.c', lines)
109
110 # Generate test_cc_includes.cc, which is a test to ensure that all the headers
111 # in ppapi/cpp can be compiled with a C++ compiler.
112 def generate_test_cc_includes(gyp_file_data):
113 cc_sources = get_sources_for_target('ppapi_cpp_objects', gyp_file_data)
114 header_re = re.compile('.+\.h$')
115 lines = [COPYRIGHT_STRING_CC]
116 for source in cc_sources:
117 if header_re.match(source):
118 lines.append("#include \"ppapi/" + source + "\"\n")
119 writelines('tests/test_cc_includes.cc', lines)
120
121 def main():
David Springer 2010/11/19 00:14:21 Consider passing in argv, this will make it more "
dmichael(do not use this one) 2010/11/19 18:53:27 This script makes other assumptions that might not
122 gyp_file_contents = open("ppapi.gyp").read()
David Springer 2010/11/19 00:14:21 "ppapi.gyp" should either be a constant (e.g., PPA
123 gyp_file_data = eval(gyp_file_contents)
124 verify_gyp_file(gyp_file_data)
125 generate_test_c_includes(gyp_file_data)
126 generate_test_cc_includes(gyp_file_data)
127 return 0
128
129 if __name__ == "__main__":
130 sys.exit(main())
David Springer 2010/11/19 00:14:21 main(sysargv[1:])
131
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698