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 Chromium. | 5 """Top-level presubmit script for Chromium. |
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 gcl. | 8 for more details about the presubmit API built into gcl. |
9 """ | 9 """ |
10 | 10 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 350 |
351 for line_num, line in f.ChangedContents(): | 351 for line_num, line in f.ChangedContents(): |
352 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'): | 352 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'): |
353 problems.append(' %s:%d' % (f.LocalPath(), line_num)) | 353 problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
354 | 354 |
355 if not problems: | 355 if not problems: |
356 return [] | 356 return [] |
357 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' + | 357 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' + |
358 '\n'.join(problems))] | 358 '\n'.join(problems))] |
359 | 359 |
360 def _CheckUmaHistogramChanges(input_api, output_api): | |
361 """Check that UMA histogram names in touched lines can still be found in other | |
362 lines of the patch or in histograms.xml. Note that this check would not catch | |
363 the reverse: changes in histograms.xml not matched in the code itself.""" | |
364 | |
365 touched_histograms = [] | |
366 histograms_xml_modifications = [] | |
367 pattern = input_api.re.compile('UMA_HISTOGRAM.*\("(.*)"') | |
368 for f in input_api.AffectedFiles(): | |
369 # If histograms.xml itself is modified, keep the modified lines for later. | |
370 if (f.LocalPath().endswith(('histograms.xml'))): | |
371 histograms_xml_modifications = f.ChangedContents() | |
372 continue | |
373 if (not f.LocalPath().endswith(('cc', 'mm', 'cpp'))): | |
374 continue | |
375 for line_num, line in f.ChangedContents(): | |
376 found = pattern.search(line) | |
377 if found: | |
378 touched_histograms.append([found.group(1), f, line_num]) | |
379 | |
380 # Search for the touched histogram names in the local modifications to | |
381 # histograms.xml, and if not found on the base file. | |
382 problems = [] | |
383 for histogram_name, f, line_num in touched_histograms: | |
384 histogram_name_found = False | |
385 for line_num, line in histograms_xml_modifications: | |
386 if histogram_name in line: | |
387 histogram_name_found = True; | |
388 break; | |
389 if histogram_name_found: | |
390 continue | |
391 | |
392 with open('tools/metrics/histograms/histograms.xml') as histograms_xml: | |
393 for line in histograms_xml: | |
394 if histogram_name in line: | |
395 histogram_name_found = True; | |
396 break; | |
397 if histogram_name_found: | |
398 continue | |
399 problems.append(' [%s:%d] %s' % (f.LocalPath(), line_num, histogram_name)) | |
400 | |
401 if not problems: | |
402 return [] | |
403 return [output_api.PresubmitPromptWarning('Some UMA_HISTOGRAM lines have ' | |
404 'been modified and the associated histogram name has no match in either ' | |
405 'metrics/histograms.xml or the modifications of it:', problems)] | |
406 | |
407 | 360 |
408 def _CheckNoNewWStrings(input_api, output_api): | 361 def _CheckNoNewWStrings(input_api, output_api): |
409 """Checks to make sure we don't introduce use of wstrings.""" | 362 """Checks to make sure we don't introduce use of wstrings.""" |
410 problems = [] | 363 problems = [] |
411 for f in input_api.AffectedFiles(): | 364 for f in input_api.AffectedFiles(): |
412 if (not f.LocalPath().endswith(('.cc', '.h')) or | 365 if (not f.LocalPath().endswith(('.cc', '.h')) or |
413 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h')) or | 366 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h')) or |
414 '/win/' in f.LocalPath()): | 367 '/win/' in f.LocalPath()): |
415 continue | 368 continue |
416 | 369 |
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1586 _IPC_ENUM_TRAITS_DEPRECATED, problems)] | 1539 _IPC_ENUM_TRAITS_DEPRECATED, problems)] |
1587 else: | 1540 else: |
1588 return [] | 1541 return [] |
1589 | 1542 |
1590 | 1543 |
1591 def CheckChangeOnUpload(input_api, output_api): | 1544 def CheckChangeOnUpload(input_api, output_api): |
1592 results = [] | 1545 results = [] |
1593 results.extend(_CommonChecks(input_api, output_api)) | 1546 results.extend(_CommonChecks(input_api, output_api)) |
1594 results.extend(_CheckValidHostsInDEPS(input_api, output_api)) | 1547 results.extend(_CheckValidHostsInDEPS(input_api, output_api)) |
1595 results.extend(_CheckJavaStyle(input_api, output_api)) | 1548 results.extend(_CheckJavaStyle(input_api, output_api)) |
1596 results.extend(_CheckUmaHistogramChanges(input_api, output_api)) | |
1597 results.extend( | 1549 results.extend( |
1598 input_api.canned_checks.CheckGNFormatted(input_api, output_api)) | 1550 input_api.canned_checks.CheckGNFormatted(input_api, output_api)) |
1599 return results | 1551 return results |
1600 | 1552 |
1601 | 1553 |
1602 def GetTryServerMasterForBot(bot): | 1554 def GetTryServerMasterForBot(bot): |
1603 """Returns the Try Server master for the given bot. | 1555 """Returns the Try Server master for the given bot. |
1604 | 1556 |
1605 It tries to guess the master from the bot name, but may still fail | 1557 It tries to guess the master from the bot name, but may still fail |
1606 and return None. There is no longer a default master. | 1558 and return None. There is no longer a default master. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 ] | 1667 ] |
1716 | 1668 |
1717 # Match things like path/aura/file.cc and path/file_aura.cc. | 1669 # Match things like path/aura/file.cc and path/file_aura.cc. |
1718 # Same for chromeos. | 1670 # Same for chromeos. |
1719 if any(re.search(r'[\\\/_](aura|chromeos)', f) for f in files): | 1671 if any(re.search(r'[\\\/_](aura|chromeos)', f) for f in files): |
1720 builders.extend([ | 1672 builders.extend([ |
1721 'linux_chromium_chromeos_asan_rel_ng', | 1673 'linux_chromium_chromeos_asan_rel_ng', |
1722 ]) | 1674 ]) |
1723 | 1675 |
1724 return GetDefaultTryConfigs(builders) | 1676 return GetDefaultTryConfigs(builders) |
OLD | NEW |