Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(754)

Side by Side Diff: PRESUBMIT.py

Issue 6676115: Migrating common checks to a location that affects all chromium projects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Top-level presubmit script for Chromium. 5 """Top-level presubmit script for Chromium.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl. 8 for more details about the presubmit API built into gcl.
9 """ 9 """
10 10
11 import time
12
13 _EXCLUDED_PATHS = ( 11 _EXCLUDED_PATHS = (
14 r"^breakpad[\\\/].*", 12 r"^breakpad[\\\/].*",
15 r"^net/tools/spdyshark/[\\\/].*", 13 r"^net/tools/spdyshark/[\\\/].*",
16 r"^skia[\\\/].*", 14 r"^skia[\\\/].*",
17 r"^v8[\\\/].*", 15 r"^v8[\\\/].*",
18 r".*MakeFile$", 16 r".*MakeFile$",
19 ) 17 )
20 18
21 _TEXT_FILES = (
22 r".*\.txt",
23 r".*\.json",
24 )
25 19
26 _LICENSE_HEADER = ( 20 def _CheckNoInterfacesInBase(input_api, output_api):
27 r".*? Copyright \(c\) %s The Chromium Authors\. All rights reserved\.\n"
28 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"
32 ) % time.strftime("%Y")
33
34 def _CheckNoInterfacesInBase(input_api, output_api, source_file_filter):
35 """Checks to make sure no files in libbase.a have |@interface|.""" 21 """Checks to make sure no files in libbase.a have |@interface|."""
36 pattern = input_api.re.compile(r'@interface') 22 pattern = input_api.re.compile(r'@interface')
37 files = [] 23 files = []
38 for f in input_api.AffectedSourceFiles(source_file_filter): 24 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
39 if (f.LocalPath().find('base/') != -1 and 25 if (f.LocalPath().find('base/') != -1 and
40 f.LocalPath().find('base/test/') == -1): 26 f.LocalPath().find('base/test/') == -1):
41 contents = input_api.ReadFile(f) 27 contents = input_api.ReadFile(f)
42 if pattern.search(contents): 28 if pattern.search(contents):
43 files.append(f) 29 files.append(f)
44 30
45 if len(files): 31 if len(files):
46 return [ output_api.PresubmitError( 32 return [ output_api.PresubmitError(
47 'Objective-C interfaces or categories are forbidden in libbase. ' + 33 'Objective-C interfaces or categories are forbidden in libbase. ' +
48 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' + 34 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
49 'browse_thread/thread/efb28c10435987fd', 35 'browse_thread/thread/efb28c10435987fd',
50 files) ] 36 files) ]
51 return [] 37 return []
52 38
53 def _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 []
71
72 39
40 def _CommonChecks(input_api, output_api):
41 """Checks common to both upload and commit."""
42 results = []
43 results.extend(input_api.canned_checks.PanProjectChecks(
44 input_api, output_api, excluded_paths=_EXCLUDED_PATHS))
45 results.extend(_CheckNoInterfacesInBase(input_api, output_api))
46 return results
47
48
73 def _CheckSubversionConfig(input_api, output_api): 49 def _CheckSubversionConfig(input_api, output_api):
74 """Verifies the subversion config file is correctly setup. 50 """Verifies the subversion config file is correctly setup.
75 51
76 Checks that autoprops are enabled, returns an error otherwise. 52 Checks that autoprops are enabled, returns an error otherwise.
77 """ 53 """
78 join = input_api.os_path.join 54 join = input_api.os_path.join
79 if input_api.platform == 'win32': 55 if input_api.platform == 'win32':
80 appdata = input_api.environ.get('APPDATA', '') 56 appdata = input_api.environ.get('APPDATA', '')
81 if not appdata: 57 if not appdata:
82 return [output_api.PresubmitError('%APPDATA% is not configured.')] 58 return [output_api.PresubmitError('%APPDATA% is not configured.')]
(...skipping 24 matching lines...) Expand all
107 'file or it is not up-to-date.\n' + error_msg) 83 'file or it is not up-to-date.\n' + error_msg)
108 ] 84 ]
109 except (OSError, IOError): 85 except (OSError, IOError):
110 return [ 86 return [
111 output_api.PresubmitNotifyResult( 87 output_api.PresubmitNotifyResult(
112 'Can\'t find your subversion config file.\n' + error_msg) 88 'Can\'t find your subversion config file.\n' + error_msg)
113 ] 89 ]
114 return [] 90 return []
115 91
116 92
117 def _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
138 def _CommonChecks(input_api, output_api):
139 results = []
140 # 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.
145 black_list = input_api.DEFAULT_BLACK_LIST + _EXCLUDED_PATHS
146 white_list = input_api.DEFAULT_WHITE_LIST + _TEXT_FILES
147 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
148 text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list,
149 white_list=white_list)
150
151 # TODO(dpranke): enable upload as well
152 if input_api.is_committing:
153 results.extend(input_api.canned_checks.CheckOwners(
154 input_api, output_api, source_file_filter=sources))
155
156 results.extend(input_api.canned_checks.CheckLongLines(
157 input_api, output_api, source_file_filter=sources))
158 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
159 input_api, output_api, source_file_filter=sources))
160 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
161 input_api, output_api, source_file_filter=sources))
162 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
163 input_api, output_api, source_file_filter=text_files))
164 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
165 input_api, output_api))
166 results.extend(input_api.canned_checks.CheckLicense(
167 input_api, output_api, _LICENSE_HEADER, source_file_filter=sources))
168 results.extend(_CheckConstNSObject(
169 input_api, output_api, source_file_filter=sources))
170 results.extend(_CheckSingletonInHeaders(
171 input_api, output_api, source_file_filter=sources))
172 results.extend(_CheckNoInterfacesInBase(
173 input_api, output_api, source_file_filter=sources))
174 return results
175
176
177 def CheckChangeOnUpload(input_api, output_api): 93 def CheckChangeOnUpload(input_api, output_api):
178 results = [] 94 results = []
179 results.extend(_CommonChecks(input_api, output_api)) 95 results.extend(_CommonChecks(input_api, output_api))
180 return results 96 return results
181 97
182 98
183 def CheckChangeOnCommit(input_api, output_api): 99 def CheckChangeOnCommit(input_api, output_api):
184 results = [] 100 results = []
185 if not input_api.json: 101 if not input_api.json:
186 results.append(output_api.PresubmitNotifyResult( 102 results.append(output_api.PresubmitNotifyResult(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 results.extend(input_api.canned_checks.CheckChangeHasBugField( 139 results.extend(input_api.canned_checks.CheckChangeHasBugField(
224 input_api, output_api)) 140 input_api, output_api))
225 results.extend(input_api.canned_checks.CheckChangeHasTestField( 141 results.extend(input_api.canned_checks.CheckChangeHasTestField(
226 input_api, output_api)) 142 input_api, output_api))
227 results.extend(_CheckSubversionConfig(input_api, output_api)) 143 results.extend(_CheckSubversionConfig(input_api, output_api))
228 return results 144 return results
229 145
230 146
231 def GetPreferredTrySlaves(): 147 def GetPreferredTrySlaves():
232 return ['win', 'linux', 'mac'] 148 return ['win', 'linux', 'mac']
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698