Remove COMPOSITOR_2 flag, old compositor code.
[chromium-blink-merge.git] / PRESUBMIT.py
blobeafb77a1d89ff5783b5c706145cf59657caea1cd
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Top-level presubmit script for Chromium.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl.
9 """
11 _EXCLUDED_PATHS = (
12 r"^breakpad[\\\/].*",
13 r"^net/tools/spdyshark/[\\\/].*",
14 r"^skia[\\\/].*",
15 r"^v8[\\\/].*",
16 r".*MakeFile$",
20 def _CheckNoInterfacesInBase(input_api, output_api):
21 """Checks to make sure no files in libbase.a have |@interface|."""
22 pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE)
23 files = []
24 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
25 if (f.LocalPath().find('base/') != -1 and
26 f.LocalPath().find('base/test/') == -1 and
27 not f.LocalPath().endswith('_unittest.mm')):
28 contents = input_api.ReadFile(f)
29 if pattern.search(contents):
30 files.append(f)
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 []
41 def _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))
47 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
48 return results
51 def _CheckSubversionConfig(input_api, output_api):
52 """Verifies the subversion config file is correctly setup.
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')
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'
71 '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')
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 [
83 output_api.PresubmitNotifyResult(
84 'It looks like you have not configured your subversion config '
85 'file or it is not up-to-date.\n' + error_msg)
87 except (OSError, IOError):
88 return [
89 output_api.PresubmitNotifyResult(
90 'Can\'t find your subversion config file.\n' + error_msg)
92 return []
95 def _CheckAuthorizedAuthor(input_api, output_api):
96 """For non-googler/chromites committers, verify the author's email address is
97 in AUTHORS.
98 """
99 author = input_api.change.author_email
100 if (author is None or author.endswith('@chromium.org') or
101 author.endswith('@google.com')):
102 return []
103 authors_path = input_api.os_path.join(
104 input_api.PresubmitLocalPath(), 'AUTHORS')
105 valid_authors = (
106 input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
107 for line in open(authors_path))
108 valid_authors = [item.group(1).lower() for item in valid_authors if item]
109 if not author.lower() in valid_authors:
110 return [output_api.PresubmitPromptWarning(
111 ('%s is not in AUTHORS file. If you are a new contributor, please visit'
112 '\n'
113 'http://www.chromium.org/developers/contributing-code and read the '
114 '"Legal" section\n'
115 'If you are a chromite, verify the contributor signed the CLA.') %
116 author)]
117 return []
120 def CheckChangeOnUpload(input_api, output_api):
121 results = []
122 results.extend(_CommonChecks(input_api, output_api))
123 return results
126 def CheckChangeOnCommit(input_api, output_api):
127 results = []
128 results.extend(_CommonChecks(input_api, output_api))
129 # TODO(thestig) temporarily disabled, doesn't work in third_party/
130 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
131 # input_api, output_api, sources))
132 # Make sure the tree is 'open'.
133 results.extend(input_api.canned_checks.CheckTreeIsOpen(
134 input_api,
135 output_api,
136 json_url='http://chromium-status.appspot.com/current?format=json'))
137 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
138 output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
139 'tryserver@chromium.org'))
141 results.extend(input_api.canned_checks.CheckChangeHasBugField(
142 input_api, output_api))
143 results.extend(input_api.canned_checks.CheckChangeHasTestField(
144 input_api, output_api))
145 results.extend(_CheckSubversionConfig(input_api, output_api))
146 return results
149 def GetPreferredTrySlaves():
150 return ['win', 'linux', 'mac']