From 33b4dbd8c74aefc560bb81211aac43a0e5147980 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 31 Oct 2023 15:21:03 -0700 Subject: [PATCH] Add pybind11 IWYU pragmas (for clangd Include Cleaner). Adopt the ``` // IWYU pragma: always_keep // See pybind11/docs/type_caster_iwyu.rst ``` comment used in https://github.com/google/pywrapcc/pull/30073. Currently pybind11/docs/type_caster_iwyu.rst only exists in google/pywrapcc#30073, but the intend is to upstream the changes (see PR description). See also: https://clangd.llvm.org/design/include-cleaner PiperOrigin-RevId: 578318836 --- pybind11_protobuf/enum_type_caster.h | 5 +++++ pybind11_protobuf/native_proto_caster.h | 2 ++ pybind11_protobuf/proto_cast_util.h | 2 ++ pybind11_protobuf/proto_caster_impl.h | 2 ++ pybind11_protobuf/wrapped_proto_caster.h | 2 ++ 5 files changed, 13 insertions(+) diff --git a/pybind11_protobuf/enum_type_caster.h b/pybind11_protobuf/enum_type_caster.h index 5765233..d30369b 100644 --- a/pybind11_protobuf/enum_type_caster.h +++ b/pybind11_protobuf/enum_type_caster.h @@ -1,3 +1,8 @@ +// IWYU pragma: always_keep // Appears to be the best we can do at the moment. +// What we really want (but does not work with Include Cleaner @ 2023-10-27): +// * If native_proto_caster.h is included: suggest removing enum_type_caster.h +// * If only enum_type_caster.h is included: always_keep + #ifndef PYBIND11_PROTOBUF_ENUM_TYPE_CASTER_H_ #define PYBIND11_PROTOBUF_ENUM_TYPE_CASTER_H_ diff --git a/pybind11_protobuf/native_proto_caster.h b/pybind11_protobuf/native_proto_caster.h index bc4ca54..32afb50 100644 --- a/pybind11_protobuf/native_proto_caster.h +++ b/pybind11_protobuf/native_proto_caster.h @@ -1,3 +1,5 @@ +// IWYU pragma: always_keep // See pybind11/docs/type_caster_iwyu.rst + #ifndef PYBIND11_PROTOBUF_NATIVE_PROTO_CASTERS_H_ #define PYBIND11_PROTOBUF_NATIVE_PROTO_CASTERS_H_ diff --git a/pybind11_protobuf/proto_cast_util.h b/pybind11_protobuf/proto_cast_util.h index 75c136c..4821e94 100644 --- a/pybind11_protobuf/proto_cast_util.h +++ b/pybind11_protobuf/proto_cast_util.h @@ -1,3 +1,5 @@ +// IWYU pragma: private, include "pybind11_protobuf/native_proto_caster.h" + #ifndef PYBIND11_PROTOBUF_PROTO_CAST_UTIL_H_ #define PYBIND11_PROTOBUF_PROTO_CAST_UTIL_H_ diff --git a/pybind11_protobuf/proto_caster_impl.h b/pybind11_protobuf/proto_caster_impl.h index 3508ee6..f54b175 100644 --- a/pybind11_protobuf/proto_caster_impl.h +++ b/pybind11_protobuf/proto_caster_impl.h @@ -1,3 +1,5 @@ +// IWYU pragma: private, include "pybind11_protobuf/native_proto_caster.h" + #ifndef PYBIND11_PROTOBUF_PROTO_CASTER_IMPL_H_ #define PYBIND11_PROTOBUF_PROTO_CASTER_IMPL_H_ diff --git a/pybind11_protobuf/wrapped_proto_caster.h b/pybind11_protobuf/wrapped_proto_caster.h index d45282f..18cf7da 100644 --- a/pybind11_protobuf/wrapped_proto_caster.h +++ b/pybind11_protobuf/wrapped_proto_caster.h @@ -1,3 +1,5 @@ +// IWYU pragma: always_keep // See pybind11/docs/type_caster_iwyu.rst + #ifndef PYBIND11_PROTOBUF_WRAPPED_PROTO_CASTER_H_ #define PYBIND11_PROTOBUF_WRAPPED_PROTO_CASTER_H_