[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] | 379e7dd | 2010-01-28 17:39:21 | [diff] [blame] | 11 | _EXCLUDED_PATHS = ( |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 12 | r"^breakpad[\\\/].*", |
| 13 | r"^net/tools/spdyshark/[\\\/].*", |
| 14 | r"^skia[\\\/].*", |
| 15 | r"^v8[\\\/].*", |
| 16 | r".*MakeFile$", |
[email protected] | 430641764 | 2009-06-11 00:33:40 | [diff] [blame] | 17 | ) |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 18 | |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 19 | |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 20 | def _CheckNoInterfacesInBase(input_api, output_api): |
[email protected] | 6a4c8e68 | 2010-12-19 03:31:34 | [diff] [blame] | 21 | """Checks to make sure no files in libbase.a have |@interface|.""" |
[email protected] | 839c139 | 2011-04-29 20:15:19 | [diff] [blame^] | 22 | pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE) |
[email protected] | 6a4c8e68 | 2010-12-19 03:31:34 | [diff] [blame] | 23 | files = [] |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 24 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
[email protected] | 6a4c8e68 | 2010-12-19 03:31:34 | [diff] [blame] | 25 | if (f.LocalPath().find('base/') != -1 and |
| 26 | f.LocalPath().find('base/test/') == -1): |
| 27 | contents = input_api.ReadFile(f) |
| 28 | if pattern.search(contents): |
| 29 | files.append(f) |
| 30 | |
| 31 | if len(files): |
| 32 | return [ output_api.PresubmitError( |
| 33 | 'Objective-C interfaces or categories are forbidden in libbase. ' + |
| 34 | 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' + |
| 35 | 'browse_thread/thread/efb28c10435987fd', |
| 36 | files) ] |
| 37 | return [] |
| 38 | |
[email protected] | 650c908 | 2010-12-14 14:33:44 | [diff] [blame] | 39 | |
[email protected] | 22c9bd7 | 2011-03-27 16:47:39 | [diff] [blame] | 40 | def _CommonChecks(input_api, output_api): |
| 41 | """Checks common to both upload and commit.""" |
| 42 | results = [] |
| 43 | results.extend(input_api.canned_checks.PanProjectChecks( |
| 44 | input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) |
| 45 | results.extend(_CheckNoInterfacesInBase(input_api, output_api)) |
| 46 | return results |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 47 | |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 48 | |
| 49 | def _CheckSubversionConfig(input_api, output_api): |
| 50 | """Verifies the subversion config file is correctly setup. |
| 51 | |
| 52 | Checks that autoprops are enabled, returns an error otherwise. |
| 53 | """ |
| 54 | join = input_api.os_path.join |
| 55 | if input_api.platform == 'win32': |
| 56 | appdata = input_api.environ.get('APPDATA', '') |
| 57 | if not appdata: |
| 58 | return [output_api.PresubmitError('%APPDATA% is not configured.')] |
| 59 | path = join(appdata, 'Subversion', 'config') |
| 60 | else: |
| 61 | home = input_api.environ.get('HOME', '') |
| 62 | if not home: |
| 63 | return [output_api.PresubmitError('$HOME is not configured.')] |
| 64 | path = join(home, '.subversion', 'config') |
| 65 | |
| 66 | error_msg = ( |
| 67 | 'Please look at http://dev.chromium.org/developers/coding-style to\n' |
| 68 | 'configure your subversion configuration file. This enables automatic\n' |
[email protected] | c6a3c10b | 2011-01-24 16:14:20 | [diff] [blame] | 69 | 'properties to simplify the project maintenance.\n' |
| 70 | 'Pro-tip: just download and install\n' |
| 71 | 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n') |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 72 | |
| 73 | try: |
| 74 | lines = open(path, 'r').read().splitlines() |
| 75 | # Make sure auto-props is enabled and check for 2 Chromium standard |
| 76 | # auto-prop. |
| 77 | if (not '*.cc = svn:eol-style=LF' in lines or |
| 78 | not '*.pdf = svn:mime-type=application/pdf' in lines or |
| 79 | not 'enable-auto-props = yes' in lines): |
| 80 | return [ |
[email protected] | 79ed7e6 | 2011-02-21 21:08:53 | [diff] [blame] | 81 | output_api.PresubmitNotifyResult( |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 82 | 'It looks like you have not configured your subversion config ' |
[email protected] | b5359c0 | 2011-02-01 20:29:56 | [diff] [blame] | 83 | 'file or it is not up-to-date.\n' + error_msg) |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 84 | ] |
| 85 | except (OSError, IOError): |
| 86 | return [ |
[email protected] | 79ed7e6 | 2011-02-21 21:08:53 | [diff] [blame] | 87 | output_api.PresubmitNotifyResult( |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 88 | 'Can\'t find your subversion config file.\n' + error_msg) |
| 89 | ] |
| 90 | return [] |
| 91 | |
| 92 | |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 93 | def CheckChangeOnUpload(input_api, output_api): |
| 94 | results = [] |
| 95 | results.extend(_CommonChecks(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 96 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 97 | |
| 98 | |
| 99 | def CheckChangeOnCommit(input_api, output_api): |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 100 | results = [] |
[email protected] | 1f7b417 | 2010-01-28 01:17:34 | [diff] [blame] | 101 | results.extend(_CommonChecks(input_api, output_api)) |
[email protected] | dd805fe | 2009-10-01 08:11:51 | [diff] [blame] | 102 | # TODO(thestig) temporarily disabled, doesn't work in third_party/ |
| 103 | #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories( |
| 104 | # input_api, output_api, sources)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 105 | # Make sure the tree is 'open'. |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 106 | results.extend(input_api.canned_checks.CheckTreeIsOpen( |
[email protected] | 7f23815 | 2009-08-12 19:00:34 | [diff] [blame] | 107 | input_api, |
| 108 | output_api, |
[email protected] | 4efa4214 | 2010-08-26 01:29:26 | [diff] [blame] | 109 | json_url='http://chromium-status.appspot.com/current?format=json')) |
[email protected] | 806e98e | 2010-03-19 17:49:27 | [diff] [blame] | 110 | results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api, |
| 111 | output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'), |
| 112 | '[email protected]')) |
| 113 | |
[email protected] | 3e4eb11 | 2011-01-18 03:29:54 | [diff] [blame] | 114 | results.extend(input_api.canned_checks.CheckChangeHasBugField( |
| 115 | input_api, output_api)) |
| 116 | results.extend(input_api.canned_checks.CheckChangeHasTestField( |
| 117 | input_api, output_api)) |
[email protected] | b337cb5b | 2011-01-23 21:24:05 | [diff] [blame] | 118 | results.extend(_CheckSubversionConfig(input_api, output_api)) |
[email protected] | fe5f57c5 | 2009-06-05 14:25:54 | [diff] [blame] | 119 | return results |
[email protected] | ca8d198 | 2009-02-19 16:33:12 | [diff] [blame] | 120 | |
| 121 | |
[email protected] | 5fa0629 | 2009-09-29 01:55:00 | [diff] [blame] | 122 | def GetPreferredTrySlaves(): |
| 123 | return ['win', 'linux', 'mac'] |