| 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 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 for fpath in input_api.AffectedFiles(file_filter=file_filter): | 1275 for fpath in input_api.AffectedFiles(file_filter=file_filter): |
| 1276 for lnum, line in fpath.ChangedContents(): | 1276 for lnum, line in fpath.ChangedContents(): |
| 1277 for (deprecated, replacement) in _DEPRECATED_JS: | 1277 for (deprecated, replacement) in _DEPRECATED_JS: |
| 1278 if deprecated in line: | 1278 if deprecated in line: |
| 1279 results.append(output_api.PresubmitError( | 1279 results.append(output_api.PresubmitError( |
| 1280 "%s:%d: Use of deprecated JS %s, use %s instead" % | 1280 "%s:%d: Use of deprecated JS %s, use %s instead" % |
| 1281 (fpath.LocalPath(), lnum, deprecated, replacement))) | 1281 (fpath.LocalPath(), lnum, deprecated, replacement))) |
| 1282 return results | 1282 return results |
| 1283 | 1283 |
| 1284 | 1284 |
| 1285 def _CheckForWeakPtrOrder(input_api, output_api): |
| 1286 """Check for weakptrfactory order in .h files using ChangedContents.""" |
| 1287 problems = [] |
| 1288 warnings = [] |
| 1289 for f in input_api.AffectedFiles(): |
| 1290 if not f.LocalPath().endswith(('.cc', '.cpp', '.h', '.mm')): |
| 1291 continue |
| 1292 contents = f.NewContents() |
| 1293 weak_ptr_flag = False |
| 1294 change_line_num = 0 |
| 1295 for line_num, line in f.ChangedContents(): |
| 1296 change_line_num = line_num |
| 1297 break |
| 1298 curr_line = 0 |
| 1299 change_flag = False |
| 1300 for line in contents: |
| 1301 curr_line += 1 |
| 1302 if (curr_line != change_line_num) and (change_flag != True): |
| 1303 continue |
| 1304 else: |
| 1305 change_flag = True |
| 1306 if 'base::WeakPtrFactory' in line: |
| 1307 weak_ptr_flag = True |
| 1308 continue |
| 1309 if weak_ptr_flag == True: |
| 1310 #Checking for commented line |
| 1311 strip_line = line.strip() |
| 1312 if strip_line.startswith('//'): |
| 1313 continue |
| 1314 #Check for emptyline for skipping |
| 1315 if (len(line.strip()) == 0): |
| 1316 continue |
| 1317 #Check for valid attributes after the WeakPtrFactory pointer |
| 1318 if input_api.re.search(r'(};|\bDISALLOW_COPY_AND_ASSIGN\b)', line): |
| 1319 break |
| 1320 else: |
| 1321 weak_ptr_flag = False |
| 1322 problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 1323 break |
| 1324 |
| 1325 if not problems: |
| 1326 return [] |
| 1327 return [output_api.PresubmitError( |
| 1328 'Member variables should appear before the WeakPtrFactory, to ensure ' |
| 1329 'that any WeakPtrs to Controller are \ninvalidated before its members ' |
| 1330 'variable\'s destructors are executed, rendering them invalid.', |
| 1331 problems)] |
| 1332 |
| 1333 |
| 1285 def _CommonChecks(input_api, output_api): | 1334 def _CommonChecks(input_api, output_api): |
| 1286 """Checks common to both upload and commit.""" | 1335 """Checks common to both upload and commit.""" |
| 1287 results = [] | 1336 results = [] |
| 1288 results.extend(input_api.canned_checks.PanProjectChecks( | 1337 results.extend(input_api.canned_checks.PanProjectChecks( |
| 1289 input_api, output_api, | 1338 input_api, output_api, |
| 1290 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) | 1339 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) |
| 1291 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) | 1340 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
| 1292 results.extend( | 1341 results.extend( |
| 1293 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) | 1342 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
| 1294 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) | 1343 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1318 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) | 1367 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
| 1319 results.extend(_CheckSpamLogging(input_api, output_api)) | 1368 results.extend(_CheckSpamLogging(input_api, output_api)) |
| 1320 results.extend(_CheckForAnonymousVariables(input_api, output_api)) | 1369 results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
| 1321 results.extend(_CheckCygwinShell(input_api, output_api)) | 1370 results.extend(_CheckCygwinShell(input_api, output_api)) |
| 1322 results.extend(_CheckUserActionUpdate(input_api, output_api)) | 1371 results.extend(_CheckUserActionUpdate(input_api, output_api)) |
| 1323 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) | 1372 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) |
| 1324 results.extend(_CheckNoDeprecatedJS(input_api, output_api)) | 1373 results.extend(_CheckNoDeprecatedJS(input_api, output_api)) |
| 1325 results.extend(_CheckParseErrors(input_api, output_api)) | 1374 results.extend(_CheckParseErrors(input_api, output_api)) |
| 1326 results.extend(_CheckForIPCRules(input_api, output_api)) | 1375 results.extend(_CheckForIPCRules(input_api, output_api)) |
| 1327 | 1376 |
| 1377 results.extend(_CheckForWeakPtrOrder(input_api, output_api)) |
| 1328 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): | 1378 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
| 1329 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 1379 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| 1330 input_api, output_api, | 1380 input_api, output_api, |
| 1331 input_api.PresubmitLocalPath(), | 1381 input_api.PresubmitLocalPath(), |
| 1332 whitelist=[r'^PRESUBMIT_test\.py$'])) | 1382 whitelist=[r'^PRESUBMIT_test\.py$'])) |
| 1333 return results | 1383 return results |
| 1334 | 1384 |
| 1335 | 1385 |
| 1336 def _CheckAuthorizedAuthor(input_api, output_api): | 1386 def _CheckAuthorizedAuthor(input_api, output_api): |
| 1337 """For non-googler/chromites committers, verify the author's email address is | 1387 """For non-googler/chromites committers, verify the author's email address is |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 builders.extend(['cros_x86']) | 1789 builders.extend(['cros_x86']) |
| 1740 | 1790 |
| 1741 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it | 1791 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it |
| 1742 # unless they're .gyp(i) files as changes to those files can break the gyp | 1792 # unless they're .gyp(i) files as changes to those files can break the gyp |
| 1743 # step on that bot. | 1793 # step on that bot. |
| 1744 if (not all(re.search('^chrome', f) for f in files) or | 1794 if (not all(re.search('^chrome', f) for f in files) or |
| 1745 any(re.search('\.gypi?$', f) for f in files)): | 1795 any(re.search('\.gypi?$', f) for f in files)): |
| 1746 builders.extend(['android_aosp']) | 1796 builders.extend(['android_aosp']) |
| 1747 | 1797 |
| 1748 return GetDefaultTryConfigs(builders) | 1798 return GetDefaultTryConfigs(builders) |
| OLD | NEW |