diff options
-rw-r--r-- | chrome/common/extensions/api/PRESUBMIT.py | 51 | ||||
-rw-r--r-- | extensions/common/api/externs_checker.py | 4 | ||||
-rwxr-xr-x | extensions/common/api/externs_checker_test.py | 9 |
3 files changed, 63 insertions, 1 deletions
diff --git a/chrome/common/extensions/api/PRESUBMIT.py b/chrome/common/extensions/api/PRESUBMIT.py new file mode 100644 index 0000000..c4dc1aa --- /dev/null +++ b/chrome/common/extensions/api/PRESUBMIT.py @@ -0,0 +1,51 @@ +# 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) diff --git a/extensions/common/api/externs_checker.py b/extensions/common/api/externs_checker.py index 58c0076..fd60fdd 100644 --- a/extensions/common/api/externs_checker.py +++ b/extensions/common/api/externs_checker.py @@ -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()] diff --git a/extensions/common/api/externs_checker_test.py b/extensions/common/api/externs_checker_test.py index 73b65fa..9bcc651 100755 --- a/extensions/common/api/externs_checker_test.py +++ b/extensions/common/api/externs_checker_test.py @@ -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() |