OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Top-level presubmit script for cc. | 5 """Top-level presubmit script for cc. |
6 | 6 |
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
8 for more details about the presubmit API built into depot_tools. | 8 for more details about the presubmit API built into depot_tools. |
9 """ | 9 """ |
10 | 10 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 if ('FIX'+'ME') in contents: | 139 if ('FIX'+'ME') in contents: |
140 errors.append(f.LocalPath()) | 140 errors.append(f.LocalPath()) |
141 | 141 |
142 if errors: | 142 if errors: |
143 return [output_api.PresubmitError( | 143 return [output_api.PresubmitError( |
144 'All TODO comments should be of the form TODO(name). ' + | 144 'All TODO comments should be of the form TODO(name). ' + |
145 'Use TODO instead of FIX' + 'ME', | 145 'Use TODO instead of FIX' + 'ME', |
146 items=errors)] | 146 items=errors)] |
147 return [] | 147 return [] |
148 | 148 |
149 def CheckScopedPtr(input_api, output_api, | |
150 white_list=CC_SOURCE_FILES, black_list=None): | |
151 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | |
152 source_file_filter = lambda x: input_api.FilterSourceFile(x, | |
153 white_list, | |
154 black_list) | |
155 errors = [] | |
156 for f in input_api.AffectedSourceFiles(source_file_filter): | |
157 for line_number, line in f.ChangedContents(): | |
158 # Disallow: | |
159 # return scoped_ptr<T>(foo); | |
160 # bar = scoped_ptr<T>(foo); | |
161 # But allow: | |
162 # return scoped_ptr<T[]>(foo); | |
163 # bar = scoped_ptr<T[]>(foo); | |
164 if re.search(r'(=|\breturn)\s*scoped_ptr<.*?(?<!])>\([^)]+\)', line): | |
165 errors.append(output_api.PresubmitError( | |
166 ('%s:%d uses explicit scoped_ptr constructor. ' + | |
167 'Use make_scoped_ptr() instead.') % (f.LocalPath(), line_number))) | |
168 # Disallow: | |
169 # return scoped_ptr<T>(); | |
170 # bar = scoped_ptr<T>(); | |
171 if re.search(r'(=|\breturn)\s*scoped_ptr<.*?>\(\)', line): | |
172 errors.append(output_api.PresubmitError( | |
173 '%s:%d uses scoped_ptr<T>(). Use nullptr instead.' % | |
174 (f.LocalPath(), line_number))) | |
175 # Disallow: | |
176 # foo.PassAs<T>(); | |
177 if re.search(r'\bPassAs<.*?>\(\)', line): | |
178 errors.append(output_api.PresubmitError( | |
179 '%s:%d uses PassAs<T>(). Use Pass() instead.' % | |
180 (f.LocalPath(), line_number))) | |
181 return errors | |
182 | |
183 def FindUnquotedQuote(contents, pos): | 149 def FindUnquotedQuote(contents, pos): |
184 match = re.search(r"(?<!\\)(?P<quote>\")", contents[pos:]) | 150 match = re.search(r"(?<!\\)(?P<quote>\")", contents[pos:]) |
185 return -1 if not match else match.start("quote") + pos | 151 return -1 if not match else match.start("quote") + pos |
186 | 152 |
187 def FindUselessIfdefs(input_api, output_api): | 153 def FindUselessIfdefs(input_api, output_api): |
188 errors = [] | 154 errors = [] |
189 source_file_filter = lambda x: x | 155 source_file_filter = lambda x: x |
190 for f in input_api.AffectedSourceFiles(source_file_filter): | 156 for f in input_api.AffectedSourceFiles(source_file_filter): |
191 contents = input_api.ReadFile(f, 'rb') | 157 contents = input_api.ReadFile(f, 'rb') |
192 if re.search(r'#if\s*0\s', contents): | 158 if re.search(r'#if\s*0\s', contents): |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 else: | 279 else: |
314 return [] | 280 return [] |
315 | 281 |
316 def CheckChangeOnUpload(input_api, output_api): | 282 def CheckChangeOnUpload(input_api, output_api): |
317 results = [] | 283 results = [] |
318 results += CheckAsserts(input_api, output_api) | 284 results += CheckAsserts(input_api, output_api) |
319 results += CheckStdAbs(input_api, output_api) | 285 results += CheckStdAbs(input_api, output_api) |
320 results += CheckPassByValue(input_api, output_api) | 286 results += CheckPassByValue(input_api, output_api) |
321 results += CheckChangeLintsClean(input_api, output_api) | 287 results += CheckChangeLintsClean(input_api, output_api) |
322 results += CheckTodos(input_api, output_api) | 288 results += CheckTodos(input_api, output_api) |
323 results += CheckScopedPtr(input_api, output_api) | |
324 results += CheckNamespace(input_api, output_api) | 289 results += CheckNamespace(input_api, output_api) |
325 results += CheckForUseOfWrongClock(input_api, output_api) | 290 results += CheckForUseOfWrongClock(input_api, output_api) |
326 results += FindUselessIfdefs(input_api, output_api) | 291 results += FindUselessIfdefs(input_api, output_api) |
327 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) | 292 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) |
328 return results | 293 return results |
329 | 294 |
330 def GetPreferredTryMasters(project, change): | 295 def GetPreferredTryMasters(project, change): |
331 return { | 296 return { |
332 'tryserver.blink': { | 297 'tryserver.blink': { |
333 'linux_blink_rel': set(['defaulttests']), | 298 'linux_blink_rel': set(['defaulttests']), |
334 }, | 299 }, |
335 'tryserver.chromium.gpu': { | 300 'tryserver.chromium.gpu': { |
336 'linux_gpu': set(['defaulttests']), | 301 'linux_gpu': set(['defaulttests']), |
337 'mac_gpu': set(['defaulttests']), | 302 'mac_gpu': set(['defaulttests']), |
338 'win_gpu': set(['defaulttests']), | 303 'win_gpu': set(['defaulttests']), |
339 }, | 304 }, |
340 } | 305 } |
OLD | NEW |