| 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 """ |
| 11 | 11 |
| 12 # Files with these extensions will be considered source files. | 12 # Files with these extensions will be considered source files. |
| 13 SOURCE_FILE_EXTENSIONS = [ | 13 SOURCE_FILE_EXTENSIONS = [ |
| 14 '.c', '.cc', '.cpp', '.h', '.m', '.mm', '.py', '.mk', '.am', '.json', | 14 '.c', '.cc', '.cpp', '.h', '.m', '.mm', '.py', '.mk', '.am', '.json', |
| 15 ] | 15 ] |
| 16 EXCLUDED_PATHS = [ | 16 EXCLUDED_PATHS = [ |
| 17 r"breakpad[\\\/].*", | 17 r"breakpad[\\\/].*", |
| 18 r"chrome[\\\/]Debug[\\\/].*", | 18 r"chrome[\\\/]Debug[\\\/].*", |
| 19 r"chrome[\\\/]Release[\\\/].*", | 19 r"chrome[\\\/]Release[\\\/].*", |
| 20 r"sconsbuild[\\\/].*", | 20 r"sconsbuild[\\\/].*", |
| 21 r"xcodebuild[\\\/].*", | 21 r"xcodebuild[\\\/].*", |
| 22 r"skia[\\\/].*", | 22 r"skia[\\\/].*", |
| 23 r".*third_party[\\\/].*", | 23 r".*third_party[\\\/].*", |
| 24 r"v8[\\\/].*", | 24 r"v8[\\\/].*", |
| 25 ] | 25 ] |
| 26 | 26 |
| 27 def ReadFile(path): | |
| 28 """Given a path, returns the full contents of the file. | |
| 29 | |
| 30 Reads files in binary format. | |
| 31 """ | |
| 32 fo = open(path, 'rb') | |
| 33 try: | |
| 34 contents = fo.read() | |
| 35 finally: | |
| 36 fo.close() | |
| 37 return contents | |
| 38 | |
| 39 | 27 |
| 40 def CheckChangeOnUpload(input_api, output_api): | 28 def CheckChangeOnUpload(input_api, output_api): |
| 41 # TODO(maruel): max_cols is temporarily disabled. Reenable once the source | 29 # TODO(maruel): max_cols is temporarily disabled. Reenable once the source |
| 42 # tree is in better shape. | 30 # tree is in better shape. |
| 43 results = [] | 31 results = [] |
| 44 results.extend(LocalChecks(input_api, output_api, max_cols=0)) | 32 results.extend(LocalChecks(input_api, output_api, max_cols=0)) |
| 45 results.extend(input_api.canned_checks.CheckChangeHasBugField(input_api, | 33 results.extend(input_api.canned_checks.CheckChangeHasBugField(input_api, |
| 46 output_api)) | 34 output_api)) |
| 47 results.extend(input_api.canned_checks.CheckChangeHasTestField(input_api, | 35 results.extend(input_api.canned_checks.CheckChangeHasTestField(input_api, |
| 48 output_api)) | 36 output_api)) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 found = False | 81 found = False |
| 94 for item in excluded_paths: | 82 for item in excluded_paths: |
| 95 if item.match(path): | 83 if item.match(path): |
| 96 found = True | 84 found = True |
| 97 break | 85 break |
| 98 if found: | 86 if found: |
| 99 continue | 87 continue |
| 100 | 88 |
| 101 # Need to read the file ourselves since AffectedFile.NewContents() | 89 # Need to read the file ourselves since AffectedFile.NewContents() |
| 102 # will normalize line endings. | 90 # will normalize line endings. |
| 103 contents = ReadFile(f.AbsoluteLocalPath()) | 91 contents = input_api.ReadFile(f) |
| 104 if '\r' in contents: | 92 if '\r' in contents: |
| 105 cr_files.append(path) | 93 cr_files.append(path) |
| 106 | 94 |
| 107 # Check that the file ends in one and only one newline character. | 95 # Check that the file ends in one and only one newline character. |
| 108 if len(contents) > 0 and (contents[-1:] != "\n" or contents[-2:-1] == "\n"): | 96 if len(contents) > 0 and (contents[-1:] != "\n" or contents[-2:-1] == "\n"): |
| 109 eof_files.append(path) | 97 eof_files.append(path) |
| 110 | 98 |
| 111 local_errors = [] | 99 local_errors = [] |
| 112 # Remove end of line character. | 100 # Remove end of line character. |
| 113 lines = contents.splitlines() | 101 lines = contents.splitlines() |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 # stable enough and it seems to work fine. | 172 # stable enough and it seems to work fine. |
| 185 outputs.append(output_api.PresubmitNotifyResult( | 173 outputs.append(output_api.PresubmitNotifyResult( |
| 186 'You should try the patch first.')) | 174 'You should try the patch first.')) |
| 187 else: | 175 else: |
| 188 # Another HTTP error happened, warn the user. | 176 # Another HTTP error happened, warn the user. |
| 189 # TODO(maruel): Change to a PresubmitPromptWarning once it deemed to work | 177 # TODO(maruel): Change to a PresubmitPromptWarning once it deemed to work |
| 190 # fine. | 178 # fine. |
| 191 outputs.append(output_api.PresubmitNotifyResult( | 179 outputs.append(output_api.PresubmitNotifyResult( |
| 192 'Got %s while looking for try job status.' % str(e))) | 180 'Got %s while looking for try job status.' % str(e))) |
| 193 return outputs | 181 return outputs |
| OLD | NEW |