Home | History | Annotate | Download | only in chrome
      1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """Presubmit script for changes affecting chrome/
      6 
      7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
      8 for more details about the presubmit API built into gcl.
      9 """
     10 
     11 import re
     12 
     13 INCLUDE_CPP_FILES_ONLY = (
     14   r'.*\.cc$', r'.*\.h$'
     15 )
     16 
     17 EXCLUDE = (
     18   # Objective C confuses everything.
     19   r'.*cocoa.*',
     20   r'.*_mac\.(cc|h)$',
     21   r'.*_mac_.*',
     22   # All the messages files do weird multiple include trickery
     23   r'.*_messages.*\.h$',
     24   r'render_messages.h$',
     25   # Autogenerated window resources files are off limits
     26   r'.*resource.h$',
     27   # Header trickery
     28   r'.*-inl\.h$',
     29   # Templates
     30   r'sigslotrepeater\.h$',
     31   # GCC attribute trickery
     32   r'sel_main\.cc$',
     33   # Mozilla code
     34   r'mork_reader\.h$',
     35   r'mork_reader\.cc$',
     36   r'nss_decryptor_linux\.cc$',
     37   # Has safe printf usage that cpplint complains about
     38   r'safe_browsing_util\.cc$',
     39   # Bogus ifdef tricks
     40   r'renderer_webkitplatformsupport_impl\.cc$',
     41   # Lines > 100 chars
     42   r'gcapi\.cc$',
     43 )
     44 
     45 def _CheckChangeLintsClean(input_api, output_api):
     46   """Makes sure that the chrome/ code is cpplint clean."""
     47   black_list = input_api.DEFAULT_BLACK_LIST + EXCLUDE
     48   sources = lambda x: input_api.FilterSourceFile(
     49     x, white_list=INCLUDE_CPP_FILES_ONLY, black_list=black_list)
     50   return input_api.canned_checks.CheckChangeLintsClean(
     51       input_api, output_api, sources)
     52 
     53 def _CheckNoContentUnitTestsInChrome(input_api, output_api):
     54   """Makes sure that no unit tests from content/ are included in unit_tests."""
     55   problems = []
     56   for f in input_api.AffectedFiles():
     57     if not f.LocalPath().endswith('chrome_tests.gypi'):
     58       continue
     59 
     60     for line_num, line in f.ChangedContents():
     61       m = re.search(r"'(.*\/content\/.*unittest.*)'", line)
     62       if m:
     63         problems.append(m.group(1))
     64 
     65   if not problems:
     66     return []
     67   return [output_api.PresubmitPromptWarning(
     68       'Unit tests located in content/ should be added to the ' +
     69       'content_tests.gypi:content_unittests target.',
     70       items=problems)]
     71 
     72 def _CommonChecks(input_api, output_api):
     73   """Checks common to both upload and commit."""
     74   results = []
     75   results.extend(_CheckNoContentUnitTestsInChrome(input_api, output_api))
     76   return results
     77 
     78 def CheckChangeOnUpload(input_api, output_api):
     79   results = []
     80   results.extend(_CommonChecks(input_api, output_api))
     81   results.extend(_CheckChangeLintsClean(input_api, output_api))
     82   return results
     83 
     84 def CheckChangeOnCommit(input_api, output_api):
     85   results = []
     86   results.extend(_CommonChecks(input_api, output_api))
     87   return results
     88