Index: ppapi/generate_ppapi_include_tests.py |
=================================================================== |
--- ppapi/generate_ppapi_include_tests.py (revision 0) |
+++ ppapi/generate_ppapi_include_tests.py (revision 0) |
@@ -0,0 +1,131 @@ |
+#!/usr/bin/python |
dmichael(do not use this one)
2010/11/19 18:53:27
Regarding style:
Figures, I picked the wrongest of
|
+ |
+# Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+# This script should be run manually on occasion to make sure the gyp file and |
+# the includes tests are up to date. |
+# It does the following: |
+# - Verifies that all source code is in ppapi.gyp |
+# - Verifies that all sources in ppapi.gyp really do exist |
+# - Generates tests/test_c_includes.c |
+# - Generates tests/test_cc_includes.cc |
+# These tests are checked in to SVN. |
+# TODO(dmichael): Make this script execute as a gyp action, move the include |
+# tests to some 'generated' area, and remove them from version |
+# control. |
+ |
+import re |
+import os |
+import sys |
+import posixpath |
+ |
+source_file_re = re.compile('.+\.(cc|c|h)$') |
+ |
+# TODO(dmichael): Put examples back in the build. |
+# 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
|
+ignore_re = re.compile('.*(examples|GLES|proxy).*') |
+ |
+# Open ppapi.gyp. Return a set containing all source files found. |
+def get_gyp_sources(gyp_file_data): |
+ sources = set([]) |
+ 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.
|
+ source_list = [source for source in target['sources'] |
+ if not ignore_re.match(source)] |
+ sources |= set(source_list) |
+ return sources |
+ |
+# Search the local directory and all its subdirectories for source files. |
+# Return a set containing all the source files found. |
+def get_file_sources(): |
+ file_set = set([]) |
+ for root, dirs, files in os.walk('.'): |
+ if not ignore_re.match(root): |
+ 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
|
+ sources = [posixpath.join(adjusted_root, src) |
+ for src in files if source_file_re.match(src)] |
+ file_set |= set(sources) |
+ return file_set |
+ |
+ |
+# Make sure all source files are in ppapi.gyp, and all files in ppapi.gyp exist. |
+def verify_gyp_file(gyp_file_data): |
+ gyp_sources = get_gyp_sources(gyp_file_data) |
+ file_sources = get_file_sources() |
+ in_gyp_not_file = gyp_sources - file_sources |
+ in_file_not_gyp = file_sources - gyp_sources |
+ if len(in_gyp_not_file): |
+ print "Found source file(s) in ppapi.gyp but not in the directory:", \ |
+ in_gyp_not_file |
+ if len(in_file_not_gyp): |
+ print "Found source file(s) in the directory but not in ppapi.gyp:", \ |
+ in_file_not_gyp |
+ error_count = len(in_gyp_not_file) + len(in_file_not_gyp) |
+ if error_count: |
+ sys.exit(error_count) |
+ |
+def writelines(filename, lines): |
+ outfile = open(filename, 'w') |
+ for line in lines: |
+ outfile.write(line) |
+ outfile.write("\n") |
+ |
+COPYRIGHT_STRING_C = \ |
+"/* Copyright (c) 2010 The Chromium Authors. All rights reserved.\n\ |
+ * Use of this source code is governed by a BSD-style license that can be\n\ |
+ * found in the LICENSE file.\n\ |
+ *\n\ |
+ * This test simply includes all the C headers to ensure they compile with a\n\ |
+ * C compiler. If it compiles, it passes.\n\ |
+ */\n" |
+ |
+COPYRIGHT_STRING_CC = \ |
+"// Copyright (c) 2010 The Chromium Authors. All rights reserved.\n\ |
+// Use of this source code is governed by a BSD-style license that can be\n\ |
+// found in the LICENSE file.\n\ |
+//\n\ |
+// This test simply includes all the C++ headers to ensure they compile with\n\ |
+// a C++ compiler. If it compiles, it passes.\n\ |
+//\n" |
+ |
+def get_sources_for_target(target_name, gyp_file_data): |
+ for target in gyp_file_data['targets']: |
+ if target['target_name'] == target_name: |
+ sources = target['sources'] |
+ sources.sort() |
+ return sources |
+ print "Warning: no target named ", target, " found." |
+ return [] |
+ |
+# Generate test_c_includes.c, which is a test to ensure that all the headers in |
+# ppapi/c can be compiled with a C compiler. |
+def generate_test_c_includes(gyp_file_data): |
+ c_sources = get_sources_for_target('ppapi_c', gyp_file_data) |
+ lines = [COPYRIGHT_STRING_C] |
+ for source in c_sources: |
+ lines.append("#include \"ppapi/" + source + "\"\n") |
+ writelines('tests/test_c_includes.c', lines) |
+ |
+# Generate test_cc_includes.cc, which is a test to ensure that all the headers |
+# in ppapi/cpp can be compiled with a C++ compiler. |
+def generate_test_cc_includes(gyp_file_data): |
+ cc_sources = get_sources_for_target('ppapi_cpp_objects', gyp_file_data) |
+ header_re = re.compile('.+\.h$') |
+ lines = [COPYRIGHT_STRING_CC] |
+ for source in cc_sources: |
+ if header_re.match(source): |
+ lines.append("#include \"ppapi/" + source + "\"\n") |
+ writelines('tests/test_cc_includes.cc', lines) |
+ |
+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
|
+ 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
|
+ gyp_file_data = eval(gyp_file_contents) |
+ verify_gyp_file(gyp_file_data) |
+ generate_test_c_includes(gyp_file_data) |
+ generate_test_cc_includes(gyp_file_data) |
+ return 0 |
+ |
+if __name__ == "__main__": |
+ sys.exit(main()) |
David Springer
2010/11/19 00:14:21
main(sysargv[1:])
|
+ |
Property changes on: ppapi/generate_ppapi_include_tests.py |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |