| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 """Generic presubmit checks that can be reused by other presubmit checks.""" | 5 """Generic presubmit checks that can be reused by other presubmit checks.""" |
| 6 | 6 |
| 7 | 7 |
| 8 ### Description checks | 8 ### Description checks |
| 9 | 9 |
| 10 def CheckChangeHasTestField(input_api, output_api): | 10 def CheckChangeHasTestField(input_api, output_api): |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 if input_api.change.scm != 'svn': | 146 if input_api.change.scm != 'svn': |
| 147 return [] | 147 return [] |
| 148 | 148 |
| 149 errors = [] | 149 errors = [] |
| 150 current_cl_files = input_api.change.GetModifiedFiles() | 150 current_cl_files = input_api.change.GetModifiedFiles() |
| 151 all_modified_files = input_api.change.GetAllModifiedFiles() | 151 all_modified_files = input_api.change.GetAllModifiedFiles() |
| 152 # Filter out files in the current CL. | 152 # Filter out files in the current CL. |
| 153 modified_files = [f for f in all_modified_files if f not in current_cl_files] | 153 modified_files = [f for f in all_modified_files if f not in current_cl_files] |
| 154 modified_abspaths = [input_api.os_path.abspath(f) for f in modified_files] | 154 modified_abspaths = [input_api.os_path.abspath(f) for f in modified_files] |
| 155 | 155 |
| 156 for f in input_api.AffectedFiles(source_file_filter): | 156 for f in input_api.AffectedFiles(file_filter=source_file_filter): |
| 157 if f.Action() == 'M' and f.IsDirectory(): | 157 if f.Action() == 'M' and f.IsDirectory(): |
| 158 curpath = f.AbsoluteLocalPath() | 158 curpath = f.AbsoluteLocalPath() |
| 159 bad_files = [] | 159 bad_files = [] |
| 160 # Check if any of the modified files in other CLs are under curpath. | 160 # Check if any of the modified files in other CLs are under curpath. |
| 161 for i in xrange(len(modified_files)): | 161 for i in xrange(len(modified_files)): |
| 162 abspath = modified_abspaths[i] | 162 abspath = modified_abspaths[i] |
| 163 if input_api.os_path.commonprefix([curpath, abspath]) == curpath: | 163 if input_api.os_path.commonprefix([curpath, abspath]) == curpath: |
| 164 bad_files.append(modified_files[i]) | 164 bad_files.append(modified_files[i]) |
| 165 if bad_files: | 165 if bad_files: |
| 166 if input_api.is_committing: | 166 if input_api.is_committing: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 if the rule is satisfied and False if there was a problem. | 229 if the rule is satisfied and False if there was a problem. |
| 230 input_api: object to enumerate the affected files. | 230 input_api: object to enumerate the affected files. |
| 231 source_file_filter: a filter to be passed to the input api. | 231 source_file_filter: a filter to be passed to the input api. |
| 232 error_formatter: a callable taking (filename, line_number, line) and | 232 error_formatter: a callable taking (filename, line_number, line) and |
| 233 returning a formatted error string. | 233 returning a formatted error string. |
| 234 | 234 |
| 235 Returns: | 235 Returns: |
| 236 A list of the newly-introduced violations reported by the rule. | 236 A list of the newly-introduced violations reported by the rule. |
| 237 """ | 237 """ |
| 238 errors = [] | 238 errors = [] |
| 239 for f in input_api.AffectedFiles(source_file_filter, include_deletes=False): | 239 for f in input_api.AffectedFiles(include_deletes=False, |
| 240 file_filter=source_file_filter): |
| 240 # For speed, we do two passes, checking first the full file. Shelling out | 241 # For speed, we do two passes, checking first the full file. Shelling out |
| 241 # to the SCM to determine the changed region can be quite expensive on | 242 # to the SCM to determine the changed region can be quite expensive on |
| 242 # Win32. Assuming that most files will be kept problem-free, we can | 243 # Win32. Assuming that most files will be kept problem-free, we can |
| 243 # skip the SCM operations most of the time. | 244 # skip the SCM operations most of the time. |
| 244 if all(callable_rule(line) for line in f.NewContents()): | 245 if all(callable_rule(line) for line in f.NewContents()): |
| 245 continue # No violation found in full text: can skip considering diff. | 246 continue # No violation found in full text: can skip considering diff. |
| 246 | 247 |
| 247 for line_num, line in f.ChangedContents(): | 248 for line_num, line in f.ChangedContents(): |
| 248 if not callable_rule(line): | 249 if not callable_rule(line): |
| 249 errors.append(error_formatter(f.LocalPath(), line_num, line)) | 250 errors.append(error_formatter(f.LocalPath(), line_num, line)) |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 return [] | 727 return [] |
| 727 if input_api.tbr: | 728 if input_api.tbr: |
| 728 return [output_api.PresubmitNotifyResult( | 729 return [output_api.PresubmitNotifyResult( |
| 729 '--tbr was specified, skipping OWNERS check')] | 730 '--tbr was specified, skipping OWNERS check')] |
| 730 if not input_api.change.issue: | 731 if not input_api.change.issue: |
| 731 return [output_api.PresubmitError( | 732 return [output_api.PresubmitError( |
| 732 "OWNERS check failed: this change has no Rietveld issue number, so " | 733 "OWNERS check failed: this change has no Rietveld issue number, so " |
| 733 "we can't check it for approvals.")] | 734 "we can't check it for approvals.")] |
| 734 | 735 |
| 735 affected_files = set([f.LocalPath() for f in | 736 affected_files = set([f.LocalPath() for f in |
| 736 input_api.change.AffectedFiles(source_file_filter)]) | 737 input_api.change.AffectedFiles(file_filter=source_file_filter)]) |
| 737 | 738 |
| 738 owners_db = input_api.owners_db | 739 owners_db = input_api.owners_db |
| 739 owner_email, approvers = _RietveldOwnerAndApprovers(input_api, | 740 owner_email, approvers = _RietveldOwnerAndApprovers(input_api, |
| 740 owners_db.email_regexp) | 741 owners_db.email_regexp) |
| 741 approvers_plus_owner = approvers.union(set([owner_email])) | 742 approvers_plus_owner = approvers.union(set([owner_email])) |
| 742 | 743 |
| 743 missing_files = owners_db.files_not_covered_by(affected_files, | 744 missing_files = owners_db.files_not_covered_by(affected_files, |
| 744 approvers_plus_owner) | 745 approvers_plus_owner) |
| 745 if missing_files: | 746 if missing_files: |
| 746 return [output_api.PresubmitError('Missing LGTM from an OWNER for: %s' % | 747 return [output_api.PresubmitError('Missing LGTM from an OWNER for: %s' % |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 # auto-fix most of these. | 951 # auto-fix most of these. |
| 951 if input_api.is_committing: | 952 if input_api.is_committing: |
| 952 snapshot("checking svn mime types") | 953 snapshot("checking svn mime types") |
| 953 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( | 954 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( |
| 954 input_api, output_api)) | 955 input_api, output_api)) |
| 955 snapshot("checking license") | 956 snapshot("checking license") |
| 956 results.extend(input_api.canned_checks.CheckLicense( | 957 results.extend(input_api.canned_checks.CheckLicense( |
| 957 input_api, output_api, license_header, source_file_filter=sources)) | 958 input_api, output_api, license_header, source_file_filter=sources)) |
| 958 snapshot("done") | 959 snapshot("done") |
| 959 return results | 960 return results |
| OLD | NEW |