• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
9for more details about the presubmit API built into gcl.
10"""
11
12
13PYLINT_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]
20
21
22PYLINT_DISABLED_WARNINGS = [
23    # TODO: fix me.
24    # Many tests include modules they don't use.
25    'W0611',
26    # Possible unbalanced tuple unpacking with sequence.
27    'W0632',
28    # Attempting to unpack a non-sequence.
29    'W0633',
30    # Include order doesn't properly include local files?
31    'F0401',
32    # Some use of built-in names.
33    'W0622',
34    # Some unused variables.
35    'W0612',
36    # Operator not preceded/followed by space.
37    'C0323',
38    'C0322',
39    # Unnecessary semicolon.
40    'W0301',
41    # Unused argument.
42    'W0613',
43    # String has no effect (docstring in wrong place).
44    'W0105',
45    # map/filter on lambda could be replaced by comprehension.
46    'W0110',
47    # Use of eval.
48    'W0123',
49    # Comma not followed by space.
50    'C0324',
51    # Access to a protected member.
52    'W0212',
53    # Bad indent.
54    'W0311',
55    # Line too long.
56    'C0301',
57    # Undefined variable.
58    'E0602',
59    # Not exception type specified.
60    'W0702',
61    # No member of that name.
62    'E1101',
63    # Dangerous default {}.
64    'W0102',
65    # Cyclic import.
66    'R0401',
67    # Others, too many to sort.
68    'W0201', 'W0232', 'E1103', 'W0621', 'W0108', 'W0223', 'W0231',
69    'R0201', 'E0101', 'C0321',
70    # ************* Module copy
71    # W0104:427,12:_test.odict.__setitem__: Statement seems to have no effect
72    'W0104',
73]
74
75
76def _LicenseHeader(input_api):
77  # Accept any year number from 2009 to the current year.
78  current_year = int(input_api.time.strftime('%Y'))
79  allowed_years = (str(s) for s in reversed(range(2009, current_year + 1)))
80  years_re = '(' + '|'.join(allowed_years) + ')'
81
82  # The (c) is deprecated, but tolerate it until it's removed from all files.
83  return (
84      r'.*? Copyright (\(c\) )?%(year)s Google Inc\. All rights reserved\.\n'
85      r'.*? Use of this source code is governed by a BSD-style license that '
86        r'can be\n'
87      r'.*? found in the LICENSE file\.\n'
88  ) % {
89      'year': years_re,
90  }
91
92def CheckChangeOnUpload(input_api, output_api):
93  report = []
94  report.extend(input_api.canned_checks.PanProjectChecks(
95      input_api, output_api, license_header=_LicenseHeader(input_api)))
96  return report
97
98
99def CheckChangeOnCommit(input_api, output_api):
100  report = []
101
102  report.extend(input_api.canned_checks.PanProjectChecks(
103      input_api, output_api, license_header=_LicenseHeader(input_api)))
104  report.extend(input_api.canned_checks.CheckTreeIsOpen(
105      input_api, output_api,
106      'http://gyp-status.appspot.com/status',
107      'http://gyp-status.appspot.com/current'))
108
109  import os
110  import sys
111  old_sys_path = sys.path
112  try:
113    sys.path = ['pylib', 'test/lib'] + sys.path
114    blacklist = PYLINT_BLACKLIST
115    if sys.platform == 'win32':
116      blacklist = [os.path.normpath(x).replace('\\', '\\\\')
117                   for x in PYLINT_BLACKLIST]
118    report.extend(input_api.canned_checks.RunPylint(
119        input_api,
120        output_api,
121        black_list=blacklist,
122        disabled_warnings=PYLINT_DISABLED_WARNINGS))
123  finally:
124    sys.path = old_sys_path
125  return report
126
127
128TRYBOTS = [
129    'linux_try',
130    'mac_try',
131    'win_try',
132]
133
134
135def GetPreferredTryMasters(_, change):
136  return {
137      'client.gyp': { t: set(['defaulttests']) for t in TRYBOTS },
138  }
139