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 _DidYouMeanOSMacro(bad_macro): |
| 830 try: |
| 831 return {'A': 'OS_ANDROID', |
| 832 'B': 'OS_BSD', |
| 833 'C': 'OS_CHROMEOS', |
| 834 'F': 'OS_FREEBSD', |
| 835 'L': 'OS_LINUX', |
| 836 'M': 'OS_MACOSX', |
| 837 'N': 'OS_NACL', |
| 838 'O': 'OS_OPENBSD', |
| 839 'P': 'OS_POSIX', |
| 840 'S': 'OS_SOLARIS', |
| 841 'W': 'OS_WIN'}[bad_macro[3].upper()] |
| 842 except KeyError: |
| 843 return '' |
| 844 |
| 845 |
| 846 def _CheckForInvalidOSMacrosInFile(input_api, f): |
| 847 """Check for sensible looking, totally invalid OS macros.""" |
| 848 preprocessor_statement = input_api.re.compile(r'^\s*#') |
| 849 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)') |
| 850 results = [] |
| 851 for lnum, line in f.ChangedContents(): |
| 852 if preprocessor_statement.search(line): |
| 853 for match in os_macro.finditer(line): |
| 854 if not match.group(1) in _VALID_OS_MACROS: |
| 855 good = _DidYouMeanOSMacro(match.group(1)) |
| 856 did_you_mean = ' (did you mean %s?)' % good if good else '' |
| 857 results.append(' %s:%d %s%s' % (f.LocalPath(), |
| 858 lnum, |
| 859 match.group(1), |
| 860 did_you_mean)) |
| 861 return results |
| 862 |
| 863 |
| 864 def _CheckForInvalidOSMacros(input_api, output_api): |
| 865 """Check all affected files for invalid OS macros.""" |
| 866 bad_macros = [] |
| 867 for f in input_api.AffectedFiles(): |
| 868 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')): |
| 869 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f)) |
| 870 |
| 871 if not bad_macros: |
| 872 return [] |
| 873 |
| 874 return [output_api.PresubmitError( |
| 875 'Possibly invalid OS macro[s] found. Please fix your code\n' |
| 876 'or add your macro to src/PRESUBMIT.py.', bad_macros)] |
| 877 |
| 878 |
809 def CheckChangeOnUpload(input_api, output_api): | 879 def CheckChangeOnUpload(input_api, output_api): |
810 results = [] | 880 results = [] |
811 results.extend(_CommonChecks(input_api, output_api)) | 881 results.extend(_CommonChecks(input_api, output_api)) |
812 return results | 882 return results |
813 | 883 |
814 | 884 |
815 def CheckChangeOnCommit(input_api, output_api): | 885 def CheckChangeOnCommit(input_api, output_api): |
816 results = [] | 886 results = [] |
817 results.extend(_CommonChecks(input_api, output_api)) | 887 results.extend(_CommonChecks(input_api, output_api)) |
818 # TODO(thestig) temporarily disabled, doesn't work in third_party/ | 888 # 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', | 940 'win_rel', |
871 'win:compile', | 941 'win:compile', |
872 ] | 942 ] |
873 | 943 |
874 # Match things like path/aura/file.cc and path/file_aura.cc. | 944 # Match things like path/aura/file.cc and path/file_aura.cc. |
875 # Same for chromeos. | 945 # Same for chromeos. |
876 if any(re.search('[/_](aura|chromeos)', f) for f in files): | 946 if any(re.search('[/_](aura|chromeos)', f) for f in files): |
877 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] | 947 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] |
878 | 948 |
879 return trybots | 949 return trybots |
OLD | NEW |