Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4832)

Unified Diff: chrome/common/extensions/api/PRESUBMIT.py

Issue 23512007: Prase IDL files in common/extensions/api PRESUBMIT check. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/common/extensions/api/PRESUBMIT_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..910cf27a3e82493c8af277e76ffc32bcbb2a0bcd 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,23 @@ def _GetParseErrors(input_api, output_api):
results = input_api.canned_checks.RunUnitTestsInDirectory(
input_api, output_api, '.', whitelist=[r'^PRESUBMIT_test\.py$'])
+ actions = {
+ '.json': _GetJSONParseError,
+ '.idl': _GetIDLParseError
M-A Ruel 2013/09/11 14:54:51 add a coma, and sort the keys.
Haojian Wu 2013/09/11 15:20:05 Done.
+ }
+
+ 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=get_action,
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.LocalPath())
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
« no previous file with comments | « no previous file | chrome/common/extensions/api/PRESUBMIT_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698