blob: cbce0b10e247198cafbd1c4069563dc512178163 [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
8See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
9details on the presubmit API built into gcl.
10"""
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]fe5f57c52009-06-05 14:25:5440 return results
[email protected]ca8d1982009-02-19 16:33:1241
42
43def CheckChangeOnCommit(input_api, output_api):
[email protected]fe5f57c52009-06-05 14:25:5444 results = []
[email protected]4306417642009-06-11 00:33:4045 black_list = input_api.DEFAULT_BLACK_LIST + EXCLUDED_PATHS
46 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
47 results.extend(input_api.canned_checks.CheckLongLines(
48 input_api, output_api, sources))
49 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
50 input_api, output_api, sources))
51 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
52 input_api, output_api, sources))
53 results.extend(input_api.canned_checks.CheckChangeHasBugField(
54 input_api, output_api))
55 results.extend(input_api.canned_checks.CheckChangeHasTestField(
56 input_api, output_api))
57 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
58 input_api, output_api, sources))
[email protected]fe5f57c52009-06-05 14:25:5459 # Make sure the tree is 'open'.
[email protected]4306417642009-06-11 00:33:4060 # TODO(maruel): Run it in a separate thread to parallelize checks?
[email protected]04a39f7c2009-06-11 00:41:3261 results.extend(CheckTreeIsOpen(input_api, output_api,
62 'http://chromium-status.appspot.com/status',
63 '0',
64 'http://chromium-status.appspot.com/current'))
[email protected]70ac4982009-06-08 17:31:5165 results.extend(CheckTryJobExecution(input_api, output_api))
[email protected]fe5f57c52009-06-05 14:25:5466 return results
[email protected]ca8d1982009-02-19 16:33:1267
68
[email protected]70ac4982009-06-08 17:31:5169def CheckTryJobExecution(input_api, output_api):
[email protected]4306417642009-06-11 00:33:4070 outputs = []
71 if not input_api.change.issue or not input_api.change.patchset:
72 return outputs
[email protected]70ac4982009-06-08 17:31:5173 url = "http://codereview.chromium.org/%d/get_build_results/%d" % (
74 input_api.change.issue, input_api.change.patchset)
[email protected]70ac4982009-06-08 17:31:5175 try:
76 connection = input_api.urllib2.urlopen(url)
77 # platform|status|url
78 values = [item.split('|', 2) for item in connection.read().splitlines()]
79 connection.close()
80 statuses = map(lambda x: x[1], values)
81 if 'failure' in statuses:
82 failures = filter(lambda x: x[1] != 'success', values)
83 long_text = '\n'.join("% 5s: % 7s %s" % (item[0], item[1], item[2])
84 for item in failures)
85 # TODO(maruel): Change to a PresubmitPromptWarning once the try server is
86 # stable enough and it seems to work fine.
87 message = 'You had try job failures. Are you sure you want to check-in?'
88 outputs.append(output_api.PresubmitNotifyResult(message=message,
89 long_text=long_text))
90 elif 'pending' in statuses or len(values) != 3:
91 long_text = '\n'.join("% 5s: % 7s %s" % (item[0], item[1], item[2])
92 for item in values)
93 # TODO(maruel): Change to a PresubmitPromptWarning once the try server is
94 # stable enough and it seems to work fine.
95 message = 'You should try the patch first (and wait for it to finish).'
96 outputs.append(output_api.PresubmitNotifyResult(message=message,
97 long_text=long_text))
98 except input_api.urllib2.HTTPError, e:
99 if e.code == 404:
100 # Fallback to no try job.
101 # TODO(maruel): Change to a PresubmitPromptWarning once the try server is
102 # stable enough and it seems to work fine.
103 outputs.append(output_api.PresubmitNotifyResult(
104 'You should try the patch first.'))
105 else:
106 # Another HTTP error happened, warn the user.
107 # TODO(maruel): Change to a PresubmitPromptWarning once it deemed to work
108 # fine.
109 outputs.append(output_api.PresubmitNotifyResult(
110 'Got %s while looking for try job status.' % str(e)))
111 return outputs
[email protected]04a39f7c2009-06-11 00:41:32112
113
114def CheckTreeIsOpen(input_api, output_api, url, closed, url_text):
115 """Similar to the one in presubmit_canned_checks except it shows an helpful
116 status text instead.
117 """
118 assert(input_api.is_committing)
119 try:
120 connection = input_api.urllib2.urlopen(url)
121 status = connection.read()
122 connection.close()
123 if input_api.re.match(closed, status):
124 long_text = status + '\n' + url
125 try:
126 connection = input_api.urllib2.urlopen(url_text)
127 text = connection.read()
128 connection.close()
129 match = input_api.re.search(r"\<div class\=\"Notice\"\>(.*)\<\/div\>",
130 text)
131 if match:
132 long_text = match.group(1).strip()
133 except IOError:
134 pass
135 return [output_api.PresubmitPromptWarning("The tree is closed.",
136 long_text=long_text)]
137 except IOError:
138 pass
139 return []