Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1317)

Side by Side Diff: PRESUBMIT.py

Issue 885783007: Add PRESUBMIT check if modified UMA histogram name can be found (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: asvitkine@ second round of comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 problems = []
Alexei Svitkine (slow) 2015/02/02 20:25:15 Nit: Move this down to closer where it's used.
mcasas 2015/02/02 20:30:57 Done.
396 unmatched_histograms = []
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 not histogram_name_found:
404 unmatched_histograms.append(histogram_info)
405
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);
Alexei Svitkine (slow) 2015/02/02 20:25:15 Nit: Another ; should go away ;)
mcasas 2015/02/02 20:30:57 Done.
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
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
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
OLDNEW
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698