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    # Include order doesn't properly include local files?
27    'F0401',
28    # Some use of built-in names.
29    'W0622',
30    # Some unused variables.
31    'W0612',
32    # Operator not preceded/followed by space.
33    'C0323',
34    'C0322',
35    # Unnecessary semicolon.
36    'W0301',
37    # Unused argument.
38    'W0613',
39    # String has no effect (docstring in wrong place).
40    'W0105',
41    # Comma not followed by space.
42    'C0324',
43    # Access to a protected member.
44    'W0212',
45    # Bad indent.
46    'W0311',
47    # Line too long.
48    'C0301',
49    # Undefined variable.
50    'E0602',
51    # Not exception type specified.
52    'W0702',
53    # No member of that name.
54    'E1101',
55    # Dangerous default {}.
56    'W0102',
57    # Others, too many to sort.
58    'W0201', 'W0232', 'E1103', 'W0621', 'W0108', 'W0223', 'W0231',
59    'R0201', 'E0101', 'C0321',
60    # ************* Module copy
61    # W0104:427,12:_test.odict.__setitem__: Statement seems to have no effect
62    'W0104',
63]
64
65
66def CheckChangeOnUpload(input_api, output_api):
67  report = []
68  report.extend(input_api.canned_checks.PanProjectChecks(
69      input_api, output_api))
70  return report
71
72
73def CheckChangeOnCommit(input_api, output_api):
74  report = []
75
76  # Accept any year number from 2009 to the current year.
77  current_year = int(input_api.time.strftime('%Y'))
78  allowed_years = (str(s) for s in reversed(xrange(2009, current_year + 1)))
79  years_re = '(' + '|'.join(allowed_years) + ')'
80
81  # The (c) is deprecated, but tolerate it until it's removed from all files.
82  license = (
83      r'.*? Copyright (\(c\) )?%(year)s Google Inc\. All rights reserved\.\n'
84      r'.*? Use of this source code is governed by a BSD-style license that '
85        r'can be\n'
86      r'.*? found in the LICENSE file\.\n'
87  ) % {
88      'year': years_re,
89  }
90
91  report.extend(input_api.canned_checks.PanProjectChecks(
92      input_api, output_api, license_header=license))
93  report.extend(input_api.canned_checks.CheckTreeIsOpen(
94      input_api, output_api,
95      'http://gyp-status.appspot.com/status',
96      'http://gyp-status.appspot.com/current'))
97
98  import os
99  import sys
100  old_sys_path = sys.path
101  try:
102    sys.path = ['pylib', 'test/lib'] + sys.path
103    blacklist = PYLINT_BLACKLIST
104    if sys.platform == 'win32':
105      blacklist = [os.path.normpath(x).replace('\\', '\\\\')
106                   for x in PYLINT_BLACKLIST]
107    report.extend(input_api.canned_checks.RunPylint(
108        input_api,
109        output_api,
110        black_list=blacklist,
111        disabled_warnings=PYLINT_DISABLED_WARNINGS))
112  finally:
113    sys.path = old_sys_path
114  return report
115
116
117def GetPreferredTrySlaves():
118  return ['gyp-win32', 'gyp-win64', 'gyp-linux', 'gyp-mac', 'gyp-android']
119