blob: 311cb203c616b1a67b161a28a055664b0619d720 [file] [log] [blame]
[email protected]1f7b4172010-01-28 01:17:341# Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]ca8d19842009-02-19 16:33:122# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Top-level presubmit script for Chromium.
6
[email protected]f1293792009-07-31 18:09:567See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
[email protected]50d7d721e2009-11-15 17:56:188for more details about the presubmit API built into gcl.
[email protected]ca8d19842009-02-19 16:33:129"""
10
[email protected]379e7dd2010-01-28 17:39:2111_EXCLUDED_PATHS = (
[email protected]33478702009-03-05 14:03:1412 r"breakpad[\\\/].*",
[email protected]abc6a512010-08-04 01:25:4213 r"net/tools/spdyshark/[\\\/].*",
[email protected]33478702009-03-05 14:03:1414 r"skia[\\\/].*",
[email protected]33478702009-03-05 14:03:1415 r"v8[\\\/].*",
[email protected]4306417642009-06-11 00:33:4016)
[email protected]ca8d19842009-02-19 16:33:1217
[email protected]379e7dd2010-01-28 17:39:2118_TEXT_FILES = (
19 r".*\.txt",
20 r".*\.json",
21)
[email protected]ca8d19842009-02-19 16:33:1222
[email protected]1f7b4172010-01-28 01:17:3423_LICENSE_HEADER = (
[email protected]38fdd9d2010-01-28 18:33:2224 r".*? Copyright \(c\) 20[0-9\-]{2,7} The Chromium Authors\. All rights "
25 r"reserved\." "\n"
[email protected]1f7b4172010-01-28 01:17:3426 r".*? Use of this source code is governed by a BSD-style license that can "
27 "be\n"
28 r".*? found in the LICENSE file\."
29 "\n"
30)
31
[email protected]650c9082010-12-14 14:33:4432def _CheckSingletonInHeaders(input_api, output_api, source_file_filter):
33 """Checks to make sure no header files have |Singleton<|."""
34 pattern = input_api.re.compile(r'Singleton<')
35 files = []
36 for f in input_api.AffectedSourceFiles(source_file_filter):
37 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or
38 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')):
39 contents = input_api.ReadFile(f)
40 if pattern.search(contents):
41 files.append(f)
42
43 if len(files):
44 return [ output_api.PresubmitError(
45 'Found Singleton<T> in the following header files.\n' +
46 'Please move them to an appropriate source file so that the ' +
47 'template gets instantiated in a single compilation unit.',
48 files) ]
49 return []
[email protected]1f7b4172010-01-28 01:17:3450
[email protected]542d1ad22010-08-04 17:50:5551def _CheckConstNSObject(input_api, output_api, source_file_filter):
52 """Checks to make sure no objective-c files have |const NSSomeClass*|."""
53 pattern = input_api.re.compile(r'const\s+NS\w*\s*\*')
54 files = []
55 for f in input_api.AffectedSourceFiles(source_file_filter):
56 if f.LocalPath().endswith('.h') or f.LocalPath().endswith('.mm'):
57 contents = input_api.ReadFile(f)
58 if pattern.search(contents):
59 files.append(f)
60
61 if len(files):
62 if input_api.is_committing:
63 res_type = output_api.PresubmitPromptWarning
64 else:
65 res_type = output_api.PresubmitNotifyResult
66 return [ res_type('|const NSClass*| is wrong, see ' +
67 'http://dev.chromium.org/developers/clang-mac',
68 files) ]
69 return []
70
71
[email protected]1f7b4172010-01-28 01:17:3472def _CommonChecks(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:5473 results = []
[email protected]4306417642009-06-11 00:33:4074 # What does this code do?
75 # It loads the default black list (e.g. third_party, experimental, etc) and
76 # add our black list (breakpad, skia and v8 are still not following
77 # google style and are not really living this repository).
78 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
[email protected]379e7dd2010-01-28 17:39:2179 black_list = input_api.DEFAULT_BLACK_LIST + _EXCLUDED_PATHS
80 white_list = input_api.DEFAULT_WHITE_LIST + _TEXT_FILES
[email protected]4306417642009-06-11 00:33:4081 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
[email protected]379e7dd2010-01-28 17:39:2182 text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list,
83 white_list=white_list)
[email protected]4306417642009-06-11 00:33:4084 results.extend(input_api.canned_checks.CheckLongLines(
[email protected]ea1413862010-05-05 23:24:5385 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:4086 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
[email protected]ea1413862010-05-05 23:24:5387 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:4088 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
[email protected]ea1413862010-05-05 23:24:5389 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:4090 results.extend(input_api.canned_checks.CheckChangeHasBugField(
91 input_api, output_api))
92 results.extend(input_api.canned_checks.CheckChangeHasTestField(
93 input_api, output_api))
94 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
[email protected]ea1413862010-05-05 23:24:5395 input_api, output_api, source_file_filter=text_files))
[email protected]40cdf8b32009-06-26 23:00:3796 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
97 input_api, output_api))
[email protected]1f7b4172010-01-28 01:17:3498 results.extend(input_api.canned_checks.CheckLicense(
[email protected]ea1413862010-05-05 23:24:5399 input_api, output_api, _LICENSE_HEADER, source_file_filter=sources))
[email protected]542d1ad22010-08-04 17:50:55100 results.extend(_CheckConstNSObject(
101 input_api, output_api, source_file_filter=sources))
[email protected]650c9082010-12-14 14:33:44102 results.extend(_CheckSingletonInHeaders(
103 input_api, output_api, source_file_filter=sources))
[email protected]1f7b4172010-01-28 01:17:34104 return results
105
106
107def CheckChangeOnUpload(input_api, output_api):
108 results = []
109 results.extend(_CommonChecks(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54110 return results
[email protected]ca8d19842009-02-19 16:33:12111
112
113def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54114 results = []
[email protected]806e98e2010-03-19 17:49:27115 if not input_api.json:
116 results.append(output_api.PresubmitNotifyResult(
117 'You don\'t have json nor simplejson installed.\n'
118 ' This is a warning that you will need to upgrade your python '
119 'installation.\n'
120 ' This is no big deal but you\'ll eventually need to '
121 'upgrade.\n'
122 ' How? Easy! You can do it right now and shut me off! Just:\n'
123 ' del depot_tools\\python.bat\n'
124 ' gclient\n'
125 ' Thanks for your patience.'))
[email protected]1f7b4172010-01-28 01:17:34126 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:51127 # TODO(thestig) temporarily disabled, doesn't work in third_party/
128 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
129 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:54130 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:27131 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:34132 input_api,
133 output_api,
[email protected]4efa42142010-08-26 01:29:26134 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:27135 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
136 output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
137 '[email protected]'))
138
[email protected]7fa42f12009-11-09 20:54:16139 # These builders are just too slow.
140 IGNORED_BUILDERS = [
141 'Chromium XP',
[email protected]7fa42f12009-11-09 20:54:16142 'Chromium Mac',
[email protected]01333922010-02-02 21:25:02143 'Chromium Arm (dbg)',
[email protected]7fa42f12009-11-09 20:54:16144 'Chromium Linux',
145 'Chromium Linux x64',
[email protected]7fa42f12009-11-09 20:54:16146 ]
[email protected]806e98e2010-03-19 17:49:27147 results.extend(input_api.canned_checks.CheckBuildbotPendingBuilds(
[email protected]7fa42f12009-11-09 20:54:16148 input_api,
149 output_api,
[email protected]806e98e2010-03-19 17:49:27150 'http://build.chromium.org/buildbot/waterfall/json/builders?filter=1',
[email protected]7fa42f12009-11-09 20:54:16151 6,
152 IGNORED_BUILDERS))
[email protected]fe5f57c52009-06-05 14:25:54153 return results
[email protected]ca8d19842009-02-19 16:33:12154
155
[email protected]5fa06292009-09-29 01:55:00156def GetPreferredTrySlaves():
157 return ['win', 'linux', 'mac']