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

Side by Side Diff: PRESUBMIT.py

Issue 344563003: 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 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] 1055 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')]
1056 import checkstyle 1056 import checkstyle
1057 finally: 1057 finally:
1058 # Restore sys.path to what it was before. 1058 # Restore sys.path to what it was before.
1059 sys.path = original_sys_path 1059 sys.path = original_sys_path
1060 1060
1061 return checkstyle.RunCheckstyle( 1061 return checkstyle.RunCheckstyle(
1062 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml') 1062 input_api, output_api, 'tools/android/checkstyle/chromium-style-5.0.xml')
1063 1063
1064 1064
1065 def _StripCommentsAndStrings(input_api, s):
1066 """Remove comments, replace string literals by a single token."""
1067
1068 s = input_api.re.sub(r'\r\n', r'\n', s) # Normalize line ends.
1069 s = input_api.re.sub(r'\\\n', r'', s) # Continue lines ending in backslash.
1070
1071 out = ''
1072 i = 0
1073 while i < len(s):
1074 c = s[i]
1075
1076 if c == '/':
1077 mo = input_api.re.match(r'//.*', s[i:])
1078 if mo:
1079 i += len(mo.group(0))
1080 continue
1081 mo = input_api.re.match(r'/\*.*?\*/', s[i:], input_api.re.DOTALL)
1082 if mo:
1083 i += len(mo.group(0))
1084 continue
1085
1086 if c == "'":
1087 mo = input_api.re.match(r"'((\\\\)|(\\')|[^']+?)'", s[i:])
1088 if not mo:
1089 raise Exception('bad char: ' + s[i:])
1090 i += len(mo.group(0))
1091 out += ' CHAR_LITERAL '
1092 continue
1093
1094 if c == '"':
1095 mo = input_api.re.match(r'".*?(?<!\\)(\\\\)*"', s[i:])
1096 if not mo:
1097 raise Exception('bad string: ' + s[i:])
1098 i += len(mo.group(0))
1099 out += ' STRING_LITERAL '
1100 continue
1101
1102 out += c
1103 i += 1
1104
1105 return out
1106
M-A Ruel 2014/06/18 19:35:11 2 lines between file level symbols
Thiemo Nagel 2014/06/24 12:07:38 Done.
1107 def _CheckContradictoryNotreachedUse(input_api, output_api):
1108 file_inclusion_pattern = (
1109 r".+\.c$", r".+\.cc$", r".+\.cpp$", r".+\.h$", r".+\.hpp$" )
M-A Ruel 2014/06/18 19:35:11 .m and .mm and .inl
Thiemo Nagel 2014/06/24 12:07:38 Done.
1110 black_list = (_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST)
1111 file_filter = lambda f: input_api.FilterSourceFile(
1112 f, white_list=file_inclusion_pattern, black_list=black_list)
1113 results = []
1114 for fpath in input_api.AffectedFiles(file_filter=file_filter):
1115 results += _CheckContradictoryNotreachedUseInFile(input_api, fpath)
M-A Ruel 2014/06/18 19:35:11 use extend()
Thiemo Nagel 2014/06/24 12:07:38 Done.
1116 return [ output_api.PresubmitPromptWarning(r) for r in results ]
M-A Ruel 2014/06/18 19:35:11 no space around [] or if you want: return map(outp
Thiemo Nagel 2014/06/24 12:07:38 Done.
1117
1118 def _CheckContradictoryNotreachedUseInFile(input_api, f):
1119 style_url = (
1120 'http://www.chromium.org/developers/coding-style'
1121 '#TOC-CHECK-DCHECK-and-NOTREACHED-')
1122 contents = f.NewContents()
1123 text = ''
1124 for line in contents:
M-A Ruel 2014/06/18 19:35:11 You don't use contents after and you just join so:
Thiemo Nagel 2014/06/24 12:07:38 Done.
1125 text += line + '\n'
1126 text = _StripCommentsAndStrings(input_api, text)
1127
1128 results = []
1129 while True:
1130 mo = input_api.re.search(
1131 r'[ \t]*NOTREACHED\(\s*\).*?;(?P<between>.*?)((\bbreak\b)|})',
M-A Ruel 2014/06/18 19:35:11 align arguments at +4
Thiemo Nagel 2014/06/24 12:07:38 Done.
1132 text, input_api.re.DOTALL)
1133 # TODO(tnagel): Catch loops inside which NOTREACHED() is followed by break.
1134 if not mo:
1135 break
1136 text = text[mo.end():]
1137 if input_api.re.match(r'[\s;]*[\s;]*$', mo.group('between'),
1138 input_api.re.DOTALL):
1139 continue
1140 excerpt = mo.group(0).rstrip()
1141 if len(excerpt) > 100:
1142 excerpt = excerpt[:100] + ' ...'
1143 results.append(
1144 '%s: NOTREACHED() may only be used at end-of-block '
1145 'but is followed by code.\n%s\n'
1146 'Offending section (comments/strings possibly stripped):\n%s'
1147 % (f, style_url, excerpt))
1148 return results
1149
1150
1065 def _CommonChecks(input_api, output_api): 1151 def _CommonChecks(input_api, output_api):
1066 """Checks common to both upload and commit.""" 1152 """Checks common to both upload and commit."""
1067 results = [] 1153 results = []
1068 results.extend(input_api.canned_checks.PanProjectChecks( 1154 results.extend(input_api.canned_checks.PanProjectChecks(
1069 input_api, output_api, 1155 input_api, output_api,
1070 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) 1156 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
1071 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) 1157 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
1072 results.extend( 1158 results.extend(
1073 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) 1159 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
1074 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) 1160 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
(...skipping 15 matching lines...) Expand all
1090 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) 1176 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
1091 results.extend( 1177 results.extend(
1092 input_api.canned_checks.CheckChangeHasNoTabs( 1178 input_api.canned_checks.CheckChangeHasNoTabs(
1093 input_api, 1179 input_api,
1094 output_api, 1180 output_api,
1095 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) 1181 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
1096 results.extend(_CheckSpamLogging(input_api, output_api)) 1182 results.extend(_CheckSpamLogging(input_api, output_api))
1097 results.extend(_CheckForAnonymousVariables(input_api, output_api)) 1183 results.extend(_CheckForAnonymousVariables(input_api, output_api))
1098 results.extend(_CheckCygwinShell(input_api, output_api)) 1184 results.extend(_CheckCygwinShell(input_api, output_api))
1099 results.extend(_CheckUserActionUpdate(input_api, output_api)) 1185 results.extend(_CheckUserActionUpdate(input_api, output_api))
1186 results.extend(_CheckContradictoryNotreachedUse(input_api, output_api))
1100 1187
1101 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): 1188 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1102 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( 1189 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1103 input_api, output_api, 1190 input_api, output_api,
1104 input_api.PresubmitLocalPath(), 1191 input_api.PresubmitLocalPath(),
1105 whitelist=[r'^PRESUBMIT_test\.py$'])) 1192 whitelist=[r'^PRESUBMIT_test\.py$']))
1106 return results 1193 return results
1107 1194
1108 1195
1109 def _CheckSubversionConfig(input_api, output_api): 1196 def _CheckSubversionConfig(input_api, output_api):
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 builders.extend(['cros_x86']) 1549 builders.extend(['cros_x86'])
1463 1550
1464 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it 1551 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1465 # unless they're .gyp(i) files as changes to those files can break the gyp 1552 # unless they're .gyp(i) files as changes to those files can break the gyp
1466 # step on that bot. 1553 # step on that bot.
1467 if (not all(re.search('^chrome', f) for f in files) or 1554 if (not all(re.search('^chrome', f) for f in files) or
1468 any(re.search('\.gypi?$', f) for f in files)): 1555 any(re.search('\.gypi?$', f) for f in files)):
1469 builders.extend(['android_aosp']) 1556 builders.extend(['android_aosp'])
1470 1557
1471 return GetDefaultTryConfigs(builders) 1558 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