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

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: 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 351
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 # Helper function to smartly try to find a histogram name or prefix in a line.
Alexei Svitkine (slow) 2015/01/30 15:15:36 Make this a """ comment inside the function.
mcasas 2015/01/30 23:45:48 Done.
362 def _FindHistogramNameInLine(histogram_name, line):
363 if not "affected-histogram" in line:
364 return histogram_name in line;
Alexei Svitkine (slow) 2015/01/30 15:15:37 Nit: No need for trailing ;
mcasas 2015/01/30 23:45:48 Done.
365 # A histogram_suffixes tag type has an affected-histogram name as a prefix of
366 # the histogram_name.
367 if not '"' in line:
368 return False;
369 histogram_prefix = line.split('\"')[1];
370 return histogram_prefix in histogram_name;
371
Alexei Svitkine (slow) 2015/01/30 15:15:36 Nit: Two empty lines between functions.
mcasas 2015/01/30 23:45:48 Done.
372 def _CheckUmaHistogramChanges(input_api, output_api):
373 """Check that UMA histogram names in touched lines can still be found in other
374 lines of the patch or in histograms.xml. Note that this check would not catch
375 the reverse: changes in histograms.xml not matched in the code itself."""
376
Alexei Svitkine (slow) 2015/01/30 15:15:37 Nit: No blank line.
mcasas 2015/01/30 23:45:48 Done.
377 touched_histograms = []
378 histograms_xml_modifications = []
379 pattern = input_api.re.compile('UMA_HISTOGRAM.*\("(.*)"')
380 for f in input_api.AffectedFiles():
381 # If histograms.xml itself is modified, keep the modified lines for later.
382 if (f.LocalPath().endswith(('histograms.xml'))):
Alexei Svitkine (slow) 2015/01/30 15:15:36 Nit: No need for outer parens in Python. Same for
mcasas 2015/01/30 23:45:48 Done.
383 histograms_xml_modifications = f.ChangedContents()
384 continue
385 if (not f.LocalPath().endswith(('cc', 'mm', 'cpp'))):
386 continue
387 for line_num, line in f.ChangedContents():
388 found = pattern.search(line)
389 if found:
390 touched_histograms.append([found.group(1), f, line_num])
391
392 # Search for the touched histogram names in the local modifications to
393 # histograms.xml, and, if not found, on the base file.
394 problems = []
395 for histogram_name, f, line_num in touched_histograms:
396 histogram_name_found = False
397 for line_num, line in histograms_xml_modifications:
398 histogram_name_found = _FindHistogramNameInLine(histogram_name, line);
399 if histogram_name_found:
400 break;
401 if histogram_name_found:
402 continue
403
404 with open('tools/metrics/histograms/histograms.xml') as histograms_xml:
Alexei Svitkine (slow) 2015/01/30 15:15:37 It seems inefficient to open the file and iterate
mcasas 2015/01/30 23:45:48 Done.
405 for line in histograms_xml:
406 histogram_name_found = _FindHistogramNameInLine(histogram_name, line);
407 if histogram_name_found:
408 break;
409 if histogram_name_found:
410 continue
411
412 problems.append(' [%s:%d] %s' % (f.LocalPath(), line_num, histogram_name))
413
414 if not problems:
415 return []
416 return [output_api.PresubmitPromptWarning('Some UMA_HISTOGRAM lines have '
417 'been modified and the associated histogram name has no match in either '
418 'metrics/histograms.xml or the modifications of it:', problems)]
419
361 420
362 def _CheckNoNewWStrings(input_api, output_api): 421 def _CheckNoNewWStrings(input_api, output_api):
363 """Checks to make sure we don't introduce use of wstrings.""" 422 """Checks to make sure we don't introduce use of wstrings."""
364 problems = [] 423 problems = []
365 for f in input_api.AffectedFiles(): 424 for f in input_api.AffectedFiles():
366 if (not f.LocalPath().endswith(('.cc', '.h')) or 425 if (not f.LocalPath().endswith(('.cc', '.h')) or
367 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h')) or 426 f.LocalPath().endswith(('test.cc', '_win.cc', '_win.h')) or
368 '/win/' in f.LocalPath()): 427 '/win/' in f.LocalPath()):
369 continue 428 continue
370 429
(...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 return [] 1637 return []
1579 1638
1580 1639
1581 def CheckChangeOnUpload(input_api, output_api): 1640 def CheckChangeOnUpload(input_api, output_api):
1582 results = [] 1641 results = []
1583 results.extend(_CommonChecks(input_api, output_api)) 1642 results.extend(_CommonChecks(input_api, output_api))
1584 results.extend(_CheckValidHostsInDEPS(input_api, output_api)) 1643 results.extend(_CheckValidHostsInDEPS(input_api, output_api))
1585 results.extend(_CheckJavaStyle(input_api, output_api)) 1644 results.extend(_CheckJavaStyle(input_api, output_api))
1586 results.extend( 1645 results.extend(
1587 input_api.canned_checks.CheckGNFormatted(input_api, output_api)) 1646 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
1647 results.extend(_CheckUmaHistogramChanges(input_api, output_api))
1588 return results 1648 return results
1589 1649
1590 1650
1591 def GetTryServerMasterForBot(bot): 1651 def GetTryServerMasterForBot(bot):
1592 """Returns the Try Server master for the given bot. 1652 """Returns the Try Server master for the given bot.
1593 1653
1594 It tries to guess the master from the bot name, but may still fail 1654 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. 1655 and return None. There is no longer a default master.
1596 """ 1656 """
1597 # Potentially ambiguous bot names are listed explicitly. 1657 # Potentially ambiguous bot names are listed explicitly.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 if 'presubmit' in builder: 1754 if 'presubmit' in builder:
1695 builders[master].pop(builder) 1755 builders[master].pop(builder)
1696 1756
1697 # Match things like path/aura/file.cc and path/file_aura.cc. 1757 # Match things like path/aura/file.cc and path/file_aura.cc.
1698 # Same for chromeos. 1758 # Same for chromeos.
1699 if any(re.search(r'[\\\/_](aura|chromeos)', f) for f in files): 1759 if any(re.search(r'[\\\/_](aura|chromeos)', f) for f in files):
1700 tryserver_linux = builders.setdefault('tryserver.chromium.linux', {}) 1760 tryserver_linux = builders.setdefault('tryserver.chromium.linux', {})
1701 tryserver_linux['linux_chromium_chromeos_asan_rel_ng'] = ['defaulttests'] 1761 tryserver_linux['linux_chromium_chromeos_asan_rel_ng'] = ['defaulttests']
1702 1762
1703 return builders 1763 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