blob: 65df2245acad080469ceb9c7202cc7a4c2bac924 [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]542d1ad22010-08-04 17:50:5571def _CheckConstNSObject(input_api, output_api, source_file_filter):
72 """Checks to make sure no objective-c files have |const NSSomeClass*|."""
73 pattern = input_api.re.compile(r'const\s+NS\w*\s*\*')
74 files = []
75 for f in input_api.AffectedSourceFiles(source_file_filter):
76 if f.LocalPath().endswith('.h') or f.LocalPath().endswith('.mm'):
77 contents = input_api.ReadFile(f)
78 if pattern.search(contents):
79 files.append(f)
80
81 if len(files):
82 if input_api.is_committing:
83 res_type = output_api.PresubmitPromptWarning
84 else:
85 res_type = output_api.PresubmitNotifyResult
86 return [ res_type('|const NSClass*| is wrong, see ' +
87 'http://dev.chromium.org/developers/clang-mac',
88 files) ]
89 return []
90
91
[email protected]1f7b4172010-01-28 01:17:3492def _CommonChecks(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:5493 results = []
[email protected]4306417642009-06-11 00:33:4094 # What does this code do?
95 # It loads the default black list (e.g. third_party, experimental, etc) and
96 # add our black list (breakpad, skia and v8 are still not following
97 # google style and are not really living this repository).
98 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
[email protected]379e7dd2010-01-28 17:39:2199 black_list = input_api.DEFAULT_BLACK_LIST + _EXCLUDED_PATHS
100 white_list = input_api.DEFAULT_WHITE_LIST + _TEXT_FILES
[email protected]4306417642009-06-11 00:33:40101 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
[email protected]379e7dd2010-01-28 17:39:21102 text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list,
103 white_list=white_list)
[email protected]4306417642009-06-11 00:33:40104 results.extend(input_api.canned_checks.CheckLongLines(
[email protected]ea1413862010-05-05 23:24:53105 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40106 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
[email protected]ea1413862010-05-05 23:24:53107 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40108 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
[email protected]ea1413862010-05-05 23:24:53109 input_api, output_api, source_file_filter=sources))
[email protected]4306417642009-06-11 00:33:40110 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
[email protected]ea1413862010-05-05 23:24:53111 input_api, output_api, source_file_filter=text_files))
[email protected]40cdf8b32009-06-26 23:00:37112 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
113 input_api, output_api))
[email protected]1f7b4172010-01-28 01:17:34114 results.extend(input_api.canned_checks.CheckLicense(
[email protected]ea1413862010-05-05 23:24:53115 input_api, output_api, _LICENSE_HEADER, source_file_filter=sources))
[email protected]542d1ad22010-08-04 17:50:55116 results.extend(_CheckConstNSObject(
117 input_api, output_api, source_file_filter=sources))
[email protected]650c9082010-12-14 14:33:44118 results.extend(_CheckSingletonInHeaders(
119 input_api, output_api, source_file_filter=sources))
[email protected]6a4c8e682010-12-19 03:31:34120 results.extend(_CheckNoInterfacesInBase(
121 input_api, output_api, source_file_filter=sources))
[email protected]1f7b4172010-01-28 01:17:34122 return results
123
124
125def CheckChangeOnUpload(input_api, output_api):
126 results = []
127 results.extend(_CommonChecks(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54128 return results
[email protected]ca8d1982009-02-19 16:33:12129
130
131def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54132 results = []
[email protected]806e98e2010-03-19 17:49:27133 if not input_api.json:
134 results.append(output_api.PresubmitNotifyResult(
135 'You don\'t have json nor simplejson installed.\n'
136 ' This is a warning that you will need to upgrade your python '
137 'installation.\n'
138 ' This is no big deal but you\'ll eventually need to '
139 'upgrade.\n'
140 ' How? Easy! You can do it right now and shut me off! Just:\n'
141 ' del depot_tools\\python.bat\n'
142 ' gclient\n'
143 ' Thanks for your patience.'))
[email protected]1f7b4172010-01-28 01:17:34144 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:51145 # TODO(thestig) temporarily disabled, doesn't work in third_party/
146 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
147 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:54148 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:27149 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:34150 input_api,
151 output_api,
[email protected]4efa42142010-08-26 01:29:26152 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:27153 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
154 output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
155 '[email protected]'))
156
[email protected]7fa42f12009-11-09 20:54:16157 # These builders are just too slow.
158 IGNORED_BUILDERS = [
159 'Chromium XP',
[email protected]7fa42f12009-11-09 20:54:16160 'Chromium Mac',
[email protected]01333922010-02-02 21:25:02161 'Chromium Arm (dbg)',
[email protected]7fa42f12009-11-09 20:54:16162 'Chromium Linux',
163 'Chromium Linux x64',
[email protected]7fa42f12009-11-09 20:54:16164 ]
[email protected]806e98e2010-03-19 17:49:27165 results.extend(input_api.canned_checks.CheckBuildbotPendingBuilds(
[email protected]7fa42f12009-11-09 20:54:16166 input_api,
167 output_api,
[email protected]07247462010-12-24 07:45:56168 'http://build.chromium.org/p/chromium/json/builders?filter=1',
[email protected]7fa42f12009-11-09 20:54:16169 6,
170 IGNORED_BUILDERS))
[email protected]3e4eb112011-01-18 03:29:54171 results.extend(input_api.canned_checks.CheckChangeHasBugField(
172 input_api, output_api))
173 results.extend(input_api.canned_checks.CheckChangeHasTestField(
174 input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54175 return results
[email protected]ca8d1982009-02-19 16:33:12176
177
[email protected]5fa06292009-09-29 01:55:00178def GetPreferredTrySlaves():
179 return ['win', 'linux', 'mac']