envoyproxy/envoy

Get include-what-you-use work for Envoy

Open

#12,853 建立於 2020年8月27日

在 GitHub 查看
 (2 留言) (1 反應) (0 負責人)C++ (5,373 fork)batch import
area/buildhelp wanted

倉庫指標

Star
 (27,997 star)
PR 合併指標
 (平均合併 8天) (30 天內合併 378 個 PR)

描述

Title: Get include-what-you-use work for Envoy

Description: There are lots of include-what-you-use violations in Envoy:

  1. over-inclusion: including too many unused headers slows down compilation.
  2. transitive-inclusion: some of the missing explicit includes will make further development difficult.

include-what-you-use is powerful to address those violations and fix them.

@htuch mentioned at #10917 that we need to get it work for Envoy.

I tried on my own development environment and it works.

Here are steps to get it work:

  1. follow instructions at [Instructions for developers] (https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md) to build iwyu
  2. generate compilation database by
tools/gen_compilation_database.py --include_headers
  1. replace -stdlib=libc++ -stdlib=libstdc++ in the generated json file compile_commands.json

  2. run iwyu_tool.py -p . at Envoy root directory. (Please refer to section "Using with a compilation database" from [Instructions for developers] (https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md) for details)

The output shall look like this

...
source/common/grpc/google_async_client_impl.cc should add these lines:
#include <grpc/impl/codegen/gpr_types.h>            // for GPR_CLOCK_REALTIME
#include <grpc/support/time.h>                      // for gpr_inf_future
#include <grpcpp/channel.h>                         // for Channel
#include <grpcpp/impl/codegen/async_stream_impl.h>  // for ClientAsyncReader...
#include <grpcpp/impl/codegen/call_op_set.h>        // for WriteOptions
#include <grpcpp/impl/codegen/string_ref.h>         // for string_ref
#include <chrono>                                   // for duration
#include <tuple>                                    // for tie, tuple
#include "absl/strings/match.h"                     // for EndsWith
#include "common/grpc/stat_names.h"                 // for StatNames
#include "common/http/header_map_impl.h"            // for RequestHeaderMapImpl
#include "common/protobuf/utility.h"                // for PROTOBUF_GET_WRAP...
#include "common/stats/symbol_table_impl.h"         // for StatName
#include "envoy/api/api.h"                          // for Api
#include "envoy/common/time.h"                      // for TimeSource
#include "envoy/stats/stats.h"                      // for Counter

source/common/grpc/google_async_client_impl.cc should remove these lines:
- #include "common/config/datasource.h"  // lines 9-9
- #include "common/grpc/common.h"  // lines 10-10
- #include "common/grpc/google_grpc_creds_impl.h"  // lines 11-11
- #include "grpcpp/support/proto_buffer_reader.h"  // lines 15-15

The full include-list for source/common/grpc/google_async_client_impl.cc:
#include "common/grpc/google_async_client_impl.h"
#include <grpc/impl/codegen/gpr_types.h>            // for GPR_CLOCK_REALTIME
#include <grpc/support/time.h>                      // for gpr_inf_future
#include <grpcpp/channel.h>                         // for Channel
#include <grpcpp/impl/codegen/async_stream_impl.h>  // for ClientAsyncReader...
#include <grpcpp/impl/codegen/call_op_set.h>        // for WriteOptions
#include <grpcpp/impl/codegen/string_ref.h>         // for string_ref
...

It will be useful if we can apply the iwyu check to every pull request to check iwyu violations.

貢獻者指南