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

Side by Side Diff: PRESUBMIT.py

Issue 669853003: Adding presubmit check for WeakPtrFactory in the code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed indentation issues Created 6 years, 2 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 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 if (input_api.re.search(r'\b(FINAL|OVERRIDE)\b', line)): 1267 if (input_api.re.search(r'\b(FINAL|OVERRIDE)\b', line)):
1268 problems.append(' %s:%d' % (f.LocalPath(), line_num)) 1268 problems.append(' %s:%d' % (f.LocalPath(), line_num))
1269 1269
1270 if not problems: 1270 if not problems:
1271 return [] 1271 return []
1272 return [output_api.PresubmitError('Use C++11\'s |final| and |override| ' 1272 return [output_api.PresubmitError('Use C++11\'s |final| and |override| '
1273 'rather than FINAL and OVERRIDE.', 1273 'rather than FINAL and OVERRIDE.',
1274 problems)] 1274 problems)]
1275 1275
1276 1276
1277 def _CheckForWeakPtrOrder(input_api, output_api):
1278 """Check for weakptrfactory order in .h files using ChangedContents."""
1279 problems = []
1280 warnings = []
1281 for f in input_api.AffectedFiles():
1282 if (not f.LocalPath().endswith(('.cc', '.cpp', '.h', '.mm'))):
M-A Ruel 2014/10/22 18:02:40 if not f.LocalPath().endswith(('.cc', '.cpp', '.h'
MRV 2014/10/23 03:06:31 Done.
1283 continue
1284 contents = f.NewContents()
1285 weak_ptr_flag = False
1286 change_line_num = 0
1287 for line_num, line in f.ChangedContents():
1288 change_line_num = line_num
1289 break
1290 curr_line = 0
1291 change_flag = False
1292 for line in contents:
1293 curr_line += 1
1294 if (curr_line != change_line_num) and (change_flag != True):
1295 continue
1296 else:
1297 change_flag = True
1298 if 'base::WeakPtrFactory' in line:
1299 weak_ptr_flag = True
1300 continue
1301 if weak_ptr_flag == True:
1302 #Checking for commented line
1303 strip_line = line.strip()
1304 if strip_line.startswith('//'):
1305 continue
1306 #Check for emptyline for skipping
1307 if (len(line.strip()) == 0):
1308 continue
1309 #Check for valid attributes after the WeakPtrFactory pointer
1310 if input_api.re.search(r'(};|\bDISALLOW_COPY_AND_ASSIGN\b)', line):
1311 break
1312 else:
1313 weak_ptr_flag = False
1314 problems.append(' %s:%d' % (f.LocalPath(), line_num))
1315 break
1316
1317 if not problems:
1318 return []
1319 return [output_api.PresubmitError(
1320 'Member variables should appear before the WeakPtrFactory, to ensure '
1321 'that any WeakPtrs to Controller are \ninvalidated before its members '
1322 'variable\'s destructors are executed, rendering them invalid.',
1323 problems)]
1324
1325
1277 def _CommonChecks(input_api, output_api): 1326 def _CommonChecks(input_api, output_api):
1278 """Checks common to both upload and commit.""" 1327 """Checks common to both upload and commit."""
1279 results = [] 1328 results = []
1280 results.extend(input_api.canned_checks.PanProjectChecks( 1329 results.extend(input_api.canned_checks.PanProjectChecks(
1281 input_api, output_api, 1330 input_api, output_api,
1282 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS)) 1331 excluded_paths=_EXCLUDED_PATHS + _TESTRUNNER_PATHS))
1283 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) 1332 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
1284 results.extend( 1333 results.extend(
1285 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) 1334 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
1286 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) 1335 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
(...skipping 22 matching lines...) Expand all
1309 output_api, 1358 output_api,
1310 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) 1359 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
1311 results.extend(_CheckSpamLogging(input_api, output_api)) 1360 results.extend(_CheckSpamLogging(input_api, output_api))
1312 results.extend(_CheckForAnonymousVariables(input_api, output_api)) 1361 results.extend(_CheckForAnonymousVariables(input_api, output_api))
1313 results.extend(_CheckCygwinShell(input_api, output_api)) 1362 results.extend(_CheckCygwinShell(input_api, output_api))
1314 results.extend(_CheckUserActionUpdate(input_api, output_api)) 1363 results.extend(_CheckUserActionUpdate(input_api, output_api))
1315 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) 1364 results.extend(_CheckNoDeprecatedCSS(input_api, output_api))
1316 results.extend(_CheckParseErrors(input_api, output_api)) 1365 results.extend(_CheckParseErrors(input_api, output_api))
1317 results.extend(_CheckForIPCRules(input_api, output_api)) 1366 results.extend(_CheckForIPCRules(input_api, output_api))
1318 results.extend(_CheckForOverrideAndFinalRules(input_api, output_api)) 1367 results.extend(_CheckForOverrideAndFinalRules(input_api, output_api))
1319 1368 results.extend(_CheckForWeakPtrOrder(input_api, output_api))
1320 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): 1369 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1321 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( 1370 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1322 input_api, output_api, 1371 input_api, output_api,
1323 input_api.PresubmitLocalPath(), 1372 input_api.PresubmitLocalPath(),
1324 whitelist=[r'^PRESUBMIT_test\.py$'])) 1373 whitelist=[r'^PRESUBMIT_test\.py$']))
1325 return results 1374 return results
1326 1375
1327 1376
1328 def _CheckAuthorizedAuthor(input_api, output_api): 1377 def _CheckAuthorizedAuthor(input_api, output_api):
1329 """For non-googler/chromites committers, verify the author's email address is 1378 """For non-googler/chromites committers, verify the author's email address is
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1732 builders.extend(['cros_x86']) 1781 builders.extend(['cros_x86'])
1733 1782
1734 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it 1783 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it
1735 # unless they're .gyp(i) files as changes to those files can break the gyp 1784 # unless they're .gyp(i) files as changes to those files can break the gyp
1736 # step on that bot. 1785 # step on that bot.
1737 if (not all(re.search('^chrome', f) for f in files) or 1786 if (not all(re.search('^chrome', f) for f in files) or
1738 any(re.search('\.gypi?$', f) for f in files)): 1787 any(re.search('\.gypi?$', f) for f in files)):
1739 builders.extend(['android_aosp']) 1788 builders.extend(['android_aosp'])
1740 1789
1741 return GetDefaultTryConfigs(builders) 1790 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