|
OLD | NEW |
---|---|
(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 import re | |
8 import os | |
9 import sys | |
10 import posixpath | |
11 | |
12 source_file_re = re.compile('.+\.(cc|c|h)$') | |
13 | |
14 # TODO(dmichael): Put examples back in the build. | |
15 # TODO(brettw): Put proxy in the build when it's ready. | |
16 ignore_re = re.compile('.*(examples|GLES|proxy).*') | |
17 | |
18 # Open ppapi.gyp. Return a set containing all source files found. | |
19 def get_gyp_sources(gyp_file_data): | |
David Springer
2010/11/18 21:21:42
I recommend taking a look at the Python style guid
dmichael(do not use this one)
2010/11/18 21:51:35
Looks like lowercase/underscores: http://google-s
David Springer
2010/11/19 00:14:21
Awesome - it turns out that the internal style gui
| |
20 sources = set([]) | |
21 for target in gyp_file_data['targets']: | |
22 source_list = [source for source in target['sources'] | |
23 if not ignore_re.match(source)] | |
24 sources |= set(source_list) | |
25 return sources | |
26 | |
27 # Search the local directory and all its subdirectories for source files. | |
28 # Return a set containing all the source files found. | |
29 def get_file_sources(): | |
30 file_set = set([]) | |
31 for root, dirs, files in os.walk('.'): | |
32 if (not ignore_re.match(root)): | |
33 adjusted_root = root[2:] | |
34 sources = [posixpath.join(adjusted_root, src) | |
35 for src in files if source_file_re.match(src)] | |
36 file_set |= set(sources) | |
37 return file_set | |
38 | |
39 | |
40 # Make sure all source files are in ppapi.gyp, and all files in ppapi.gyp exist. | |
41 def verify_gyp_file(gyp_file_data): | |
42 gyp_sources = get_gyp_sources(gyp_file_data) | |
43 file_sources = get_file_sources() | |
44 in_gyp_not_file = gyp_sources - file_sources | |
45 in_file_not_gyp = file_sources - gyp_sources | |
46 if (len(in_gyp_not_file)): | |
47 print "Found source file(s) in ppapi.gyp but not in the directory:", \ | |
48 in_gyp_not_file | |
49 if (len(in_file_not_gyp)): | |
50 print "Found source file(s) in the directory but not in ppapi.gyp:", \ | |
51 in_file_not_gyp | |
52 error_count = len(in_gyp_not_file) + len(in_file_not_gyp) | |
53 if (error_count): | |
54 sys.exit(error_count) | |
55 | |
56 def writelines(filename, lines): | |
57 outfile = open(filename, 'w') | |
58 for line in lines: | |
59 outfile.write(line) | |
60 outfile.write("\n") | |
61 | |
62 copyright_string_c = \ | |
63 "/* Copyright (c) 2010 The Chromium Authors. All rights reserved.\n\ | |
64 * Use of this source code is governed by a BSD-style license that can be\n\ | |
65 * found in the LICENSE file.\n\ | |
66 *\n\ | |
67 * This test simply includes all the C headers to ensure they compile with a\n\ | |
68 * C compiler. If it compiles, it passes.\n\ | |
69 */\n" | |
70 | |
71 copyright_string_cc = \ | |
72 "// Copyright (c) 2010 The Chromium Authors. All rights reserved.\n\ | |
73 // Use of this source code is governed by a BSD-style license that can be\n\ | |
74 // found in the LICENSE file.\n\ | |
75 //\n\ | |
76 // This test simply includes all the C++ headers to ensure they compile with\n\ | |
77 // a C++ compiler. If it compiles, it passes.\n\ | |
78 //\n" | |
79 | |
80 def get_sources_for_target(target_name, gyp_file_data): | |
81 for target in gyp_file_data['targets']: | |
82 if target['target_name'] == target_name: | |
83 sources = target['sources'] | |
84 sources.sort() | |
85 return sources | |
86 print "Warning: no target named ", target, " found." | |
87 return [] | |
88 | |
89 # Generate test_c_includes.c, which is a test to ensure that all the headers in | |
90 # ppapi/c can be compiled with a C compiler. | |
David Springer
2010/11/18 21:21:42
When you generate this, does test_c_includes.c go
dmichael(do not use this one)
2010/11/18 21:51:35
Currently it just goes in "tests" alongside non-ge
| |
91 def generate_test_c_includes(gyp_file_data): | |
92 c_sources = get_sources_for_target('ppapi_c', gyp_file_data) | |
93 lines = [copyright_string_c] | |
94 for source in c_sources: | |
95 lines.append("#include \"ppapi/" + source + "\"\n") | |
96 writelines('tests/test_c_includes.c', lines) | |
97 | |
98 # Generate test_cc_includes.cc, which is a test to ensure that all the headers | |
99 # in ppapi/cpp can be compiled with a C++ compiler. | |
100 def generate_test_cc_includes(gyp_file_data): | |
101 cc_sources = get_sources_for_target('ppapi_cpp_objects', gyp_file_data) | |
102 header_re = re.compile('.+\.h$') | |
103 lines = [copyright_string_cc] | |
104 for source in cc_sources: | |
105 if (header_re.match(source)): | |
106 lines.append("#include \"ppapi/" + source + "\"\n") | |
107 writelines('tests/test_cc_includes.cc', lines) | |
108 | |
109 if __name__ == "__main__": | |
David Springer
2010/11/18 21:21:42
From looking around at other .py files, it seems t
dmichael(do not use this one)
2010/11/18 21:51:35
Done.
| |
110 gyp_file_contents = open("ppapi.gyp").read() | |
111 gyp_file_data = eval(gyp_file_contents) | |
112 verify_gyp_file(gyp_file_data) | |
113 generate_test_c_includes(gyp_file_data) | |
114 generate_test_cc_includes(gyp_file_data) | |
115 | |
116 # Generate test_c_includes.c, which is a test to ensure that all | |
David Springer
2010/11/18 21:21:42
This comment seems to be spurious - or the file go
dmichael(do not use this one)
2010/11/18 21:51:35
Oops, Done.
| |
OLD | NEW |