blob: f42176d47297ecff03182c0f8718fa4502788c7a [file] [log] [blame]
[email protected]ca8d1982009-02-19 16:33:121#!/usr/bin/python
2# Copyright (c) 2009 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Top-level presubmit script for Chromium.
7
[email protected]f1293792009-07-31 18:09:568See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
[email protected]37cc1a12009-09-24 01:01:339for more details on the presubmit API built into gcl.
[email protected]ca8d1982009-02-19 16:33:1210"""
11
[email protected]4306417642009-06-11 00:33:4012EXCLUDED_PATHS = (
[email protected]33478702009-03-05 14:03:1413 r"breakpad[\\\/].*",
[email protected]33478702009-03-05 14:03:1414 r"skia[\\\/].*",
[email protected]33478702009-03-05 14:03:1415 r"v8[\\\/].*",
[email protected]4306417642009-06-11 00:33:4016)
[email protected]ca8d1982009-02-19 16:33:1217
[email protected]ca8d1982009-02-19 16:33:1218
[email protected]ca8d1982009-02-19 16:33:1219def CheckChangeOnUpload(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:5420 results = []
[email protected]4306417642009-06-11 00:33:4021 # What does this code do?
22 # It loads the default black list (e.g. third_party, experimental, etc) and
23 # add our black list (breakpad, skia and v8 are still not following
24 # google style and are not really living this repository).
25 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
26 black_list = input_api.DEFAULT_BLACK_LIST + EXCLUDED_PATHS
27 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
28 results.extend(input_api.canned_checks.CheckLongLines(
29 input_api, output_api, sources))
30 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
31 input_api, output_api, sources))
32 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
33 input_api, output_api, sources))
34 results.extend(input_api.canned_checks.CheckChangeHasBugField(
35 input_api, output_api))
36 results.extend(input_api.canned_checks.CheckChangeHasTestField(
37 input_api, output_api))
38 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
39 input_api, output_api, sources))
[email protected]40cdf8b32009-06-26 23:00:3740 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
41 input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:5442 return results
[email protected]ca8d1982009-02-19 16:33:1243
44
45def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:5446 results = []
[email protected]4306417642009-06-11 00:33:4047 black_list = input_api.DEFAULT_BLACK_LIST + EXCLUDED_PATHS
48 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
49 results.extend(input_api.canned_checks.CheckLongLines(
50 input_api, output_api, sources))
51 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
52 input_api, output_api, sources))
53 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
54 input_api, output_api, sources))
55 results.extend(input_api.canned_checks.CheckChangeHasBugField(
56 input_api, output_api))
57 results.extend(input_api.canned_checks.CheckChangeHasTestField(
58 input_api, output_api))
59 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
60 input_api, output_api, sources))
[email protected]40cdf8b32009-06-26 23:00:3761 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
62 input_api, output_api))
[email protected]3748d1b2009-08-15 01:30:2763 results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
64 input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:5465 # Make sure the tree is 'open'.
[email protected]4306417642009-06-11 00:33:4066 # TODO(maruel): Run it in a separate thread to parallelize checks?
[email protected]7f238152009-08-12 19:00:3467 results.extend(CheckTreeIsOpen(
68 input_api,
69 output_api,
70 'http://chromium-status.appspot.com/status',
71 '0',
72 'http://chromium-status.appspot.com/current?format=raw'))
[email protected]70ac4982009-06-08 17:31:5173 results.extend(CheckTryJobExecution(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:5474 return results
[email protected]ca8d1982009-02-19 16:33:1275
76
[email protected]70ac4982009-06-08 17:31:5177def CheckTryJobExecution(input_api, output_api):
[email protected]4306417642009-06-11 00:33:4078 outputs = []
79 if not input_api.change.issue or not input_api.change.patchset:
80 return outputs
[email protected]70ac4982009-06-08 17:31:5181 url = "http://codereview.chromium.org/%d/get_build_results/%d" % (
82 input_api.change.issue, input_api.change.patchset)
[email protected]7f238152009-08-12 19:00:3483 PLATFORMS = ('win', 'linux', 'mac')
[email protected]70ac4982009-06-08 17:31:5184 try:
85 connection = input_api.urllib2.urlopen(url)
86 # platform|status|url
87 values = [item.split('|', 2) for item in connection.read().splitlines()]
88 connection.close()
[email protected]71cdeb482009-09-18 18:55:0389 if not values:
90 # It returned an empty list. Probably a private review.
91 return outputs
[email protected]7f238152009-08-12 19:00:3492 # Reformat as an dict of platform: [status, url]
93 values = dict([[v[0], [v[1], v[2]]] for v in values])
94 for platform in PLATFORMS:
95 values.setdefault(platform, ['not started', ''])
[email protected]72303832009-07-10 19:09:0896 message = None
[email protected]7f238152009-08-12 19:00:3497 non_success = [k.upper() for k,v in values.iteritems() if v[0] != 'success']
98 if 'failure' in [v[0] for v in values.itervalues()]:
99 message = 'Try job failures on %s!\n' % ', '.join(non_success)
100 elif non_success:
101 message = ('Unfinished (or not even started) try jobs on '
102 '%s.\n') % ', '.join(non_success)
[email protected]72303832009-07-10 19:09:08103 if message:
104 message += (
105 'Is try server wrong or broken? Please notify [email protected]. '
106 'Thanks.\n')
[email protected]7f238152009-08-12 19:00:34107 outputs.append(output_api.PresubmitPromptWarning(message=message))
[email protected]70ac4982009-06-08 17:31:51108 except input_api.urllib2.HTTPError, e:
109 if e.code == 404:
110 # Fallback to no try job.
111 # TODO(maruel): Change to a PresubmitPromptWarning once the try server is
112 # stable enough and it seems to work fine.
113 outputs.append(output_api.PresubmitNotifyResult(
114 'You should try the patch first.'))
115 else:
116 # Another HTTP error happened, warn the user.
117 # TODO(maruel): Change to a PresubmitPromptWarning once it deemed to work
118 # fine.
119 outputs.append(output_api.PresubmitNotifyResult(
120 'Got %s while looking for try job status.' % str(e)))
121 return outputs
[email protected]04a39f7c2009-06-11 00:41:32122
123
124def CheckTreeIsOpen(input_api, output_api, url, closed, url_text):
125 """Similar to the one in presubmit_canned_checks except it shows an helpful
126 status text instead.
127 """
128 assert(input_api.is_committing)
129 try:
130 connection = input_api.urllib2.urlopen(url)
131 status = connection.read()
132 connection.close()
133 if input_api.re.match(closed, status):
134 long_text = status + '\n' + url
135 try:
136 connection = input_api.urllib2.urlopen(url_text)
[email protected]7f238152009-08-12 19:00:34137 long_text = connection.read().strip()
[email protected]04a39f7c2009-06-11 00:41:32138 connection.close()
[email protected]04a39f7c2009-06-11 00:41:32139 except IOError:
140 pass
[email protected]b3fbe1c2009-07-29 18:44:39141 return [output_api.PresubmitError("The tree is closed.",
142 long_text=long_text)]
[email protected]04a39f7c2009-06-11 00:41:32143 except IOError:
144 pass
145 return []
[email protected]5fa06292009-09-29 01:55:00146
147
148def GetPreferredTrySlaves():
149 return ['win', 'linux', 'mac']