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 preprocessor_statement = input_api.re.compile(r'^\s*#') | |
832 os_macro = input_api.re.compile(r'defined\((OS_[^)]+)\)') | |
833 results = [] | |
834 for lnum, line in f.ChangedContents(): | |
835 if preprocessor_statement.search(line): | |
836 for match in os_macro.finditer(line): | |
837 if not match.group(1) in _VALID_OS_MACROS: | |
838 results.append(' %s:%d %s' % (f.LocalPath(), lnum, match.group(1))) | |
839 return results | |
840 | |
841 | |
842 def _CheckForInvalidOSMacros(input_api, output_api): | |
843 """Check all affected files for invalid OS macros.""" | |
844 bad_macros = [] | |
845 for f in input_api.AffectedFiles(): | |
846 if not f.LocalPath().endswith(('.py', '.js', '.html', '.css')): | |
847 bad_macros.extend(_CheckForInvalidOSMacrosInFile(input_api, f)) | |
848 | |
849 if not bad_macros: | |
850 return [] | |
851 | |
852 return [output_api.PresubmitError( | |
853 'Possibly invalid OS macros found. Please add your macro to\n' | |
854 'src/PRESUBMIT.py or update your code.', bad_macros)] | |
Scott Hess - ex-Googler
2013/03/26 02:45:46
Do most presubmit failures suggest how to work aro
Dan Beam
2013/03/26 03:46:03
I added a crappy suggest function. I could just li
| |
855 | |
856 | |
809 def CheckChangeOnUpload(input_api, output_api): | 857 def CheckChangeOnUpload(input_api, output_api): |
810 results = [] | 858 results = [] |
811 results.extend(_CommonChecks(input_api, output_api)) | 859 results.extend(_CommonChecks(input_api, output_api)) |
812 return results | 860 return results |
813 | 861 |
814 | 862 |
815 def CheckChangeOnCommit(input_api, output_api): | 863 def CheckChangeOnCommit(input_api, output_api): |
816 results = [] | 864 results = [] |
817 results.extend(_CommonChecks(input_api, output_api)) | 865 results.extend(_CommonChecks(input_api, output_api)) |
818 # TODO(thestig) temporarily disabled, doesn't work in third_party/ | 866 # 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', | 918 'win_rel', |
871 'win:compile', | 919 'win:compile', |
872 ] | 920 ] |
873 | 921 |
874 # Match things like path/aura/file.cc and path/file_aura.cc. | 922 # Match things like path/aura/file.cc and path/file_aura.cc. |
875 # Same for chromeos. | 923 # Same for chromeos. |
876 if any(re.search('[/_](aura|chromeos)', f) for f in files): | 924 if any(re.search('[/_](aura|chromeos)', f) for f in files): |
877 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] | 925 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] |
878 | 926 |
879 return trybots | 927 return trybots |
OLD | NEW |