| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # This script should be run manually on occasion to make sure the gyp file and | 7 # This script should be run manually on occasion to make sure the gyp file and |
| 8 # the includes tests are up to date. | 8 # the includes tests are up to date. |
| 9 # It does the following: | 9 # It does the following: |
| 10 # - Verifies that all source code is in ppapi.gyp | 10 # - Verifies that all source code is in ppapi.gyp |
| 11 # - Verifies that all sources in ppapi.gyp really do exist | 11 # - Verifies that all sources in ppapi.gyp really do exist |
| 12 # - Generates tests/test_c_includes.c | 12 # - Generates tests/test_c_includes.c |
| 13 # - Generates tests/test_cc_includes.cc | 13 # - Generates tests/test_cpp_includes.cc |
| 14 # These tests are checked in to SVN. | 14 # These tests are checked in to SVN. |
| 15 # TODO(dmichael): Make this script execute as a gyp action, move the include | 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 | 16 # tests to some 'generated' area, and remove them from version |
| 17 # control. | 17 # control. |
| 18 | 18 |
| 19 import re | 19 import re |
| 20 import os | 20 import os |
| 21 import sys | 21 import sys |
| 22 import posixpath | 22 import posixpath |
| 23 | 23 |
| 24 # A simple regular expression that should match source files for C++ and C. | 24 # A simple regular expression that should match source files for C++ and C. |
| 25 SOURCE_FILE_RE = re.compile('.+\.(cc|c|h)$') | 25 SOURCE_FILE_RE = re.compile('.+\.(cc|c|h)$') |
| 26 | 26 |
| 27 # IGNORE_RE is a regular expression that matches directories which contain | 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 | 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. | 29 # not check whether source files under these directories are in the gyp file. |
| 30 # TODO(dmichael): Put examples back in the build. | 30 # TODO(dmichael): Put examples back in the build. |
| 31 # TODO(brettw): Put proxy in the build when it's ready. | 31 # TODO(brettw): Put proxy in the build when it's ready. |
| 32 IGNORE_RE = re.compile('^(examples|GLES2|proxy).*') | 32 IGNORE_RE = re.compile('^(examples|GLES2|proxy|tests\/clang).*') |
| 33 | 33 |
| 34 GYP_TARGETS_KEY = 'targets' | 34 GYP_TARGETS_KEY = 'targets' |
| 35 GYP_SOURCES_KEY = 'sources' | 35 GYP_SOURCES_KEY = 'sources' |
| 36 GYP_TARGET_NAME_KEY = 'target_name' | 36 GYP_TARGET_NAME_KEY = 'target_name' |
| 37 | 37 |
| 38 | 38 |
| 39 # Return a set containing all source files found given an object read from a gyp | 39 # Return a set containing all source files found given an object read from a gyp |
| 40 # file. | 40 # file. |
| 41 def GetAllGypSources(gyp_file_data): | 41 def GetAllGypSources(gyp_file_data): |
| 42 sources = set([]) | 42 sources = set([]) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 | 86 |
| 87 def WriteLines(filename, lines): | 87 def WriteLines(filename, lines): |
| 88 outfile = open(filename, 'w') | 88 outfile = open(filename, 'w') |
| 89 for line in lines: | 89 for line in lines: |
| 90 outfile.write(line) | 90 outfile.write(line) |
| 91 outfile.write('\n') | 91 outfile.write('\n') |
| 92 | 92 |
| 93 | 93 |
| 94 COPYRIGHT_STRING_C = \ | 94 COPYRIGHT_STRING_C = \ |
| 95 """ | 95 """/* Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 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 | 96 * Use of this source code is governed by a BSD-style license that can be |
| 98 * found in the LICENSE file. | 97 * found in the LICENSE file. |
| 99 * | 98 * |
| 100 * This test simply includes all the C headers to ensure they compile with a C | 99 * This test simply includes all the C headers to ensure they compile with a C |
| 101 * compiler. If it compiles, it passes. | 100 * compiler. If it compiles, it passes. |
| 102 */ | 101 */ |
| 103 """ | 102 """ |
| 104 | 103 |
| 105 COPYRIGHT_STRING_CC = \ | 104 COPYRIGHT_STRING_CC = \ |
| 106 """ | 105 """// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 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 | 106 // Use of this source code is governed by a BSD-style license that can be |
| 109 // found in the LICENSE file. | 107 // found in the LICENSE file. |
| 110 // | 108 // |
| 111 // This test simply includes all the C++ headers to ensure they compile with a | 109 // This test simply includes all the C++ headers to ensure they compile with a |
| 112 // C++ compiler. If it compiles, it passes. | 110 // C++ compiler. If it compiles, it passes. |
| 113 // | 111 // |
| 114 """ | 112 """ |
| 115 | 113 |
| 116 | 114 |
| 117 # Get the source file names out of the given gyp file data object (as evaluated | 115 # 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 | 116 # from a gyp file) for the given target name. Return the string names in |
| 119 # sorted order. | 117 # sorted order. |
| 120 def GetSourcesForTarget(target_name, gyp_file_data): | 118 def GetSourcesForTarget(target_name, gyp_file_data): |
| 121 for target in gyp_file_data[GYP_TARGETS_KEY]: | 119 for target in gyp_file_data[GYP_TARGETS_KEY]: |
| 122 if target[GYP_TARGET_NAME_KEY] == target_name: | 120 if target[GYP_TARGET_NAME_KEY] == target_name: |
| 123 sources = target[GYP_SOURCES_KEY] | 121 sources = target[GYP_SOURCES_KEY] |
| 124 sources.sort() | 122 sources.sort() |
| 125 return sources | 123 return sources |
| 126 print 'Warning: no target named ', target, ' found.' | 124 print 'Warning: no target named ', target, ' found.' |
| 127 return [] | 125 return [] |
| 128 | 126 |
| 129 | 127 |
| 130 # Generate test_c_includes.c, which is a test to ensure that all the headers in | 128 # Generate all_c_includes.h, which includes all C headers. This is part of |
| 131 # ppapi/c can be compiled with a C compiler. | 129 # tests/test_c_sizes.c, which includes all C API files to ensure that all |
| 130 # the headers in ppapi/c can be compiled with a C compiler, and also asserts |
| 131 # (with compile-time assertions) that all structs and enums are a particular |
| 132 # size. |
| 132 def GenerateCIncludeTest(gyp_file_data): | 133 def GenerateCIncludeTest(gyp_file_data): |
| 133 c_sources = GetSourcesForTarget('ppapi_c', gyp_file_data) | 134 c_sources = GetSourcesForTarget('ppapi_c', gyp_file_data) |
| 134 lines = [COPYRIGHT_STRING_C] | 135 lines = [COPYRIGHT_STRING_C] |
| 136 lines.append('#ifndef PPAPI_TESTS_ALL_C_INCLUDES_H_\n') |
| 137 lines.append('#define PPAPI_TESTS_ALL_C_INCLUDES_H_\n\n') |
| 135 for source in c_sources: | 138 for source in c_sources: |
| 136 lines.append('#include "ppapi/' + source + '"\n') | 139 lines.append('#include "ppapi/' + source + '"\n') |
| 137 WriteLines('tests/test_c_includes.c', lines) | 140 lines.append('\n#endif /* PPAPI_TESTS_ALL_C_INCLUDES_H_ */\n') |
| 141 WriteLines('tests/all_c_includes.h', lines) |
| 138 | 142 |
| 139 | 143 |
| 140 # Generate test_cc_includes.cc, which is a test to ensure that all the headers | 144 # Generate all_cpp_includes.h, which is used by test_cpp_includes.cc to ensure |
| 141 # in ppapi/cpp can be compiled with a C++ compiler. | 145 # that all the headers in ppapi/cpp can be compiled with a C++ compiler. |
| 142 def GenerateCCIncludeTest(gyp_file_data): | 146 def GenerateCCIncludeTest(gyp_file_data): |
| 143 cc_sources = GetSourcesForTarget('ppapi_cpp_objects', gyp_file_data) | 147 cc_sources = GetSourcesForTarget('ppapi_cpp_objects', gyp_file_data) |
| 144 header_re = re.compile('.+\.h$') | 148 header_re = re.compile('.+\.h$') |
| 145 lines = [COPYRIGHT_STRING_CC] | 149 lines = [COPYRIGHT_STRING_CC] |
| 150 lines.append('#ifndef PPAPI_TESTS_ALL_CPP_INCLUDES_H_\n') |
| 151 lines.append('#define PPAPI_TESTS_ALL_CPP_INCLUDES_H_\n\n') |
| 146 for source in cc_sources: | 152 for source in cc_sources: |
| 147 if header_re.match(source): | 153 if header_re.match(source): |
| 148 lines.append('#include "ppapi/' + source + '"\n') | 154 lines.append('#include "ppapi/' + source + '"\n') |
| 149 WriteLines('tests/test_cc_includes.cc', lines) | 155 lines.append('\n#endif // PPAPI_TESTS_ALL_CPP_INCLUDES_H_\n') |
| 156 WriteLines('tests/all_cpp_includes.h', lines) |
| 150 | 157 |
| 151 | 158 |
| 152 def main(): | 159 def main(): |
| 153 ppapi_gyp_file_name = 'ppapi.gyp' | 160 ppapi_gyp_file_name = 'ppapi.gyp' |
| 154 gyp_file_contents = open(ppapi_gyp_file_name).read() | 161 gyp_file_contents = open(ppapi_gyp_file_name).read() |
| 155 gyp_file_data = eval(gyp_file_contents) | 162 gyp_file_data = eval(gyp_file_contents) |
| 156 VerifyGypFile(gyp_file_data) | 163 VerifyGypFile(gyp_file_data) |
| 157 GenerateCIncludeTest(gyp_file_data) | 164 GenerateCIncludeTest(gyp_file_data) |
| 158 GenerateCCIncludeTest(gyp_file_data) | 165 GenerateCCIncludeTest(gyp_file_data) |
| 159 return 0 | 166 return 0 |
| 160 | 167 |
| 161 | 168 |
| 162 if __name__ == '__main__': | 169 if __name__ == '__main__': |
| 163 sys.exit(main()) | 170 sys.exit(main()) |
| 164 | 171 |
| OLD | NEW |