| 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..46bbd977c1e988c18d20fafe0e600115794190cd 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,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
|
|
|
|
|
|
|