Commit 0b5ae24b authored by Hokein.Wu@gmail.com's avatar Hokein.Wu@gmail.com

Add "implemented_in" key in IDL schema compiler

The "implemented_in" key format like this:
  [implemented_in="path/to/implemented_file"]
  namespace Foo {...};

BUG=313579
TEST=pass idl_schema_test

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233442 0039d316-1c4b-4281-b951-d872f2087c98
parent 9b07c98d
...@@ -324,11 +324,13 @@ class Namespace(object): ...@@ -324,11 +324,13 @@ class Namespace(object):
description, description,
nodoc=False, nodoc=False,
internal=False, internal=False,
platforms=None): platforms=None,
compiler_options=None):
self.namespace = namespace_node self.namespace = namespace_node
self.nodoc = nodoc self.nodoc = nodoc
self.internal = internal self.internal = internal
self.platforms = platforms self.platforms = platforms
self.compiler_options = compiler_options
self.events = [] self.events = []
self.functions = [] self.functions = []
self.types = [] self.types = []
...@@ -350,6 +352,10 @@ class Namespace(object): ...@@ -350,6 +352,10 @@ class Namespace(object):
self.types.append(Enum(node).process(self.callbacks)) self.types.append(Enum(node).process(self.callbacks))
else: else:
sys.exit('Did not process %s %s' % (node.cls, node)) sys.exit('Did not process %s %s' % (node.cls, node))
if self.compiler_options is not None:
compiler_options = self.compiler_options
else:
compiler_options = {}
return {'namespace': self.namespace.GetName(), return {'namespace': self.namespace.GetName(),
'description': self.description, 'description': self.description,
'nodoc': self.nodoc, 'nodoc': self.nodoc,
...@@ -357,7 +363,8 @@ class Namespace(object): ...@@ -357,7 +363,8 @@ class Namespace(object):
'functions': self.functions, 'functions': self.functions,
'internal': self.internal, 'internal': self.internal,
'events': self.events, 'events': self.events,
'platforms': self.platforms} 'platforms': self.platforms,
'compiler_options': compiler_options}
def process_interface(self, node): def process_interface(self, node):
members = [] members = []
...@@ -383,6 +390,7 @@ class IDLSchema(object): ...@@ -383,6 +390,7 @@ class IDLSchema(object):
internal = False internal = False
description = None description = None
platforms = None platforms = None
compiler_options = None
for node in self.idl: for node in self.idl:
if node.cls == 'Namespace': if node.cls == 'Namespace':
if not description: if not description:
...@@ -390,11 +398,14 @@ class IDLSchema(object): ...@@ -390,11 +398,14 @@ class IDLSchema(object):
print('%s must have a namespace-level comment. This will ' print('%s must have a namespace-level comment. This will '
'appear on the API summary page.' % node.GetName()) 'appear on the API summary page.' % node.GetName())
description = '' description = ''
namespace = Namespace(node, description, nodoc, internal, platforms) namespace = Namespace(node, description, nodoc, internal,
platforms=platforms,
compiler_options=compiler_options)
namespaces.append(namespace.process()) namespaces.append(namespace.process())
nodoc = False nodoc = False
internal = False internal = False
platforms = None platforms = None
compiler_options = None
elif node.cls == 'Copyright': elif node.cls == 'Copyright':
continue continue
elif node.cls == 'Comment': elif node.cls == 'Comment':
...@@ -406,6 +417,8 @@ class IDLSchema(object): ...@@ -406,6 +417,8 @@ class IDLSchema(object):
internal = bool(node.value) internal = bool(node.value)
elif node.name == 'platforms': elif node.name == 'platforms':
platforms = list(node.value) platforms = list(node.value)
elif node.name == 'implemented_in':
compiler_options = {'implemented_in': node.value}
else: else:
continue continue
else: else:
......
...@@ -129,6 +129,24 @@ class IdlSchemaTest(unittest.TestCase): ...@@ -129,6 +129,24 @@ class IdlSchemaTest(unittest.TestCase):
expected = None expected = None
self.assertEquals(expected, schema['platforms']) self.assertEquals(expected, schema['platforms'])
def testSpecificImplementNamespace(self):
schema = idl_schema.Load('test/idl_namespace_specific_implement.idl')[0]
self.assertEquals('idl_namespace_specific_implement',
schema['namespace'])
expected = 'idl_namespace_specific_implement.idl'
self.assertEquals(expected, schema['compiler_options']['implemented_in'])
def testSpecificImplementOnChromeOSNamespace(self):
schema = idl_schema.Load(
'test/idl_namespace_specific_implement_chromeos.idl')[0]
self.assertEquals('idl_namespace_specific_implement_chromeos',
schema['namespace'])
expected_implemented_path = 'idl_namespace_specific_implement_chromeos.idl'
expected_platform = ['chromeos']
self.assertEquals(expected_implemented_path,
schema['compiler_options']['implemented_in'])
self.assertEquals(expected_platform, schema['platforms'])
def testCallbackComment(self): def testCallbackComment(self):
schema = self.idl_basics schema = self.idl_basics
self.assertEquals('A comment on a callback.', self.assertEquals('A comment on a callback.',
......
// 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 specific implemented file.
[implemented_in="idl_namespace_specific_implement.idl"]
namespace idl_namespace_specific_implement {
};
// 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 specific implemented file on chromeos.
[platforms=("chromeos"),
implemented_in="idl_namespace_specific_implement_chromeos.idl"]
namespace idl_namespace_specific_implement_chromeos {
};
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