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
'^\s*@interface', input_api
.re
.MULTILINE
)
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
):
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',
41 def _CommonChecks(input_api
, output_api
):
42 """Checks common to both upload and commit."""
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
))
50 def _CheckSubversionConfig(input_api
, output_api
):
51 """Verifies the subversion config file is correctly setup.
53 Checks that autoprops are enabled, returns an error otherwise.
55 join
= input_api
.os_path
.join
56 if input_api
.platform
== 'win32':
57 appdata
= input_api
.environ
.get('APPDATA', '')
59 return [output_api
.PresubmitError('%APPDATA% is not configured.')]
60 path
= join(appdata
, 'Subversion', 'config')
62 home
= input_api
.environ
.get('HOME', '')
64 return [output_api
.PresubmitError('$HOME is not configured.')]
65 path
= join(home
, '.subversion', 'config')
68 'Please look at http://dev.chromium.org/developers/coding-style to\n'
69 'configure your subversion configuration file. This enables automatic\n'
70 'properties to simplify the project maintenance.\n'
71 'Pro-tip: just download and install\n'
72 'http://src.chromium.org/viewvc/chrome/trunk/tools/build/slave/config\n')
75 lines
= open(path
, 'r').read().splitlines()
76 # Make sure auto-props is enabled and check for 2 Chromium standard
78 if (not '*.cc = svn:eol-style=LF' in lines
or
79 not '*.pdf = svn:mime-type=application/pdf' in lines
or
80 not 'enable-auto-props = yes' in lines
):
82 output_api
.PresubmitNotifyResult(
83 'It looks like you have not configured your subversion config '
84 'file or it is not up-to-date.\n' + error_msg
)
86 except (OSError, IOError):
88 output_api
.PresubmitNotifyResult(
89 'Can\'t find your subversion config file.\n' + error_msg
)
94 def CheckChangeOnUpload(input_api
, output_api
):
96 results
.extend(_CommonChecks(input_api
, output_api
))
100 def CheckChangeOnCommit(input_api
, output_api
):
102 results
.extend(_CommonChecks(input_api
, output_api
))
103 # TODO(thestig) temporarily disabled, doesn't work in third_party/
104 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
105 # input_api, output_api, sources))
106 # Make sure the tree is 'open'.
107 results
.extend(input_api
.canned_checks
.CheckTreeIsOpen(
110 json_url
='http://chromium-status.appspot.com/current?format=json'))
111 results
.extend(input_api
.canned_checks
.CheckRietveldTryJobExecution(input_api
,
112 output_api
, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
113 'tryserver@chromium.org'))
115 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
116 input_api
, output_api
))
117 results
.extend(input_api
.canned_checks
.CheckChangeHasTestField(
118 input_api
, output_api
))
119 results
.extend(_CheckSubversionConfig(input_api
, output_api
))
123 def GetPreferredTrySlaves():
124 return ['win', 'linux', 'mac']