blob: b11ed8d40d31f70cfa535ce9e0e80d3ea7c3599d [file] [log] [blame]
[email protected]377ab1da2011-03-17 15:36:281# Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]ca8d1982009-02-19 16:33:122# 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]f1293792009-07-31 18:09:567See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
[email protected]50d7d721e2009-11-15 17:56:188for more details about the presubmit API built into gcl.
[email protected]ca8d1982009-02-19 16:33:129"""
10
[email protected]379e7dd2010-01-28 17:39:2111_EXCLUDED_PATHS = (
[email protected]3e4eb112011-01-18 03:29:5412 r"^breakpad[\\\/].*",
13 r"^net/tools/spdyshark/[\\\/].*",
14 r"^skia[\\\/].*",
15 r"^v8[\\\/].*",
16 r".*MakeFile$",
[email protected]4306417642009-06-11 00:33:4017)
[email protected]ca8d1982009-02-19 16:33:1218
[email protected]ca8d1982009-02-19 16:33:1219
[email protected]22c9bd72011-03-27 16:47:3920def _CheckNoInterfacesInBase(input_api, output_api):
[email protected]6a4c8e682010-12-19 03:31:3421 """Checks to make sure no files in libbase.a have |@interface|."""
[email protected]839c1392011-04-29 20:15:1922 pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE)
[email protected]6a4c8e682010-12-19 03:31:3423 files = []
[email protected]22c9bd72011-03-27 16:47:3924 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
[email protected]6a4c8e682010-12-19 03:31:3425 if (f.LocalPath().find('base/') != -1 and
[email protected]0b2f07b02011-05-02 17:29:0026 f.LocalPath().find('base/test/') == -1 and
27 not f.LocalPath().endswith('_unittest.mm')):
[email protected]6a4c8e682010-12-19 03:31:3428 contents = input_api.ReadFile(f)
29 if pattern.search(contents):
30 files.append(f)
31
32 if len(files):
33 return [ output_api.PresubmitError(
34 'Objective-C interfaces or categories are forbidden in libbase. ' +
35 'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
36 'browse_thread/thread/efb28c10435987fd',
37 files) ]
38 return []
39
[email protected]650c9082010-12-14 14:33:4440
[email protected]22c9bd72011-03-27 16:47:3941def _CommonChecks(input_api, output_api):
42 """Checks common to both upload and commit."""
43 results = []
44 results.extend(input_api.canned_checks.PanProjectChecks(
45 input_api, output_api, excluded_paths=_EXCLUDED_PATHS))
46 results.extend(_CheckNoInterfacesInBase(input_api, output_api))
[email protected]66daa702011-05-28 14:41:4647 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
[email protected]22c9bd72011-03-27 16:47:3948 return results
[email protected]1f7b4172010-01-28 01:17:3449
[email protected]b337cb5b2011-01-23 21:24:0550
51def _CheckSubversionConfig(input_api, output_api):
52 """Verifies the subversion config file is correctly setup.
53
54 Checks that autoprops are enabled, returns an error otherwise.
55 """
56 join = input_api.os_path.join
57 if input_api.platform == 'win32':
58 appdata = input_api.environ.get('APPDATA', '')
59 if not appdata:
60 return [output_api.PresubmitError('%APPDATA% is not configured.')]
61 path = join(appdata, 'Subversion', 'config')
62 else:
63 home = input_api.environ.get('HOME', '')
64 if not home:
65 return [output_api.PresubmitError('$HOME is not configured.')]
66 path = join(home, '.subversion', 'config')
67
68 error_msg = (
69 'Please look at http://dev.chromium.org/developers/coding-style to\n'
70 'configure your subversion configuration file. This enables automatic\n'
[email protected]c6a3c10b2011-01-24 16:14:2071 'properties to simplify the project maintenance.\n'
72 'Pro-tip: just download and install\n'
73 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
[email protected]b337cb5b2011-01-23 21:24:0574
75 try:
76 lines = open(path, 'r').read().splitlines()
77 # Make sure auto-props is enabled and check for 2 Chromium standard
78 # auto-prop.
79 if (not '*.cc = svn:eol-style=LF' in lines or
80 not '*.pdf = svn:mime-type=application/pdf' in lines or
81 not 'enable-auto-props = yes' in lines):
82 return [
[email protected]79ed7e62011-02-21 21:08:5383 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:0584 'It looks like you have not configured your subversion config '
[email protected]b5359c02011-02-01 20:29:5685 'file or it is not up-to-date.\n' + error_msg)
[email protected]b337cb5b2011-01-23 21:24:0586 ]
87 except (OSError, IOError):
88 return [
[email protected]79ed7e62011-02-21 21:08:5389 output_api.PresubmitNotifyResult(
[email protected]b337cb5b2011-01-23 21:24:0590 'Can\'t find your subversion config file.\n' + error_msg)
91 ]
92 return []
93
94
[email protected]66daa702011-05-28 14:41:4695def _CheckAuthorizedAuthor(input_api, output_api):
96 """For non-googler/chromites committers, verify the author's email address is
97 in AUTHORS.
98 """
[email protected]9bb9cb82011-06-13 20:43:0199 # TODO(maruel): Add it to input_api?
100 import fnmatch
101
[email protected]66daa702011-05-28 14:41:46102 author = input_api.change.author_email
[email protected]9bb9cb82011-06-13 20:43:01103 if not author:
104 input_api.logging.info('No author, skipping AUTHOR check')
[email protected]66daa702011-05-28 14:41:46105 return []
[email protected]c99663292011-05-31 19:46:08106 authors_path = input_api.os_path.join(
[email protected]66daa702011-05-28 14:41:46107 input_api.PresubmitLocalPath(), 'AUTHORS')
108 valid_authors = (
109 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
110 for line in open(authors_path))
[email protected]ac54b132011-06-06 18:11:18111 valid_authors = [item.group(1).lower() for item in valid_authors if item]
[email protected]9bb9cb82011-06-13 20:43:01112 if input_api.verbose:
113 print 'Valid authors are %s' % ', '.join(valid_authors)
[email protected]d8b50be2011-06-15 14:19:44114 if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
[email protected]66daa702011-05-28 14:41:46115 return [output_api.PresubmitPromptWarning(
116 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
117 '\n'
118 'http://www.chromium.org/developers/contributing-code and read the '
119 '"Legal" section\n'
120 'If you are a chromite, verify the contributor signed the CLA.') %
121 author)]
122 return []
123
124
[email protected]1f7b4172010-01-28 01:17:34125def CheckChangeOnUpload(input_api, output_api):
126 results = []
127 results.extend(_CommonChecks(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54128 return results
[email protected]ca8d1982009-02-19 16:33:12129
130
131def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:54132 results = []
[email protected]1f7b4172010-01-28 01:17:34133 results.extend(_CommonChecks(input_api, output_api))
[email protected]dd805fe2009-10-01 08:11:51134 # TODO(thestig) temporarily disabled, doesn't work in third_party/
135 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
136 # input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:54137 # Make sure the tree is 'open'.
[email protected]806e98e2010-03-19 17:49:27138 results.extend(input_api.canned_checks.CheckTreeIsOpen(
[email protected]7f238152009-08-12 19:00:34139 input_api,
140 output_api,
[email protected]4efa42142010-08-26 01:29:26141 json_url='http://chromium-status.appspot.com/current?format=json'))
[email protected]806e98e2010-03-19 17:49:27142 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
143 output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
144 '[email protected]'))
145
[email protected]3e4eb112011-01-18 03:29:54146 results.extend(input_api.canned_checks.CheckChangeHasBugField(
147 input_api, output_api))
148 results.extend(input_api.canned_checks.CheckChangeHasTestField(
149 input_api, output_api))
[email protected]b337cb5b2011-01-23 21:24:05150 results.extend(_CheckSubversionConfig(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:54151 return results
[email protected]ca8d1982009-02-19 16:33:12152
153
[email protected]5fa06292009-09-29 01:55:00154def GetPreferredTrySlaves():
155 return ['win', 'linux', 'mac']