bradnelson@google.com | 46d34d8 | 2012-05-22 21:06:31 +0000 | [diff] [blame] | 1 | # Copyright (c) 2012 Google Inc. All rights reserved. |
bradnelson@google.com | 58cc353 | 2011-04-01 22:56:20 +0000 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
bradnelson@google.com | 729a886 | 2010-03-09 05:28:05 +0000 | [diff] [blame] | 4 | |
| 5 | |
bradnelson@google.com | 58cc353 | 2011-04-01 22:56:20 +0000 | [diff] [blame] | 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 | """ |
bradnelson@google.com | 729a886 | 2010-03-09 05:28:05 +0000 | [diff] [blame] | 11 | |
| 12 | |
bradnelson@google.com | 46d34d8 | 2012-05-22 21:06:31 +0000 | [diff] [blame] | 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', |
bradnelson@google.com | 46d34d8 | 2012-05-22 21:06:31 +0000 | [diff] [blame] | 19 | ] |
| 20 | |
| 21 | |
| 22 | PYLINT_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.com | 69c5522 | 2012-05-25 21:36:14 +0000 | [diff] [blame] | 59 | 'R0201', 'E0101', 'C0321', |
bradnelson@google.com | 77b7833 | 2012-06-28 17:20:49 +0000 | [diff] [blame] | 60 | # ************* Module copy |
| 61 | # W0104:427,12:_test.odict.__setitem__: Statement seems to have no effect |
| 62 | 'W0104', |
bradnelson@google.com | 46d34d8 | 2012-05-22 21:06:31 +0000 | [diff] [blame] | 63 | ] |
| 64 | |
| 65 | |
bradnelson@google.com | 729a886 | 2010-03-09 05:28:05 +0000 | [diff] [blame] | 66 | def CheckChangeOnUpload(input_api, output_api): |
| 67 | report = [] |
bradnelson@google.com | 58cc353 | 2011-04-01 22:56:20 +0000 | [diff] [blame] | 68 | report.extend(input_api.canned_checks.PanProjectChecks( |
| 69 | input_api, output_api)) |
bradnelson@google.com | 729a886 | 2010-03-09 05:28:05 +0000 | [diff] [blame] | 70 | return report |
| 71 | |
| 72 | |
| 73 | def CheckChangeOnCommit(input_api, output_api): |
| 74 | report = [] |
mark@chromium.org | 19501fb | 2013-01-16 20:12:08 +0000 | [diff] [blame] | 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. |
maruel@chromium.org | 45254f3 | 2011-06-12 22:27:21 +0000 | [diff] [blame] | 82 | license = ( |
mark@chromium.org | 19501fb | 2013-01-16 20:12:08 +0000 | [diff] [blame] | 83 | r'.*? Copyright (\(c\) )?%(year)s Google Inc\. All rights reserved\.\n' |
maruel@chromium.org | 45254f3 | 2011-06-12 22:27:21 +0000 | [diff] [blame] | 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 | ) % { |
mark@chromium.org | 19501fb | 2013-01-16 20:12:08 +0000 | [diff] [blame] | 88 | 'year': years_re, |
maruel@chromium.org | 45254f3 | 2011-06-12 22:27:21 +0000 | [diff] [blame] | 89 | } |
| 90 | |
bradnelson@google.com | 58cc353 | 2011-04-01 22:56:20 +0000 | [diff] [blame] | 91 | report.extend(input_api.canned_checks.PanProjectChecks( |
maruel@chromium.org | 45254f3 | 2011-06-12 22:27:21 +0000 | [diff] [blame] | 92 | input_api, output_api, license_header=license)) |
bradnelson@google.com | 729a886 | 2010-03-09 05:28:05 +0000 | [diff] [blame] | 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')) |
maruel@chromium.org | 2b3dd69 | 2011-11-28 16:31:34 +0000 | [diff] [blame] | 97 | |
scottmg@chromium.org | 27c626e | 2013-12-04 17:25:10 +0000 | [diff] [blame] | 98 | import os |
maruel@chromium.org | 2b3dd69 | 2011-11-28 16:31:34 +0000 | [diff] [blame] | 99 | import sys |
| 100 | old_sys_path = sys.path |
| 101 | try: |
| 102 | sys.path = ['pylib', 'test/lib'] + sys.path |
scottmg@chromium.org | 27c626e | 2013-12-04 17:25:10 +0000 | [diff] [blame] | 103 | blacklist = PYLINT_BLACKLIST |
| 104 | if sys.platform == 'win32': |
| 105 | blacklist = [os.path.normpath(x).replace('\\', '\\\\') |
| 106 | for x in PYLINT_BLACKLIST] |
maruel@chromium.org | 2b3dd69 | 2011-11-28 16:31:34 +0000 | [diff] [blame] | 107 | report.extend(input_api.canned_checks.RunPylint( |
| 108 | input_api, |
bradnelson@google.com | 46d34d8 | 2012-05-22 21:06:31 +0000 | [diff] [blame] | 109 | output_api, |
scottmg@chromium.org | 27c626e | 2013-12-04 17:25:10 +0000 | [diff] [blame] | 110 | black_list=blacklist, |
bradnelson@google.com | 46d34d8 | 2012-05-22 21:06:31 +0000 | [diff] [blame] | 111 | disabled_warnings=PYLINT_DISABLED_WARNINGS)) |
maruel@chromium.org | 2b3dd69 | 2011-11-28 16:31:34 +0000 | [diff] [blame] | 112 | finally: |
| 113 | sys.path = old_sys_path |
bradnelson@google.com | 729a886 | 2010-03-09 05:28:05 +0000 | [diff] [blame] | 114 | return report |
bradnelson@google.com | 58cc353 | 2011-04-01 22:56:20 +0000 | [diff] [blame] | 115 | |
| 116 | |
| 117 | def GetPreferredTrySlaves(): |
torne@chromium.org | f1d6506 | 2013-01-16 19:59:37 +0000 | [diff] [blame] | 118 | return ['gyp-win32', 'gyp-win64', 'gyp-linux', 'gyp-mac', 'gyp-android'] |