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

Side by Side Diff: PRESUBMIT.py

Issue 15755002: Ignore hardcoded URLs and ForTest(ing)/for_test(ing) in comments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 that ignores header files and may have some false positives. A 224 that ignores header files and may have some false positives. A
225 better implementation would probably need a proper C++ parser. 225 better implementation would probably need a proper C++ parser.
226 """ 226 """
227 # We only scan .cc files and the like, as the declaration of 227 # We only scan .cc files and the like, as the declaration of
228 # for-testing functions in header files are hard to distinguish from 228 # for-testing functions in header files are hard to distinguish from
229 # calls to such functions without a proper C++ parser. 229 # calls to such functions without a proper C++ parser.
230 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS 230 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS
231 231
232 base_function_pattern = r'ForTest(ing)?|for_test(ing)?' 232 base_function_pattern = r'ForTest(ing)?|for_test(ing)?'
233 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern) 233 inclusion_pattern = input_api.re.compile(r'(%s)\s*\(' % base_function_pattern)
234 comment_pattern = input_api.re.compile(r'//.*%s' % base_function_pattern)
234 exclusion_pattern = input_api.re.compile( 235 exclusion_pattern = input_api.re.compile(
235 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % ( 236 r'::[A-Za-z0-9_]+(%s)|(%s)[^;]+\{' % (
236 base_function_pattern, base_function_pattern)) 237 base_function_pattern, base_function_pattern))
237 238
238 def FilterFile(affected_file): 239 def FilterFile(affected_file):
239 black_list = (_EXCLUDED_PATHS + 240 black_list = (_EXCLUDED_PATHS +
240 _TEST_CODE_EXCLUDED_PATHS + 241 _TEST_CODE_EXCLUDED_PATHS +
241 input_api.DEFAULT_BLACK_LIST) 242 input_api.DEFAULT_BLACK_LIST)
242 return input_api.FilterSourceFile( 243 return input_api.FilterSourceFile(
243 affected_file, 244 affected_file,
244 white_list=(file_inclusion_pattern, ), 245 white_list=(file_inclusion_pattern, ),
245 black_list=black_list) 246 black_list=black_list)
246 247
247 problems = [] 248 problems = []
248 for f in input_api.AffectedSourceFiles(FilterFile): 249 for f in input_api.AffectedSourceFiles(FilterFile):
249 local_path = f.LocalPath() 250 local_path = f.LocalPath()
250 lines = input_api.ReadFile(f).splitlines() 251 lines = input_api.ReadFile(f).splitlines()
251 line_number = 0 252 line_number = 0
252 for line in lines: 253 for line in lines:
253 if (inclusion_pattern.search(line) and 254 if (inclusion_pattern.search(line) and
255 not comment_pattern.search(line) and
254 not exclusion_pattern.search(line)): 256 not exclusion_pattern.search(line)):
255 problems.append( 257 problems.append(
256 '%s:%d\n %s' % (local_path, line_number, line.strip())) 258 '%s:%d\n %s' % (local_path, line_number, line.strip()))
257 line_number += 1 259 line_number += 1
258 260
259 if problems: 261 if problems:
260 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)] 262 return [output_api.PresubmitPromptOrNotify(_TEST_ONLY_WARNING, problems)]
261 else: 263 else:
262 return [] 264 return []
263 265
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 top-level directories that generally speaking should not hard-code 683 top-level directories that generally speaking should not hard-code
682 service URLs (e.g. src/android_webview/, src/content/ and others). 684 service URLs (e.g. src/android_webview/, src/content/ and others).
683 """ 685 """
684 return input_api.FilterSourceFile( 686 return input_api.FilterSourceFile(
685 affected_file, 687 affected_file,
686 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ), 688 white_list=(r'^(android_webview|base|content|net)[\\\/].*', ),
687 black_list=(_EXCLUDED_PATHS + 689 black_list=(_EXCLUDED_PATHS +
688 _TEST_CODE_EXCLUDED_PATHS + 690 _TEST_CODE_EXCLUDED_PATHS +
689 input_api.DEFAULT_BLACK_LIST)) 691 input_api.DEFAULT_BLACK_LIST))
690 692
691 pattern = input_api.re.compile('"[^"]*google\.com[^"]*"') 693 base_pattern = '"[^"]*google\.com[^"]*"'
694 comment_pattern = input_api.re.compile('//.*%s' % base_pattern)
695 pattern = input_api.re.compile(base_pattern)
692 problems = [] # items are (filename, line_number, line) 696 problems = [] # items are (filename, line_number, line)
693 for f in input_api.AffectedSourceFiles(FilterFile): 697 for f in input_api.AffectedSourceFiles(FilterFile):
694 for line_num, line in f.ChangedContents(): 698 for line_num, line in f.ChangedContents():
695 if pattern.search(line): 699 if not comment_pattern.search(line) and pattern.search(line):
696 problems.append((f.LocalPath(), line_num, line)) 700 problems.append((f.LocalPath(), line_num, line))
697 701
698 if problems: 702 if problems:
699 return [output_api.PresubmitPromptOrNotify( 703 return [output_api.PresubmitPromptOrNotify(
700 'Most layers below src/chrome/ should not hardcode service URLs.\n' 704 'Most layers below src/chrome/ should not hardcode service URLs.\n'
701 'Are you sure this is correct? (Contact: joi@chromium.org)', 705 'Are you sure this is correct? (Contact: joi@chromium.org)',
702 [' %s:%d: %s' % ( 706 [' %s:%d: %s' % (
703 problem[0], problem[1], problem[2]) for problem in problems])] 707 problem[0], problem[1], problem[2]) for problem in problems])]
704 else: 708 else:
705 return [] 709 return []
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 output = output_api.PresubmitNotifyResult 771 output = output_api.PresubmitNotifyResult
768 772
769 owners_db = input_api.owners_db 773 owners_db = input_api.owners_db
770 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers( 774 owner_email, reviewers = input_api.canned_checks._RietveldOwnerAndReviewers(
771 input_api, 775 input_api,
772 owners_db.email_regexp, 776 owners_db.email_regexp,
773 approval_needed=input_api.is_committing) 777 approval_needed=input_api.is_committing)
774 778
775 owner_email = owner_email or input_api.change.author_email 779 owner_email = owner_email or input_api.change.author_email
776 780
777 reviewers_plus_owner = reviewers 781 reviewers_plus_owner = set(reviewers)
778 if owner_email: 782 if owner_email:
779 reviewers_plus_owner = set([owner_email]).union(reviewers) 783 reviewers_plus_owner.add(owner_email)
780 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files, 784 missing_files = owners_db.files_not_covered_by(virtual_depended_on_files,
781 reviewers_plus_owner) 785 reviewers_plus_owner)
782 unapproved_dependencies = ["'+%s'," % path[:-len('/DEPS')] 786 unapproved_dependencies = ["'+%s'," % path[:-len('/DEPS')]
783 for path in missing_files] 787 for path in missing_files]
784 788
785 if unapproved_dependencies: 789 if unapproved_dependencies:
786 output_list = [ 790 output_list = [
787 output('Missing LGTM from OWNERS of directories added to DEPS:\n %s' % 791 output('Missing LGTM from OWNERS of directories added to DEPS:\n %s' %
788 '\n '.join(sorted(unapproved_dependencies)))] 792 '\n '.join(sorted(unapproved_dependencies)))]
789 if not input_api.is_committing: 793 if not input_api.is_committing:
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 'win_rel', 1031 'win_rel',
1028 'win:compile', 1032 'win:compile',
1029 ] 1033 ]
1030 1034
1031 # Match things like path/aura/file.cc and path/file_aura.cc. 1035 # Match things like path/aura/file.cc and path/file_aura.cc.
1032 # Same for chromeos. 1036 # Same for chromeos.
1033 if any(re.search('[/_](aura|chromeos)', f) for f in files): 1037 if any(re.search('[/_](aura|chromeos)', f) for f in files):
1034 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] 1038 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan']
1035 1039
1036 return trybots 1040 return trybots
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