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 | 12 import os |
13 import sys | 13 import sys |
14 | 14 |
15 | 15 |
| 16 SKIA_TREE_STATUS_URL = 'http://skia-tree-status.appspot.com' |
| 17 |
| 18 |
16 def _CheckChangeHasEol(input_api, output_api, source_file_filter=None): | 19 def _CheckChangeHasEol(input_api, output_api, source_file_filter=None): |
17 """Checks that files end with atleast one \n (LF).""" | 20 """Checks that files end with atleast one \n (LF).""" |
18 eof_files = [] | 21 eof_files = [] |
19 for f in input_api.AffectedSourceFiles(source_file_filter): | 22 for f in input_api.AffectedSourceFiles(source_file_filter): |
20 contents = input_api.ReadFile(f, 'rb') | 23 contents = input_api.ReadFile(f, 'rb') |
21 # Check that the file ends in atleast one newline character. | 24 # Check that the file ends in atleast one newline character. |
22 if len(contents) > 1 and contents[-1:] != '\n': | 25 if len(contents) > 1 and contents[-1:] != '\n': |
23 eof_files.append(f.LocalPath()) | 26 eof_files.append(f.LocalPath()) |
24 | 27 |
25 if eof_files: | 28 if eof_files: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 if ('caution' in status['message'].lower() and | 76 if ('caution' in status['message'].lower() and |
74 os.isatty(sys.stdout.fileno())): | 77 os.isatty(sys.stdout.fileno())): |
75 # Display a prompt only if we are in an interactive shell. Without this | 78 # Display a prompt only if we are in an interactive shell. Without this |
76 # check the commit queue behaves incorrectly because it considers | 79 # check the commit queue behaves incorrectly because it considers |
77 # prompts to be failures. | 80 # prompts to be failures. |
78 short_text = 'Tree state is: ' + status['general_state'] | 81 short_text = 'Tree state is: ' + status['general_state'] |
79 long_text = status['message'] + '\n' + json_url | 82 long_text = status['message'] + '\n' + json_url |
80 tree_status_results.append( | 83 tree_status_results.append( |
81 output_api.PresubmitPromptWarning( | 84 output_api.PresubmitPromptWarning( |
82 message=short_text, long_text=long_text)) | 85 message=short_text, long_text=long_text)) |
| 86 else: |
| 87 # Tree status is closed. Put in message about contacting sheriff. |
| 88 connection = input_api.urllib2.urlopen( |
| 89 SKIA_TREE_STATUS_URL + '/current-sheriff') |
| 90 sheriff_details = input_api.json.loads(connection.read()) |
| 91 if sheriff_details: |
| 92 tree_status_results[0]._message += ( |
| 93 '\n\nPlease contact the current Skia sheriff (%s) if you are trying ' |
| 94 'to submit a build fix\nand do not know how to submit because the ' |
| 95 'tree is closed') % sheriff_details['username'] |
83 return tree_status_results | 96 return tree_status_results |
84 | 97 |
85 | 98 |
86 def CheckChangeOnCommit(input_api, output_api): | 99 def CheckChangeOnCommit(input_api, output_api): |
87 """Presubmit checks for the change on commit. | 100 """Presubmit checks for the change on commit. |
88 | 101 |
89 The following are the presubmit checks: | 102 The following are the presubmit checks: |
90 * Check change has one and only one EOL. | 103 * Check change has one and only one EOL. |
91 * Ensures that the Skia tree is open in | 104 * Ensures that the Skia tree is open in |
92 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' | 105 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' |
93 state and an error if it is in 'Closed' state. | 106 state and an error if it is in 'Closed' state. |
94 """ | 107 """ |
95 results = [] | 108 results = [] |
96 results.extend(_CommonChecks(input_api, output_api)) | 109 results.extend(_CommonChecks(input_api, output_api)) |
97 results.extend( | 110 results.extend( |
98 _CheckTreeStatus(input_api, output_api, json_url=( | 111 _CheckTreeStatus(input_api, output_api, json_url=( |
99 'http://skia-tree-status.appspot.com/banner-status?format=json'))) | 112 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) |
100 return results | 113 return results |
OLD | NEW |