Add debug logging to Chromoting client UI.
[chromium-blink-merge.git] / PRESUBMIT.py
blob2cfb37f56f66728c2e6bd5c850f40711da3c8e68
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Top-level presubmit script for Chromium.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl.
9 """
11 _EXCLUDED_PATHS = (
12 r"^breakpad[\\\/].*",
13 r"^net/tools/spdyshark/[\\\/].*",
14 r"^skia[\\\/].*",
15 r"^v8[\\\/].*",
16 r".*MakeFile$",
19 _TEXT_FILES = (
20 r".*\.txt",
21 r".*\.json",
24 _LICENSE_HEADER = (
25 r".*? Copyright \(c\) 20[0-9\-]{2,7} The Chromium Authors\. All rights "
26 r"reserved\." "\n"
27 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"
33 def _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)
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 []
52 def _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)
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 []
72 def _CheckSubversionConfig(input_api, output_api):
73 """Verifies the subversion config file is correctly setup.
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')
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.\n'
93 'Pro-tip: just download and install\n'
94 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
96 try:
97 lines = open(path, 'r').read().splitlines()
98 # Make sure auto-props is enabled and check for 2 Chromium standard
99 # auto-prop.
100 if (not '*.cc = svn:eol-style=LF' in lines or
101 not '*.pdf = svn:mime-type=application/pdf' in lines or
102 not 'enable-auto-props = yes' in lines):
103 return [
104 output_api.PresubmitNotifyResult(
105 'It looks like you have not configured your subversion config '
106 'file or it is not up-to-date.\n' + error_msg)
108 except (OSError, IOError):
109 return [
110 output_api.PresubmitNotifyResult(
111 'Can\'t find your subversion config file.\n' + error_msg)
113 return []
116 def _CheckConstNSObject(input_api, output_api, source_file_filter):
117 """Checks to make sure no objective-c files have |const NSSomeClass*|."""
118 pattern = input_api.re.compile(r'const\s+NS\w*\s*\*')
119 files = []
120 for f in input_api.AffectedSourceFiles(source_file_filter):
121 if f.LocalPath().endswith('.h') or f.LocalPath().endswith('.mm'):
122 contents = input_api.ReadFile(f)
123 if pattern.search(contents):
124 files.append(f)
126 if len(files):
127 if input_api.is_committing:
128 res_type = output_api.PresubmitPromptWarning
129 else:
130 res_type = output_api.PresubmitNotifyResult
131 return [ res_type('|const NSClass*| is wrong, see ' +
132 'http://dev.chromium.org/developers/clang-mac',
133 files) ]
134 return []
137 def _CommonChecks(input_api, output_api):
138 results = []
139 # What does this code do?
140 # It loads the default black list (e.g. third_party, experimental, etc) and
141 # add our black list (breakpad, skia and v8 are still not following
142 # google style and are not really living this repository).
143 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
144 black_list = input_api.DEFAULT_BLACK_LIST + _EXCLUDED_PATHS
145 white_list = input_api.DEFAULT_WHITE_LIST + _TEXT_FILES
146 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
147 text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list,
148 white_list=white_list)
149 results.extend(input_api.canned_checks.CheckLongLines(
150 input_api, output_api, source_file_filter=sources))
151 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
152 input_api, output_api, source_file_filter=sources))
153 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
154 input_api, output_api, source_file_filter=sources))
155 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
156 input_api, output_api, source_file_filter=text_files))
157 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
158 input_api, output_api))
159 results.extend(input_api.canned_checks.CheckLicense(
160 input_api, output_api, _LICENSE_HEADER, source_file_filter=sources))
161 results.extend(_CheckConstNSObject(
162 input_api, output_api, source_file_filter=sources))
163 results.extend(_CheckSingletonInHeaders(
164 input_api, output_api, source_file_filter=sources))
165 results.extend(_CheckNoInterfacesInBase(
166 input_api, output_api, source_file_filter=sources))
167 return results
170 def CheckChangeOnUpload(input_api, output_api):
171 results = []
172 results.extend(_CommonChecks(input_api, output_api))
173 return results
176 def CheckChangeOnCommit(input_api, output_api):
177 results = []
178 if not input_api.json:
179 results.append(output_api.PresubmitNotifyResult(
180 'You don\'t have json nor simplejson installed.\n'
181 ' This is a warning that you will need to upgrade your python '
182 'installation.\n'
183 ' This is no big deal but you\'ll eventually need to '
184 'upgrade.\n'
185 ' How? Easy! You can do it right now and shut me off! Just:\n'
186 ' del depot_tools\\python.bat\n'
187 ' gclient\n'
188 ' Thanks for your patience.'))
189 results.extend(_CommonChecks(input_api, output_api))
190 # TODO(thestig) temporarily disabled, doesn't work in third_party/
191 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
192 # input_api, output_api, sources))
193 # Make sure the tree is 'open'.
194 results.extend(input_api.canned_checks.CheckTreeIsOpen(
195 input_api,
196 output_api,
197 json_url='http://chromium-status.appspot.com/current?format=json'))
198 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
199 output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
200 'tryserver@chromium.org'))
202 # These builders are just too slow.
203 IGNORED_BUILDERS = [
204 'Chromium XP',
205 'Chromium Mac',
206 'Chromium Arm (dbg)',
207 'Chromium Linux',
208 'Chromium Linux x64',
210 results.extend(input_api.canned_checks.CheckBuildbotPendingBuilds(
211 input_api,
212 output_api,
213 'http://build.chromium.org/p/chromium/json/builders?filter=1',
215 IGNORED_BUILDERS))
216 results.extend(input_api.canned_checks.CheckChangeHasBugField(
217 input_api, output_api))
218 results.extend(input_api.canned_checks.CheckChangeHasTestField(
219 input_api, output_api))
220 results.extend(_CheckSubversionConfig(input_api, output_api))
221 return results
224 def GetPreferredTrySlaves():
225 return ['win', 'linux', 'mac']