| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Top-level presubmit script for Chromium. | 6 """Top-level presubmit script for Chromium. |
| 7 | 7 |
| 8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for | 8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
| 9 details on the presubmit API built into gcl. | 9 details on the presubmit API built into gcl. |
| 10 """ | 10 """ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 Reads files in binary format. | 30 Reads files in binary format. |
| 31 """ | 31 """ |
| 32 fo = open(path, 'rb') | 32 fo = open(path, 'rb') |
| 33 try: | 33 try: |
| 34 contents = fo.read() | 34 contents = fo.read() |
| 35 finally: | 35 finally: |
| 36 fo.close() | 36 fo.close() |
| 37 return contents | 37 return contents |
| 38 | 38 |
| 39 | 39 |
| 40 # Seam for unit testing | |
| 41 _ReadFile = ReadFile | |
| 42 | |
| 43 | |
| 44 def CheckChangeOnUpload(input_api, output_api): | 40 def CheckChangeOnUpload(input_api, output_api): |
| 45 # TODO(maruel): max_cols is temporarily disabled. Reenable once the source | 41 # TODO(maruel): max_cols is temporarily disabled. Reenable once the source |
| 46 # tree is in better shape. | 42 # tree is in better shape. |
| 47 return LocalChecks(input_api, output_api, max_cols=0) | 43 return LocalChecks(input_api, output_api, max_cols=0) |
| 48 | 44 |
| 49 | 45 |
| 50 def CheckChangeOnCommit(input_api, output_api): | 46 def CheckChangeOnCommit(input_api, output_api): |
| 51 # TODO(maruel): max_cols is temporarily disabled. Reenable once the source | 47 # TODO(maruel): max_cols is temporarily disabled. Reenable once the source |
| 52 # tree is in better shape. | 48 # tree is in better shape. |
| 53 return (LocalChecks(input_api, output_api, max_cols=0) + | 49 return (LocalChecks(input_api, output_api, max_cols=0) + |
| (...skipping 26 matching lines...) Expand all Loading... |
| 80 found = False | 76 found = False |
| 81 for item in excluded_paths: | 77 for item in excluded_paths: |
| 82 if item.match(path): | 78 if item.match(path): |
| 83 found = True | 79 found = True |
| 84 break | 80 break |
| 85 if found: | 81 if found: |
| 86 continue | 82 continue |
| 87 | 83 |
| 88 # Need to read the file ourselves since AffectedFile.NewContents() | 84 # Need to read the file ourselves since AffectedFile.NewContents() |
| 89 # will normalize line endings. | 85 # will normalize line endings. |
| 90 contents = _ReadFile(path) | 86 contents = ReadFile(path) |
| 91 if '\r' in contents: | 87 if '\r' in contents: |
| 92 cr_files.append(path) | 88 cr_files.append(path) |
| 93 | 89 |
| 94 # Check that the file ends in one and only one newline character. | 90 # Check that the file ends in one and only one newline character. |
| 95 if len(contents) > 0 and (contents[-1:] != "\n" or contents[-2:-1] == "\n"): | 91 if len(contents) > 0 and (contents[-1:] != "\n" or contents[-2:-1] == "\n"): |
| 96 eof_files.append(path) | 92 eof_files.append(path) |
| 97 | 93 |
| 98 local_errors = [] | 94 local_errors = [] |
| 99 # Remove EOL character. | 95 # Remove EOL character. |
| 100 lines = contents.splitlines() | 96 lines = contents.splitlines() |
| (...skipping 27 matching lines...) Expand all Loading... |
| 128 | 124 |
| 129 if cr_files: | 125 if cr_files: |
| 130 results.append(output_api.PresubmitError( | 126 results.append(output_api.PresubmitError( |
| 131 'Found CR (or CRLF) line ending in these files, please use only LF:', | 127 'Found CR (or CRLF) line ending in these files, please use only LF:', |
| 132 items=cr_files)) | 128 items=cr_files)) |
| 133 if eof_files: | 129 if eof_files: |
| 134 results.append(output_api.PresubmitError( | 130 results.append(output_api.PresubmitError( |
| 135 'These files should end in one (and only one) newline character:', | 131 'These files should end in one (and only one) newline character:', |
| 136 items=eof_files)) | 132 items=eof_files)) |
| 137 return results | 133 return results |
| OLD | NEW |