OLD | NEW |
---|---|
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 Loading... | |
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. Requires that | |
1067 input data is formatted with unix-style line ends.""" | |
M-A Ruel
2014/06/24 17:45:22
The CRLF -> LF reduction is unnecessary as per ht
Thiemo Nagel
2014/06/25 06:45:54
Thanks. I was foiled into believing \r wasn't str
| |
1068 | |
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 | |
1107 | |
1108 def _CheckContradictoryNotreachedUse(input_api, output_api): | |
1109 file_inclusion_pattern = ( | |
1110 r".+\.c$", r".+\.cc$", r".+\.cpp$", r".+\.h$", r".+\.hpp$", r".+\.inl$", | |
1111 r".+\.m$", r".+\.mm$" ) | |
1112 black_list = (_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST) | |
1113 file_filter = lambda f: input_api.FilterSourceFile( | |
1114 f, white_list=file_inclusion_pattern, black_list=black_list) | |
1115 results = [] | |
1116 for fpath in input_api.AffectedFiles(file_filter=file_filter): | |
1117 results.extend(_CheckContradictoryNotreachedUseInFile(input_api, fpath)) | |
1118 return [output_api.PresubmitPromptWarning(r) for r in results] | |
1119 | |
1120 | |
1121 def _CheckContradictoryNotreachedUseInFile(input_api, f): | |
1122 style_url = ( | |
1123 'http://www.chromium.org/developers/coding-style' | |
M-A Ruel
2014/06/24 17:45:22
optional: you can skip 'www.' to save a few chars
Thiemo Nagel
2014/06/25 06:45:54
Done.
| |
1124 '#TOC-CHECK-DCHECK-and-NOTREACHED-') | |
1125 contents = f.NewContents() | |
1126 text = ''.join(line.rstrip('\r') + '\n' for line in f.NewContents()) | |
1127 text = _StripCommentsAndStrings(input_api, text) | |
1128 | |
1129 results = [] | |
1130 while True: | |
1131 # Capture text between NOTREACHED(); and the next closing brace or "break". | |
1132 mo = input_api.re.search( | |
1133 r'[ \t]*NOTREACHED\(\s*\).*?;(?P<between>.*?)((\bbreak\b)|})', | |
1134 text, input_api.re.DOTALL) | |
1135 # TODO(tnagel): Catch loops inside which NOTREACHED() is followed by break. | |
1136 if not mo: | |
1137 break | |
1138 text = text[mo.end():] | |
1139 if input_api.re.match(r'[\s;]*$', mo.group('between'), input_api.re.DOTALL): | |
1140 continue | |
1141 excerpt = mo.group(0).rstrip() | |
1142 if len(excerpt) > 100: | |
1143 excerpt = excerpt[:100] + ' ...' | |
M-A Ruel
2014/06/24 17:45:22
nit: Replace ' ...' with '\u2026'. It should work
Thiemo Nagel
2014/06/25 06:45:54
Done.
| |
1144 results.append( | |
1145 '%s: NOTREACHED() may only be used at end-of-block ' | |
1146 'but is followed by code.\n%s\n' | |
1147 'Offending section (comments/strings possibly stripped):\n%s' | |
1148 % (f, style_url, excerpt)) | |
1149 return results | |
1150 | |
1151 | |
1065 def _CommonChecks(input_api, output_api): | 1152 def _CommonChecks(input_api, output_api): |
1066 """Checks common to both upload and commit.""" | 1153 """Checks common to both upload and commit.""" |
1067 results = [] | 1154 results = [] |
1068 results.extend(input_api.canned_checks.PanProjectChecks( | 1155 results.extend(input_api.canned_checks.PanProjectChecks( |
1069 input_api, output_api, | 1156 input_api, output_api, |
1070 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) | 1157 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) |
1071 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) | 1158 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
1072 results.extend( | 1159 results.extend( |
1073 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) | 1160 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
1074 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) | 1161 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
(...skipping 15 matching lines...) Expand all Loading... | |
1090 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) | 1177 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) |
1091 results.extend( | 1178 results.extend( |
1092 input_api.canned_checks.CheckChangeHasNoTabs( | 1179 input_api.canned_checks.CheckChangeHasNoTabs( |
1093 input_api, | 1180 input_api, |
1094 output_api, | 1181 output_api, |
1095 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) | 1182 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
1096 results.extend(_CheckSpamLogging(input_api, output_api)) | 1183 results.extend(_CheckSpamLogging(input_api, output_api)) |
1097 results.extend(_CheckForAnonymousVariables(input_api, output_api)) | 1184 results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
1098 results.extend(_CheckCygwinShell(input_api, output_api)) | 1185 results.extend(_CheckCygwinShell(input_api, output_api)) |
1099 results.extend(_CheckUserActionUpdate(input_api, output_api)) | 1186 results.extend(_CheckUserActionUpdate(input_api, output_api)) |
1187 results.extend(_CheckContradictoryNotreachedUse(input_api, output_api)) | |
1100 | 1188 |
1101 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): | 1189 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
1102 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 1190 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
1103 input_api, output_api, | 1191 input_api, output_api, |
1104 input_api.PresubmitLocalPath(), | 1192 input_api.PresubmitLocalPath(), |
1105 whitelist=[r'^PRESUBMIT_test\.py$'])) | 1193 whitelist=[r'^PRESUBMIT_test\.py$'])) |
1106 return results | 1194 return results |
1107 | 1195 |
1108 | 1196 |
1109 def _CheckSubversionConfig(input_api, output_api): | 1197 def _CheckSubversionConfig(input_api, output_api): |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1462 builders.extend(['cros_x86']) | 1550 builders.extend(['cros_x86']) |
1463 | 1551 |
1464 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it | 1552 # 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 | 1553 # unless they're .gyp(i) files as changes to those files can break the gyp |
1466 # step on that bot. | 1554 # step on that bot. |
1467 if (not all(re.search('^chrome', f) for f in files) or | 1555 if (not all(re.search('^chrome', f) for f in files) or |
1468 any(re.search('\.gypi?$', f) for f in files)): | 1556 any(re.search('\.gypi?$', f) for f in files)): |
1469 builders.extend(['android_aosp']) | 1557 builders.extend(['android_aosp']) |
1470 | 1558 |
1471 return GetDefaultTryConfigs(builders) | 1559 return GetDefaultTryConfigs(builders) |
OLD | NEW |