diff --git a/include/grpc/compression.h b/include/grpc/compression.h index 176956642ad..2c39c6b3af6 100644 --- a/include/grpc/compression.h +++ b/include/grpc/compression.h @@ -23,7 +23,7 @@ #include -#include +#include // IWYU pragma: export #include #ifdef __cplusplus diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 0d863b9ad52..cc02b644ebe 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -24,8 +24,8 @@ #include #include -#include -#include +#include // IWYU pragma: export +#include // IWYU pragma: export #include #include #include diff --git a/include/grpc/impl/codegen/compression_types.h b/include/grpc/impl/codegen/compression_types.h index 35f49075d09..c1870307916 100644 --- a/include/grpc/impl/codegen/compression_types.h +++ b/include/grpc/impl/codegen/compression_types.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 +// IWYU pragma: friend "src/.*" #include diff --git a/include/grpc/impl/codegen/connectivity_state.h b/include/grpc/impl/codegen/connectivity_state.h index 52084da4cd8..218afd778d5 100644 --- a/include/grpc/impl/codegen/connectivity_state.h +++ b/include/grpc/impl/codegen/connectivity_state.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 +// IWYU pragma: friend "src/.*" #ifdef __cplusplus extern "C" { diff --git a/include/grpc/impl/codegen/gpr_types.h b/include/grpc/impl/codegen/gpr_types.h index 415bf7a9da1..253ff3ae96b 100644 --- a/include/grpc/impl/codegen/gpr_types.h +++ b/include/grpc/impl/codegen/gpr_types.h @@ -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 +// IWYU pragma: friend "src/.*" #include diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 5ed6bd55a0c..eb1f39055b3 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.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 +// IWYU pragma: friend "src/.*" #include diff --git a/src/cpp/client/client_callback.cc b/src/cpp/client/client_callback.cc index 719b8597052..7c4d9f42406 100644 --- a/src/cpp/client/client_callback.cc +++ b/src/cpp/client/client_callback.cc @@ -15,8 +15,11 @@ * */ -#include +#include + +#include #include +#include #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/error.h" diff --git a/tools/distrib/add-iwyu.py b/tools/distrib/add-iwyu.py index cbe0a81692f..5d180c4256d 100755 --- a/tools/distrib/add-iwyu.py +++ b/tools/distrib/add-iwyu.py @@ -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) diff --git a/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh b/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh index c5608910058..d36c8baa0c9 100755 --- a/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh +++ b/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh @@ -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