| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 for line_num, line in f.ChangedContents(): | 352 for line_num, line in f.ChangedContents(): |
| 353 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'): | 353 if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'): |
| 354 problems.append(' %s:%d' % (f.LocalPath(), line_num)) | 354 problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 355 | 355 |
| 356 if not problems: | 356 if not problems: |
| 357 return [] | 357 return [] |
| 358 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' + | 358 return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' + |
| 359 '\n'.join(problems))] | 359 '\n'.join(problems))] |
| 360 | 360 |
| 361 | 361 |
| 362 def _FindHistogramNameInLine(histogram_name, line): |
| 363 """Tries to find a histogram name or prefix in a line.""" |
| 364 if not "affected-histogram" in line: |
| 365 return histogram_name in line |
| 366 # A histogram_suffixes tag type has an affected-histogram name as a prefix of |
| 367 # the histogram_name. |
| 368 if not '"' in line: |
| 369 return False |
| 370 histogram_prefix = line.split('\"')[1] |
| 371 return histogram_prefix in histogram_name |
| 372 |
| 373 |
| 374 def _CheckUmaHistogramChanges(input_api, output_api): |
| 375 """Check that UMA histogram names in touched lines can still be found in other |
| 376 lines of the patch or in histograms.xml. Note that this check would not catch |
| 377 the reverse: changes in histograms.xml not matched in the code itself.""" |
| 378 touched_histograms = [] |
| 379 histograms_xml_modifications = [] |
| 380 pattern = input_api.re.compile('UMA_HISTOGRAM.*\("(.*)"') |
| 381 for f in input_api.AffectedFiles(): |
| 382 # If histograms.xml itself is modified, keep the modified lines for later. |
| 383 if f.LocalPath().endswith(('histograms.xml')): |
| 384 histograms_xml_modifications = f.ChangedContents() |
| 385 continue |
| 386 if not f.LocalPath().endswith(('cc', 'mm', 'cpp')): |
| 387 continue |
| 388 for line_num, line in f.ChangedContents(): |
| 389 found = pattern.search(line) |
| 390 if found: |
| 391 touched_histograms.append([found.group(1), f, line_num]) |
| 392 |
| 393 # Search for the touched histogram names in the local modifications to |
| 394 # histograms.xml, and, if not found, on the base histograms.xml file. |
| 395 unmatched_histograms = [] |
| 396 for histogram_info in touched_histograms: |
| 397 histogram_name_found = False |
| 398 for line_num, line in histograms_xml_modifications: |
| 399 histogram_name_found = _FindHistogramNameInLine(histogram_info[0], line) |
| 400 if histogram_name_found: |
| 401 break |
| 402 if not histogram_name_found: |
| 403 unmatched_histograms.append(histogram_info) |
| 404 |
| 405 problems = [] |
| 406 if unmatched_histograms: |
| 407 with open('tools/metrics/histograms/histograms.xml') as histograms_xml: |
| 408 for histogram_name, f, line_num in unmatched_histograms: |
| 409 histogram_name_found = False |
| 410 for line in histograms_xml: |
| 411 histogram_name_found = _FindHistogramNameInLine(histogram_name, line) |
| 412 if histogram_name_found: |
| 413 break |
| 414 if not histogram_name_found: |
| 415 problems.append(' [%s:%d] %s' % |
| 416 (f.LocalPath(), line_num, histogram_name)) |
| 417 |
| 418 if not problems: |
| 419 return [] |
| 420 return [output_api.PresubmitPromptWarning('Some UMA_HISTOGRAM lines have ' |
| 421 'been modified and the associated histogram name has no match in either ' |
| 422 'metrics/histograms.xml or the modifications of it:', problems)] |
| 423 |
| 424 |
| 362 def _CheckNoNewWStrings(input_api, output_api): | 425 def _CheckNoNewWStrings(input_api, output_api): |
| 363 """Checks to make sure we don't introduce use of wstrings.""" | 426 """Checks to make sure we don't introduce use of wstrings.""" |
| 364 problems = [] | 427 problems = [] |
| 365 for f in input_api.AffectedFiles(): | 428 for f in input_api.AffectedFiles(): |
| 366 if (not f.LocalPath().endswith(('.cc', '.h')) or | 429 if (not f.LocalPath().endswith(('.cc', '.h')) or |
| 367 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h')) or | 430 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h')) or |
| 368 '/win/' in f.LocalPath()): | 431 '/win/' in f.LocalPath()): |
| 369 continue | 432 continue |
| 370 | 433 |
| 371 allowWString = False | 434 allowWString = False |
| (...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 return [] | 1641 return [] |
| 1579 | 1642 |
| 1580 | 1643 |
| 1581 def CheckChangeOnUpload(input_api, output_api): | 1644 def CheckChangeOnUpload(input_api, output_api): |
| 1582 results = [] | 1645 results = [] |
| 1583 results.extend(_CommonChecks(input_api, output_api)) | 1646 results.extend(_CommonChecks(input_api, output_api)) |
| 1584 results.extend(_CheckValidHostsInDEPS(input_api, output_api)) | 1647 results.extend(_CheckValidHostsInDEPS(input_api, output_api)) |
| 1585 results.extend(_CheckJavaStyle(input_api, output_api)) | 1648 results.extend(_CheckJavaStyle(input_api, output_api)) |
| 1586 results.extend( | 1649 results.extend( |
| 1587 input_api.canned_checks.CheckGNFormatted(input_api, output_api)) | 1650 input_api.canned_checks.CheckGNFormatted(input_api, output_api)) |
| 1651 results.extend(_CheckUmaHistogramChanges(input_api, output_api)) |
| 1588 return results | 1652 return results |
| 1589 | 1653 |
| 1590 | 1654 |
| 1591 def GetTryServerMasterForBot(bot): | 1655 def GetTryServerMasterForBot(bot): |
| 1592 """Returns the Try Server master for the given bot. | 1656 """Returns the Try Server master for the given bot. |
| 1593 | 1657 |
| 1594 It tries to guess the master from the bot name, but may still fail | 1658 It tries to guess the master from the bot name, but may still fail |
| 1595 and return None. There is no longer a default master. | 1659 and return None. There is no longer a default master. |
| 1596 """ | 1660 """ |
| 1597 # Potentially ambiguous bot names are listed explicitly. | 1661 # Potentially ambiguous bot names are listed explicitly. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1694 if 'presubmit' in builder: | 1758 if 'presubmit' in builder: |
| 1695 builders[master].pop(builder) | 1759 builders[master].pop(builder) |
| 1696 | 1760 |
| 1697 # Match things like path/aura/file.cc and path/file_aura.cc. | 1761 # Match things like path/aura/file.cc and path/file_aura.cc. |
| 1698 # Same for chromeos. | 1762 # Same for chromeos. |
| 1699 if any(re.search(r'[\\\/_](aura|chromeos)', f) for f in files): | 1763 if any(re.search(r'[\\\/_](aura|chromeos)', f) for f in files): |
| 1700 tryserver_linux = builders.setdefault('tryserver.chromium.linux', {}) | 1764 tryserver_linux = builders.setdefault('tryserver.chromium.linux', {}) |
| 1701 tryserver_linux['linux_chromium_chromeos_asan_rel_ng'] = ['defaulttests'] | 1765 tryserver_linux['linux_chromium_chromeos_asan_rel_ng'] = ['defaulttests'] |
| 1702 | 1766 |
| 1703 return builders | 1767 return builders |
| OLD | NEW |