Commit 2714fec9 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Support typemaps inlined as GN targets

This introduces support for typemaps specified as GN targets, with new
cpp_typemaps and blink_cpp_typemaps variables that mojom() targets can
used to reference their typemap rules.

The underlying work to use the typemap configuration is shared with the
existing typemap infrastructure, but the net result is that we no longer
need separate .typemap files or global "bindings configurations" once
everything is converted to this approach.

Bug: 1059389
Change-Id: Id2e5fe765d3c7600a3f50e337fb693f1b3a3cc0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090716
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747990}
parent 8aea30e0
This diff is collapsed.
...@@ -81,6 +81,36 @@ def ParseTypemapArgs(args): ...@@ -81,6 +81,36 @@ def ParseTypemapArgs(args):
return result return result
def LoadCppTypemapConfigs(paths):
_SUPPORTED_KEYS = set([
'mojom', 'cpp', 'public_headers', 'copyable_pass_by_value',
'force_serialize', 'hashable', 'move_only', 'nullable_is_same_type'
])
configs = {}
for path in paths:
with open(path) as f:
config = json.load(f)
for entry in config['types']:
for key in entry.iterkeys():
if key not in _SUPPORTED_KEYS:
raise IOError('Invalid typemap property "%s" when processing %s' %
(key, path))
configs[entry['mojom']] = {
'typename': entry['cpp'],
'public_headers': config.get('public_headers', []),
'copyable_pass_by_value': entry.get('copyable_pass_by_value',
False),
'force_serialize': entry.get('force_serialize', False),
'hashable': entry.get('hashable', False),
'move_only': entry.get('move_only', False),
'nullable_is_same_type': entry.get('nullable_is_same_type', False),
'non_copyable_non_movable': False,
}
return configs
def ParseTypemap(typemap): def ParseTypemap(typemap):
values = {'type_mappings': [], 'public_headers': [], 'traits_headers': []} values = {'type_mappings': [], 'public_headers': [], 'traits_headers': []}
for line in typemap.split('\n'): for line in typemap.split('\n'):
...@@ -137,12 +167,21 @@ def main(): ...@@ -137,12 +167,21 @@ def main():
default=[], default=[],
help=('A path to another JSON typemap to merge into the output. ' help=('A path to another JSON typemap to merge into the output. '
'This may be repeated to merge multiple typemaps.')) 'This may be repeated to merge multiple typemaps.'))
parser.add_argument(
'--cpp-typemap-config',
type=str,
action='append',
default=[],
dest='cpp_config_paths',
help=('A path to a single JSON-formatted typemap config as emitted by'
'GN when processing a mojom_cpp_typemap build rule.'))
parser.add_argument('--output', parser.add_argument('--output',
type=str, type=str,
required=True, required=True,
help='The path to which to write the generated JSON.') help='The path to which to write the generated JSON.')
params, typemap_params = parser.parse_known_args() params, typemap_params = parser.parse_known_args()
typemaps = ParseTypemapArgs(typemap_params) typemaps = ParseTypemapArgs(typemap_params)
typemaps.update(LoadCppTypemapConfigs(params.cpp_config_paths))
missing = [path for path in params.dependency if not os.path.exists(path)] missing = [path for path in params.dependency if not os.path.exists(path)]
if missing: if missing:
raise IOError('Missing dependencies: %s' % ', '.join(missing)) raise IOError('Missing dependencies: %s' % ', '.join(missing))
......
This diff is collapsed.
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