Chromium Code Reviews| Index: chrome/common/extensions/api/PRESUBMIT.py |
| diff --git a/chrome/common/extensions/api/PRESUBMIT.py b/chrome/common/extensions/api/PRESUBMIT.py |
| index 20d61fa8b06500277977202a5593842e12b8dd97..bb27887f80677f4367c9fa981ef80d6da5b40c42 100644 |
| --- a/chrome/common/extensions/api/PRESUBMIT.py |
| +++ b/chrome/common/extensions/api/PRESUBMIT.py |
| @@ -2,8 +2,9 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| -def _GetJSONParseError(input_api, contents): |
| +def _GetJSONParseError(input_api, filename): |
| try: |
| + contents = input_api.ReadFile(filename) |
| json_comment_eater = input_api.os_path.join( |
| input_api.PresubmitLocalPath(), |
| '..', '..', '..', '..', 'tools', |
| @@ -11,7 +12,8 @@ def _GetJSONParseError(input_api, contents): |
| process = input_api.subprocess.Popen( |
| [input_api.python_executable, json_comment_eater], |
| stdin=input_api.subprocess.PIPE, |
| - stdout=input_api.subprocess.PIPE) |
| + stdout=input_api.subprocess.PIPE, |
| + universal_newlines=True) |
| (nommed, _) = process.communicate(input=contents) |
| input_api.json.loads(nommed) |
| except ValueError as e: |
| @@ -19,6 +21,19 @@ def _GetJSONParseError(input_api, contents): |
| return None |
| +def _GetIDLParseError(input_api, filename): |
| + idl_schema = input_api.os_path.join( |
| + input_api.PresubmitLocalPath(), |
| + '..', '..', '..', '..', 'tools', |
| + 'json_schema_compiler', 'idl_schema.py') |
| + process = input_api.subprocess.Popen( |
|
Yoyo Zhou
2013/09/22 18:17:22
Do we need universal_newlines here too?
Haojian Wu
2013/09/23 04:21:43
Done.
|
| + [input_api.python_executable, idl_schema, filename], |
| + stdout=input_api.subprocess.PIPE, |
| + stderr=input_api.subprocess.PIPE) |
| + (_, error) = process.communicate() |
| + return error or None |
| + |
| + |
| def _GetParseErrors(input_api, output_api): |
| # Run unit tests. |
| results = [] |
| @@ -27,17 +42,24 @@ def _GetParseErrors(input_api, output_api): |
| results = input_api.canned_checks.RunUnitTestsInDirectory( |
| input_api, output_api, '.', whitelist=[r'^PRESUBMIT_test\.py$']) |
| + actions = { |
| + '.idl': _GetIDLParseError, |
| + '.json': _GetJSONParseError, |
| + } |
| + |
| + def get_action(affected_file): |
| + filename = affected_file.LocalPath() |
| + return actions.get(input_api.os_path.splitext(filename)[1]) |
| + |
| for affected_file in input_api.AffectedFiles( |
| - file_filter=lambda f: f.LocalPath().endswith('.json'), |
| + file_filter= |
| + lambda f: "test_presubmit" not in f.LocalPath() and get_action(f), |
| include_deletes=False): |
| - filename = affected_file.AbsoluteLocalPath() |
| - contents = input_api.ReadFile(filename) |
| - parse_error = _GetJSONParseError(input_api, contents) |
| + parse_error = get_action(affected_file)(input_api, |
| + affected_file.AbsoluteLocalPath()) |
| if parse_error: |
| - results.append(output_api.PresubmitError( |
| - 'Features file %s could not be parsed: %s' % |
| + results.append(output_api.PresubmitError('%s could not be parsed: %s' % |
| (affected_file.LocalPath(), parse_error))) |
| - # TODO(yoz): Also ensure IDL files are parseable. |
| return results |