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

Side by Side Diff: PRESUBMIT.py

Issue 929043002: Add a presubmit check that warns about declaring Singleton<T> in header files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added presubmit test Created 5 years, 10 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 depot_tools. 8 for more details about the presubmit API built into depot_tools.
9 """ 9 """
10 10
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 sys.path = sys.path + [input_api.os_path.join( 1298 sys.path = sys.path + [input_api.os_path.join(
1299 input_api.PresubmitLocalPath(), 'android_webview', 'tools')] 1299 input_api.PresubmitLocalPath(), 'android_webview', 'tools')]
1300 import copyright_scanner 1300 import copyright_scanner
1301 finally: 1301 finally:
1302 # Restore sys.path to what it was before. 1302 # Restore sys.path to what it was before.
1303 sys.path = original_sys_path 1303 sys.path = original_sys_path
1304 1304
1305 return copyright_scanner.ScanAtPresubmit(input_api, output_api) 1305 return copyright_scanner.ScanAtPresubmit(input_api, output_api)
1306 1306
1307 1307
1308 def _CheckSingletonInHeaders(input_api, output_api):
1309 """Checks to make sure no header files have |Singleton<|."""
1310 def FileFilter(affected_file):
1311 # It's ok for base/memory/singleton.h to have |Singleton<|.
1312 black_list = (_EXCLUDED_PATHS +
1313 input_api.DEFAULT_BLACK_LIST +
1314 (r"^base[\\\/]memory[\\\/]singleton\.h$",))
1315 return input_api.FilterSourceFile(affected_file, black_list=black_list)
1316
1317 pattern = input_api.re.compile(r'(?<!class\s)Singleton\s*<')
1318 files = []
1319 for f in input_api.AffectedSourceFiles(FileFilter):
1320 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or
1321 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')):
1322 contents = input_api.ReadFile(f.LocalPath())
1323 for line in contents.splitlines(False):
1324 if (not input_api.re.match(r'//', line) and # Strip C++ comment.
1325 pattern.search(line)):
1326 files.append(f)
1327 break
1328
1329 if files:
1330 return [ output_api.PresubmitError(
1331 'Found Singleton<T> in the following header files.\n' +
1332 'Please move them to an appropriate source file so that the ' +
1333 'template gets instantiated in a single compilation unit.',
1334 files) ]
1335 return []
1336
1337
1308 _DEPRECATED_CSS = [ 1338 _DEPRECATED_CSS = [
1309 # Values 1339 # Values
1310 ( "-webkit-box", "flex" ), 1340 ( "-webkit-box", "flex" ),
1311 ( "-webkit-inline-box", "inline-flex" ), 1341 ( "-webkit-inline-box", "inline-flex" ),
1312 ( "-webkit-flex", "flex" ), 1342 ( "-webkit-flex", "flex" ),
1313 ( "-webkit-inline-flex", "inline-flex" ), 1343 ( "-webkit-inline-flex", "inline-flex" ),
1314 ( "-webkit-min-content", "min-content" ), 1344 ( "-webkit-min-content", "min-content" ),
1315 ( "-webkit-max-content", "max-content" ), 1345 ( "-webkit-max-content", "max-content" ),
1316 1346
1317 # Properties 1347 # Properties
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 results.extend(_CheckSpamLogging(input_api, output_api)) 1445 results.extend(_CheckSpamLogging(input_api, output_api))
1416 results.extend(_CheckForAnonymousVariables(input_api, output_api)) 1446 results.extend(_CheckForAnonymousVariables(input_api, output_api))
1417 results.extend(_CheckCygwinShell(input_api, output_api)) 1447 results.extend(_CheckCygwinShell(input_api, output_api))
1418 results.extend(_CheckUserActionUpdate(input_api, output_api)) 1448 results.extend(_CheckUserActionUpdate(input_api, output_api))
1419 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) 1449 results.extend(_CheckNoDeprecatedCSS(input_api, output_api))
1420 results.extend(_CheckNoDeprecatedJS(input_api, output_api)) 1450 results.extend(_CheckNoDeprecatedJS(input_api, output_api))
1421 results.extend(_CheckParseErrors(input_api, output_api)) 1451 results.extend(_CheckParseErrors(input_api, output_api))
1422 results.extend(_CheckForIPCRules(input_api, output_api)) 1452 results.extend(_CheckForIPCRules(input_api, output_api))
1423 results.extend(_CheckForCopyrightedCode(input_api, output_api)) 1453 results.extend(_CheckForCopyrightedCode(input_api, output_api))
1424 results.extend(_CheckForWindowsLineEndings(input_api, output_api)) 1454 results.extend(_CheckForWindowsLineEndings(input_api, output_api))
1455 results.extend(_CheckSingletonInHeaders(input_api, output_api))
1425 1456
1426 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): 1457 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
1427 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( 1458 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
1428 input_api, output_api, 1459 input_api, output_api,
1429 input_api.PresubmitLocalPath(), 1460 input_api.PresubmitLocalPath(),
1430 whitelist=[r'^PRESUBMIT_test\.py$'])) 1461 whitelist=[r'^PRESUBMIT_test\.py$']))
1431 return results 1462 return results
1432 1463
1433 1464
1434 def _CheckAuthorizedAuthor(input_api, output_api): 1465 def _CheckAuthorizedAuthor(input_api, output_api):
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1757 if 'presubmit' in builder: 1788 if 'presubmit' in builder:
1758 builders[master].pop(builder) 1789 builders[master].pop(builder)
1759 1790
1760 # Match things like path/aura/file.cc and path/file_aura.cc. 1791 # Match things like path/aura/file.cc and path/file_aura.cc.
1761 # Same for chromeos. 1792 # Same for chromeos.
1762 if any(re.search(r'[\\\/_](aura|chromeos)', f) for f in files): 1793 if any(re.search(r'[\\\/_](aura|chromeos)', f) for f in files):
1763 tryserver_linux = builders.setdefault('tryserver.chromium.linux', {}) 1794 tryserver_linux = builders.setdefault('tryserver.chromium.linux', {})
1764 tryserver_linux['linux_chromium_chromeos_asan_rel_ng'] = ['defaulttests'] 1795 tryserver_linux['linux_chromium_chromeos_asan_rel_ng'] = ['defaulttests']
1765 1796
1766 return builders 1797 return 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