blob: ce630c99f2189f8b8ee2bc9cdd08272961256c03 [file] [log] [blame]
[email protected]377ab1da2011-03-17 15:36:281# Copyright (c) 2011 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]377ab1da2011-03-17 15:36:2811import time
12
[email protected]379e7dd2010-01-28 17:39:2113_EXCLUDED_PATHS = (
[email protected]3e4eb112011-01-18 03:29:5414 r"^breakpad[\\\/].*",
15 r"^net/tools/spdyshark/[\\\/].*",
16 r"^skia[\\\/].*",
17 r"^v8[\\\/].*",
18 r".*MakeFile$",
[email protected]4306417642009-06-11 00:33:4019)
[email protected]ca8d1982009-02-19 16:33:1220
[email protected]379e7dd2010-01-28 17:39:2121_TEXT_FILES = (
22 r".*\.txt",
23 r".*\.json",
24)
[email protected]ca8d1982009-02-19 16:33:1225
[email protected]1f7b4172010-01-28 01:17:3426_LICENSE_HEADER = (
[email protected]377ab1da2011-03-17 15:36:2827 r".*? Copyright \(c\) %s The Chromium Authors\. All rights reserved\.\n"
[email protected]1f7b4172010-01-28 01:17:3428 r".*? Use of this source code is governed by a BSD-style license that can "
29 "be\n"
30 r".*? found in the LICENSE file\."
31 "\n"
[email protected]377ab1da2011-03-17 15:36:2832) % time.strftime("%Y")
[email protected]1f7b4172010-01-28 01:17:3433
[email protected]6a4c8e682010-12-19 03:31:3434def _CheckNoInterfacesInBase(input_api, output_api, source_file_filter):
35 """Checks to make sure no files in libbase.a have |@interface|."""
36 pattern = input_api.re.compile(r'@interface')
37 files = []
38 for f in input_api.AffectedSourceFiles(source_file_filter):
39 if (f.LocalPath().find('base/') != -1 and
40 f.LocalPath().find('base/test/') == -1):
41 contents = input_api.ReadFile(f)
42 if pattern.search(contents):
43 files.append(f)
44
45 if len(files):
46 return [ output_api.PresubmitError(
47 'Objective-C interfaces or categories are forbidden in libbase. ' +
48 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
49 'browse_thread/thread/efb28c10435987fd',
50 files) ]
51 return []
52
[email protected]650c9082010-12-14 14:33:4453def _CheckSingletonInHeaders(input_api, output_api, source_file_filter):
54 """Checks to make sure no header files have |Singleton<|."""
55 pattern = input_api.re.compile(r'Singleton<')
56 files = []
57 for f in input_api.AffectedSourceFiles(source_file_filter):
58 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or
59 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')):
60 contents = input_api.ReadFile(f)
61 if pattern.search(contents):
62 files.append(f)
63
64 if len(files):
65 return [ output_api.PresubmitError(
66 'Found Singleton<T> in the following header files.\n' +
67 'Please move them to an appropriate source file so that the ' +
68 'template gets instantiated in a single compilation unit.',
69 files) ]
70 return []
[email protected]1f7b4172010-01-28 01:17:3471
[email protected]b337cb5b2011-01-23 21:24:0572
73def _CheckSubversionConfig(input_api, output_api):
74 """Verifies the subversion config file is correctly setup.
75
76 Checks that autoprops are enabled, returns an error otherwise.
77 """
78 join = input_api.os_path.join
79 if input_api.platform == 'win32':
80 appdata = input_api.environ.get('APPDATA', '')
81 if not appdata:
82 return [output_api.PresubmitError('%APPDATA% is not configured.')]
83 path = join(appdata, 'Subversion', 'config')
84 else:
85 home = input_api.environ.get('HOME', '')
86 if not home:
87 return [output_api.PresubmitError('$HOME is not configured.')]
88 path = join(home, '.subversion', 'config')
89
90 error_msg = (
91 'Please look at http://dev.chromium.org/developers/coding-style to\n'
92 'configure your subversion configuration file. This enables automatic\n'
[email protected]c6a3c10b2011-01-24 16:14:2093 'properties to simplify the project maintenance.\n'
94 'Pro-tip: just download and install\n'
95 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
[email protected]b337cb5b2011-01-23 21:24:0596
97 try:
98 lines = open(path, 'r').read().splitlines()
99 # Make sure auto-props is enabled and check for 2 Chromium standard
100 # auto-prop.
101 if (not '*.cc = svn:eol-style=LF' in lines or
102 not '*.pdf = svn:mime-type=application/pdf' in lines or
103 not 'enable-auto-props = yes' in lines):
104 return [
[email protected]79ed7e62011-02-21 21:08:53105 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:05106 'It looks like you have not configured your subversion config '
[email protected]b5359c02011-02-01 20:29:56107 'file or it is not up-to-date.\n' + error_msg)
[email protected]b337cb5b2011-01-23 21:24:05108 ]
109 except (OSError, IOError):
110 return [
[email protected]79ed7e62011-02-21 21:08:53111 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:05112 'Can\'t find your subversion config file.\n' + error_msg)
113 ]
114 return []
115
116
[email protected]542d1ad22010-08-04 17:50:55117def _CheckConstNSObject(input_api, output_api, source_file_filter):
118 """Checks to make sure no objective-c files have |const NSSomeClass*|."""
119 pattern = input_api.re.compile(r'const\s+NS\w*\s*\*')
120 files = []
121 for f in input_api.AffectedSourceFiles(source_file_filter):
122 if f.LocalPath().endswith('.h') or f.LocalPath().endswith('.mm'):
123 contents = input_api.ReadFile(f)
124 if pattern.search(contents):
125 files.append(f)
126
127 if len(files):
128 if input_api.is_committing:
129 res_type = output_api.PresubmitPromptWarning
130 else:
131 res_type = output_api.PresubmitNotifyResult
132 return [ res_type('|const NSClass*| is wrong, see ' +
133 'http://dev.chromium.org/developers/clang-mac',
134 files) ]
135 return []
136
137
[email protected]1f7b4172010-01-28 01:17:34138def _CommonChecks(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54139 results = []
[email protected]4306417642009-06-11 00:33:40140 # What does this code do?
141 # It loads the default black list (e.g. third_party, experimental, etc) and
142 # add our black list (breakpad, skia and v8 are still not following
143 # google style and are not really living this repository).
144 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
[email protected]379e7dd2010-01-28 17:39:21145 black_list = input_api.DEFAULT_BLACK_LIST + _EXCLUDED_PATHS
146 white_list = input_api.DEFAULT_WHITE_LIST + _TEXT_FILES
[email protected]4306417642009-06-11 00:33:40147 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
[email protected]379e7dd2010-01-28 17:39:21148 text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list,
149 white_list=white_list)
[email protected]4306417642009-06-11 00:33:40150 results.extend(input_api.canned_checks.CheckLongLines(
[email protected]ea1413862010-05-05 23:24:53151 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40152 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
[email protected]ea1413862010-05-05 23:24:53153 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40154 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
[email protected]ea1413862010-05-05 23:24:53155 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40156 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
[email protected]ea1413862010-05-05 23:24:53157 input_api, output_api, source_file_filter=text_files))
[email protected]40cdf8b32009-06-26 23:00:37158 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
159 input_api, output_api))
[email protected]1f7b4172010-01-28 01:17:34160 results.extend(input_api.canned_checks.CheckLicense(
[email protected]ea1413862010-05-05 23:24:53161 input_api, output_api, _LICENSE_HEADER, source_file_filter=sources))
[email protected]542d1ad22010-08-04 17:50:55162 results.extend(_CheckConstNSObject(
163 input_api, output_api, source_file_filter=sources))
[email protected]650c9082010-12-14 14:33:44164 results.extend(_CheckSingletonInHeaders(
165 input_api, output_api, source_file_filter=sources))
[email protected]6a4c8e682010-12-19 03:31:34166 results.extend(_CheckNoInterfacesInBase(
167 input_api, output_api, source_file_filter=sources))
[email protected]1f7b4172010-01-28 01:17:34168 return results
169
170
171def CheckChangeOnUpload(input_api, output_api):
172 results = []
173 results.extend(_CommonChecks(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54174 return results
[email protected]ca8d1982009-02-19 16:33:12175
176
177def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54178 results = []
[email protected]806e98e2010-03-19 17:49:27179 if not input_api.json:
180 results.append(output_api.PresubmitNotifyResult(
181 'You don\'t have json nor simplejson installed.\n'
182 ' This is a warning that you will need to upgrade your python '
183 'installation.\n'
184 ' This is no big deal but you\'ll eventually need to '
185 'upgrade.\n'
186 ' How? Easy! You can do it right now and shut me off! Just:\n'
187 ' del depot_tools\\python.bat\n'
188 ' gclient\n'
189 ' Thanks for your patience.'))
[email protected]1f7b4172010-01-28 01:17:34190 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:51191 # TODO(thestig) temporarily disabled, doesn't work in third_party/
192 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
193 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:54194 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:27195 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:34196 input_api,
197 output_api,
[email protected]4efa42142010-08-26 01:29:26198 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:27199 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
200 output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
201 '[email protected]'))
202
[email protected]7fa42f12009-11-09 20:54:16203 # These builders are just too slow.
204 IGNORED_BUILDERS = [
205 'Chromium XP',
[email protected]7fa42f12009-11-09 20:54:16206 'Chromium Mac',
[email protected]01333922010-02-02 21:25:02207 'Chromium Arm (dbg)',
[email protected]7fa42f12009-11-09 20:54:16208 'Chromium Linux',
209 'Chromium Linux x64',
[email protected]7fa42f12009-11-09 20:54:16210 ]
[email protected]806e98e2010-03-19 17:49:27211 results.extend(input_api.canned_checks.CheckBuildbotPendingBuilds(
[email protected]7fa42f12009-11-09 20:54:16212 input_api,
213 output_api,
[email protected]07247462010-12-24 07:45:56214 'http://build.chromium.org/p/chromium/json/builders?filter=1',
[email protected]7fa42f12009-11-09 20:54:16215 6,
216 IGNORED_BUILDERS))
[email protected]3e4eb112011-01-18 03:29:54217 results.extend(input_api.canned_checks.CheckChangeHasBugField(
218 input_api, output_api))
219 results.extend(input_api.canned_checks.CheckChangeHasTestField(
220 input_api, output_api))
[email protected]b337cb5b2011-01-23 21:24:05221 results.extend(_CheckSubversionConfig(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54222 return results
[email protected]ca8d1982009-02-19 16:33:12223
224
[email protected]5fa06292009-09-29 01:55:00225def GetPreferredTrySlaves():
226 return ['win', 'linux', 'mac']