rmistry@google.com | 8e3ff8c | 2013-01-17 12:55:34 +0000 | [diff] [blame] | 1 | # 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 | |
| 8 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 9 | for more details about the presubmit API built into gcl. |
| 10 | """ |
| 11 | |
rmistry@google.com | c299344 | 2013-01-23 14:35:58 +0000 | [diff] [blame] | 12 | |
rmistry@google.com | 6be0b4c | 2013-01-17 14:50:59 +0000 | [diff] [blame] | 13 | def _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.com | 8e3ff8c | 2013-01-17 12:55:34 +0000 | [diff] [blame] | 27 | |
| 28 | def CheckChangeOnUpload(input_api, output_api): |
rmistry@google.com | 6be0b4c | 2013-01-17 14:50:59 +0000 | [diff] [blame] | 29 | """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.com | 8e3ff8c | 2013-01-17 12:55:34 +0000 | [diff] [blame] | 37 | |
| 38 | |
rmistry@google.com | c299344 | 2013-01-23 14:35:58 +0000 | [diff] [blame] | 39 | def _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.com | 8e3ff8c | 2013-01-17 12:55:34 +0000 | [diff] [blame] | 63 | def CheckChangeOnCommit(input_api, output_api): |
| 64 | """Presubmit checks for the change on commit. |
| 65 | |
| 66 | The following are the presubmit checks: |
rmistry@google.com | 6be0b4c | 2013-01-17 14:50:59 +0000 | [diff] [blame] | 67 | * Check change has one and only one EOL. |
rmistry@google.com | c299344 | 2013-01-23 14:35:58 +0000 | [diff] [blame] | 68 | * 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.com | 8e3ff8c | 2013-01-17 12:55:34 +0000 | [diff] [blame] | 71 | """ |
| 72 | results = [] |
rmistry@google.com | 6be0b4c | 2013-01-17 14:50:59 +0000 | [diff] [blame] | 73 | results.extend(_CommonChecks(input_api, output_api)) |
rmistry@google.com | 8e3ff8c | 2013-01-17 12:55:34 +0000 | [diff] [blame] | 74 | results.extend( |
rmistry@google.com | c299344 | 2013-01-23 14:35:58 +0000 | [diff] [blame] | 75 | _CheckTreeStatus(input_api, output_api, json_url=( |
| 76 | 'http://skia-tree-status.appspot.com/banner-status?format=json'))) |
rmistry@google.com | 8e3ff8c | 2013-01-17 12:55:34 +0000 | [diff] [blame] | 77 | return results |