Commit 61601922 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Remove .typemap file support

All typemap files have been converted to inlined GN target
configuration. This removes all support for aggregating .typemap files
at buildgen time and any associated build logic needed to process those
files.

Fixed: 1059389
Change-Id: Iabf8b8680d3bd9c9e310830c36a01c1c8ca5c389
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2408274
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807277}
parent ce94b50c
# 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.
_typemap_imports = []
_typemaps = []
foreach(typemap_import, _typemap_imports) {
# Avoid reassignment error by assigning to empty scope first.
_imported = {
}
_imported = read_file(typemap_import, "scope")
_typemaps += _imported.typemaps
}
typemaps = []
foreach(typemap, _typemaps) {
typemaps += [
{
filename = typemap
config = read_file(typemap, "scope")
},
]
}
component_macro_suffix = ""
#!/usr/bin/env python
# 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.
from __future__ import print_function
import sys
# This utility converts mojom dependencies into their corresponding typemap
# paths and formats them to be consumed by generate_type_mappings.py.
def FormatTypemap(typemap_filename):
# A simple typemap is valid Python with a minor alteration.
with open(typemap_filename) as f:
typemap_content = f.read().replace('=\n', '=')
typemap = {}
exec typemap_content in typemap
for header in typemap.get('public_headers', []):
yield 'public_headers=%s' % header
for header in typemap.get('traits_headers', []):
yield 'traits_headers=%s' % header
for header in typemap.get('type_mappings', []):
yield 'type_mappings=%s' % header
def main():
typemaps = sys.argv[1:]
print(' '.join('--start-typemap %s' % ' '.join(FormatTypemap(typemap))
for typemap in typemaps))
if __name__ == '__main__':
sys.exit(main())
......@@ -75,14 +75,6 @@ def ReadTypemap(path):
return json.load(f)['c++']
def ParseTypemapArgs(args):
typemaps = [s for s in '\n'.join(args).split('--start-typemap\n') if s]
result = {}
for typemap in typemaps:
result.update(ParseTypemap(typemap))
return result
def LoadCppTypemapConfig(path):
configs = {}
with open(path) as f:
......@@ -102,52 +94,6 @@ def LoadCppTypemapConfig(path):
}
return configs
def ParseTypemap(typemap):
values = {'type_mappings': [], 'public_headers': [], 'traits_headers': []}
for line in typemap.split('\n'):
if not line:
continue
key, _, value = line.partition('=')
values[key].append(value.lstrip('/'))
result = {}
mapping_pattern = \
re.compile(r"""^([^=]+) # mojom type
=
([^[]+) # native type
(?:\[([^]]+)\])?$ # optional attribute in square brackets
""", re.X)
for typename in values['type_mappings']:
match_result = mapping_pattern.match(typename)
assert match_result, (
"Cannot parse entry in the \"type_mappings\" section: %s" % typename)
mojom_type = match_result.group(1)
native_type = match_result.group(2)
attributes = []
if match_result.group(3):
attributes = match_result.group(3).split(',')
assert mojom_type not in result, (
"Cannot map multiple native types (%s, %s) to the same mojom type: %s" %
(result[mojom_type]['typename'], native_type, mojom_type))
result[mojom_type] = {
'public_headers': values['public_headers'],
'traits_headers': values['traits_headers'],
'typename': native_type,
# Attributes supported for individual mappings.
'copyable_pass_by_value': 'copyable_pass_by_value' in attributes,
'force_serialize': 'force_serialize' in attributes,
'hashable': 'hashable' in attributes,
'move_only': 'move_only' in attributes,
'non_copyable_non_movable': 'non_copyable_non_movable' in attributes,
'nullable_is_same_type': 'nullable_is_same_type' in attributes,
}
return result
def main():
parser = argparse.ArgumentParser(
description=__doc__,
......@@ -170,10 +116,10 @@ def main():
type=str,
required=True,
help='The path to which to write the generated JSON.')
params, typemap_params = parser.parse_known_args()
typemaps = ParseTypemapArgs(typemap_params)
params, _ = parser.parse_known_args()
typemaps = {}
if params.cpp_config_path:
typemaps.update(LoadCppTypemapConfig(params.cpp_config_path))
typemaps = LoadCppTypemapConfig(params.cpp_config_path)
missing = [path for path in params.dependency if not os.path.exists(path)]
if missing:
raise IOError('Missing dependencies: %s' % ', '.join(missing))
......
......@@ -140,43 +140,6 @@ if (enable_scrambled_message_ids) {
message_scrambling_inputs = []
}
if (enable_mojom_typemapping) {
_bindings_configuration_files =
[ "//mojo/public/tools/bindings/chromium_bindings_configuration.gni" ]
_bindings_configurations = []
foreach(config_file, _bindings_configuration_files) {
_bindings_configurations += [ read_file(config_file, "scope") ]
}
foreach(configuration, _bindings_configurations) {
# Check that the mojom field of each typemap refers to a mojom that exists.
foreach(typemap, configuration.typemaps) {
_typemap_config = {
}
_typemap_config = typemap.config
read_file(_typemap_config.mojom, "")
}
}
} else {
_bindings_configuration_files = []
_bindings_configurations = [
{
typemaps = []
component_macro_suffix = ""
},
]
}
if (!is_ios) {
_bindings_configurations += [
{
variant = "blink"
component_macro_suffix = "_BLINK"
for_blink = true
typemaps = []
},
]
}
# Generates targets for building C++, JavaScript and Java bindings from mojom
# files. The output files will go under the generated file directory tree with
# the same path as each input file.
......@@ -995,12 +958,22 @@ template("mojom") {
}
# Generate code for variants.
if (!defined(invoker.disable_variants) || !invoker.disable_variants) {
enabled_configurations = _bindings_configurations
default_variant = {
component_macro_suffix = ""
}
if ((!defined(invoker.disable_variants) || !invoker.disable_variants) &&
!is_ios) {
blink_variant = {
variant = "blink"
component_macro_suffix = "_BLINK"
for_blink = true
}
enabled_configurations = [
default_variant,
blink_variant,
]
} else {
first_config = _bindings_configurations[0]
assert(!defined(first_config.variant))
enabled_configurations = [ first_config ]
enabled_configurations = [ default_variant ]
}
foreach(bindings_configuration, enabled_configurations) {
cpp_only = false
......@@ -1089,7 +1062,6 @@ template("mojom") {
type_mappings_target_name = "${target_name}${variant_suffix}__type_mappings"
type_mappings_path =
"$target_gen_dir/${target_name}${variant_suffix}__type_mappings"
active_typemaps = []
if (sources_list != []) {
generator_cpp_output_suffixes = []
variant_dash_suffix = ""
......@@ -1104,17 +1076,6 @@ template("mojom") {
"${variant_dash_suffix}.cc",
"${variant_dash_suffix}.h",
]
foreach(source, sources_list) {
# TODO(sammc): Use a map instead of a linear scan when GN supports maps.
foreach(typemap, bindings_configuration.typemaps) {
_typemap_config = {
}
_typemap_config = typemap.config
if (get_path_info(source, "abspath") == _typemap_config.mojom) {
active_typemaps += [ typemap ]
}
}
}
generator_target_name = "${target_name}${variant_suffix}__generator"
action(generator_target_name) {
......@@ -1260,18 +1221,6 @@ template("mojom") {
public_deps += [ "${full_name}_mojolpm" ]
}
foreach(typemap, active_typemaps) {
_typemap_config = {
}
_typemap_config = typemap.config
if (defined(_typemap_config.deps)) {
deps += _typemap_config.deps
}
if (defined(_typemap_config.public_deps)) {
public_deps += _typemap_config.public_deps
}
}
foreach(config, cpp_typemap_configs) {
if (defined(config.traits_deps)) {
deps += config.traits_deps
......@@ -1321,8 +1270,8 @@ template("mojom") {
}
action(type_mappings_target_name) {
inputs = _bindings_configuration_files + mojom_generator_sources +
jinja2_sources + [ _typemap_stamp_filename ]
inputs =
mojom_generator_sources + jinja2_sources + [ _typemap_stamp_filename ]
outputs = [ type_mappings_path ]
script = "$mojom_generator_root/generate_type_mappings.py"
deps = [ ":$_typemap_validator_target_name" ]
......@@ -1349,46 +1298,12 @@ template("mojom") {
]
}
if (sources_list != []) {
# TODO(sammc): Pass the typemap description in a file to avoid command
# line length limitations.
typemap_description = []
foreach(typemap, active_typemaps) {
_typemap_config = {
}
_typemap_config = typemap.config
typemap_description += [ "--start-typemap" ]
if (defined(_typemap_config.public_headers)) {
foreach(value, _typemap_config.public_headers) {
typemap_description += [ "public_headers=$value" ]
}
}
if (defined(_typemap_config.traits_headers)) {
foreach(value, _typemap_config.traits_headers) {
typemap_description += [ "traits_headers=$value" ]
}
}
foreach(value, _typemap_config.type_mappings) {
typemap_description += [ "type_mappings=$value" ]
}
# The typemap configuration files are not actually used as inputs here
# but this establishes a necessary build dependency to ensure that
# typemap changes force a rebuild of affected targets.
if (defined(typemap.filename)) {
inputs += [ typemap.filename ]
}
}
args += typemap_description
# Newer GN-based typemaps are aggregated into a single config.
inputs += [ _typemap_config_filename ]
args += [
"--cpp-typemap-config",
rebase_path(_typemap_config_filename, root_build_dir),
]
}
# Newer GN-based typemaps are aggregated into a single config.
inputs += [ _typemap_config_filename ]
args += [
"--cpp-typemap-config",
rebase_path(_typemap_config_filename, root_build_dir),
]
}
group("${target_name}${variant_suffix}_headers") {
......@@ -1493,20 +1408,6 @@ template("mojom") {
public_deps += invoker.component_deps
}
}
foreach(typemap, active_typemaps) {
_typemap_config = {
}
_typemap_config = typemap.config
if (defined(_typemap_config.sources)) {
sources += _typemap_config.sources
}
if (defined(_typemap_config.public_deps)) {
public_deps += _typemap_config.public_deps
}
if (defined(_typemap_config.deps)) {
deps += _typemap_config.deps
}
}
foreach(config, cpp_typemap_configs) {
if (defined(config.traits_sources)) {
sources += config.traits_sources
......
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