blob: ffb668cd1e9bed5aa9beebabf853f7b5cb68e661 [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]3e4eb112011-01-18 03:29:5412 r"^breakpad[\\\/].*",
13 r"^net/tools/spdyshark/[\\\/].*",
14 r"^skia[\\\/].*",
15 r"^v8[\\\/].*",
16 r".*MakeFile$",
[email protected]4306417642009-06-11 00:33:4017)
[email protected]ca8d1982009-02-19 16:33:1218
[email protected]379e7dd2010-01-28 17:39:2119_TEXT_FILES = (
20 r".*\.txt",
21 r".*\.json",
22)
[email protected]ca8d1982009-02-19 16:33:1223
[email protected]1f7b4172010-01-28 01:17:3424_LICENSE_HEADER = (
[email protected]38fdd9d2010-01-28 18:33:2225 r".*? Copyright \(c\) 20[0-9\-]{2,7} The Chromium Authors\. All rights "
26 r"reserved\." "\n"
[email protected]1f7b4172010-01-28 01:17:3427 r".*? Use of this source code is governed by a BSD-style license that can "
28 "be\n"
29 r".*? found in the LICENSE file\."
30 "\n"
31)
32
[email protected]6a4c8e682010-12-19 03:31:3433def _CheckNoInterfacesInBase(input_api, output_api, source_file_filter):
34 """Checks to make sure no files in libbase.a have |@interface|."""
35 pattern = input_api.re.compile(r'@interface')
36 files = []
37 for f in input_api.AffectedSourceFiles(source_file_filter):
38 if (f.LocalPath().find('base/') != -1 and
39 f.LocalPath().find('base/test/') == -1):
40 contents = input_api.ReadFile(f)
41 if pattern.search(contents):
42 files.append(f)
43
44 if len(files):
45 return [ output_api.PresubmitError(
46 'Objective-C interfaces or categories are forbidden in libbase. ' +
47 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
48 'browse_thread/thread/efb28c10435987fd',
49 files) ]
50 return []
51
[email protected]650c9082010-12-14 14:33:4452def _CheckSingletonInHeaders(input_api, output_api, source_file_filter):
53 """Checks to make sure no header files have |Singleton<|."""
54 pattern = input_api.re.compile(r'Singleton<')
55 files = []
56 for f in input_api.AffectedSourceFiles(source_file_filter):
57 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or
58 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')):
59 contents = input_api.ReadFile(f)
60 if pattern.search(contents):
61 files.append(f)
62
63 if len(files):
64 return [ output_api.PresubmitError(
65 'Found Singleton<T> in the following header files.\n' +
66 'Please move them to an appropriate source file so that the ' +
67 'template gets instantiated in a single compilation unit.',
68 files) ]
69 return []
[email protected]1f7b4172010-01-28 01:17:3470
[email protected]b337cb5b2011-01-23 21:24:0571
72def _CheckSubversionConfig(input_api, output_api):
73 """Verifies the subversion config file is correctly setup.
74
75 Checks that autoprops are enabled, returns an error otherwise.
76 """
77 join = input_api.os_path.join
78 if input_api.platform == 'win32':
79 appdata = input_api.environ.get('APPDATA', '')
80 if not appdata:
81 return [output_api.PresubmitError('%APPDATA% is not configured.')]
82 path = join(appdata, 'Subversion', 'config')
83 else:
84 home = input_api.environ.get('HOME', '')
85 if not home:
86 return [output_api.PresubmitError('$HOME is not configured.')]
87 path = join(home, '.subversion', 'config')
88
89 error_msg = (
90 'Please look at http://dev.chromium.org/developers/coding-style to\n'
91 'configure your subversion configuration file. This enables automatic\n'
92 'properties to simplify the project maintenance.')
93
94 try:
95 lines = open(path, 'r').read().splitlines()
96 # Make sure auto-props is enabled and check for 2 Chromium standard
97 # auto-prop.
98 if (not '*.cc = svn:eol-style=LF' in lines or
99 not '*.pdf = svn:mime-type=application/pdf' in lines or
100 not 'enable-auto-props = yes' in lines):
101 return [
102 output_api.PresubmitError(
103 'It looks like you have not configured your subversion config '
104 'file.\n' + error_msg)
105 ]
106 except (OSError, IOError):
107 return [
108 output_api.PresubmitError(
109 'Can\'t find your subversion config file.\n' + error_msg)
110 ]
111 return []
112
113
[email protected]542d1ad22010-08-04 17:50:55114def _CheckConstNSObject(input_api, output_api, source_file_filter):
115 """Checks to make sure no objective-c files have |const NSSomeClass*|."""
116 pattern = input_api.re.compile(r'const\s+NS\w*\s*\*')
117 files = []
118 for f in input_api.AffectedSourceFiles(source_file_filter):
119 if f.LocalPath().endswith('.h') or f.LocalPath().endswith('.mm'):
120 contents = input_api.ReadFile(f)
121 if pattern.search(contents):
122 files.append(f)
123
124 if len(files):
125 if input_api.is_committing:
126 res_type = output_api.PresubmitPromptWarning
127 else:
128 res_type = output_api.PresubmitNotifyResult
129 return [ res_type('|const NSClass*| is wrong, see ' +
130 'http://dev.chromium.org/developers/clang-mac',
131 files) ]
132 return []
133
134
[email protected]1f7b4172010-01-28 01:17:34135def _CommonChecks(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54136 results = []
[email protected]4306417642009-06-11 00:33:40137 # What does this code do?
138 # It loads the default black list (e.g. third_party, experimental, etc) and
139 # add our black list (breakpad, skia and v8 are still not following
140 # google style and are not really living this repository).
141 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
[email protected]379e7dd2010-01-28 17:39:21142 black_list = input_api.DEFAULT_BLACK_LIST + _EXCLUDED_PATHS
143 white_list = input_api.DEFAULT_WHITE_LIST + _TEXT_FILES
[email protected]4306417642009-06-11 00:33:40144 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
[email protected]379e7dd2010-01-28 17:39:21145 text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list,
146 white_list=white_list)
[email protected]4306417642009-06-11 00:33:40147 results.extend(input_api.canned_checks.CheckLongLines(
[email protected]ea1413862010-05-05 23:24:53148 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40149 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
[email protected]ea1413862010-05-05 23:24:53150 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40151 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
[email protected]ea1413862010-05-05 23:24:53152 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40153 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
[email protected]ea1413862010-05-05 23:24:53154 input_api, output_api, source_file_filter=text_files))
[email protected]40cdf8b32009-06-26 23:00:37155 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
156 input_api, output_api))
[email protected]1f7b4172010-01-28 01:17:34157 results.extend(input_api.canned_checks.CheckLicense(
[email protected]ea1413862010-05-05 23:24:53158 input_api, output_api, _LICENSE_HEADER, source_file_filter=sources))
[email protected]542d1ad22010-08-04 17:50:55159 results.extend(_CheckConstNSObject(
160 input_api, output_api, source_file_filter=sources))
[email protected]650c9082010-12-14 14:33:44161 results.extend(_CheckSingletonInHeaders(
162 input_api, output_api, source_file_filter=sources))
[email protected]6a4c8e682010-12-19 03:31:34163 results.extend(_CheckNoInterfacesInBase(
164 input_api, output_api, source_file_filter=sources))
[email protected]1f7b4172010-01-28 01:17:34165 return results
166
167
168def CheckChangeOnUpload(input_api, output_api):
169 results = []
170 results.extend(_CommonChecks(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54171 return results
[email protected]ca8d1982009-02-19 16:33:12172
173
174def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54175 results = []
[email protected]806e98e2010-03-19 17:49:27176 if not input_api.json:
177 results.append(output_api.PresubmitNotifyResult(
178 'You don\'t have json nor simplejson installed.\n'
179 ' This is a warning that you will need to upgrade your python '
180 'installation.\n'
181 ' This is no big deal but you\'ll eventually need to '
182 'upgrade.\n'
183 ' How? Easy! You can do it right now and shut me off! Just:\n'
184 ' del depot_tools\\python.bat\n'
185 ' gclient\n'
186 ' Thanks for your patience.'))
[email protected]1f7b4172010-01-28 01:17:34187 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:51188 # TODO(thestig) temporarily disabled, doesn't work in third_party/
189 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
190 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:54191 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:27192 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:34193 input_api,
194 output_api,
[email protected]4efa42142010-08-26 01:29:26195 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:27196 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
197 output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
198 '[email protected]'))
199
[email protected]7fa42f12009-11-09 20:54:16200 # These builders are just too slow.
201 IGNORED_BUILDERS = [
202 'Chromium XP',
[email protected]7fa42f12009-11-09 20:54:16203 'Chromium Mac',
[email protected]01333922010-02-02 21:25:02204 'Chromium Arm (dbg)',
[email protected]7fa42f12009-11-09 20:54:16205 'Chromium Linux',
206 'Chromium Linux x64',
[email protected]7fa42f12009-11-09 20:54:16207 ]
[email protected]806e98e2010-03-19 17:49:27208 results.extend(input_api.canned_checks.CheckBuildbotPendingBuilds(
[email protected]7fa42f12009-11-09 20:54:16209 input_api,
210 output_api,
[email protected]07247462010-12-24 07:45:56211 'http://build.chromium.org/p/chromium/json/builders?filter=1',
[email protected]7fa42f12009-11-09 20:54:16212 6,
213 IGNORED_BUILDERS))
[email protected]3e4eb112011-01-18 03:29:54214 results.extend(input_api.canned_checks.CheckChangeHasBugField(
215 input_api, output_api))
216 results.extend(input_api.canned_checks.CheckChangeHasTestField(
217 input_api, output_api))
[email protected]b337cb5b2011-01-23 21:24:05218 results.extend(_CheckSubversionConfig(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54219 return results
[email protected]ca8d1982009-02-19 16:33:12220
221
[email protected]5fa06292009-09-29 01:55:00222def GetPreferredTrySlaves():
223 return ['win', 'linux', 'mac']