Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 'pool or the FILE thread instead.', | 158 'pool or the FILE thread instead.', |
| 159 ), | 159 ), |
| 160 True, | 160 True, |
| 161 ( | 161 ( |
| 162 r"^content[\\\/]shell[\\\/]shell_browser_main\.cc$", | 162 r"^content[\\\/]shell[\\\/]shell_browser_main\.cc$", |
| 163 ), | 163 ), |
| 164 ), | 164 ), |
| 165 ) | 165 ) |
| 166 | 166 |
| 167 | 167 |
| 168 _VALID_OS_MACROS = ( | |
| 169 # Please keep sorted. | |
| 170 'OS_ANDROID', | |
| 171 'OS_BSD', | |
| 172 'OS_CAT', # For testing. | |
| 173 'OS_CHROMEOS', | |
| 174 'OS_FREEBSD', | |
| 175 'OS_IOS', | |
| 176 'OS_LINUX', | |
| 177 'OS_MACOSX', | |
| 178 'OS_NACL', | |
| 179 'OS_OPENBSD', | |
| 180 'OS_POSIX', | |
| 181 'OS_SOLARIS', | |
| 182 'OS_SUN', # Not in build/build_config.h but in skia. | |
| 183 'OS_WIN', | |
| 184 ) | |
| 185 | |
| 186 | |
| 168 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): | 187 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api): |
| 169 """Attempts to prevent use of functions intended only for testing in | 188 """Attempts to prevent use of functions intended only for testing in |
| 170 non-testing code. For now this is just a best-effort implementation | 189 non-testing code. For now this is just a best-effort implementation |
| 171 that ignores header files and may have some false positives. A | 190 that ignores header files and may have some false positives. A |
| 172 better implementation would probably need a proper C++ parser. | 191 better implementation would probably need a proper C++ parser. |
| 173 """ | 192 """ |
| 174 # We only scan .cc files and the like, as the declaration of | 193 # We only scan .cc files and the like, as the declaration of |
| 175 # for-testing functions in header files are hard to distinguish from | 194 # for-testing functions in header files are hard to distinguish from |
| 176 # calls to such functions without a proper C++ parser. | 195 # calls to such functions without a proper C++ parser. |
| 177 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS | 196 file_inclusion_pattern = r'.+%s' % _IMPLEMENTATION_EXTENSIONS |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 results.extend(_CheckNoPragmaOnce(input_api, output_api)) | 726 results.extend(_CheckNoPragmaOnce(input_api, output_api)) |
| 708 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) | 727 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) |
| 709 results.extend(_CheckUnwantedDependencies(input_api, output_api)) | 728 results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
| 710 results.extend(_CheckFilePermissions(input_api, output_api)) | 729 results.extend(_CheckFilePermissions(input_api, output_api)) |
| 711 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) | 730 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) |
| 712 results.extend(_CheckIncludeOrder(input_api, output_api)) | 731 results.extend(_CheckIncludeOrder(input_api, output_api)) |
| 713 results.extend(_CheckForVersionControlConflicts(input_api, output_api)) | 732 results.extend(_CheckForVersionControlConflicts(input_api, output_api)) |
| 714 results.extend(_CheckPatchFiles(input_api, output_api)) | 733 results.extend(_CheckPatchFiles(input_api, output_api)) |
| 715 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api)) | 734 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api)) |
| 716 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api)) | 735 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api)) |
| 736 results.extend(_CheckForInvalidOSMacros(input_api, output_api)) | |
| 717 | 737 |
| 718 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): | 738 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
| 719 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 739 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| 720 input_api, output_api, | 740 input_api, output_api, |
| 721 input_api.PresubmitLocalPath(), | 741 input_api.PresubmitLocalPath(), |
| 722 whitelist=[r'^PRESUBMIT_test\.py$'])) | 742 whitelist=[r'^PRESUBMIT_test\.py$'])) |
| 723 return results | 743 return results |
| 724 | 744 |
| 725 | 745 |
| 726 def _CheckSubversionConfig(input_api, output_api): | 746 def _CheckSubversionConfig(input_api, output_api): |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 def _CheckPatchFiles(input_api, output_api): | 819 def _CheckPatchFiles(input_api, output_api): |
| 800 problems = [f.LocalPath() for f in input_api.AffectedFiles() | 820 problems = [f.LocalPath() for f in input_api.AffectedFiles() |
| 801 if f.LocalPath().endswith(('.orig', '.rej'))] | 821 if f.LocalPath().endswith(('.orig', '.rej'))] |
| 802 if problems: | 822 if problems: |
| 803 return [output_api.PresubmitError( | 823 return [output_api.PresubmitError( |
| 804 "Don't commit .rej and .orig files.", problems)] | 824 "Don't commit .rej and .orig files.", problems)] |
| 805 else: | 825 else: |
| 806 return [] | 826 return [] |
| 807 | 827 |
| 808 | 828 |
| 829 def _CheckForInvalidOSMacrosInFile(input_api, f): | |
| 830 """Check for sensible looking, totally invalid OS macros.""" | |
| 831 results = [] | |
| 832 pattern = input_api.re.compile(r'\b(OS_[A-Z]{3,})\b') | |
|
Scott Hess - ex-Googler
2013/03/21 04:20:00
Have you run this over the existing codebase? I h
Dan Beam
2013/03/21 04:29:09
I think people putting OS_BLAH in comments is equa
Scott Hess - ex-Googler
2013/03/21 05:03:51
I can see both ways, but if the comment doesn't co
| |
| 833 for lnum, line in f.ChangedContents(): | |
| 834 for match in pattern.finditer(line): | |
| 835 if not match.group(1) in _VALID_OS_MACROS: | |
| 836 results.append(' %s:%d %s' % (f.LocalPath(), lnum, match.group(1))) | |
| 837 return results | |
| 838 | |
| 839 | |
| 840 def _CheckForInvalidOSMacros(input_api, output_api): | |
| 841 """Check all affected files for invalid OS macros.""" | |
| 842 bad_macros = [] | |
| 843 for f in input_api.AffectedFiles(): | |
| 844 if not f.LocalPath().endswith('.py'): | |
| 845 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f)) | |
| 846 | |
| 847 if not bad_macros: | |
| 848 return [] | |
| 849 | |
| 850 return [output_api.PresubmitError( | |
| 851 'Possibly invalid OS macros found. Please add your macro to\n' | |
| 852 'src/PRESUBMIT.py or update your code.', bad_macros)] | |
| 853 | |
| 854 | |
| 809 def CheckChangeOnUpload(input_api, output_api): | 855 def CheckChangeOnUpload(input_api, output_api): |
| 810 results = [] | 856 results = [] |
| 811 results.extend(_CommonChecks(input_api, output_api)) | 857 results.extend(_CommonChecks(input_api, output_api)) |
| 812 return results | 858 return results |
| 813 | 859 |
| 814 | 860 |
| 815 def CheckChangeOnCommit(input_api, output_api): | 861 def CheckChangeOnCommit(input_api, output_api): |
| 816 results = [] | 862 results = [] |
| 817 results.extend(_CommonChecks(input_api, output_api)) | 863 results.extend(_CommonChecks(input_api, output_api)) |
| 818 # TODO(thestig) temporarily disabled, doesn't work in third_party/ | 864 # TODO(thestig) temporarily disabled, doesn't work in third_party/ |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 870 'win_rel', | 916 'win_rel', |
| 871 'win:compile', | 917 'win:compile', |
| 872 ] | 918 ] |
| 873 | 919 |
| 874 # Match things like path/aura/file.cc and path/file_aura.cc. | 920 # Match things like path/aura/file.cc and path/file_aura.cc. |
| 875 # Same for chromeos. | 921 # Same for chromeos. |
| 876 if any(re.search('[/_](aura|chromeos)', f) for f in files): | 922 if any(re.search('[/_](aura|chromeos)', f) for f in files): |
| 877 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] | 923 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] |
| 878 | 924 |
| 879 return trybots | 925 return trybots |
| OLD | NEW |