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..720f54c2fc30d686aefa63175fe821ae09dd0dd6 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', |
| @@ -19,6 +20,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( |
| + [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 +41,22 @@ def _GetParseErrors(input_api, output_api): |
| results = input_api.canned_checks.RunUnitTestsInDirectory( |
| input_api, output_api, '.', whitelist=[r'^PRESUBMIT_test\.py$']) |
| - for affected_file in input_api.AffectedFiles( |
| - file_filter=lambda f: f.LocalPath().endswith('.json'), |
| - include_deletes=False): |
| - filename = affected_file.AbsoluteLocalPath() |
| - contents = input_api.ReadFile(filename) |
| - parse_error = _GetJSONParseError(input_api, contents) |
| + 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 filter(lambda f: "test_presubmit" not in f.LocalPath(), |
|
Haojian Wu
2013/09/14 08:13:25
Here, please review it again.
Yoyo Zhou
2013/09/17 19:50:20
I'd prefer to not have an additional filter here,
Haojian Wu
2013/09/18 00:37:34
Done.
|
| + (input_api.AffectedFiles(file_filter=get_action, include_deletes=False))): |
| + 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 |