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

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: 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..f8a20afd729fb8fedb704a9c7257ea7006e0eabd 100644
--- a/chrome/common/extensions/api/PRESUBMIT.py
+++ b/chrome/common/extensions/api/PRESUBMIT.py
@@ -2,8 +2,12 @@
# 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):
+import os
M-A Ruel 2013/09/11 13:37:59 Not necessary
Haojian Wu 2013/09/11 14:48:57 Done.
+
+
+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 +23,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 +44,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
+ }
+
+ def get_action(affected_file):
+ filename = affected_file.AbsoluteLocalPath()
M-A Ruel 2013/09/11 13:37:59 FYI, (optional) filename = affected_file.LocalPath
Haojian Wu 2013/09/11 14:48:57 Done.
+ return actions.get(os.path.splitext(filename)[1])
M-A Ruel 2013/09/11 13:37:59 input_api.os_path.splitext()
Haojian Wu 2013/09/11 14:48:57 Done.
+
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.AbsoluteLocalPath())
if parse_error:
- results.append(output_api.PresubmitError(
- 'Features file %s could not be parsed: %s' %
- (affected_file.LocalPath(), parse_error)))
- # TODO(yoz): Also ensure IDL files are parseable.
+ results.append(output_api.PresubmitError('%s could not be parsed: %s' %
+ (affected_file.LocalPath(), parse_error)))
M-A Ruel 2013/09/11 13:37:59 weird alignment
Haojian Wu 2013/09/11 14:48:57 Done.
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