blob: 1f97a89ddf37165b0a0243b78e91d2fe948253c2 [file] [log] [blame]
[email protected]1f7b4172010-01-28 01:17:341# Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]ca8d1982009-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]ca8d1982009-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]ca8d1982009-02-19 16:33:1217
[email protected]379e7dd2010-01-28 17:39:2118_TEXT_FILES = (
19 r".*\.txt",
20 r".*\.json",
21)
[email protected]ca8d1982009-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]6a4c8e682010-12-19 03:31:3432def _CheckNoInterfacesInBase(input_api, output_api, source_file_filter):
33 """Checks to make sure no files in libbase.a have |@interface|."""
34 pattern = input_api.re.compile(r'@interface')
35 files = []
36 for f in input_api.AffectedSourceFiles(source_file_filter):
37 if (f.LocalPath().find('base/') != -1 and
38 f.LocalPath().find('base/test/') == -1):
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 'Objective-C interfaces or categories are forbidden in libbase. ' +
46 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
47 'browse_thread/thread/efb28c10435987fd',
48 files) ]
49 return []
50
[email protected]650c9082010-12-14 14:33:4451def _CheckSingletonInHeaders(input_api, output_api, source_file_filter):
52 """Checks to make sure no header files have |Singleton<|."""
53 pattern = input_api.re.compile(r'Singleton<')
54 files = []
55 for f in input_api.AffectedSourceFiles(source_file_filter):
56 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or
57 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')):
58 contents = input_api.ReadFile(f)
59 if pattern.search(contents):
60 files.append(f)
61
62 if len(files):
63 return [ output_api.PresubmitError(
64 'Found Singleton<T> in the following header files.\n' +
65 'Please move them to an appropriate source file so that the ' +
66 'template gets instantiated in a single compilation unit.',
67 files) ]
68 return []
[email protected]1f7b4172010-01-28 01:17:3469
[email protected]542d1ad22010-08-04 17:50:5570def _CheckConstNSObject(input_api, output_api, source_file_filter):
71 """Checks to make sure no objective-c files have |const NSSomeClass*|."""
72 pattern = input_api.re.compile(r'const\s+NS\w*\s*\*')
73 files = []
74 for f in input_api.AffectedSourceFiles(source_file_filter):
75 if f.LocalPath().endswith('.h') or f.LocalPath().endswith('.mm'):
76 contents = input_api.ReadFile(f)
77 if pattern.search(contents):
78 files.append(f)
79
80 if len(files):
81 if input_api.is_committing:
82 res_type = output_api.PresubmitPromptWarning
83 else:
84 res_type = output_api.PresubmitNotifyResult
85 return [ res_type('|const NSClass*| is wrong, see ' +
86 'http://dev.chromium.org/developers/clang-mac',
87 files) ]
88 return []
89
90
[email protected]1f7b4172010-01-28 01:17:3491def _CommonChecks(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:5492 results = []
[email protected]4306417642009-06-11 00:33:4093 # What does this code do?
94 # It loads the default black list (e.g. third_party, experimental, etc) and
95 # add our black list (breakpad, skia and v8 are still not following
96 # google style and are not really living this repository).
97 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
[email protected]379e7dd2010-01-28 17:39:2198 black_list = input_api.DEFAULT_BLACK_LIST + _EXCLUDED_PATHS
99 white_list = input_api.DEFAULT_WHITE_LIST + _TEXT_FILES
[email protected]4306417642009-06-11 00:33:40100 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
[email protected]379e7dd2010-01-28 17:39:21101 text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list,
102 white_list=white_list)
[email protected]4306417642009-06-11 00:33:40103 results.extend(input_api.canned_checks.CheckLongLines(
[email protected]ea1413862010-05-05 23:24:53104 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40105 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
[email protected]ea1413862010-05-05 23:24:53106 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40107 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
[email protected]ea1413862010-05-05 23:24:53108 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40109 results.extend(input_api.canned_checks.CheckChangeHasBugField(
110 input_api, output_api))
111 results.extend(input_api.canned_checks.CheckChangeHasTestField(
112 input_api, output_api))
113 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
[email protected]ea1413862010-05-05 23:24:53114 input_api, output_api, source_file_filter=text_files))
[email protected]40cdf8b32009-06-26 23:00:37115 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
116 input_api, output_api))
[email protected]1f7b4172010-01-28 01:17:34117 results.extend(input_api.canned_checks.CheckLicense(
[email protected]ea1413862010-05-05 23:24:53118 input_api, output_api, _LICENSE_HEADER, source_file_filter=sources))
[email protected]542d1ad22010-08-04 17:50:55119 results.extend(_CheckConstNSObject(
120 input_api, output_api, source_file_filter=sources))
[email protected]650c9082010-12-14 14:33:44121 results.extend(_CheckSingletonInHeaders(
122 input_api, output_api, source_file_filter=sources))
[email protected]6a4c8e682010-12-19 03:31:34123 results.extend(_CheckNoInterfacesInBase(
124 input_api, output_api, source_file_filter=sources))
[email protected]1f7b4172010-01-28 01:17:34125 return results
126
127
128def CheckChangeOnUpload(input_api, output_api):
129 results = []
130 results.extend(_CommonChecks(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54131 return results
[email protected]ca8d1982009-02-19 16:33:12132
133
134def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54135 results = []
[email protected]806e98e2010-03-19 17:49:27136 if not input_api.json:
137 results.append(output_api.PresubmitNotifyResult(
138 'You don\'t have json nor simplejson installed.\n'
139 ' This is a warning that you will need to upgrade your python '
140 'installation.\n'
141 ' This is no big deal but you\'ll eventually need to '
142 'upgrade.\n'
143 ' How? Easy! You can do it right now and shut me off! Just:\n'
144 ' del depot_tools\\python.bat\n'
145 ' gclient\n'
146 ' Thanks for your patience.'))
[email protected]1f7b4172010-01-28 01:17:34147 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:51148 # TODO(thestig) temporarily disabled, doesn't work in third_party/
149 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
150 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:54151 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:27152 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:34153 input_api,
154 output_api,
[email protected]4efa42142010-08-26 01:29:26155 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:27156 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
157 output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
158 '[email protected]'))
159
[email protected]7fa42f12009-11-09 20:54:16160 # These builders are just too slow.
161 IGNORED_BUILDERS = [
162 'Chromium XP',
[email protected]7fa42f12009-11-09 20:54:16163 'Chromium Mac',
[email protected]01333922010-02-02 21:25:02164 'Chromium Arm (dbg)',
[email protected]7fa42f12009-11-09 20:54:16165 'Chromium Linux',
166 'Chromium Linux x64',
[email protected]7fa42f12009-11-09 20:54:16167 ]
[email protected]806e98e2010-03-19 17:49:27168 results.extend(input_api.canned_checks.CheckBuildbotPendingBuilds(
[email protected]7fa42f12009-11-09 20:54:16169 input_api,
170 output_api,
[email protected]806e98e2010-03-19 17:49:27171 'http://build.chromium.org/buildbot/waterfall/json/builders?filter=1',
[email protected]7fa42f12009-11-09 20:54:16172 6,
173 IGNORED_BUILDERS))
[email protected]fe5f57c52009-06-05 14:25:54174 return results
[email protected]ca8d1982009-02-19 16:33:12175
176
[email protected]5fa06292009-09-29 01:55:00177def GetPreferredTrySlaves():
178 return ['win', 'linux', 'mac']