From aef38024a1d6d99deb565a89cd7dd8b3bc21f971 Mon Sep 17 00:00:00 2001 From: yzshen Date: Fri, 18 Mar 2016 17:34:40 -0700 Subject: Mojo C++ bindings: assume that all imported mojoms have the same variant as current mojom. This CL also disable struct_traits_unittest because variant+typemap is not supported currently. BUG=596202,596162 Review URL: https://codereview.chromium.org/1816703002 Cr-Commit-Position: refs/heads/master@{#382143} --- mojo/mojo_edk_tests.gyp | 7 ++++--- mojo/mojo_public.gyp | 1 + mojo/public/cpp/bindings/tests/BUILD.gn | 9 ++++++--- mojo/public/interfaces/bindings/tests/BUILD.gn | 1 + mojo/public/interfaces/bindings/tests/blink_test.typemap | 12 ++++++------ mojo/public/interfaces/bindings/tests/chromium_test.typemap | 12 ++++++------ .../public/interfaces/bindings/tests/test_native_types.mojom | 11 ++++++----- mojo/public/interfaces/bindings/tests/test_variant.mojom | 7 +++++++ .../interfaces/bindings/tests/test_variant_import.mojom | 7 +++++++ .../bindings/generators/cpp_templates/module-internal.h.tmpl | 4 ++++ .../tools/bindings/generators/cpp_templates/module.h.tmpl | 4 ++++ .../cpp_templates/struct_serialization_declaration.tmpl | 2 +- mojo/public/tools/bindings/generators/mojom_cpp_generator.py | 6 +++++- 13 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 mojo/public/interfaces/bindings/tests/test_variant_import.mojom (limited to 'mojo') diff --git a/mojo/mojo_edk_tests.gyp b/mojo/mojo_edk_tests.gyp index e6c82c9..e7a396f 100644 --- a/mojo/mojo_edk_tests.gyp +++ b/mojo/mojo_edk_tests.gyp @@ -83,8 +83,9 @@ 'public/cpp/bindings/tests/pickled_struct_blink.h', 'public/cpp/bindings/tests/pickled_struct_chromium.cc', 'public/cpp/bindings/tests/pickled_struct_chromium.h', - 'public/cpp/bindings/tests/rect_blink.h', - 'public/cpp/bindings/tests/rect_chromium.h', + # TODO: crbug.com/596202 + # 'public/cpp/bindings/tests/rect_blink.h', + # 'public/cpp/bindings/tests/rect_chromium.h', 'public/cpp/bindings/tests/request_response_unittest.cc', 'public/cpp/bindings/tests/router_test_util.cc', 'public/cpp/bindings/tests/router_test_util.h', @@ -93,7 +94,7 @@ 'public/cpp/bindings/tests/serialization_warning_unittest.cc', 'public/cpp/bindings/tests/stl_converters_unittest.cc', 'public/cpp/bindings/tests/string_unittest.cc', - 'public/cpp/bindings/tests/struct_traits_unittest.cc', + # 'public/cpp/bindings/tests/struct_traits_unittest.cc', 'public/cpp/bindings/tests/struct_unittest.cc', 'public/cpp/bindings/tests/struct_with_traits_impl.cc', 'public/cpp/bindings/tests/struct_with_traits_impl.h', diff --git a/mojo/mojo_public.gyp b/mojo/mojo_public.gyp index 8c5961d..800adfd 100644 --- a/mojo/mojo_public.gyp +++ b/mojo/mojo_public.gyp @@ -515,6 +515,7 @@ 'mojom_variant': 'test_variant', }, 'sources': [ + 'public/interfaces/bindings/tests/test_variant_import.mojom', 'public/interfaces/bindings/tests/test_variant.mojom', ], 'includes': [ 'mojom_bindings_generator.gypi' ], diff --git a/mojo/public/cpp/bindings/tests/BUILD.gn b/mojo/public/cpp/bindings/tests/BUILD.gn index c002d76..00693e0 100644 --- a/mojo/public/cpp/bindings/tests/BUILD.gn +++ b/mojo/public/cpp/bindings/tests/BUILD.gn @@ -33,8 +33,10 @@ source_set("tests") { "pickled_struct_blink.h", "pickled_struct_chromium.cc", "pickled_struct_chromium.h", - "rect_blink.h", - "rect_chromium.h", + + # TODO: crbug.com/596202 + #"rect_blink.h", + #"rect_chromium.h", "request_response_unittest.cc", "router_test_util.cc", "router_test_util.h", @@ -43,7 +45,8 @@ source_set("tests") { "serialization_warning_unittest.cc", "stl_converters_unittest.cc", "string_unittest.cc", - "struct_traits_unittest.cc", + + #"struct_traits_unittest.cc", "struct_unittest.cc", "struct_with_traits_impl.cc", "struct_with_traits_impl.h", diff --git a/mojo/public/interfaces/bindings/tests/BUILD.gn b/mojo/public/interfaces/bindings/tests/BUILD.gn index 57ab1ff..6e6d24c 100644 --- a/mojo/public/interfaces/bindings/tests/BUILD.gn +++ b/mojo/public/interfaces/bindings/tests/BUILD.gn @@ -122,6 +122,7 @@ mojom("test_variant") { sources = [ "test_variant.mojom", + "test_variant_import.mojom", ] variant = "variant_test" diff --git a/mojo/public/interfaces/bindings/tests/blink_test.typemap b/mojo/public/interfaces/bindings/tests/blink_test.typemap index effc0a2..5425ee1 100644 --- a/mojo/public/interfaces/bindings/tests/blink_test.typemap +++ b/mojo/public/interfaces/bindings/tests/blink_test.typemap @@ -9,12 +9,12 @@ "headers": [ "mojo/public/cpp/bindings/tests/pickled_struct_blink.h" ] - }, - "mojo.test.Rect": { - "typename": "mojo::test::RectBlink", - "headers": [ - "mojo/public/cpp/bindings/tests/rect_blink.h" - ] } +// "mojo.test.Rect": { +// "typename": "mojo::test::RectBlink", +// "headers": [ +// "mojo/public/cpp/bindings/tests/rect_blink.h" +// ] +// } } } diff --git a/mojo/public/interfaces/bindings/tests/chromium_test.typemap b/mojo/public/interfaces/bindings/tests/chromium_test.typemap index 95b08e6..260826e 100644 --- a/mojo/public/interfaces/bindings/tests/chromium_test.typemap +++ b/mojo/public/interfaces/bindings/tests/chromium_test.typemap @@ -9,12 +9,12 @@ "headers": [ "mojo/public/cpp/bindings/tests/pickled_struct_chromium.h" ] - }, - "mojo.test.Rect": { - "typename": "mojo::test::RectChromium", - "headers": [ - "mojo/public/cpp/bindings/tests/rect_chromium.h" - ] } +// "mojo.test.Rect": { +// "typename": "mojo::test::RectChromium", +// "headers": [ +// "mojo/public/cpp/bindings/tests/rect_chromium.h" +// ] +// } } } diff --git a/mojo/public/interfaces/bindings/tests/test_native_types.mojom b/mojo/public/interfaces/bindings/tests/test_native_types.mojom index ddb88cf..3fcedde 100644 --- a/mojo/public/interfaces/bindings/tests/test_native_types.mojom +++ b/mojo/public/interfaces/bindings/tests/test_native_types.mojom @@ -4,7 +4,7 @@ module mojo.test; -import "mojo/public/interfaces/bindings/tests/rect.mojom"; +// import "mojo/public/interfaces/bindings/tests/rect.mojom"; // Used to verify that structs can be declared with no body in mojom. @@ -23,10 +23,11 @@ interface PicklePasser { => (array> passed); }; +// TODO: crbug.com/596202 // Used to verify support for native serialization of mojom-defined structs // using StrucTraits with different variants of the Rect type from rect.mojom. -interface RectService { - AddRect(Rect r); - GetLargestRect() => (Rect largest); -}; +// interface RectService { +// AddRect(Rect r); +// GetLargestRect() => (Rect largest); +// }; diff --git a/mojo/public/interfaces/bindings/tests/test_variant.mojom b/mojo/public/interfaces/bindings/tests/test_variant.mojom index 318b6a7..8c36985 100644 --- a/mojo/public/interfaces/bindings/tests/test_variant.mojom +++ b/mojo/public/interfaces/bindings/tests/test_variant.mojom @@ -4,7 +4,14 @@ module mojo.test; +import "test_variant_import.mojom"; + enum TestEnum { VALUE1, VALUE2 }; + +interface TestUseImportedType { + Use(mojo.test.test_import.ImportedType param) + => (mojo.test.test_import.ImportedType param); +}; diff --git a/mojo/public/interfaces/bindings/tests/test_variant_import.mojom b/mojo/public/interfaces/bindings/tests/test_variant_import.mojom new file mode 100644 index 0000000..1c7a783 --- /dev/null +++ b/mojo/public/interfaces/bindings/tests/test_variant_import.mojom @@ -0,0 +1,7 @@ +// 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. + +module mojo.test.test_import; + +struct ImportedType {}; diff --git a/mojo/public/tools/bindings/generators/cpp_templates/module-internal.h.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/module-internal.h.tmpl index 52aab99..dfad049 100644 --- a/mojo/public/tools/bindings/generators/cpp_templates/module-internal.h.tmpl +++ b/mojo/public/tools/bindings/generators/cpp_templates/module-internal.h.tmpl @@ -26,7 +26,11 @@ {%- endfor %} {%- for import in imports %} +{%- if variant %} +#include "{{"%s-%s-internal.h"|format(import.module.path, variant)}}" +{%- else %} #include "{{import.module.path}}-internal.h" +{%- endif %} {%- endfor %} namespace mojo { diff --git a/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl index 901fa69..d506e6c 100644 --- a/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl +++ b/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl @@ -35,7 +35,11 @@ #include "mojo/public/cpp/bindings/struct_traits.h" #include "{{variant_path}}-internal.h" {%- for import in imports %} +{%- if variant %} +#include "{{"%s-%s.h"|format(import.module.path, variant)}}" +{%- else %} #include "{{import.module.path}}.h" +{%- endif %} {%- endfor %} {%- if not for_blink %} #include "mojo/public/cpp/bindings/array.h" diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl index d5e224b..2e88cb4 100644 --- a/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl +++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl @@ -43,7 +43,7 @@ namespace {{variant}} { {%- endif %} -{%- if not variant and not struct|is_native_only_kind %} +{%- if not variant and not struct|is_native_only_kind %} {# NOTE: Generated Reader instances are intentionally cheap to copy and devoid of heap allocations. They should stay this way. #} diff --git a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py index 184c8bb..0d28239 100644 --- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py +++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py @@ -84,6 +84,8 @@ def GetNamePartsForKind(kind, add_same_module_namespaces, add_variant, parts = [] if kind.imported_from: parts.extend(NamespaceToArray(kind.imported_from["namespace"])) + if _variant and add_variant: + parts.append(_variant) elif add_same_module_namespaces: if hasattr(kind, "module"): parts.extend(NamespaceToArray(kind.module.namespace)) @@ -97,7 +99,7 @@ def GetNamePartsForKind(kind, add_same_module_namespaces, add_variant, return parts def GetNameForKind(kind, internal=False): - parts = GetNamePartsForKind(kind, False, False, internal) + parts = GetNamePartsForKind(kind, False, True, internal) return "::".join(parts) def GetQualifiedNameForKind(kind, internal=False): @@ -382,6 +384,8 @@ def TranslateConstants(token, kind): name = [] if token.imported_from: name.extend(NamespaceToArray(token.namespace)) + if _variant: + name.append(_variant) if token.parent_kind: name.append(token.parent_kind.name) if isinstance(token, mojom.EnumValue): -- cgit v1.1