blob: b5aeffcd18e812eee1dc723a47f135a8dbe067b2 [file] [log] [blame]
rmistry@google.com8e3ff8c2013-01-17 12:55:34 +00001# Copyright (c) 2013 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.
4
5
6"""Top-level presubmit script for Skia.
7
8See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
9for more details about the presubmit API built into gcl.
10"""
11
rmistry@google.comc2993442013-01-23 14:35:58 +000012
rmistry@google.com6be0b4c2013-01-17 14:50:59 +000013def _CommonChecks(input_api, output_api):
14 """Presubmit checks common to upload and commit."""
15 results = []
16 sources = lambda x: (x.LocalPath().endswith('.h') or
17 x.LocalPath().endswith('.gypi') or
18 x.LocalPath().endswith('.gyp') or
19 x.LocalPath().endswith('.py') or
20 x.LocalPath().endswith('.sh') or
21 x.LocalPath().endswith('.cpp'))
22 results.extend(
23 input_api.canned_checks.CheckChangeHasOnlyOneEol(
24 input_api, output_api, source_file_filter=sources))
25 return results
26
rmistry@google.com8e3ff8c2013-01-17 12:55:34 +000027
28def CheckChangeOnUpload(input_api, output_api):
rmistry@google.com6be0b4c2013-01-17 14:50:59 +000029 """Presubmit checks for the change on upload.
30
31 The following are the presubmit checks:
32 * Check change has one and only one EOL.
33 """
34 results = []
35 results.extend(_CommonChecks(input_api, output_api))
36 return results
rmistry@google.com8e3ff8c2013-01-17 12:55:34 +000037
38
rmistry@google.comc2993442013-01-23 14:35:58 +000039def _CheckTreeStatus(input_api, output_api, json_url):
40 """Check whether to allow commit.
41
42 Args:
43 input_api: input related apis.
44 output_api: output related apis.
45 json_url: url to download json style status.
46 """
47 tree_status_results = input_api.canned_checks.CheckTreeIsOpen(
48 input_api, output_api, json_url=json_url)
49 if not tree_status_results:
50 # Check for caution state only if tree is not closed.
51 connection = input_api.urllib2.urlopen(json_url)
52 status = input_api.json.loads(connection.read())
53 connection.close()
54 if 'caution' in status['message'].lower():
55 short_text = 'Tree state is: ' + status['general_state']
56 long_text = status['message'] + '\n' + json_url
57 tree_status_results.append(
58 output_api.PresubmitPromptWarning(
59 message=short_text, long_text=long_text))
60 return tree_status_results
61
62
rmistry@google.com8e3ff8c2013-01-17 12:55:34 +000063def CheckChangeOnCommit(input_api, output_api):
64 """Presubmit checks for the change on commit.
65
66 The following are the presubmit checks:
rmistry@google.com6be0b4c2013-01-17 14:50:59 +000067 * Check change has one and only one EOL.
rmistry@google.comc2993442013-01-23 14:35:58 +000068 * Ensures that the Skia tree is open in
69 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution'
70 state and an error if it is in 'Closed' state.
rmistry@google.com8e3ff8c2013-01-17 12:55:34 +000071 """
72 results = []
rmistry@google.com6be0b4c2013-01-17 14:50:59 +000073 results.extend(_CommonChecks(input_api, output_api))
rmistry@google.com8e3ff8c2013-01-17 12:55:34 +000074 results.extend(
rmistry@google.comc2993442013-01-23 14:35:58 +000075 _CheckTreeStatus(input_api, output_api, json_url=(
76 'http://skia-tree-status.appspot.com/banner-status?format=json')))
rmistry@google.com8e3ff8c2013-01-17 12:55:34 +000077 return results