diff --git a/tools/code_format/check_format.py b/tools/code_format/check_format.py index ea5214dda67f3..351414da436b0 100755 --- a/tools/code_format/check_format.py +++ b/tools/code_format/check_format.py @@ -2,7 +2,6 @@ import argparse import common -import difflib import functools import multiprocessing import os @@ -85,21 +84,6 @@ "./source/server/admin/prometheus_stats.cc", "./tools/clang_tools/api_booster/main.cc", "./tools/clang_tools/api_booster/proto_cxx_utils.cc", "./source/common/common/version.cc") -# These triples (file1, file2, diff) represent two files, file1 and file2 that should maintain -# the diff diff. This is meant to keep these two files in sync. -CODEC_DIFFS = (("./source/common/http/http1/codec_impl.h", - "./source/common/http/http1/codec_impl_legacy.h", - "./tools/code_format/codec_diffs/http1_codec_impl_h"), - ("./source/common/http/http1/codec_impl.cc", - "./source/common/http/http1/codec_impl_legacy.cc", - "./tools/code_format/codec_diffs/http1_codec_impl_cc"), - ("./source/common/http/http2/codec_impl.h", - "./source/common/http/http2/codec_impl_legacy.h", - "./tools/code_format/codec_diffs/http2_codec_impl_h"), - ("./source/common/http/http2/codec_impl.cc", - "./source/common/http/http2/codec_impl_legacy.cc", - "./tools/code_format/codec_diffs/http2_codec_impl_cc")) - # Only one C++ file should instantiate grpc_init GRPC_INIT_ALLOWLIST = ("./source/common/grpc/google_grpc_context.cc") @@ -548,38 +532,6 @@ def fixSourceLine(line, line_number): return line -def codecDiffHelper(file1, file2, diff): - f1 = readLines(file1) - f2 = readLines(file2) - - # Create diff between two files - code_diff = list(difflib.unified_diff(f1, f2, lineterm="")) - # Compare with golden diff. - golden_diff = readLines(diff) - # It is fairly ugly to diff a diff, so return a warning to sync codec changes - # and/or update golden_diff. - if code_diff != golden_diff: - error_message = "Codecs are not synced: %s does not match %s. Update codec implementations to sync and/or update the diff manually to:\n%s" % ( - file1, file2, '\n'.join(code_diff)) - # The following line will write the diff to the file diff if it does not match. - # Do not uncomment unless you know the change is safe! - # new_diff = pathlib.Path(diff) - #new_diff.open('w') - # new_diff.write_text('\n'.join(code_diff), encoding='utf-8') - return error_message - - -def checkCodecDiffs(error_messages): - try: - for triple in CODEC_DIFFS: - codec_diff = codecDiffHelper(*triple) - if codec_diff != None: - error_messages.append(codecDiffHelper(*triple)) - return error_messages - except IOError: # for check format tests - return error_messages - - # We want to look for a call to condvar.waitFor, but there's no strong pattern # to the variable name of the condvar. If we just look for ".waitFor" we'll also # pick up time_system_.waitFor(...), and we don't want to return true for that @@ -1096,9 +1048,6 @@ def ownedDirectories(error_messages): error_messages = [] owned_directories = ownedDirectories(error_messages) - # Check codec synchronization once per run. - checkCodecDiffs(error_messages) - if os.path.isfile(target_path): error_messages += checkFormat("./" + target_path) else: diff --git a/tools/code_format/codec_diffs/http1_codec_impl_cc b/tools/code_format/codec_diffs/http1_codec_impl_cc deleted file mode 100644 index b9ea3f3ae0024..0000000000000 --- a/tools/code_format/codec_diffs/http1_codec_impl_cc +++ /dev/null @@ -1,35 +0,0 @@ ---- -+++ -@@ -1,4 +1,4 @@ --#include "common/http/http1/codec_impl.h" -+#include "common/http/http1/codec_impl_legacy.h" - - #include - #include -@@ -25,6 +25,7 @@ - - namespace Envoy { - namespace Http { -+namespace Legacy { - namespace Http1 { - namespace { - -@@ -48,6 +49,10 @@ - - using Http1ResponseCodeDetails = ConstSingleton; - using Http1HeaderTypes = ConstSingleton; -+using Http::Http1::CodecStats; -+using Http::Http1::HeaderKeyFormatter; -+using Http::Http1::HeaderKeyFormatterPtr; -+using Http::Http1::ProperCaseHeaderKeyFormatter; - - const StringUtil::CaseUnorderedSet& caseUnorderdSetContainingUpgradeAndHttp2Settings() { - CONSTRUCT_ON_FIRST_USE(StringUtil::CaseUnorderedSet, -@@ -1236,6 +1241,7 @@ - } - - } // namespace Http1 -+} // namespace Legacy - } // namespace Http - } // namespace Envoy - \ No newline at end of file diff --git a/tools/code_format/codec_diffs/http1_codec_impl_h b/tools/code_format/codec_diffs/http1_codec_impl_h deleted file mode 100644 index e81d2c838d5e4..0000000000000 --- a/tools/code_format/codec_diffs/http1_codec_impl_h +++ /dev/null @@ -1,130 +0,0 @@ ---- -+++ -@@ -24,6 +24,7 @@ - - namespace Envoy { - namespace Http { -+namespace Legacy { - namespace Http1 { - - class ConnectionImpl; -@@ -75,7 +76,8 @@ - void clearReadDisableCallsForTests() { read_disable_calls_ = 0; } - - protected: -- StreamEncoderImpl(ConnectionImpl& connection, HeaderKeyFormatter* header_key_formatter); -+ StreamEncoderImpl(ConnectionImpl& connection, -+ Http::Http1::HeaderKeyFormatter* header_key_formatter); - void encodeHeadersBase(const RequestOrResponseHeaderMap& headers, absl::optional status, - bool end_stream); - void encodeTrailersBase(const HeaderMap& headers); -@@ -114,7 +116,7 @@ - - void encodeFormattedHeader(absl::string_view key, absl::string_view value); - -- const HeaderKeyFormatter* const header_key_formatter_; -+ const Http::Http1::HeaderKeyFormatter* const header_key_formatter_; - absl::string_view details_; - }; - -@@ -123,7 +125,8 @@ - */ - class ResponseEncoderImpl : public StreamEncoderImpl, public ResponseEncoder { - public: -- ResponseEncoderImpl(ConnectionImpl& connection, HeaderKeyFormatter* header_key_formatter) -+ ResponseEncoderImpl(ConnectionImpl& connection, -+ Http::Http1::HeaderKeyFormatter* header_key_formatter) - : StreamEncoderImpl(connection, header_key_formatter) {} - - bool startedResponse() { return started_response_; } -@@ -142,7 +145,8 @@ - */ - class RequestEncoderImpl : public StreamEncoderImpl, public RequestEncoder { - public: -- RequestEncoderImpl(ConnectionImpl& connection, HeaderKeyFormatter* header_key_formatter) -+ RequestEncoderImpl(ConnectionImpl& connection, -+ Http::Http1::HeaderKeyFormatter* header_key_formatter) - : StreamEncoderImpl(connection, header_key_formatter) {} - bool upgradeRequest() const { return upgrade_request_; } - bool headRequest() const { return head_request_; } -@@ -203,7 +207,7 @@ - virtual bool supportsHttp10() { return false; } - bool maybeDirectDispatch(Buffer::Instance& data); - virtual void maybeAddSentinelBufferFragment(Buffer::WatermarkBuffer&) {} -- CodecStats& stats() { return stats_; } -+ Http::Http1::CodecStats& stats() { return stats_; } - bool enableTrailers() const { return enable_trailers_; } - - // Http::Connection -@@ -218,9 +222,9 @@ - bool strict1xxAnd204Headers() { return strict_1xx_and_204_headers_; } - - protected: -- ConnectionImpl(Network::Connection& connection, CodecStats& stats, http_parser_type type, -- uint32_t max_headers_kb, const uint32_t max_headers_count, -- HeaderKeyFormatterPtr&& header_key_formatter, bool enable_trailers); -+ ConnectionImpl(Network::Connection& connection, Http::Http1::CodecStats& stats, -+ http_parser_type type, uint32_t max_headers_kb, const uint32_t max_headers_count, -+ Http::Http1::HeaderKeyFormatterPtr&& header_key_formatter, bool enable_trailers); - - bool resetStreamCalled() { return reset_stream_called_; } - void onMessageBeginBase(); -@@ -240,10 +244,10 @@ - void checkMaxHeadersSize(); - - Network::Connection& connection_; -- CodecStats& stats_; -+ Http::Http1::CodecStats& stats_; - http_parser parser_; - Http::Code error_code_{Http::Code::BadRequest}; -- const HeaderKeyFormatterPtr header_key_formatter_; -+ const Http::Http1::HeaderKeyFormatterPtr header_key_formatter_; - HeaderString current_header_field_; - HeaderString current_header_value_; - bool processing_trailers_ : 1; -@@ -420,7 +424,7 @@ - */ - class ServerConnectionImpl : public ServerConnection, public ConnectionImpl { - public: -- ServerConnectionImpl(Network::Connection& connection, CodecStats& stats, -+ ServerConnectionImpl(Network::Connection& connection, Http::Http1::CodecStats& stats, - ServerConnectionCallbacks& callbacks, const Http1Settings& settings, - uint32_t max_request_headers_kb, const uint32_t max_request_headers_count, - envoy::config::core::v3::HttpProtocolOptions::HeadersWithUnderscoresAction -@@ -432,7 +436,7 @@ - * An active HTTP/1.1 request. - */ - struct ActiveRequest { -- ActiveRequest(ConnectionImpl& connection, HeaderKeyFormatter* header_key_formatter) -+ ActiveRequest(ConnectionImpl& connection, Http::Http1::HeaderKeyFormatter* header_key_formatter) - : response_encoder_(connection, header_key_formatter) {} - - HeaderString request_url_; -@@ -524,7 +528,7 @@ - */ - class ClientConnectionImpl : public ClientConnection, public ConnectionImpl { - public: -- ClientConnectionImpl(Network::Connection& connection, CodecStats& stats, -+ ClientConnectionImpl(Network::Connection& connection, Http::Http1::CodecStats& stats, - ConnectionCallbacks& callbacks, const Http1Settings& settings, - const uint32_t max_response_headers_count); - -@@ -533,8 +537,8 @@ - - private: - struct PendingResponse { -- PendingResponse(ConnectionImpl& connection, HeaderKeyFormatter* header_key_formatter, -- ResponseDecoder* decoder) -+ PendingResponse(ConnectionImpl& connection, -+ Http::Http1::HeaderKeyFormatter* header_key_formatter, ResponseDecoder* decoder) - : encoder_(connection, header_key_formatter), decoder_(decoder) {} - - RequestEncoderImpl encoder_; -@@ -598,6 +602,7 @@ - }; - - } // namespace Http1 -+} // namespace Legacy - } // namespace Http - } // namespace Envoy - \ No newline at end of file diff --git a/tools/code_format/codec_diffs/http2_codec_impl_cc b/tools/code_format/codec_diffs/http2_codec_impl_cc deleted file mode 100644 index 46123d9ef0316..0000000000000 --- a/tools/code_format/codec_diffs/http2_codec_impl_cc +++ /dev/null @@ -1,34 +0,0 @@ ---- -+++ -@@ -1,4 +1,4 @@ --#include "common/http/http2/codec_impl.h" -+#include "common/http/http2/codec_impl_legacy.h" - - #include - #include -@@ -25,6 +25,7 @@ - - namespace Envoy { - namespace Http { -+namespace Legacy { - namespace Http2 { - - class Http2ResponseCodeDetailValues { -@@ -52,6 +53,9 @@ - }; - - using Http2ResponseCodeDetails = ConstSingleton; -+using Http::Http2::CodecStats; -+using Http::Http2::MetadataDecoder; -+using Http::Http2::MetadataEncoder; - - bool Utility::reconstituteCrumbledCookies(const HeaderString& key, const HeaderString& value, - HeaderString& cookies) { -@@ -1464,6 +1468,7 @@ - } - - } // namespace Http2 -+} // namespace Legacy - } // namespace Http - } // namespace Envoy - \ No newline at end of file diff --git a/tools/code_format/codec_diffs/http2_codec_impl_h b/tools/code_format/codec_diffs/http2_codec_impl_h deleted file mode 100644 index 70c306568061e..0000000000000 --- a/tools/code_format/codec_diffs/http2_codec_impl_h +++ /dev/null @@ -1,77 +0,0 @@ ---- -+++ -@@ -30,6 +30,7 @@ - - namespace Envoy { - namespace Http { -+namespace Legacy { - namespace Http2 { - - // This is not the full client magic, but it's the smallest size that should be able to -@@ -89,7 +90,7 @@ - */ - class ConnectionImpl : public virtual Connection, protected Logger::Loggable { - public: -- ConnectionImpl(Network::Connection& connection, CodecStats& stats, -+ ConnectionImpl(Network::Connection& connection, Http::Http2::CodecStats& stats, - const envoy::config::core::v3::Http2ProtocolOptions& http2_options, - const uint32_t max_headers_kb, const uint32_t max_headers_count); - -@@ -252,9 +253,9 @@ - virtual void decodeTrailers() PURE; - - // Get MetadataEncoder for this stream. -- MetadataEncoder& getMetadataEncoder(); -+ Http::Http2::MetadataEncoder& getMetadataEncoder(); - // Get MetadataDecoder for this stream. -- MetadataDecoder& getMetadataDecoder(); -+ Http::Http2::MetadataDecoder& getMetadataDecoder(); - // Callback function for MetadataDecoder. - void onMetadataDecoded(MetadataMapPtr&& metadata_map_ptr); - -@@ -273,8 +274,8 @@ - [this]() -> void { this->pendingSendBufferHighWatermark(); }, - []() -> void { /* TODO(adisuissa): Handle overflow watermark */ }}; - HeaderMapPtr pending_trailers_to_encode_; -- std::unique_ptr metadata_decoder_; -- std::unique_ptr metadata_encoder_; -+ std::unique_ptr metadata_decoder_; -+ std::unique_ptr metadata_encoder_; - absl::optional deferred_reset_; - HeaderString cookies_; - bool local_end_stream_sent_ : 1; -@@ -414,7 +415,7 @@ - - std::list active_streams_; - nghttp2_session* session_{}; -- CodecStats& stats_; -+ Http::Http2::CodecStats& stats_; - Network::Connection& connection_; - const uint32_t max_headers_kb_; - const uint32_t max_headers_count_; -@@ -522,7 +523,7 @@ - public: - using SessionFactory = Nghttp2SessionFactory; - ClientConnectionImpl(Network::Connection& connection, ConnectionCallbacks& callbacks, -- CodecStats& stats, -+ Http::Http2::CodecStats& stats, - const envoy::config::core::v3::Http2ProtocolOptions& http2_options, - const uint32_t max_response_headers_kb, - const uint32_t max_response_headers_count, -@@ -557,7 +558,7 @@ - class ServerConnectionImpl : public ServerConnection, public ConnectionImpl { - public: - ServerConnectionImpl(Network::Connection& connection, ServerConnectionCallbacks& callbacks, -- CodecStats& stats, -+ Http::Http2::CodecStats& stats, - const envoy::config::core::v3::Http2ProtocolOptions& http2_options, - const uint32_t max_request_headers_kb, - const uint32_t max_request_headers_count, -@@ -596,6 +597,7 @@ - }; - - } // namespace Http2 -+} // namespace Legacy - } // namespace Http - } // namespace Envoy - \ No newline at end of file