[email protected] | 377ab1da | 2011-03-17 15:36:28 | [diff] [blame^] | 1 | # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Top-level presubmit script for Chromium. |
| 6 | |
[email protected] | f129379 | 2009-07-31 18:09:56 | [diff] [blame] | 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
[email protected] | 50d7d721e | 2009-11-15 17:56:18 | [diff] [blame] | 8 | for more details about the presubmit API built into gcl. |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 9 | """ |
| 10 | |
[email protected] | 377ab1da | 2011-03-17 15:36:28 | [diff] [blame^] | 11 | import time |
| 12 | |
[email protected] | 379e7dd | 2010-01-28 17:39:21 | [diff] [blame] | 13 | _EXCLUDED_PATHS = ( |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 14 | r"^breakpad[\\\/].*", |
| 15 | r"^net/tools/spdyshark/[\\\/].*", |
| 16 | r"^skia[\\\/].*", |
| 17 | r"^v8[\\\/].*", |
| 18 | r".*MakeFile$", |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 19 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 20 | |
[email protected] | 379e7dd | 2010-01-28 17:39:21 | [diff] [blame] | 21 | _TEXT_FILES = ( |
| 22 | r".*\.txt", |
| 23 | r".*\.json", |
| 24 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 25 | |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 26 | _LICENSE_HEADER = ( |
[email protected] | 377ab1da | 2011-03-17 15:36:28 | [diff] [blame^] | 27 | r".*? Copyright \(c\) %s The Chromium Authors\. All rights reserved\.\n" |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 28 | r".*? Use of this source code is governed by a BSD-style license that can " |
| 29 | "be\n" |
| 30 | r".*? found in the LICENSE file\." |
| 31 | "\n" |
[email protected] | 377ab1da | 2011-03-17 15:36:28 | [diff] [blame^] | 32 | ) % time.strftime("%Y") |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 33 | |
[email protected] | 6a4c8e68 | 2010-12-19 03:31:34 | [diff] [blame] | 34 | def _CheckNoInterfacesInBase(input_api, output_api, source_file_filter): |
| 35 | """Checks to make sure no files in libbase.a have |@interface|.""" |
| 36 | pattern = input_api.re.compile(r'@interface') |
| 37 | files = [] |
| 38 | for f in input_api.AffectedSourceFiles(source_file_filter): |
| 39 | if (f.LocalPath().find('base/') != -1 and |
| 40 | f.LocalPath().find('base/test/') == -1): |
| 41 | contents = input_api.ReadFile(f) |
| 42 | if pattern.search(contents): |
| 43 | files.append(f) |
| 44 | |
| 45 | if len(files): |
| 46 | return [ output_api.PresubmitError( |
| 47 | 'Objective-C interfaces or categories are forbidden in libbase. ' + |
| 48 | 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' + |
| 49 | 'browse_thread/thread/efb28c10435987fd', |
| 50 | files) ] |
| 51 | return [] |
| 52 | |
[email protected] | 650c908 | 2010-12-14 14:33:44 | [diff] [blame] | 53 | def _CheckSingletonInHeaders(input_api, output_api, source_file_filter): |
| 54 | """Checks to make sure no header files have |Singleton<|.""" |
| 55 | pattern = input_api.re.compile(r'Singleton<') |
| 56 | files = [] |
| 57 | for f in input_api.AffectedSourceFiles(source_file_filter): |
| 58 | if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or |
| 59 | f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): |
| 60 | contents = input_api.ReadFile(f) |
| 61 | if pattern.search(contents): |
| 62 | files.append(f) |
| 63 | |
| 64 | if len(files): |
| 65 | return [ output_api.PresubmitError( |
| 66 | 'Found Singleton<T> in the following header files.\n' + |
| 67 | 'Please move them to an appropriate source file so that the ' + |
| 68 | 'template gets instantiated in a single compilation unit.', |
| 69 | files) ] |
| 70 | return [] |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 71 | |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 72 | |
| 73 | def _CheckSubversionConfig(input_api, output_api): |
| 74 | """Verifies the subversion config file is correctly setup. |
| 75 | |
| 76 | Checks that autoprops are enabled, returns an error otherwise. |
| 77 | """ |
| 78 | join = input_api.os_path.join |
| 79 | if input_api.platform == 'win32': |
| 80 | appdata = input_api.environ.get('APPDATA', '') |
| 81 | if not appdata: |
| 82 | return [output_api.PresubmitError('%APPDATA% is not configured.')] |
| 83 | path = join(appdata, 'Subversion', 'config') |
| 84 | else: |
| 85 | home = input_api.environ.get('HOME', '') |
| 86 | if not home: |
| 87 | return [output_api.PresubmitError('$HOME is not configured.')] |
| 88 | path = join(home, '.subversion', 'config') |
| 89 | |
| 90 | error_msg = ( |
| 91 | 'Please look at http://dev.chromium.org/developers/coding-style to\n' |
| 92 | 'configure your subversion configuration file. This enables automatic\n' |
[email protected] | c6a3c10b | 2011-01-24 16:14:20 | [diff] [blame] | 93 | 'properties to simplify the project maintenance.\n' |
| 94 | 'Pro-tip: just download and install\n' |
| 95 | 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n') |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 96 | |
| 97 | try: |
| 98 | lines = open(path, 'r').read().splitlines() |
| 99 | # Make sure auto-props is enabled and check for 2 Chromium standard |
| 100 | # auto-prop. |
| 101 | if (not '*.cc = svn:eol-style=LF' in lines or |
| 102 | not '*.pdf = svn:mime-type=application/pdf' in lines or |
| 103 | not 'enable-auto-props = yes' in lines): |
| 104 | return [ |
[email protected] | 79ed7e6 | 2011-02-21 21:08:53 | [diff] [blame] | 105 | output_api.PresubmitNotifyResult( |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 106 | 'It looks like you have not configured your subversion config ' |
[email protected] | b5359c0 | 2011-02-01 20:29:56 | [diff] [blame] | 107 | 'file or it is not up-to-date.\n' + error_msg) |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 108 | ] |
| 109 | except (OSError, IOError): |
| 110 | return [ |
[email protected] | 79ed7e6 | 2011-02-21 21:08:53 | [diff] [blame] | 111 | output_api.PresubmitNotifyResult( |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 112 | 'Can\'t find your subversion config file.\n' + error_msg) |
| 113 | ] |
| 114 | return [] |
| 115 | |
| 116 | |
[email protected] | 542d1ad2 | 2010-08-04 17:50:55 | [diff] [blame] | 117 | def _CheckConstNSObject(input_api, output_api, source_file_filter): |
| 118 | """Checks to make sure no objective-c files have |const NSSomeClass*|.""" |
| 119 | pattern = input_api.re.compile(r'const\s+NS\w*\s*\*') |
| 120 | files = [] |
| 121 | for f in input_api.AffectedSourceFiles(source_file_filter): |
| 122 | if f.LocalPath().endswith('.h') or f.LocalPath().endswith('.mm'): |
| 123 | contents = input_api.ReadFile(f) |
| 124 | if pattern.search(contents): |
| 125 | files.append(f) |
| 126 | |
| 127 | if len(files): |
| 128 | if input_api.is_committing: |
| 129 | res_type = output_api.PresubmitPromptWarning |
| 130 | else: |
| 131 | res_type = output_api.PresubmitNotifyResult |
| 132 | return [ res_type('|const NSClass*| is wrong, see ' + |
| 133 | 'http://dev.chromium.org/developers/clang-mac', |
| 134 | files) ] |
| 135 | return [] |
| 136 | |
| 137 | |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 138 | def _CommonChecks(input_api, output_api): |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 139 | results = [] |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 140 | # What does this code do? |
| 141 | # It loads the default black list (e.g. third_party, experimental, etc) and |
| 142 | # add our black list (breakpad, skia and v8 are still not following |
| 143 | # google style and are not really living this repository). |
| 144 | # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage. |
[email protected] | 379e7dd | 2010-01-28 17:39:21 | [diff] [blame] | 145 | black_list = input_api.DEFAULT_BLACK_LIST + _EXCLUDED_PATHS |
| 146 | white_list = input_api.DEFAULT_WHITE_LIST + _TEXT_FILES |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 147 | sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list) |
[email protected] | 379e7dd | 2010-01-28 17:39:21 | [diff] [blame] | 148 | text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list, |
| 149 | white_list=white_list) |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 150 | results.extend(input_api.canned_checks.CheckLongLines( |
[email protected] | ea141386 | 2010-05-05 23:24:53 | [diff] [blame] | 151 | input_api, output_api, source_file_filter=sources)) |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 152 | results.extend(input_api.canned_checks.CheckChangeHasNoTabs( |
[email protected] | ea141386 | 2010-05-05 23:24:53 | [diff] [blame] | 153 | input_api, output_api, source_file_filter=sources)) |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 154 | results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( |
[email protected] | ea141386 | 2010-05-05 23:24:53 | [diff] [blame] | 155 | input_api, output_api, source_file_filter=sources)) |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 156 | results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( |
[email protected] | ea141386 | 2010-05-05 23:24:53 | [diff] [blame] | 157 | input_api, output_api, source_file_filter=text_files)) |
[email protected] | 40cdf8b3 | 2009-06-26 23:00:37 | [diff] [blame] | 158 | results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( |
| 159 | input_api, output_api)) |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 160 | results.extend(input_api.canned_checks.CheckLicense( |
[email protected] | ea141386 | 2010-05-05 23:24:53 | [diff] [blame] | 161 | input_api, output_api, _LICENSE_HEADER, source_file_filter=sources)) |
[email protected] | 542d1ad2 | 2010-08-04 17:50:55 | [diff] [blame] | 162 | results.extend(_CheckConstNSObject( |
| 163 | input_api, output_api, source_file_filter=sources)) |
[email protected] | 650c908 | 2010-12-14 14:33:44 | [diff] [blame] | 164 | results.extend(_CheckSingletonInHeaders( |
| 165 | input_api, output_api, source_file_filter=sources)) |
[email protected] | 6a4c8e68 | 2010-12-19 03:31:34 | [diff] [blame] | 166 | results.extend(_CheckNoInterfacesInBase( |
| 167 | input_api, output_api, source_file_filter=sources)) |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 168 | return results |
| 169 | |
| 170 | |
| 171 | def CheckChangeOnUpload(input_api, output_api): |
| 172 | results = [] |
| 173 | results.extend(_CommonChecks(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 174 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 175 | |
| 176 | |
| 177 | def CheckChangeOnCommit(input_api, output_api): |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 178 | results = [] |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 179 | if not input_api.json: |
| 180 | results.append(output_api.PresubmitNotifyResult( |
| 181 | 'You don\'t have json nor simplejson installed.\n' |
| 182 | ' This is a warning that you will need to upgrade your python ' |
| 183 | 'installation.\n' |
| 184 | ' This is no big deal but you\'ll eventually need to ' |
| 185 | 'upgrade.\n' |
| 186 | ' How? Easy! You can do it right now and shut me off! Just:\n' |
| 187 | ' del depot_tools\\python.bat\n' |
| 188 | ' gclient\n' |
| 189 | ' Thanks for your patience.')) |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 190 | results.extend(_CommonChecks(input_api, output_api)) |
[email protected] | dd805fe | 2009-10-01 08:11:51 | [diff] [blame] | 191 | # TODO(thestig) temporarily disabled, doesn't work in third_party/ |
| 192 | #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories( |
| 193 | # input_api, output_api, sources)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 194 | # Make sure the tree is 'open'. |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 195 | results.extend(input_api.canned_checks.CheckTreeIsOpen( |
[email protected] | 7f23815 | 2009-08-12 19:00:34 | [diff] [blame] | 196 | input_api, |
| 197 | output_api, |
[email protected] | 4efa4214 | 2010-08-26 01:29:26 | [diff] [blame] | 198 | json_url='http://chromium-status.appspot.com/current?format=json')) |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 199 | results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api, |
| 200 | output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'), |
| 201 | '[email protected]')) |
| 202 | |
[email protected] | 7fa42f1 | 2009-11-09 20:54:16 | [diff] [blame] | 203 | # These builders are just too slow. |
| 204 | IGNORED_BUILDERS = [ |
| 205 | 'Chromium XP', |
[email protected] | 7fa42f1 | 2009-11-09 20:54:16 | [diff] [blame] | 206 | 'Chromium Mac', |
[email protected] | 0133392 | 2010-02-02 21:25:02 | [diff] [blame] | 207 | 'Chromium Arm (dbg)', |
[email protected] | 7fa42f1 | 2009-11-09 20:54:16 | [diff] [blame] | 208 | 'Chromium Linux', |
| 209 | 'Chromium Linux x64', |
[email protected] | 7fa42f1 | 2009-11-09 20:54:16 | [diff] [blame] | 210 | ] |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 211 | results.extend(input_api.canned_checks.CheckBuildbotPendingBuilds( |
[email protected] | 7fa42f1 | 2009-11-09 20:54:16 | [diff] [blame] | 212 | input_api, |
| 213 | output_api, |
[email protected] | 0724746 | 2010-12-24 07:45:56 | [diff] [blame] | 214 | 'http://build.chromium.org/p/chromium/json/builders?filter=1', |
[email protected] | 7fa42f1 | 2009-11-09 20:54:16 | [diff] [blame] | 215 | 6, |
| 216 | IGNORED_BUILDERS)) |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 217 | results.extend(input_api.canned_checks.CheckChangeHasBugField( |
| 218 | input_api, output_api)) |
| 219 | results.extend(input_api.canned_checks.CheckChangeHasTestField( |
| 220 | input_api, output_api)) |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 221 | results.extend(_CheckSubversionConfig(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 222 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 223 | |
| 224 | |
[email protected] | 5fa0629 | 2009-09-29 01:55:00 | [diff] [blame] | 225 | def GetPreferredTrySlaves(): |
| 226 | return ['win', 'linux', 'mac'] |