1 # Copyright (c) 2009 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.
18 def CheckChangeOnUpload(input_api
, output_api
):
20 # What does this code do?
21 # It loads the default black list (e.g. third_party, experimental, etc) and
22 # add our black list (breakpad, skia and v8 are still not following
23 # google style and are not really living this repository).
24 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
25 black_list
= input_api
.DEFAULT_BLACK_LIST
+ EXCLUDED_PATHS
26 sources
= lambda x
: input_api
.FilterSourceFile(x
, black_list
=black_list
)
27 results
.extend(input_api
.canned_checks
.CheckLongLines(
28 input_api
, output_api
, sources
))
29 results
.extend(input_api
.canned_checks
.CheckChangeHasNoTabs(
30 input_api
, output_api
, sources
))
31 results
.extend(input_api
.canned_checks
.CheckChangeHasNoStrayWhitespace(
32 input_api
, output_api
, sources
))
33 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
34 input_api
, output_api
))
35 results
.extend(input_api
.canned_checks
.CheckChangeHasTestField(
36 input_api
, output_api
))
37 results
.extend(input_api
.canned_checks
.CheckChangeSvnEolStyle(
38 input_api
, output_api
, sources
))
39 results
.extend(input_api
.canned_checks
.CheckSvnForCommonMimeTypes(
40 input_api
, output_api
))
44 def CheckChangeOnCommit(input_api
, output_api
):
46 black_list
= input_api
.DEFAULT_BLACK_LIST
+ EXCLUDED_PATHS
47 sources
= lambda x
: input_api
.FilterSourceFile(x
, black_list
=black_list
)
48 results
.extend(input_api
.canned_checks
.CheckLongLines(
49 input_api
, output_api
, sources
))
50 results
.extend(input_api
.canned_checks
.CheckChangeHasNoTabs(
51 input_api
, output_api
, sources
))
52 results
.extend(input_api
.canned_checks
.CheckChangeHasNoStrayWhitespace(
53 input_api
, output_api
, sources
))
54 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
55 input_api
, output_api
))
56 results
.extend(input_api
.canned_checks
.CheckChangeHasTestField(
57 input_api
, output_api
))
58 results
.extend(input_api
.canned_checks
.CheckChangeSvnEolStyle(
59 input_api
, output_api
, sources
))
60 results
.extend(input_api
.canned_checks
.CheckSvnForCommonMimeTypes(
61 input_api
, output_api
))
62 # TODO(thestig) temporarily disabled, doesn't work in third_party/
63 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
64 # input_api, output_api, sources))
65 # Make sure the tree is 'open'.
66 # TODO(maruel): Run it in a separate thread to parallelize checks?
67 results
.extend(CheckTreeIsOpen(
70 'http://chromium-status.appspot.com/status',
72 'http://chromium-status.appspot.com/current?format=raw'))
73 results
.extend(CheckTryJobExecution(input_api
, output_api
))
74 # These builders are just too slow.
78 'Chromium Mac (valgrind)',
79 'Chromium Mac UI (valgrind)(1)',
80 'Chromium Mac UI (valgrind)(2)',
81 'Chromium Mac UI (valgrind)(3)',
82 'Chromium Mac (tsan)',
83 'Webkit Mac (valgrind)',
86 'Linux Tests (valgrind)(1)',
87 'Linux Tests (valgrind)(2)',
88 'Linux Tests (valgrind)(3)',
89 'Linux Tests (valgrind)(4)',
90 'Webkit Linux (valgrind layout)',
92 results
.extend(CheckPendingBuilds(
95 'http://build.chromium.org/buildbot/waterfall/json/builders',
101 def CheckTryJobExecution(input_api
, output_api
):
103 if not input_api
.change
.issue
or not input_api
.change
.patchset
:
105 url
= "http://codereview.chromium.org/%d/get_build_results/%d" % (
106 input_api
.change
.issue
, input_api
.change
.patchset
)
107 PLATFORMS
= ('win', 'linux', 'mac')
109 connection
= input_api
.urllib2
.urlopen(url
)
110 # platform|status|url
111 values
= [item
.split('|', 2) for item
in connection
.read().splitlines()]
114 # It returned an empty list. Probably a private review.
116 # Reformat as an dict of platform: [status, url]
117 values
= dict([[v
[0], [v
[1], v
[2]]] for v
in values
])
118 for platform
in PLATFORMS
:
119 values
.setdefault(platform
, ['not started', ''])
121 non_success
= [k
.upper() for k
,v
in values
.iteritems() if v
[0] != 'success']
122 if 'failure' in [v
[0] for v
in values
.itervalues()]:
123 message
= 'Try job failures on %s!\n' % ', '.join(non_success
)
125 message
= ('Unfinished (or not even started) try jobs on '
126 '%s.\n') % ', '.join(non_success
)
129 'Is try server wrong or broken? Please notify maruel@chromium.org. '
131 outputs
.append(output_api
.PresubmitPromptWarning(message
=message
))
132 except input_api
.urllib2
.HTTPError
, e
:
134 # Fallback to no try job.
135 # TODO(maruel): Change to a PresubmitPromptWarning once the try server is
136 # stable enough and it seems to work fine.
137 outputs
.append(output_api
.PresubmitNotifyResult(
138 'You should try the patch first.'))
140 # Another HTTP error happened, warn the user.
141 # TODO(maruel): Change to a PresubmitPromptWarning once it deemed to work
143 outputs
.append(output_api
.PresubmitNotifyResult(
144 'Got %s while looking for try job status.' % str(e
)))
148 def CheckTreeIsOpen(input_api
, output_api
, url
, closed
, url_text
):
149 """Similar to the one in presubmit_canned_checks except it shows an helpful
152 assert(input_api
.is_committing
)
154 connection
= input_api
.urllib2
.urlopen(url
)
155 status
= connection
.read()
157 if input_api
.re
.match(closed
, status
):
158 long_text
= status
+ '\n' + url
160 connection
= input_api
.urllib2
.urlopen(url_text
)
161 long_text
= connection
.read().strip()
165 return [output_api
.PresubmitError("The tree is closed.",
166 long_text
=long_text
)]
172 def CheckPendingBuilds(input_api
, output_api
, url
, max_pendings
, ignored
):
174 connection
= input_api
.urllib2
.urlopen(url
)
175 raw_data
= connection
.read()
179 data
= simplejson
.loads(raw_data
)
181 # simplejson is much safer. But we should be just fine enough with that:
182 data
= eval(raw_data
.replace('null', 'None'))
184 for (builder_name
, builder
) in data
.iteritems():
185 if builder_name
in ignored
:
187 pending_builds_len
= len(builder
.get('pending_builds', []))
188 if pending_builds_len
> max_pendings
:
189 out
.append('%s has %d build(s) pending' %
190 (builder_name
, pending_builds_len
))
192 return [output_api
.PresubmitPromptWarning(
193 'Build(s) pending. It is suggested to wait that no more than %d '
194 'builds are pending.' % max_pendings
,
195 long_text
='\n'.join(out
))]
202 def GetPreferredTrySlaves():
203 return ['win', 'linux', 'mac']