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

Side by Side Diff: PRESUBMIT.py

Issue 11811004: Revert 176986 - breaks tools/perf and tools/telemetry presubmit (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 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 ) 50 )
51 51
52 _TEST_ONLY_WARNING = ( 52 _TEST_ONLY_WARNING = (
53 'You might be calling functions intended only for testing from\n' 53 'You might be calling functions intended only for testing from\n'
54 'production code. It is OK to ignore this warning if you know what\n' 54 'production code. It is OK to ignore this warning if you know what\n'
55 'you are doing, as the heuristics used to detect the situation are\n' 55 'you are doing, as the heuristics used to detect the situation are\n'
56 'not perfect. The commit queue will not block on this warning.\n' 56 'not perfect. The commit queue will not block on this warning.\n'
57 'Email joi@chromium.org if you have questions.') 57 'Email joi@chromium.org if you have questions.')
58 58
59 59
60 _HTTPS_ONLY_WARNING = (
61 'You should prefer to refer to HTTPS URLs, rather than HTTP URLs.\n'
62 'Do not bypass this warning if there is an equivalent HTTPS endpoint\n'
63 'that you could refer to instead. (Contact: palmer@chromium.org)')
64
65
66 _INCLUDE_ORDER_WARNING = ( 60 _INCLUDE_ORDER_WARNING = (
67 'Your #include order seems to be broken. Send mail to\n' 61 'Your #include order seems to be broken. Send mail to\n'
68 'marja@chromium.org if this is not the case.') 62 'marja@chromium.org if this is not the case.')
69 63
70 64
71 _BANNED_OBJC_FUNCTIONS = ( 65 _BANNED_OBJC_FUNCTIONS = (
72 ( 66 (
73 'addTrackingRect:', 67 'addTrackingRect:',
74 ( 68 (
75 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' 69 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 _TEST_CODE_EXCLUDED_PATHS + 187 _TEST_CODE_EXCLUDED_PATHS +
194 input_api.DEFAULT_BLACK_LIST) 188 input_api.DEFAULT_BLACK_LIST)
195 return input_api.FilterSourceFile( 189 return input_api.FilterSourceFile(
196 affected_file, 190 affected_file,
197 white_list=(file_inclusion_pattern, ), 191 white_list=(file_inclusion_pattern, ),
198 black_list=black_list) 192 black_list=black_list)
199 193
200 problems = [] 194 problems = []
201 for f in input_api.AffectedSourceFiles(FilterFile): 195 for f in input_api.AffectedSourceFiles(FilterFile):
202 local_path = f.LocalPath() 196 local_path = f.LocalPath()
203 for line_number, line in enumerate(input_api.ReadFile(f).splitlines()): 197 lines = input_api.ReadFile(f).splitlines()
204 if inclusion_pattern.search(line) and not exclusion_pattern.search(line): 198 line_number = 0
199 for line in lines:
200 if (inclusion_pattern.search(line) and
201 not exclusion_pattern.search(line)):
205 problems.append( 202 problems.append(
206 '%s:%d\n %s' % (local_path, line_number + 1, line.strip())) 203 '%s:%d\n %s' % (local_path, line_number, line.strip()))
204 line_number += 1
207 205
208 if problems: 206 if problems:
209 if input_api.is_committing: 207 if not input_api.is_committing:
208 return [output_api.PresubmitPromptWarning(_TEST_ONLY_WARNING, problems)]
209 else:
210 # We don't warn on commit, to avoid stopping commits going through CQ. 210 # We don't warn on commit, to avoid stopping commits going through CQ.
211 return [output_api.PresubmitNotifyResult(_TEST_ONLY_WARNING, problems)] 211 return [output_api.PresubmitNotifyResult(_TEST_ONLY_WARNING, problems)]
212 else: 212 else:
213 return [output_api.PresubmitPromptWarning(_TEST_ONLY_WARNING, problems)] 213 return []
214
215 return []
216
217
218 def _CheckNoHttpUrls(input_api, output_api):
219 """Attempts to prevent use of http:// URLs. Production Chrome code, and
220 Chromium infrastructure code, should strive to use https:// URLs (preferably
221 HSTS and with pinned public keys, as well). Some URLs will not be
222 translatable, but gradually the number of those should diminish.
223 """
224
225 # Include all sorts of files, both code and infrastructure scripts.
226 file_inclusion_pattern = r'.+\.(h|cc|cpp|cxx|mm|py|bat|sh)$'
227
228 inclusion_pattern = input_api.re.compile(r'''["']http:/''',
229 input_api.re.IGNORECASE)
230
231 # Allow http:/ in comments. https://chromium.org and
232 # https://cr{bug,osbug,rev}.com don't work yet. See e.g.
233 # https://code.google.com/p/chromium/issues/detail?id=106096.
234 # TODO(palmer): Remove this once 106096 and its dependent bugs are fixed.
235 exclusion_pattern = input_api.re.compile(r'(#|//|/\*| \*).*http:/',
236 input_api.re.IGNORECASE)
237
238 def FilterFile(affected_file):
239 black_list = (_TEST_CODE_EXCLUDED_PATHS +
240 input_api.DEFAULT_BLACK_LIST)
241 return input_api.FilterSourceFile(
242 affected_file,
243 white_list=(file_inclusion_pattern, ),
244 black_list=black_list)
245
246 problems = []
247 for f in input_api.AffectedSourceFiles(FilterFile):
248 local_path = f.LocalPath()
249 for line_number, line in enumerate(input_api.ReadFile(f).splitlines()):
250 if inclusion_pattern.search(line) and not exclusion_pattern.search(line):
251 problems.append(
252 '%s:%d\n %s' % (local_path, line_number + 1, line.strip()))
253
254 if problems:
255 if input_api.is_committing:
256 # We don't warn on commit, to avoid stopping commits going through CQ.
257 return [output_api.PresubmitNotifyResult(_HTTPS_ONLY_WARNING, problems)]
258 else:
259 return [output_api.PresubmitPromptWarning(_HTTPS_ONLY_WARNING, problems)]
260
261 return []
262 214
263 215
264 def _CheckNoIOStreamInHeaders(input_api, output_api): 216 def _CheckNoIOStreamInHeaders(input_api, output_api):
265 """Checks to make sure no .h files include <iostream>.""" 217 """Checks to make sure no .h files include <iostream>."""
266 files = [] 218 files = []
267 pattern = input_api.re.compile(r'^#include\s*<iostream>', 219 pattern = input_api.re.compile(r'^#include\s*<iostream>',
268 input_api.re.MULTILINE) 220 input_api.re.MULTILINE)
269 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): 221 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
270 if not f.LocalPath().endswith('.h'): 222 if not f.LocalPath().endswith('.h'):
271 continue 223 continue
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 error_descriptions.append(description_with_path) 414 error_descriptions.append(description_with_path)
463 else: 415 else:
464 warning_descriptions.append(description_with_path) 416 warning_descriptions.append(description_with_path)
465 417
466 results = [] 418 results = []
467 if error_descriptions: 419 if error_descriptions:
468 results.append(output_api.PresubmitError( 420 results.append(output_api.PresubmitError(
469 'You added one or more #includes that violate checkdeps rules.', 421 'You added one or more #includes that violate checkdeps rules.',
470 error_descriptions)) 422 error_descriptions))
471 if warning_descriptions: 423 if warning_descriptions:
472 if input_api.is_committing: 424 if not input_api.is_committing:
425 warning_factory = output_api.PresubmitPromptWarning
426 else:
473 # We don't want to block use of the CQ when there is a warning 427 # We don't want to block use of the CQ when there is a warning
474 # of this kind, so we only show a message when committing. 428 # of this kind, so we only show a message when committing.
475 warning_factory = output_api.PresubmitNotifyResult 429 warning_factory = output_api.PresubmitNotifyResult
476 else:
477 warning_factory = output_api.PresubmitPromptWarning
478 results.append(warning_factory( 430 results.append(warning_factory(
479 'You added one or more #includes of files that are temporarily\n' 431 'You added one or more #includes of files that are temporarily\n'
480 'allowed but being removed. Can you avoid introducing the\n' 432 'allowed but being removed. Can you avoid introducing the\n'
481 '#include? See relevant DEPS file(s) for details and contacts.', 433 '#include? See relevant DEPS file(s) for details and contacts.',
482 warning_descriptions)) 434 warning_descriptions))
483 return results 435 return results
484 436
485 437
486 def _CheckFilePermissions(input_api, output_api): 438 def _CheckFilePermissions(input_api, output_api):
487 """Check that all files have their permissions properly set.""" 439 """Check that all files have their permissions properly set."""
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 """ 597 """
646 598
647 warnings = [] 599 warnings = []
648 for f in input_api.AffectedFiles(): 600 for f in input_api.AffectedFiles():
649 if f.LocalPath().endswith(('.cc', '.h')): 601 if f.LocalPath().endswith(('.cc', '.h')):
650 changed_linenums = set(line_num for line_num, _ in f.ChangedContents()) 602 changed_linenums = set(line_num for line_num, _ in f.ChangedContents())
651 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums)) 603 warnings.extend(_CheckIncludeOrderInFile(input_api, f, changed_linenums))
652 604
653 results = [] 605 results = []
654 if warnings: 606 if warnings:
655 if input_api.is_committing: 607 if not input_api.is_committing:
608 results.append(output_api.PresubmitPromptWarning(_INCLUDE_ORDER_WARNING,
609 warnings))
610 else:
656 # We don't warn on commit, to avoid stopping commits going through CQ. 611 # We don't warn on commit, to avoid stopping commits going through CQ.
657 results.append(output_api.PresubmitNotifyResult(_INCLUDE_ORDER_WARNING, 612 results.append(output_api.PresubmitNotifyResult(_INCLUDE_ORDER_WARNING,
658 warnings)) 613 warnings))
659 else:
660 results.append(output_api.PresubmitPromptWarning(_INCLUDE_ORDER_WARNING,
661 warnings))
662 return results 614 return results
663 615
664 616
665 def _CheckForVersionControlConflictsInFile(input_api, f): 617 def _CheckForVersionControlConflictsInFile(input_api, f):
666 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$') 618 pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$')
667 errors = [] 619 errors = []
668 for line_num, line in f.ChangedContents(): 620 for line_num, line in f.ChangedContents():
669 if pattern.match(line): 621 if pattern.match(line):
670 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) 622 errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line))
671 return errors 623 return errors
(...skipping 27 matching lines...) Expand all
699 input_api.DEFAULT_BLACK_LIST)) 651 input_api.DEFAULT_BLACK_LIST))
700 652
701 pattern = input_api.re.compile('"[^"]*google\.com[^"]*"') 653 pattern = input_api.re.compile('"[^"]*google\.com[^"]*"')
702 problems = [] # items are (filename, line_number, line) 654 problems = [] # items are (filename, line_number, line)
703 for f in input_api.AffectedSourceFiles(FilterFile): 655 for f in input_api.AffectedSourceFiles(FilterFile):
704 for line_num, line in f.ChangedContents(): 656 for line_num, line in f.ChangedContents():
705 if pattern.search(line): 657 if pattern.search(line):
706 problems.append((f.LocalPath(), line_num, line)) 658 problems.append((f.LocalPath(), line_num, line))
707 659
708 if problems: 660 if problems:
709 if input_api.is_committing: 661 if not input_api.is_committing:
662 warning_factory = output_api.PresubmitPromptWarning
663 else:
710 # We don't want to block use of the CQ when there is a warning 664 # We don't want to block use of the CQ when there is a warning
711 # of this kind, so we only show a message when committing. 665 # of this kind, so we only show a message when committing.
712 warning_factory = output_api.PresubmitNotifyResult 666 warning_factory = output_api.PresubmitNotifyResult
713 else:
714 warning_factory = output_api.PresubmitPromptWarning
715 return [warning_factory( 667 return [warning_factory(
716 'Most layers below src/chrome/ should not hardcode service URLs.\n' 668 'Most layers below src/chrome/ should not hardcode service URLs.\n'
717 'Are you sure this is correct? (Contact: joi@chromium.org)', 669 'Are you sure this is correct? (Contact: joi@chromium.org)',
718 [' %s:%d: %s' % ( 670 [' %s:%d: %s' % (
719 problem[0], problem[1], problem[2]) for problem in problems])] 671 problem[0], problem[1], problem[2]) for problem in problems])]
720 672 else:
721 return [] 673 return []
722 674
723 675
724 def _CommonChecks(input_api, output_api): 676 def _CommonChecks(input_api, output_api):
725 """Checks common to both upload and commit.""" 677 """Checks common to both upload and commit."""
726 results = [] 678 results = []
727 results.extend(input_api.canned_checks.PanProjectChecks( 679 results.extend(input_api.canned_checks.PanProjectChecks(
728 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) 680 input_api, output_api, excluded_paths=_EXCLUDED_PATHS))
729 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) 681 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
730 results.extend( 682 results.extend(
731 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) 683 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
732 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) 684 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
733 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) 685 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
734 results.extend(_CheckNoNewWStrings(input_api, output_api)) 686 results.extend(_CheckNoNewWStrings(input_api, output_api))
735 results.extend(_CheckNoDEPSGIT(input_api, output_api)) 687 results.extend(_CheckNoDEPSGIT(input_api, output_api))
736 results.extend(_CheckNoBannedFunctions(input_api, output_api)) 688 results.extend(_CheckNoBannedFunctions(input_api, output_api))
737 results.extend(_CheckNoPragmaOnce(input_api, output_api)) 689 results.extend(_CheckNoPragmaOnce(input_api, output_api))
738 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) 690 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
739 results.extend(_CheckUnwantedDependencies(input_api, output_api)) 691 results.extend(_CheckUnwantedDependencies(input_api, output_api))
740 results.extend(_CheckFilePermissions(input_api, output_api)) 692 results.extend(_CheckFilePermissions(input_api, output_api))
741 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) 693 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
742 results.extend(_CheckIncludeOrder(input_api, output_api)) 694 results.extend(_CheckIncludeOrder(input_api, output_api))
743 results.extend(_CheckForVersionControlConflicts(input_api, output_api)) 695 results.extend(_CheckForVersionControlConflicts(input_api, output_api))
744 results.extend(_CheckPatchFiles(input_api, output_api)) 696 results.extend(_CheckPatchFiles(input_api, output_api))
745 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api)) 697 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api))
746 results.extend(_CheckNoHttpUrls(input_api, output_api))
747 698
748 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): 699 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
749 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( 700 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
750 input_api, output_api, 701 input_api, output_api,
751 input_api.PresubmitLocalPath(), 702 input_api.PresubmitLocalPath(),
752 whitelist=[r'.+_test\.py$'])) 703 whitelist=[r'.+_test\.py$']))
753 return results 704 return results
754 705
755 706
756 def _CheckSubversionConfig(input_api, output_api): 707 def _CheckSubversionConfig(input_api, output_api):
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 author)] 776 author)]
826 return [] 777 return []
827 778
828 779
829 def _CheckPatchFiles(input_api, output_api): 780 def _CheckPatchFiles(input_api, output_api):
830 problems = [f.LocalPath() for f in input_api.AffectedFiles() 781 problems = [f.LocalPath() for f in input_api.AffectedFiles()
831 if f.LocalPath().endswith(('.orig', '.rej'))] 782 if f.LocalPath().endswith(('.orig', '.rej'))]
832 if problems: 783 if problems:
833 return [output_api.PresubmitError( 784 return [output_api.PresubmitError(
834 "Don't commit .rej and .orig files.", problems)] 785 "Don't commit .rej and .orig files.", problems)]
835 786 else:
836 return [] 787 return []
837 788
838 789
839 def CheckChangeOnUpload(input_api, output_api): 790 def CheckChangeOnUpload(input_api, output_api):
840 results = [] 791 results = []
841 results.extend(_CommonChecks(input_api, output_api)) 792 results.extend(_CommonChecks(input_api, output_api))
842 return results 793 return results
843 794
844 795
845 def CheckChangeOnCommit(input_api, output_api): 796 def CheckChangeOnCommit(input_api, output_api):
846 results = [] 797 results = []
847 results.extend(_CommonChecks(input_api, output_api)) 798 results.extend(_CommonChecks(input_api, output_api))
848 # TODO(thestig) temporarily disabled, doesn't work in third_party/ 799 # TODO(thestig) temporarily disabled, doesn't work in third_party/
849 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories( 800 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
850 # input_api, output_api, sources)) 801 # input_api, output_api, sources))
851 # Make sure the tree is 'open'. 802 # Make sure the tree is 'open'.
852 results.extend(input_api.canned_checks.CheckTreeIsOpen( 803 results.extend(input_api.canned_checks.CheckTreeIsOpen(
853 input_api, 804 input_api,
854 output_api, 805 output_api,
855 json_url='https://chromium-status.appspot.com/current?format=json')) 806 json_url='http://chromium-status.appspot.com/current?format=json'))
856 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api, 807 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
857 output_api, 'https://codereview.chromium.org', 808 output_api, 'http://codereview.chromium.org',
858 ('win_rel', 'linux_rel', 'mac_rel, win:compile'), 809 ('win_rel', 'linux_rel', 'mac_rel, win:compile'),
859 'tryserver@chromium.org')) 810 'tryserver@chromium.org'))
860 811
861 results.extend(input_api.canned_checks.CheckChangeHasBugField( 812 results.extend(input_api.canned_checks.CheckChangeHasBugField(
862 input_api, output_api)) 813 input_api, output_api))
863 results.extend(input_api.canned_checks.CheckChangeHasDescription( 814 results.extend(input_api.canned_checks.CheckChangeHasDescription(
864 input_api, output_api)) 815 input_api, output_api))
865 results.extend(_CheckSubversionConfig(input_api, output_api)) 816 results.extend(_CheckSubversionConfig(input_api, output_api))
866 return results 817 return results
867 818
(...skipping 30 matching lines...) Expand all
898 'win7_aura', 849 'win7_aura',
899 'win_rel', 850 'win_rel',
900 ] 851 ]
901 852
902 # Match things like path/aura/file.cc and path/file_aura.cc. 853 # Match things like path/aura/file.cc and path/file_aura.cc.
903 # Same for chromeos. 854 # Same for chromeos.
904 if any(re.search('[/_](aura|chromeos)', f) for f in files): 855 if any(re.search('[/_](aura|chromeos)', f) for f in files):
905 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] 856 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan']
906 857
907 return trybots 858 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