Home | History | Annotate | Download | only in gyp
      1 # Copyright (c) 2012 Google Inc. 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 
      6 """Top-level presubmit script for GYP.
      7 
      8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
      9 for more details about the presubmit API built into gcl.
     10 """
     11 
     12 
     13 PYLINT_BLACKLIST = [
     14     # TODO: fix me.
     15     # From SCons, not done in google style.
     16     'test/lib/TestCmd.py',
     17     'test/lib/TestCommon.py',
     18     'test/lib/TestGyp.py',
     19     # Needs style fix.
     20     'pylib/gyp/generator/xcode.py',
     21 ]
     22 
     23 
     24 PYLINT_DISABLED_WARNINGS = [
     25     # TODO: fix me.
     26     # Many tests include modules they don't use.
     27     'W0611',
     28     # Include order doesn't properly include local files?
     29     'F0401',
     30     # Some use of built-in names.
     31     'W0622',
     32     # Some unused variables.
     33     'W0612',
     34     # Operator not preceded/followed by space.
     35     'C0323',
     36     'C0322',
     37     # Unnecessary semicolon.
     38     'W0301',
     39     # Unused argument.
     40     'W0613',
     41     # String has no effect (docstring in wrong place).
     42     'W0105',
     43     # Comma not followed by space.
     44     'C0324',
     45     # Access to a protected member.
     46     'W0212',
     47     # Bad indent.
     48     'W0311',
     49     # Line too long.
     50     'C0301',
     51     # Undefined variable.
     52     'E0602',
     53     # Not exception type specified.
     54     'W0702',
     55     # No member of that name.
     56     'E1101',
     57     # Dangerous default {}.
     58     'W0102',
     59     # Others, too many to sort.
     60     'W0201', 'W0232', 'E1103', 'W0621', 'W0108', 'W0223', 'W0231',
     61     'R0201', 'E0101', 'C0321',
     62     # ************* Module copy
     63     # W0104:427,12:_test.odict.__setitem__: Statement seems to have no effect
     64     'W0104',
     65 ]
     66 
     67 
     68 def CheckChangeOnUpload(input_api, output_api):
     69   report = []
     70   report.extend(input_api.canned_checks.PanProjectChecks(
     71       input_api, output_api))
     72   return report
     73 
     74 
     75 def CheckChangeOnCommit(input_api, output_api):
     76   report = []
     77 
     78   # Accept any year number from 2009 to the current year.
     79   current_year = int(input_api.time.strftime('%Y'))
     80   allowed_years = (str(s) for s in reversed(xrange(2009, current_year + 1)))
     81   years_re = '(' + '|'.join(allowed_years) + ')'
     82 
     83   # The (c) is deprecated, but tolerate it until it's removed from all files.
     84   license = (
     85       r'.*? Copyright (\(c\) )?%(year)s Google Inc\. All rights reserved\.\n'
     86       r'.*? Use of this source code is governed by a BSD-style license that '
     87         r'can be\n'
     88       r'.*? found in the LICENSE file\.\n'
     89   ) % {
     90       'year': years_re,
     91   }
     92 
     93   report.extend(input_api.canned_checks.PanProjectChecks(
     94       input_api, output_api, license_header=license))
     95   report.extend(input_api.canned_checks.CheckTreeIsOpen(
     96       input_api, output_api,
     97       'http://gyp-status.appspot.com/status',
     98       'http://gyp-status.appspot.com/current'))
     99 
    100   import sys
    101   old_sys_path = sys.path
    102   try:
    103     sys.path = ['pylib', 'test/lib'] + sys.path
    104     report.extend(input_api.canned_checks.RunPylint(
    105         input_api,
    106         output_api,
    107         black_list=PYLINT_BLACKLIST,
    108         disabled_warnings=PYLINT_DISABLED_WARNINGS))
    109   finally:
    110     sys.path = old_sys_path
    111   return report
    112 
    113 
    114 def GetPreferredTrySlaves():
    115   return ['gyp-win32', 'gyp-win64', 'gyp-linux', 'gyp-mac', 'gyp-android']
    116