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