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

Side by Side Diff: cc/PRESUBMIT.py

Issue 11794017: cc: Ban (f)printf via presubmit.py (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 cc. 5 """Top-level presubmit script for cc.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8 details on the presubmit API built into gcl. 8 details on the presubmit API built into gcl.
9 """ 9 """
10 10
11 import re 11 import re
12 12
13 CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',) 13 CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',)
14 CC_PERF_TEST =(r'^.*_perftest.*\.(cc|h)$',)
14 15
15 def CheckAsserts(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=N one): 16 def CheckAsserts(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=N one):
16 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) 17 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
17 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black _list) 18 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black _list)
18 19
19 assert_files = [] 20 assert_files = []
20 notreached_files = [] 21 notreached_files = []
21 22
22 for f in input_api.AffectedSourceFiles(source_file_filter): 23 for f in input_api.AffectedSourceFiles(source_file_filter):
23 contents = input_api.ReadFile(f, 'rb') 24 contents = input_api.ReadFile(f, 'rb')
(...skipping 11 matching lines...) Expand all
35 if notreached_files: 36 if notreached_files:
36 return [output_api.PresubmitError( 37 return [output_api.PresubmitError(
37 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:', 38 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:',
38 items=notreached_files)] 39 items=notreached_files)]
39 return [] 40 return []
40 41
41 def CheckSpamLogging(input_api, output_api, white_list=CC_SOURCE_FILES, black_li st=None): 42 def CheckSpamLogging(input_api, output_api, white_list=CC_SOURCE_FILES, black_li st=None):
42 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) 43 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
43 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black _list) 44 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black _list)
44 45
45 bad_files = [] 46 log_info = []
47 printf = []
46 48
47 for f in input_api.AffectedSourceFiles(source_file_filter): 49 for f in input_api.AffectedSourceFiles(source_file_filter):
48 contents = input_api.ReadFile(f, 'rb') 50 contents = input_api.ReadFile(f, 'rb')
49 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents): 51 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
50 bad_files.append(f.LocalPath()) 52 log_info.append(f.LocalPath())
53 if re.search(r"\bf?printf\(", contents):
54 printf.append(f.LocalPath())
51 55
52 if bad_files: 56 if log_info:
53 return [output_api.PresubmitError( 57 return [output_api.PresubmitError(
54 'These files spam the console log with LOG(INFO):', 58 'These files spam the console log with LOG(INFO):',
55 items=bad_files)] 59 items=log_info)]
60 if printf:
61 return [output_api.PresubmitError(
62 'These files spam the console log with printf/fprintf:',
63 items=printf)]
56 return [] 64 return []
57 65
58 66
59 def CheckChangeOnUpload(input_api, output_api): 67 def CheckChangeOnUpload(input_api, output_api):
60 results = [] 68 results = []
61 results += CheckAsserts(input_api, output_api) 69 results += CheckAsserts(input_api, output_api)
62 results += CheckSpamLogging(input_api, output_api) 70 results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST)
63 return results 71 return results
64 72
65 def GetPreferredTrySlaves(project, change): 73 def GetPreferredTrySlaves(project, change):
66 return [ 74 return [
67 'linux_layout_rel', 75 'linux_layout_rel',
68 ] 76 ]
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698