OLD | NEW |
---|---|
1 # Copyright 2012 the V8 project authors. All rights reserved. | 1 # Copyright 2012 the V8 project authors. All rights reserved. |
2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
4 # met: | 4 # met: |
5 # | 5 # |
6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
(...skipping 16 matching lines...) Expand all Loading... | |
27 | 27 |
28 """Top-level presubmit script for V8. | 28 """Top-level presubmit script for V8. |
29 | 29 |
30 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 30 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
31 for more details about the presubmit API built into gcl. | 31 for more details about the presubmit API built into gcl. |
32 """ | 32 """ |
33 | 33 |
34 import sys | 34 import sys |
35 | 35 |
36 | 36 |
37 _EXCLUDED_PATHS = ( | |
38 r"^test[\\\/].*", | |
39 r"^testing[\\\/].*", | |
40 r"^third_party[\\\/].*", | |
41 r"^tools[\\\/].*", | |
42 ) | |
43 | |
44 | |
45 # Regular expression that matches code only used for test binaries | |
46 # (best effort). | |
47 _TEST_CODE_EXCLUDED_PATHS = ( | |
48 r'.+-unittest\.cc', | |
49 # Has a method VisitForTest(). | |
Michael Starzinger
2014/09/22 22:25:51
Please turn this into a TODO(mstarzinger), I'll pr
| |
50 r'src[\\\/]compiler[\\\/]ast-graph-builder\.cc', | |
51 # Test extension. | |
52 r'src[\\\/]extensions[\\\/]gc-extension\.cc', | |
53 ) | |
54 | |
55 | |
56 _TEST_ONLY_WARNING = ( | |
57 'You might be calling functions intended only for testing from\n' | |
58 'production code. It is OK to ignore this warning if you know what\n' | |
59 'you are doing, as the heuristics used to detect the situation are\n' | |
60 'not perfect. The commit queue will not block on this warning.') | |
61 | |
62 | |
37 def _V8PresubmitChecks(input_api, output_api): | 63 def _V8PresubmitChecks(input_api, output_api): |
38 """Runs the V8 presubmit checks.""" | 64 """Runs the V8 presubmit checks.""" |
39 import sys | 65 import sys |
40 sys.path.append(input_api.os_path.join( | 66 sys.path.append(input_api.os_path.join( |
41 input_api.PresubmitLocalPath(), 'tools')) | 67 input_api.PresubmitLocalPath(), 'tools')) |
42 from presubmit import CppLintProcessor | 68 from presubmit import CppLintProcessor |
43 from presubmit import SourceProcessor | 69 from presubmit import SourceProcessor |
44 from presubmit import CheckRuntimeVsNativesNameClashes | 70 from presubmit import CheckRuntimeVsNativesNameClashes |
45 from presubmit import CheckExternalReferenceRegistration | 71 from presubmit import CheckExternalReferenceRegistration |
46 | 72 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 error_descriptions)) | 132 error_descriptions)) |
107 if warning_descriptions: | 133 if warning_descriptions: |
108 results.append(output_api.PresubmitPromptOrNotify( | 134 results.append(output_api.PresubmitPromptOrNotify( |
109 'You added one or more #includes of files that are temporarily\n' | 135 'You added one or more #includes of files that are temporarily\n' |
110 'allowed but being removed. Can you avoid introducing the\n' | 136 'allowed but being removed. Can you avoid introducing the\n' |
111 '#include? See relevant DEPS file(s) for details and contacts.', | 137 '#include? See relevant DEPS file(s) for details and contacts.', |
112 warning_descriptions)) | 138 warning_descriptions)) |
113 return results | 139 return results |
114 | 140 |
115 | 141 |
142 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): | |
143 """Attempts to prevent use of functions intended only for testing in | |
144 non-testing code. For now this is just a best-effort implementation | |
145 that ignores header files and may have some false positives. A | |
146 better implementation would probably need a proper C++ parser. | |
147 """ | |
148 # We only scan .cc files, as the declaration of for-testing functions in | |
149 # header files are hard to distinguish from calls to such functions without a | |
150 # proper C++ parser. | |
151 file_inclusion_pattern = r'.+\.cc' | |
152 | |
153 base_function_pattern = r'[ :]test::[^\s]+|ForTest(ing)?|for_test(ing)?' | |
154 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern) | |
155 comment_pattern = input_api.re.compile(r'//.*(%s)' % base_function_pattern) | |
156 exclusion_pattern = input_api.re.compile( | |
157 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % ( | |
158 base_function_pattern, base_function_pattern)) | |
159 | |
160 def FilterFile(affected_file): | |
161 black_list = (_EXCLUDED_PATHS + | |
162 _TEST_CODE_EXCLUDED_PATHS + | |
163 input_api.DEFAULT_BLACK_LIST) | |
164 return input_api.FilterSourceFile( | |
165 affected_file, | |
166 white_list=(file_inclusion_pattern, ), | |
167 black_list=black_list) | |
168 | |
169 problems = [] | |
170 for f in input_api.AffectedSourceFiles(FilterFile): | |
171 local_path = f.LocalPath() | |
172 for line_number, line in f.ChangedContents(): | |
173 if (inclusion_pattern.search(line) and | |
174 not comment_pattern.search(line) and | |
175 not exclusion_pattern.search(line)): | |
176 problems.append( | |
177 '%s:%d\n %s' % (local_path, line_number, line.strip())) | |
178 | |
179 if problems: | |
180 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)] | |
181 else: | |
182 return [] | |
183 | |
184 | |
116 def _CommonChecks(input_api, output_api): | 185 def _CommonChecks(input_api, output_api): |
117 """Checks common to both upload and commit.""" | 186 """Checks common to both upload and commit.""" |
118 results = [] | 187 results = [] |
119 results.extend(input_api.canned_checks.CheckOwners( | 188 results.extend(input_api.canned_checks.CheckOwners( |
120 input_api, output_api, source_file_filter=None)) | 189 input_api, output_api, source_file_filter=None)) |
121 results.extend(input_api.canned_checks.CheckPatchFormatted( | 190 results.extend(input_api.canned_checks.CheckPatchFormatted( |
122 input_api, output_api)) | 191 input_api, output_api)) |
123 results.extend(_V8PresubmitChecks(input_api, output_api)) | 192 results.extend(_V8PresubmitChecks(input_api, output_api)) |
124 results.extend(_CheckUnwantedDependencies(input_api, output_api)) | 193 results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
194 results.extend( | |
195 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) | |
125 return results | 196 return results |
126 | 197 |
127 | 198 |
128 def _SkipTreeCheck(input_api, output_api): | 199 def _SkipTreeCheck(input_api, output_api): |
129 """Check the env var whether we want to skip tree check. | 200 """Check the env var whether we want to skip tree check. |
130 Only skip if src/version.cc has been updated.""" | 201 Only skip if src/version.cc has been updated.""" |
131 src_version = 'src/version.cc' | 202 src_version = 'src/version.cc' |
132 FilterFile = lambda file: file.LocalPath() == src_version | 203 FilterFile = lambda file: file.LocalPath() == src_version |
133 if not input_api.AffectedSourceFiles( | 204 if not input_api.AffectedSourceFiles( |
134 lambda file: file.LocalPath() == src_version): | 205 lambda file: file.LocalPath() == src_version): |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 'v8_linux_nosnap_dbg': set(['defaulttests']), | 247 'v8_linux_nosnap_dbg': set(['defaulttests']), |
177 'v8_linux64_rel': set(['defaulttests']), | 248 'v8_linux64_rel': set(['defaulttests']), |
178 'v8_linux_arm_dbg': set(['defaulttests']), | 249 'v8_linux_arm_dbg': set(['defaulttests']), |
179 'v8_linux_arm64_rel': set(['defaulttests']), | 250 'v8_linux_arm64_rel': set(['defaulttests']), |
180 'v8_linux_layout_dbg': set(['defaulttests']), | 251 'v8_linux_layout_dbg': set(['defaulttests']), |
181 'v8_mac_rel': set(['defaulttests']), | 252 'v8_mac_rel': set(['defaulttests']), |
182 'v8_win_rel': set(['defaulttests']), | 253 'v8_win_rel': set(['defaulttests']), |
183 'v8_win64_compile_rel': set(['defaulttests']), | 254 'v8_win64_compile_rel': set(['defaulttests']), |
184 }, | 255 }, |
185 } | 256 } |
OLD | NEW |