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

Side by Side Diff: PRESUBMIT.py

Issue 8586024: ForTest presubmit check non-failing for CQ by making it just a message (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use input_api.is_committing. Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2011 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
11
11 _EXCLUDED_PATHS = ( 12 _EXCLUDED_PATHS = (
12 r"^breakpad[\\\/].*", 13 r"^breakpad[\\\/].*",
13 r"^net/tools/spdyshark/[\\\/].*", 14 r"^net/tools/spdyshark/[\\\/].*",
14 r"^skia[\\\/].*", 15 r"^skia[\\\/].*",
15 r"^v8[\\\/].*", 16 r"^v8[\\\/].*",
16 r".*MakeFile$", 17 r".*MakeFile$",
17 ) 18 )
18 19
19 20
21 _TEST_ONLY_WARNING = (
22 'You might be calling functions intended only for testing from\n'
23 'production code. It is OK to ignore this warning if you know what\n'
24 'you are doing, as the heuristics used to detect the situation are\n'
25 'not perfect. The commit queue will not block on this warning.\n'
26 'Email joi@chromium.org if you have questions.')
27
28
29
20 def _CheckNoInterfacesInBase(input_api, output_api): 30 def _CheckNoInterfacesInBase(input_api, output_api):
21 """Checks to make sure no files in libbase.a have |@interface|.""" 31 """Checks to make sure no files in libbase.a have |@interface|."""
22 pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE) 32 pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE)
23 files = [] 33 files = []
24 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): 34 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
25 if (f.LocalPath().startswith('base/') and 35 if (f.LocalPath().startswith('base/') and
26 not f.LocalPath().endswith('_unittest.mm')): 36 not f.LocalPath().endswith('_unittest.mm')):
27 contents = input_api.ReadFile(f) 37 contents = input_api.ReadFile(f)
28 if pattern.search(contents): 38 if pattern.search(contents):
29 files.append(f) 39 files.append(f)
30 40
31 if len(files): 41 if len(files):
32 return [ output_api.PresubmitError( 42 return [ output_api.PresubmitError(
33 'Objective-C interfaces or categories are forbidden in libbase. ' + 43 'Objective-C interfaces or categories are forbidden in libbase. ' +
34 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' + 44 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
35 'browse_thread/thread/efb28c10435987fd', 45 'browse_thread/thread/efb28c10435987fd',
36 files) ] 46 files) ]
37 return [] 47 return []
38 48
39 49
40 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): 50 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api,
M-A Ruel 2011/11/18 11:26:49 Not necessary. :)
51 output_api):
41 """Attempts to prevent use of functions intended only for testing in 52 """Attempts to prevent use of functions intended only for testing in
42 non-testing code. For now this is just a best-effort implementation 53 non-testing code. For now this is just a best-effort implementation
43 that ignores header files and may have some false positives. A 54 that ignores header files and may have some false positives. A
44 better implementation would probably need a proper C++ parser. 55 better implementation would probably need a proper C++ parser.
45 """ 56 """
46 # We only scan .cc files and the like, as the declaration of 57 # We only scan .cc files and the like, as the declaration of
47 # for-testing functions in header files are hard to distinguish from 58 # for-testing functions in header files are hard to distinguish from
48 # calls to such functions without a proper C++ parser. 59 # calls to such functions without a proper C++ parser.
49 source_extensions = r'\.(cc|cpp|cxx|mm)$' 60 source_extensions = r'\.(cc|cpp|cxx|mm)$'
50 file_inclusion_pattern = r'.+%s' % source_extensions 61 file_inclusion_pattern = r'.+%s' % source_extensions
(...skipping 29 matching lines...) Expand all
80 lines = input_api.ReadFile(f).splitlines() 91 lines = input_api.ReadFile(f).splitlines()
81 line_number = 0 92 line_number = 0
82 for line in lines: 93 for line in lines:
83 if (inclusion_pattern.search(line) and 94 if (inclusion_pattern.search(line) and
84 not exclusion_pattern.search(line)): 95 not exclusion_pattern.search(line)):
85 problems.append( 96 problems.append(
86 '%s:%d\n %s' % (local_path, line_number, line.strip())) 97 '%s:%d\n %s' % (local_path, line_number, line.strip()))
87 line_number += 1 98 line_number += 1
88 99
89 if problems: 100 if problems:
90 return [output_api.PresubmitPromptWarning( 101 if not input_api.is_committing:
91 'You might be calling functions intended only for testing from\n' 102 return [output_api.PresubmitPromptWarning(_TEST_ONLY_WARNING, problems)]
92 'production code. Please verify that the following usages are OK,\n' 103 else:
93 'and email joi@chromium.org if you are seeing false positives:', 104 # We don't warn on commit, to avoid stopping commits going through CQ.
94 problems)] 105 return [output_api.PresubmitNotifyResult(_TEST_ONLY_WARNING, problems)]
95 else: 106 else:
96 return [] 107 return []
97 108
98 109
99 def _CheckNoIOStreamInHeaders(input_api, output_api): 110 def _CheckNoIOStreamInHeaders(input_api, output_api):
100 """Checks to make sure no .h files include <iostream>.""" 111 """Checks to make sure no .h files include <iostream>."""
101 files = [] 112 files = []
102 pattern = input_api.re.compile(r'^#include\s*<iostream>', 113 pattern = input_api.re.compile(r'^#include\s*<iostream>',
103 input_api.re.MULTILINE) 114 input_api.re.MULTILINE)
104 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): 115 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 results.extend(_CheckSubversionConfig(input_api, output_api)) 277 results.extend(_CheckSubversionConfig(input_api, output_api))
267 return results 278 return results
268 279
269 280
270 def GetPreferredTrySlaves(project, change): 281 def GetPreferredTrySlaves(project, change):
271 only_objc_files = all( 282 only_objc_files = all(
272 f.LocalPath().endswith(('.mm', '.m')) for f in change.AffectedFiles()) 283 f.LocalPath().endswith(('.mm', '.m')) for f in change.AffectedFiles())
273 if only_objc_files: 284 if only_objc_files:
274 return ['mac'] 285 return ['mac']
275 return ['win', 'linux', 'mac'] 286 return ['win', 'linux', 'mac']
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