diff options
author | Hokein.Wu@gmail.com <Hokein.Wu@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-30 05:28:58 +0000 |
---|---|---|
committer | Hokein.Wu@gmail.com <Hokein.Wu@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-30 05:28:58 +0000 |
commit | e0eec63f26c1b5b1783670484a53e325e528b7fe (patch) | |
tree | dae65c691a9a5a52b2d9018df7e7465b94a01354 /tools/json_schema_compiler | |
parent | 79e7e602c4ac1c8031977a6725ea81b77f4abb24 (diff) | |
download | chromium_src-e0eec63f26c1b5b1783670484a53e325e528b7fe.zip chromium_src-e0eec63f26c1b5b1783670484a53e325e528b7fe.tar.gz chromium_src-e0eec63f26c1b5b1783670484a53e325e528b7fe.tar.bz2 |
Add "platforms" key in IDL schema compiler.
Add analogue to JSON "platforms" key in IDL to restrict extension APIs'
availability on different OS.
The "platforms" key format like this:
[platforms=("linux", "chromeos", "mac", "win", "chromeos_touch")]
namespace Foo { ... };
BUG=119398
TEST=manual
Review URL: https://codereview.chromium.org/38573008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231767 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler')
7 files changed, 94 insertions, 5 deletions
diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py index 44a4a55..e33f8f0 100644 --- a/tools/json_schema_compiler/idl_schema.py +++ b/tools/json_schema_compiler/idl_schema.py @@ -313,10 +313,16 @@ class Namespace(object): dictionary that the JSON schema compiler expects to see. ''' - def __init__(self, namespace_node, description, nodoc=False, internal=False): + def __init__(self, + namespace_node, + description, + nodoc=False, + internal=False, + platforms=None): self.namespace = namespace_node self.nodoc = nodoc self.internal = internal + self.platforms = platforms self.events = [] self.functions = [] self.types = [] @@ -344,7 +350,8 @@ class Namespace(object): 'types': self.types, 'functions': self.functions, 'internal': self.internal, - 'events': self.events} + 'events': self.events, + 'platforms': self.platforms} def process_interface(self, node): members = [] @@ -369,6 +376,7 @@ class IDLSchema(object): nodoc = False internal = False description = None + platforms = None for node in self.idl: if node.cls == 'Namespace': if not description: @@ -376,10 +384,11 @@ class IDLSchema(object): print('%s must have a namespace-level comment. This will ' 'appear on the API summary page.' % node.GetName()) description = '' - namespace = Namespace(node, description, nodoc, internal) + namespace = Namespace(node, description, nodoc, internal, platforms) namespaces.append(namespace.process()) nodoc = False internal = False + platforms = None elif node.cls == 'Copyright': continue elif node.cls == 'Comment': @@ -389,6 +398,8 @@ class IDLSchema(object): nodoc = bool(node.value) elif node.name == 'internal': internal = bool(node.value) + elif node.name == 'platforms': + platforms = list(node.value) else: continue else: diff --git a/tools/json_schema_compiler/idl_schema_test.py b/tools/json_schema_compiler/idl_schema_test.py index 1f5d7d67..e0c987e 100755 --- a/tools/json_schema_compiler/idl_schema_test.py +++ b/tools/json_schema_compiler/idl_schema_test.py @@ -108,6 +108,25 @@ class IdlSchemaTest(unittest.TestCase): self.assertTrue(idl_basics['internal']) self.assertFalse(idl_basics['nodoc']) + def testChromeOSPlatformsNamespace(self): + schema = idl_schema.Load('test/idl_namespace_chromeos.idl')[0] + self.assertEquals('idl_namespace_chromeos', schema['namespace']) + expected = ['chromeos'] + self.assertEquals(expected, schema['platforms']) + + def testAllPlatformsNamespace(self): + schema = idl_schema.Load('test/idl_namespace_all_platforms.idl')[0] + self.assertEquals('idl_namespace_all_platforms', schema['namespace']) + expected = ['chromeos', 'chromeos_touch', 'linux', 'mac', 'win'] + self.assertEquals(expected, schema['platforms']) + + def testNonSpecificPlatformsNamespace(self): + schema = idl_schema.Load('test/idl_namespace_non_specific_platforms.idl')[0] + self.assertEquals('idl_namespace_non_specific_platforms', + schema['namespace']) + expected = None + self.assertEquals(expected, schema['platforms']) + def testCallbackComment(self): schema = self.idl_basics self.assertEquals('A comment on a callback.', diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py index cc876df..7507ae7 100644 --- a/tools/json_schema_compiler/model.py +++ b/tools/json_schema_compiler/model.py @@ -486,8 +486,11 @@ class Platforms(object): WIN = _PlatformInfo("win") def _GetPlatforms(json): - if 'platforms' not in json: + if 'platforms' not in json or json['platforms'] == None: return None + # Sanity check: platforms should not be an empty list. + if not json['platforms']: + raise ValueError('"platforms" cannot be an empty list') platforms = [] for platform_name in json['platforms']: for platform_enum in _Enum.GetAll(Platforms): diff --git a/tools/json_schema_compiler/model_test.py b/tools/json_schema_compiler/model_test.py index bdd2009..0e398a5 100755 --- a/tools/json_schema_compiler/model_test.py +++ b/tools/json_schema_compiler/model_test.py @@ -4,6 +4,8 @@ # found in the LICENSE file. from json_schema import CachedLoad +from idl_schema import Load +from model import Platforms import model import unittest @@ -22,9 +24,25 @@ class ModelTest(unittest.TestCase): self.model.AddNamespace(self.tabs_json[0], 'path/to/tabs.json') self.tabs = self.model.namespaces.get('tabs') + self.idl_chromeos = Load('test/idl_namespace_chromeos.idl') + self.model.AddNamespace(self.idl_chromeos[0], + 'path/to/idl_namespace_chromeos.idl') + self.idl_namespace_chromeos = self.model.namespaces.get( + 'idl_namespace_chromeos') + self.idl_all_platforms = Load('test/idl_namespace_all_platforms.idl') + self.model.AddNamespace(self.idl_all_platforms[0], + 'path/to/idl_namespace_all_platforms.idl') + self.idl_namespace_all_platforms = self.model.namespaces.get( + 'idl_namespace_all_platforms') + self.idl_non_specific_platforms = Load( + 'test/idl_namespace_non_specific_platforms.idl') + self.model.AddNamespace(self.idl_non_specific_platforms[0], + 'path/to/idl_namespace_non_specific_platforms.idl') + self.idl_namespace_non_specific_platforms = self.model.namespaces.get( + 'idl_namespace_non_specific_platforms') def testNamespaces(self): - self.assertEquals(3, len(self.model.namespaces)) + self.assertEquals(6, len(self.model.namespaces)) self.assertTrue(self.permissions) def testHasFunctions(self): @@ -100,6 +118,15 @@ class ModelTest(unittest.TestCase): for name in expectations: self.assertEquals(expectations[name], model.UnixName(name)) + def testPlatforms(self): + self.assertEqual([Platforms.CHROMEOS], + self.idl_namespace_chromeos.platforms) + self.assertEqual( + [Platforms.CHROMEOS, Platforms.CHROMEOS_TOUCH, Platforms.LINUX, + Platforms.MAC, Platforms.WIN], + self.idl_namespace_all_platforms.platforms) + self.assertEqual(None, + self.idl_namespace_non_specific_platforms.platforms) if __name__ == '__main__': unittest.main() diff --git a/tools/json_schema_compiler/test/idl_namespace_all_platforms.idl b/tools/json_schema_compiler/test/idl_namespace_all_platforms.idl new file mode 100644 index 0000000..7ffd84a --- /dev/null +++ b/tools/json_schema_compiler/test/idl_namespace_all_platforms.idl @@ -0,0 +1,10 @@ +// Copyright 2013 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. + +// Tests a variety of basic API definition features. + +[platforms=("chromeos", "chromeos_touch", "linux", "mac", "win")] +namespace idl_namespace_all_platforms { + +}; diff --git a/tools/json_schema_compiler/test/idl_namespace_chromeos.idl b/tools/json_schema_compiler/test/idl_namespace_chromeos.idl new file mode 100644 index 0000000..ad748ff --- /dev/null +++ b/tools/json_schema_compiler/test/idl_namespace_chromeos.idl @@ -0,0 +1,10 @@ +// Copyright 2013 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. + +// Tests the case of a namespace with chromeos platforms. + +[platforms=("chromeos")] +namespace idl_namespace_chromeos { + +}; diff --git a/tools/json_schema_compiler/test/idl_namespace_non_specific_platforms.idl b/tools/json_schema_compiler/test/idl_namespace_non_specific_platforms.idl new file mode 100644 index 0000000..cff64f8 --- /dev/null +++ b/tools/json_schema_compiler/test/idl_namespace_non_specific_platforms.idl @@ -0,0 +1,9 @@ +// Copyright 2013 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. + +// Tests the case of a namespace with non specific platforms. + +namespace idl_namespace_non_specific_platforms { + +}; |