diff --git a/tools/inspector_protocol/code_generator.py b/tools/inspector_protocol/code_generator.py index c1f78dc7492d78..0b8baea0ae710e 100755 --- a/tools/inspector_protocol/code_generator.py +++ b/tools/inspector_protocol/code_generator.py @@ -103,6 +103,17 @@ def init_defaults(config_tuple, path, defaults): ".lib": False, ".lib.export_macro": "", ".lib.export_header": False, + # The encoding lib consists of encoding/encoding.h and + # encoding/encoding.cc in its subdirectory, which binaries + # may link / depend on, instead of relying on the + # JINJA2 templates lib/encoding_{h,cc}.template. + # In that case, |header| identifies the include file + # and |namespace| is the namespace it's using. Usually + # inspector_protocol_encoding but for v8's copy it's + # v8_inspector_protocol_encoding. + # TODO(johannes): Migrate away from lib/encoding_{h,cc}.template + # in favor of this. + ".encoding_lib": { "header": "", "namespace": []}, } for key_value in config_values: parts = key_value.split("=") diff --git a/tools/inspector_protocol/lib/Values_cpp.template b/tools/inspector_protocol/lib/Values_cpp.template index 17c69255851ee7..8b4dfc91e3b9c9 100644 --- a/tools/inspector_protocol/lib/Values_cpp.template +++ b/tools/inspector_protocol/lib/Values_cpp.template @@ -6,6 +6,10 @@ //#include "Values.h" +{% if config.encoding_lib.header %} +#include "{{config.encoding_lib.header}}" +{% endif %} + {% for namespace in config.protocol.namespace %} namespace {{namespace}} { {% endfor %} @@ -64,6 +68,30 @@ void escapeStringForJSONInternal(const Char* str, unsigned len, // to this constant. static constexpr int kStackLimitValues = 1000; +{% if config.encoding_lib.namespace %} +using {{"::".join(config.encoding_lib.namespace)}}::Error; +using {{"::".join(config.encoding_lib.namespace)}}::Status; +using {{"::".join(config.encoding_lib.namespace)}}::span; +namespace cbor { +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::CBORTokenTag; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::CBORTokenizer; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeBinary; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeDouble; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeFalse; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeFromLatin1; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeFromUTF16; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeIndefiniteLengthArrayStart; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeIndefiniteLengthMapStart; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeInt32; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeNull; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeStop; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeString8; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EncodeTrue; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::EnvelopeEncoder; +using {{"::".join(config.encoding_lib.namespace + ['cbor'])}}::InitialByteForEnvelope; +} // namespace cbor +{% endif %} + // Below are three parsing routines for CBOR, which cover enough // to roundtrip JSON messages. std::unique_ptr parseMap(int32_t stack_depth, cbor::CBORTokenizer* tokenizer); diff --git a/tools/inspector_protocol/lib/encoding_cpp.template b/tools/inspector_protocol/lib/encoding_cpp.template index 70bf9091a7dd6a..e950acd6a6f34d 100644 --- a/tools/inspector_protocol/lib/encoding_cpp.template +++ b/tools/inspector_protocol/lib/encoding_cpp.template @@ -5,6 +5,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +{% if config.encoding_lib.header == "" %} #include #include @@ -2196,3 +2197,5 @@ Status ConvertJSONToCBOR(const Platform& platform, {% for namespace in config.protocol.namespace %} } // namespace {{namespace}} {% endfor %} + +{% endif %} diff --git a/tools/inspector_protocol/lib/encoding_h.template b/tools/inspector_protocol/lib/encoding_h.template index 406c4b87ff8aa5..2c6cfc10d594c2 100644 --- a/tools/inspector_protocol/lib/encoding_h.template +++ b/tools/inspector_protocol/lib/encoding_h.template @@ -5,6 +5,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +{% if config.encoding_lib.header == "" %} #ifndef {{"_".join(config.protocol.namespace)}}_encoding_h #define {{"_".join(config.protocol.namespace)}}_encoding_h @@ -518,3 +519,4 @@ Status ConvertJSONToCBOR(const Platform& platform, } // namespace {{namespace}} {% endfor %} #endif // !defined({{"_".join(config.protocol.namespace)}}_encoding_h) +{% endif %}