[iwyu] Improve iwyu for public headers (#29834)

* [iwyu] Improve iwyu for public headers

* Automated change: Fix sanity tests

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/29436/head
Craig Tiller 3 years ago committed by GitHub
parent 17bec49af7
commit a5b08d7a77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      include/grpc/compression.h
  2. 4
      include/grpc/grpc.h
  3. 3
      include/grpc/impl/codegen/compression_types.h
  4. 3
      include/grpc/impl/codegen/connectivity_state.h
  5. 3
      include/grpc/impl/codegen/gpr_types.h
  6. 3
      include/grpc/impl/codegen/grpc_types.h
  7. 5
      src/cpp/client/client_callback.cc
  8. 35
      tools/distrib/add-iwyu.py
  9. 2
      tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh

@ -23,7 +23,7 @@
#include <stdlib.h>
#include <grpc/impl/codegen/compression_types.h>
#include <grpc/impl/codegen/compression_types.h> // IWYU pragma: export
#include <grpc/slice.h>
#ifdef __cplusplus

@ -24,8 +24,8 @@
#include <stddef.h>
#include <grpc/byte_buffer.h>
#include <grpc/impl/codegen/connectivity_state.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/impl/codegen/connectivity_state.h> // IWYU pragma: export
#include <grpc/impl/codegen/grpc_types.h> // IWYU pragma: export
#include <grpc/impl/codegen/propagation_bits.h>
#include <grpc/slice.h>
#include <grpc/status.h>

@ -19,7 +19,8 @@
#ifndef GRPC_IMPL_CODEGEN_COMPRESSION_TYPES_H
#define GRPC_IMPL_CODEGEN_COMPRESSION_TYPES_H
// IWYU pragma: private
// IWYU pragma: private, include <grpc/compression.h>
// IWYU pragma: friend "src/.*"
#include <grpc/impl/codegen/port_platform.h>

@ -19,7 +19,8 @@
#ifndef GRPC_IMPL_CODEGEN_CONNECTIVITY_STATE_H
#define GRPC_IMPL_CODEGEN_CONNECTIVITY_STATE_H
// IWYU pragma: private
// IWYU pragma: private, include <grpc/grpc.h>
// IWYU pragma: friend "src/.*"
#ifdef __cplusplus
extern "C" {

@ -19,7 +19,8 @@
#ifndef GRPC_IMPL_CODEGEN_GPR_TYPES_H
#define GRPC_IMPL_CODEGEN_GPR_TYPES_H
// IWYU pragma: private
// IWYU pragma: private, include <grpc/grpc.h>
// IWYU pragma: friend "src/.*"
#include <grpc/impl/codegen/port_platform.h>

@ -19,7 +19,8 @@
#ifndef GRPC_IMPL_CODEGEN_GRPC_TYPES_H
#define GRPC_IMPL_CODEGEN_GRPC_TYPES_H
// IWYU pragma: private
// IWYU pragma: private, include <grpc/grpc.h>
// IWYU pragma: friend "src/.*"
#include <grpc/impl/codegen/port_platform.h>

@ -15,8 +15,11 @@
*
*/
#include <grpcpp/impl/codegen/client_callback.h>
#include <utility>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpcpp/support/client_callback.h>
#include <grpcpp/support/status.h>
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/error.h"

@ -25,7 +25,7 @@ def to_inc(filename):
return '"%s"' % filename
def set_pragma(filename, pragma):
def set_pragmas(filename, pragmas):
"""Set the file-level IWYU pragma in filename"""
lines = []
saw_first_define = False
@ -36,7 +36,8 @@ def set_pragma(filename, pragma):
if not saw_first_define and line.startswith('#define '):
saw_first_define = True
lines.append('')
lines.append('// IWYU pragma: %s' % pragma)
for pragma in pragmas:
lines.append('// IWYU pragma: %s' % pragma)
lines.append('')
open(filename, 'w').write('\n'.join(lines) + '\n')
@ -53,12 +54,16 @@ def set_exports(pub, cg):
CG_ROOTS_GRPC = (
(r'sync', 'grpc/support/sync.h'),
(r'atm', 'grpc/support/atm.h'),
(r'sync', 'grpc/support/sync.h', False),
(r'atm', 'grpc/support/atm.h', False),
(r'grpc_types', 'grpc/grpc.h', True),
(r'gpr_types', 'grpc/grpc.h', True),
(r'compression_types', 'grpc/compression.h', True),
(r'connectivity_state', 'grpc/grpc.h', True),
)
CG_ROOTS_GRPCPP = [
(r'status_code_enum', 'grpcpp/support/status.h'),
(r'status_code_enum', 'grpcpp/support/status.h', False),
]
@ -78,13 +83,15 @@ def fix_tree(tree, cg_roots):
# Exclude non-headers
if not filename.endswith('.h'):
continue
pragma = None
pragmas = []
# Check for our 'special' headers: if we see one of these, we just
# hardcode where they go to because there's some complicated rules.
for root, target in cg_roots:
print(root, target)
for root, target, friend in cg_roots:
print(root, target, friend)
if filename.startswith(root):
pragma = 'private, include <%s>' % target
pragmas = ['private, include <%s>' % target]
if friend:
pragmas.append('friend "src/.*"')
if len(paths) == 1:
path = paths[0]
if filename.startswith(root + '.'):
@ -93,7 +100,7 @@ def fix_tree(tree, cg_roots):
set_exports(path + '/' + root + '.h',
path + '/' + filename)
# If the path for a file in /impl/codegen is ambiguous, just don't bother
if not pragma and len(paths) == 1:
if not pragmas and len(paths) == 1:
path = paths[0]
# Check if we have an exporting candidate
if filename in reverse_map:
@ -106,16 +113,16 @@ def fix_tree(tree, cg_roots):
# And see if the public file actually includes the /impl/codegen file
if ('#include %s' % to_inc(cg)) in open(pub).read():
# Finally, if it does, we'll set that pragma
pragma = 'private, include %s' % to_inc(pub)
pragmas = ['private, include %s' % to_inc(pub)]
# And mark the export
set_exports(pub, cg)
# If we can't find a good alternative include to point people to,
# mark things private anyway... we don't want to recommend people include
# from impl/codegen
if not pragma:
pragma = 'private'
if not pragmas:
pragmas = ['private']
for path in paths:
set_pragma(path + '/' + filename, pragma)
set_pragmas(path + '/' + filename, pragmas)
fix_tree('include/grpc', CG_ROOTS_GRPC)

@ -44,7 +44,7 @@ fi
if [ "$TEST" == "" ]
then
echo $files | xargs -P $CPU_COUNT -n 10 $CLANG_FORMAT -i
echo $files | xargs -P $CPU_COUNT -n 1 $CLANG_FORMAT -i
else
ok=yes
for file in $files

Loading…
Cancel
Save