blob: b79316a9152902f8debe4d1708e8970aded2bf1a [file] [log] [blame]
bradnelson@google.com46d34d82012-05-22 21:06:31 +00001# Copyright (c) 2012 Google Inc. All rights reserved.
bradnelson@google.com58cc3532011-04-01 22:56:20 +00002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
bradnelson@google.com729a8862010-03-09 05:28:05 +00004
5
bradnelson@google.com58cc3532011-04-01 22:56:20 +00006"""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"""
bradnelson@google.com729a8862010-03-09 05:28:05 +000011
12
bradnelson@google.com46d34d82012-05-22 21:06:31 +000013PYLINT_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',
bradnelson@google.com46d34d82012-05-22 21:06:31 +000019]
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',
bradnelson@google.com69c55222012-05-25 21:36:14 +000059 'R0201', 'E0101', 'C0321',
bradnelson@google.com77b78332012-06-28 17:20:49 +000060 # ************* Module copy
61 # W0104:427,12:_test.odict.__setitem__: Statement seems to have no effect
62 'W0104',
bradnelson@google.com46d34d82012-05-22 21:06:31 +000063]
64
65
bradnelson@google.com729a8862010-03-09 05:28:05 +000066def CheckChangeOnUpload(input_api, output_api):
67 report = []
bradnelson@google.com58cc3532011-04-01 22:56:20 +000068 report.extend(input_api.canned_checks.PanProjectChecks(
69 input_api, output_api))
bradnelson@google.com729a8862010-03-09 05:28:05 +000070 return report
71
72
73def CheckChangeOnCommit(input_api, output_api):
74 report = []
mark@chromium.org19501fb2013-01-16 20:12:08 +000075
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.
maruel@chromium.org45254f32011-06-12 22:27:21 +000082 license = (
mark@chromium.org19501fb2013-01-16 20:12:08 +000083 r'.*? Copyright (\(c\) )?%(year)s Google Inc\. All rights reserved\.\n'
maruel@chromium.org45254f32011-06-12 22:27:21 +000084 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 ) % {
mark@chromium.org19501fb2013-01-16 20:12:08 +000088 'year': years_re,
maruel@chromium.org45254f32011-06-12 22:27:21 +000089 }
90
bradnelson@google.com58cc3532011-04-01 22:56:20 +000091 report.extend(input_api.canned_checks.PanProjectChecks(
maruel@chromium.org45254f32011-06-12 22:27:21 +000092 input_api, output_api, license_header=license))
bradnelson@google.com729a8862010-03-09 05:28:05 +000093 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'))
maruel@chromium.org2b3dd692011-11-28 16:31:34 +000097
scottmg@chromium.org27c626e2013-12-04 17:25:10 +000098 import os
maruel@chromium.org2b3dd692011-11-28 16:31:34 +000099 import sys
100 old_sys_path = sys.path
101 try:
102 sys.path = ['pylib', 'test/lib'] + sys.path
scottmg@chromium.org27c626e2013-12-04 17:25:10 +0000103 blacklist = PYLINT_BLACKLIST
104 if sys.platform == 'win32':
105 blacklist = [os.path.normpath(x).replace('\\', '\\\\')
106 for x in PYLINT_BLACKLIST]
maruel@chromium.org2b3dd692011-11-28 16:31:34 +0000107 report.extend(input_api.canned_checks.RunPylint(
108 input_api,
bradnelson@google.com46d34d82012-05-22 21:06:31 +0000109 output_api,
scottmg@chromium.org27c626e2013-12-04 17:25:10 +0000110 black_list=blacklist,
bradnelson@google.com46d34d82012-05-22 21:06:31 +0000111 disabled_warnings=PYLINT_DISABLED_WARNINGS))
maruel@chromium.org2b3dd692011-11-28 16:31:34 +0000112 finally:
113 sys.path = old_sys_path
bradnelson@google.com729a8862010-03-09 05:28:05 +0000114 return report
bradnelson@google.com58cc3532011-04-01 22:56:20 +0000115
116
117def GetPreferredTrySlaves():
torne@chromium.orgf1d65062013-01-16 19:59:37 +0000118 return ['gyp-win32', 'gyp-win64', 'gyp-linux', 'gyp-mac', 'gyp-android']