diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index 1e878401d52..f0f7104270a 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -25,8 +25,8 @@ #include -#include "hpack_constants.h" -#include "hpack_encoder_table.h" +#include "src/core/ext/transport/chttp2/transport/hpack_constants.h" +#include "src/core/ext/transport/chttp2/transport/hpack_encoder_table.h" /* This is here for grpc_is_binary_header * TODO(murgatroid99): Remove this diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc b/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc index 55c5f2d8fb8..5731a95adb5 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc @@ -24,11 +24,11 @@ #include #include "absl/strings/str_format.h" -#include "hpack_constants.h" #include #include +#include "src/core/ext/transport/chttp2/transport/hpack_constants.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/gpr/murmur_hash.h" #include "src/core/lib/slice/slice_internal.h" diff --git a/test/core/util/fake_udp_and_tcp_server.cc b/test/core/util/fake_udp_and_tcp_server.cc index f7af63d7c9a..44193fee76c 100644 --- a/test/core/util/fake_udp_and_tcp_server.cc +++ b/test/core/util/fake_udp_and_tcp_server.cc @@ -16,7 +16,7 @@ #include -#include "fake_udp_and_tcp_server.h" +#include "test/core/util/fake_udp_and_tcp_server.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" diff --git a/test/cpp/qps/qps_server_builder.cc b/test/cpp/qps/qps_server_builder.cc index 87cb452a334..4b515a12612 100644 --- a/test/cpp/qps/qps_server_builder.cc +++ b/test/cpp/qps/qps_server_builder.cc @@ -16,7 +16,7 @@ * */ -#include "qps_server_builder.h" +#include "test/cpp/qps/qps_server_builder.h" #include "absl/memory/memory.h" diff --git a/tools/distrib/check_naked_includes.py b/tools/distrib/check_naked_includes.py new file mode 100755 index 00000000000..5af510a42b6 --- /dev/null +++ b/tools/distrib/check_naked_includes.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 + +# Copyright 2022 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Check for includes of the form `#include "bar.h"` - i.e. not including the subdirectory. We require instead `#include "foo/bar.h"`. + +import argparse +import os +import re +import sys + +# find our home +ROOT = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../..')) +os.chdir(ROOT) + +# parse command line +argp = argparse.ArgumentParser(description='include guard checker') +argp.add_argument('-f', '--fix', default=False, action='store_true') +args = argp.parse_args() + +# error count +errors = 0 + +CHECK_SUBDIRS = [ + 'src/core', + 'src/cpp', + 'test/core', + 'test/cpp', +] + +for subdir in CHECK_SUBDIRS: + for root, dirs, files in os.walk(subdir): + for f in files: + if f.endswith('.h') or f.endswith('.cc'): + fpath = os.path.join(root, f) + output = open(fpath, 'r').readlines() + changed = False + for (i, line) in enumerate(output): + m = re.match(r'^#include "([^"]*)"(.*)', line) + if not m: + continue + include = m.group(1) + if '/' in include: + continue + expect_path = os.path.join(root, include) + trailing = m.group(2) + if not os.path.exists(expect_path): + continue + changed = True + errors += 1 + output[i] = '#include "{0}"{1}\n'.format( + expect_path, trailing) + print("Found naked include '{0}' in {1}".format( + include, fpath)) + if changed and args.fix: + open(fpath, 'w').writelines(output) + +if errors > 0: + print('{} errors found.'.format(errors)) + sys.exit(1) diff --git a/tools/distrib/sanitize.sh b/tools/distrib/sanitize.sh index 56e6920c024..a1976aa30f3 100755 --- a/tools/distrib/sanitize.sh +++ b/tools/distrib/sanitize.sh @@ -19,6 +19,7 @@ cd $(dirname $0)/../.. tools/buildgen/generate_projects.sh tools/distrib/check_include_guards.py --fix +tools/distrib/check_naked_includes.py --fix || true tools/distrib/check_copyright.py --fix tools/distrib/add-iwyu.py tools/distrib/check_trailing_newlines.sh --fix diff --git a/tools/run_tests/sanity/sanity_tests.yaml b/tools/run_tests/sanity/sanity_tests.yaml index 5744f413844..25959c119d9 100644 --- a/tools/run_tests/sanity/sanity_tests.yaml +++ b/tools/run_tests/sanity/sanity_tests.yaml @@ -23,6 +23,7 @@ cpu_cost: 3 - script: tools/distrib/check_copyright.py - script: tools/distrib/check_include_guards.py +- script: tools/distrib/check_naked_includes.py - script: tools/distrib/check_trailing_newlines.sh - script: tools/distrib/check_upb_output.sh - script: tools/distrib/check_pytype.sh