OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 """Top-level presubmit script for Skia. | 6 """Top-level presubmit script for Skia. |
7 | 7 |
8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
9 for more details about the presubmit API built into gcl. | 9 for more details about the presubmit API built into gcl. |
10 """ | 10 """ |
11 | 11 |
| 12 import os |
| 13 import sys |
| 14 |
12 | 15 |
13 def _CheckChangeHasEol(input_api, output_api, source_file_filter=None): | 16 def _CheckChangeHasEol(input_api, output_api, source_file_filter=None): |
14 """Checks that files end with atleast one \n (LF).""" | 17 """Checks that files end with atleast one \n (LF).""" |
15 eof_files = [] | 18 eof_files = [] |
16 for f in input_api.AffectedSourceFiles(source_file_filter): | 19 for f in input_api.AffectedSourceFiles(source_file_filter): |
17 contents = input_api.ReadFile(f, 'rb') | 20 contents = input_api.ReadFile(f, 'rb') |
18 # Check that the file ends in atleast one newline character. | 21 # Check that the file ends in atleast one newline character. |
19 if len(contents) > 1 and contents[-1:] != '\n': | 22 if len(contents) > 1 and contents[-1:] != '\n': |
20 eof_files.append(f.LocalPath()) | 23 eof_files.append(f.LocalPath()) |
21 | 24 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 output_api: output related apis. | 63 output_api: output related apis. |
61 json_url: url to download json style status. | 64 json_url: url to download json style status. |
62 """ | 65 """ |
63 tree_status_results = input_api.canned_checks.CheckTreeIsOpen( | 66 tree_status_results = input_api.canned_checks.CheckTreeIsOpen( |
64 input_api, output_api, json_url=json_url) | 67 input_api, output_api, json_url=json_url) |
65 if not tree_status_results: | 68 if not tree_status_results: |
66 # Check for caution state only if tree is not closed. | 69 # Check for caution state only if tree is not closed. |
67 connection = input_api.urllib2.urlopen(json_url) | 70 connection = input_api.urllib2.urlopen(json_url) |
68 status = input_api.json.loads(connection.read()) | 71 status = input_api.json.loads(connection.read()) |
69 connection.close() | 72 connection.close() |
70 if 'caution' in status['message'].lower(): | 73 if ('caution' in status['message'].lower() and |
| 74 os.isatty(sys.stdout.fileno())): |
| 75 # Display a prompt only if we are in an interactive shell. Without this |
| 76 # check the commit queue behaves incorrectly because it considers |
| 77 # prompts to be failures. |
71 short_text = 'Tree state is: ' + status['general_state'] | 78 short_text = 'Tree state is: ' + status['general_state'] |
72 long_text = status['message'] + '\n' + json_url | 79 long_text = status['message'] + '\n' + json_url |
73 tree_status_results.append( | 80 tree_status_results.append( |
74 output_api.PresubmitPromptWarning( | 81 output_api.PresubmitPromptWarning( |
75 message=short_text, long_text=long_text)) | 82 message=short_text, long_text=long_text)) |
76 return tree_status_results | 83 return tree_status_results |
77 | 84 |
78 | 85 |
79 def CheckChangeOnCommit(input_api, output_api): | 86 def CheckChangeOnCommit(input_api, output_api): |
80 """Presubmit checks for the change on commit. | 87 """Presubmit checks for the change on commit. |
81 | 88 |
82 The following are the presubmit checks: | 89 The following are the presubmit checks: |
83 * Check change has one and only one EOL. | 90 * Check change has one and only one EOL. |
84 * Ensures that the Skia tree is open in | 91 * Ensures that the Skia tree is open in |
85 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' | 92 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' |
86 state and an error if it is in 'Closed' state. | 93 state and an error if it is in 'Closed' state. |
87 """ | 94 """ |
88 results = [] | 95 results = [] |
89 results.extend(_CommonChecks(input_api, output_api)) | 96 results.extend(_CommonChecks(input_api, output_api)) |
90 results.extend( | 97 results.extend( |
91 _CheckTreeStatus(input_api, output_api, json_url=( | 98 _CheckTreeStatus(input_api, output_api, json_url=( |
92 'http://skia-tree-status.appspot.com/banner-status?format=json'))) | 99 'http://skia-tree-status.appspot.com/banner-status?format=json'))) |
93 return results | 100 return results |
OLD | NEW |