Commit 953fd79d authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Closure Externs] Add more APIs to the presubmit warning list

Add a bunch of private APIs to the list that will get presubmit checks. Also
normalize the paths and check that each exists.

BUG=469920

Review URL: https://codereview.chromium.org/1761663002

Cr-Commit-Position: refs/heads/master@{#380488}
parent 0958a444
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Chromium presubmit script for src/extensions/common.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details on the presubmit API built into depot_tools.
"""
import sys
def _CheckExterns(input_api, output_api):
original_sys_path = sys.path
join = input_api.os_path.join
api_root = input_api.PresubmitLocalPath()
src_root = join(api_root, '..', '..', '..', '..')
try:
sys.path.append(join(src_root, 'extensions', 'common', 'api'))
from externs_checker import ExternsChecker
finally:
sys.path = original_sys_path
externs_root = join(src_root, 'third_party', 'closure_compiler', 'externs')
api_pair_names = {
'autofill_private.idl': 'autofill_private.js',
'developer_private.idl': 'developer_private.js',
'bookmark_manager_private.json': 'bookmark_manager_private.js',
'command_line_private.json': 'command_line_private.js',
'file_manager_private.idl': 'file_manager_private.js',
'language_settings_private.idl': 'language_settings_private.js',
'metrics_private.json': 'metrics_private.js',
'passwords_private.idl': 'passwords_private.js',
'system_private.json': 'system_private.js',
'users_private.idl': 'users_private.js',
# TODO(rdevlin.cronin): Add more!
}
normpath = input_api.os_path.normpath
api_pairs = {
normpath(join(api_root, k)):
normpath(join(externs_root, v)) for k, v in api_pair_names.items()
}
return ExternsChecker(input_api, output_api, api_pairs).RunChecks()
def CheckChangeOnUpload(input_api, output_api):
return _CheckExterns(input_api, output_api)
......@@ -12,6 +12,10 @@ class ExternsChecker(object):
self._output_api = output_api
self._api_pairs = api_pairs
for path in api_pairs.keys() + api_pairs.values():
if not input_api.os_path.exists(path):
raise OSError('Path Not Found: %s' % path)
def RunChecks(self):
bad_files = []
affected = [f.AbsoluteLocalPath() for f in self._input_api.AffectedFiles()]
......
......@@ -18,8 +18,9 @@ from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockFile
class ExternsCheckerTest(unittest.TestCase):
API_PAIRS = {'a': '1', 'b': '2', 'c': '3'}
def _runChecks(self, files):
def _runChecks(self, files, exists=lambda f: True):
input_api = MockInputApi()
input_api.os_path.exists = exists
input_api.files = [MockFile(f, '') for f in files]
output_api = MockOutputApi()
checker = ExternsChecker(input_api, output_api, self.API_PAIRS)
......@@ -58,6 +59,12 @@ class ExternsCheckerTest(unittest.TestCase):
self.assertEquals(1, len(results[0].items))
self.assertEquals('c', results[0].items[0])
def testApiFileDoesNotExist(self):
exists = lambda f: f in ['a', 'b', 'c', '1', '2']
with self.assertRaises(OSError) as e:
self._runChecks(['a'], exists)
self.assertEqual('Path Not Found: 3', str(e.exception))
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment