| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 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 def _GetJSONParseError(input_api, contents): | 5 def _GetJSONParseError(input_api, contents): |
| 6 try: | 6 try: |
| 7 json_comment_eater = input_api.os_path.join( | 7 json_comment_eater = input_api.os_path.join( |
| 8 input_api.PresubmitLocalPath(), | 8 input_api.PresubmitLocalPath(), |
| 9 '..', '..', '..', '..', 'tools', | 9 '..', '..', '..', '..', 'tools', |
| 10 'json_comment_eater', 'json_comment_eater.py') | 10 'json_comment_eater', 'json_comment_eater.py') |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 def _GetParseErrors(input_api, output_api): | 22 def _GetParseErrors(input_api, output_api): |
| 23 # Run unit tests. | 23 # Run unit tests. |
| 24 results = [] | 24 results = [] |
| 25 if input_api.AffectedFiles( | 25 if input_api.AffectedFiles( |
| 26 file_filter=lambda f: 'PRESUBMIT' in f.LocalPath()): | 26 file_filter=lambda f: 'PRESUBMIT' in f.LocalPath()): |
| 27 results = input_api.canned_checks.RunUnitTestsInDirectory( | 27 results = input_api.canned_checks.RunUnitTestsInDirectory( |
| 28 input_api, output_api, '.', whitelist=[r'^PRESUBMIT_test\.py$']) | 28 input_api, output_api, '.', whitelist=[r'^PRESUBMIT_test\.py$']) |
| 29 | 29 |
| 30 for affected_file in input_api.AffectedFiles( | 30 for affected_file in input_api.AffectedFiles( |
| 31 file_filter=lambda f: f.LocalPath().endswith('.json')): | 31 file_filter=lambda f: f.LocalPath().endswith('.json'), |
| 32 include_deletes=False): |
| 32 filename = affected_file.AbsoluteLocalPath() | 33 filename = affected_file.AbsoluteLocalPath() |
| 33 contents = input_api.ReadFile(filename) | 34 contents = input_api.ReadFile(filename) |
| 34 parse_error = _GetJSONParseError(input_api, contents) | 35 parse_error = _GetJSONParseError(input_api, contents) |
| 35 if parse_error: | 36 if parse_error: |
| 36 results.append(output_api.PresubmitError( | 37 results.append(output_api.PresubmitError( |
| 37 'Features file %s could not be parsed: %s' % | 38 'Features file %s could not be parsed: %s' % |
| 38 (affected_file.LocalPath(), parse_error))) | 39 (affected_file.LocalPath(), parse_error))) |
| 39 # TODO(yoz): Also ensure IDL files are parseable. | 40 # TODO(yoz): Also ensure IDL files are parseable. |
| 40 return results | 41 return results |
| 41 | 42 |
| 42 | 43 |
| 43 def CheckChangeOnUpload(input_api, output_api): | 44 def CheckChangeOnUpload(input_api, output_api): |
| 44 return _GetParseErrors(input_api, output_api) | 45 return _GetParseErrors(input_api, output_api) |
| 45 | 46 |
| 46 | 47 |
| 47 def CheckChangeOnCommit(input_api, output_api): | 48 def CheckChangeOnCommit(input_api, output_api): |
| 48 return _GetParseErrors(input_api, output_api) | 49 return _GetParseErrors(input_api, output_api) |
| OLD | NEW |