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

Side by Side Diff: PRESUBMIT.py

Issue 357693004: Revert of Add PRESUBMIT.py warning for contradictory NOTREACHED() use. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 f, white_list=file_inclusion_pattern, black_list=black_list) 1222 f, white_list=file_inclusion_pattern, black_list=black_list)
1223 for fpath in input_api.AffectedFiles(file_filter=file_filter): 1223 for fpath in input_api.AffectedFiles(file_filter=file_filter):
1224 for line_num, line in fpath.ChangedContents(): 1224 for line_num, line in fpath.ChangedContents():
1225 for (deprecated_value, value) in _DEPRECATED_CSS: 1225 for (deprecated_value, value) in _DEPRECATED_CSS:
1226 if input_api.re.search(deprecated_value, line): 1226 if input_api.re.search(deprecated_value, line):
1227 results.append(output_api.PresubmitError( 1227 results.append(output_api.PresubmitError(
1228 "%s:%d: Use of deprecated CSS %s, use %s instead" % 1228 "%s:%d: Use of deprecated CSS %s, use %s instead" %
1229 (fpath.LocalPath(), line_num, deprecated_value, value))) 1229 (fpath.LocalPath(), line_num, deprecated_value, value)))
1230 return results 1230 return results
1231 1231
1232
1233 def _StripCommentsAndStrings(input_api, s):
1234 """Remove comments, replace string literals by a single token. Requires that
1235 input data is formatted with unix-style line ends."""
1236
1237 s = input_api.re.sub(r'\\\n', r'', s) # Continue lines ending in backslash.
1238
1239 out = ''
1240 i = 0
1241 while i < len(s):
1242 c = s[i]
1243
1244 if c == '/':
1245 mo = input_api.re.match(r'//.*', s[i:])
1246 if mo:
1247 i += len(mo.group(0))
1248 continue
1249 mo = input_api.re.match(r'/\*.*?\*/', s[i:], input_api.re.DOTALL)
1250 if mo:
1251 i += len(mo.group(0))
1252 continue
1253
1254 if c == "'":
1255 mo = input_api.re.match(r"'((\\\\)|(\\')|[^']+?)'", s[i:])
1256 if not mo:
1257 raise Exception('bad char: ' + s[i:])
1258 i += len(mo.group(0))
1259 out += ' CHAR_LITERAL '
1260 continue
1261
1262 if c == '"':
1263 mo = input_api.re.match(r'".*?(?<!\\)(\\\\)*"', s[i:])
1264 if not mo:
1265 raise Exception('bad string: ' + s[i:])
1266 i += len(mo.group(0))
1267 out += ' STRING_LITERAL '
1268 continue
1269
1270 out += c
1271 i += 1
1272
1273 return out
1274
1275
1276 def _CheckContradictoryNotreachedUse(input_api, output_api):
1277 file_inclusion_pattern = (
1278 r".+\.c$", r".+\.cc$", r".+\.cpp$", r".+\.h$", r".+\.hpp$", r".+\.inl$",
1279 r".+\.m$", r".+\.mm$" )
1280 black_list = (_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST)
1281 file_filter = lambda f: input_api.FilterSourceFile(
1282 f, white_list=file_inclusion_pattern, black_list=black_list)
1283 results = []
1284 for fpath in input_api.AffectedFiles(file_filter=file_filter):
1285 results.extend(_CheckContradictoryNotreachedUseInFile(input_api, fpath))
1286 return [output_api.PresubmitPromptWarning(r) for r in results]
1287
1288
1289 def _CheckContradictoryNotreachedUseInFile(input_api, f):
1290 style_url = (
1291 'http://chromium.org/developers/coding-style'
1292 '#TOC-CHECK-DCHECK-and-NOTREACHED-')
1293 contents = f.NewContents()
1294 text = ''.join(line + '\n' for line in f.NewContents())
1295 text = _StripCommentsAndStrings(input_api, text)
1296
1297 results = []
1298 while True:
1299 # Capture text between NOTREACHED(); and the next closing brace or "break".
1300 mo = input_api.re.search(
1301 r'[ \t]*NOTREACHED\(\s*\).*?;(?P<between>.*?)((\bbreak\b)|})',
1302 text, input_api.re.DOTALL)
1303 # TODO(tnagel): Catch loops inside which NOTREACHED() is followed by break.
1304 if not mo:
1305 break
1306 text = text[mo.end():]
1307 if input_api.re.match(r'[\s;]*$', mo.group('between'), input_api.re.DOTALL):
1308 continue
1309 excerpt = mo.group(0).rstrip()
1310 if len(excerpt) > 100:
1311 excerpt = excerpt[:100] + ' \u2026' # ellipsis
1312 results.append(
1313 '%s: NOTREACHED() may only be used at end-of-block '
1314 'but is followed by code.\n%s\n'
1315 'Offending section (comments/strings possibly stripped):\n%s'
1316 % (f, style_url, excerpt))
1317 return results
1318
1319
1320 def _CommonChecks(input_api, output_api): 1232 def _CommonChecks(input_api, output_api):
1321 """Checks common to both upload and commit.""" 1233 """Checks common to both upload and commit."""
1322 results = [] 1234 results = []
1323 results.extend(input_api.canned_checks.PanProjectChecks( 1235 results.extend(input_api.canned_checks.PanProjectChecks(
1324 input_api, output_api, 1236 input_api, output_api,
1325 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) 1237 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
1326 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) 1238 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
1327 results.extend( 1239 results.extend(
1328 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) 1240 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
1329 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) 1241 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
(...skipping 17 matching lines...) Expand all
1347 input_api.canned_checks.CheckChangeHasNoTabs( 1259 input_api.canned_checks.CheckChangeHasNoTabs(
1348 input_api, 1260 input_api,
1349 output_api, 1261 output_api,
1350 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) 1262 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
1351 results.extend(_CheckSpamLogging(input_api, output_api)) 1263 results.extend(_CheckSpamLogging(input_api, output_api))
1352 results.extend(_CheckForAnonymousVariables(input_api, output_api)) 1264 results.extend(_CheckForAnonymousVariables(input_api, output_api))
1353 results.extend(_CheckCygwinShell(input_api, output_api)) 1265 results.extend(_CheckCygwinShell(input_api, output_api))
1354 results.extend(_CheckUserActionUpdate(input_api, output_api)) 1266 results.extend(_CheckUserActionUpdate(input_api, output_api))
1355 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) 1267 results.extend(_CheckNoDeprecatedCSS(input_api, output_api))
1356 results.extend(_CheckParseErrors(input_api, output_api)) 1268 results.extend(_CheckParseErrors(input_api, output_api))
1357 results.extend(_CheckContradictoryNotreachedUse(input_api, output_api))
1358 1269
1359 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): 1270 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1360 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( 1271 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1361 input_api, output_api, 1272 input_api, output_api,
1362 input_api.PresubmitLocalPath(), 1273 input_api.PresubmitLocalPath(),
1363 whitelist=[r'^PRESUBMIT_test\.py$'])) 1274 whitelist=[r'^PRESUBMIT_test\.py$']))
1364 return results 1275 return results
1365 1276
1366 1277
1367 def _CheckSubversionConfig(input_api, output_api): 1278 def _CheckSubversionConfig(input_api, output_api):
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 builders.extend(['cros_x86']) 1605 builders.extend(['cros_x86'])
1695 1606
1696 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it 1607 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1697 # unless they're .gyp(i) files as changes to those files can break the gyp 1608 # unless they're .gyp(i) files as changes to those files can break the gyp
1698 # step on that bot. 1609 # step on that bot.
1699 if (not all(re.search('^chrome', f) for f in files) or 1610 if (not all(re.search('^chrome', f) for f in files) or
1700 any(re.search('\.gypi?$', f) for f in files)): 1611 any(re.search('\.gypi?$', f) for f in files)):
1701 builders.extend(['android_aosp']) 1612 builders.extend(['android_aosp'])
1702 1613
1703 return GetDefaultTryConfigs(builders) 1614 return GetDefaultTryConfigs(builders)
OLDNEW
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698