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.
13 r
"^net/tools/spdyshark/[\\\/].*",
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
'@interface')
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):
27 contents
= input_api
.ReadFile(f
)
28 if pattern
.search(contents
):
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',
40 def _CommonChecks(input_api
, output_api
):
41 """Checks common to both upload and commit."""
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
))
49 def _CheckSubversionConfig(input_api
, output_api
):
50 """Verifies the subversion config file is correctly setup.
52 Checks that autoprops are enabled, returns an error otherwise.
54 join
= input_api
.os_path
.join
55 if input_api
.platform
== 'win32':
56 appdata
= input_api
.environ
.get('APPDATA', '')
58 return [output_api
.PresubmitError('%APPDATA% is not configured.')]
59 path
= join(appdata
, 'Subversion', 'config')
61 home
= input_api
.environ
.get('HOME', '')
63 return [output_api
.PresubmitError('$HOME is not configured.')]
64 path
= join(home
, '.subversion', 'config')
67 'Please look at http://dev.chromium.org/developers/coding-style to\n'
68 'configure your subversion configuration file. This enables automatic\n'
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')
74 lines
= open(path
, 'r').read().splitlines()
75 # Make sure auto-props is enabled and check for 2 Chromium standard
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
):
81 output_api
.PresubmitNotifyResult(
82 'It looks like you have not configured your subversion config '
83 'file or it is not up-to-date.\n' + error_msg
)
85 except (OSError, IOError):
87 output_api
.PresubmitNotifyResult(
88 'Can\'t find your subversion config file.\n' + error_msg
)
93 def CheckChangeOnUpload(input_api
, output_api
):
95 results
.extend(_CommonChecks(input_api
, output_api
))
99 def CheckChangeOnCommit(input_api
, output_api
):
101 if not input_api
.json
:
102 results
.append(output_api
.PresubmitNotifyResult(
103 'You don\'t have json nor simplejson installed.\n'
104 ' This is a warning that you will need to upgrade your python '
106 ' This is no big deal but you\'ll eventually need to '
108 ' How? Easy! You can do it right now and shut me off! Just:\n'
109 ' del depot_tools\\python.bat\n'
111 ' Thanks for your patience.'))
112 results
.extend(_CommonChecks(input_api
, output_api
))
113 # TODO(thestig) temporarily disabled, doesn't work in third_party/
114 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
115 # input_api, output_api, sources))
116 # Make sure the tree is 'open'.
117 results
.extend(input_api
.canned_checks
.CheckTreeIsOpen(
120 json_url
='http://chromium-status.appspot.com/current?format=json'))
121 results
.extend(input_api
.canned_checks
.CheckRietveldTryJobExecution(input_api
,
122 output_api
, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
123 'tryserver@chromium.org'))
125 # These builders are just too slow.
129 'Chromium Arm (dbg)',
131 'Chromium Linux x64',
133 results
.extend(input_api
.canned_checks
.CheckBuildbotPendingBuilds(
136 'http://build.chromium.org/p/chromium/json/builders?filter=1',
139 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
140 input_api
, output_api
))
141 results
.extend(input_api
.canned_checks
.CheckChangeHasTestField(
142 input_api
, output_api
))
143 results
.extend(_CheckSubversionConfig(input_api
, output_api
))
147 def GetPreferredTrySlaves():
148 return ['win', 'linux', 'mac']