CDRIVER-6085 Reorder + annotate include directives with "IWYU pragma: export" #2167
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to CDRIVER-6085. Applies IWYU export pragmas to component headers in mongo-c-driver. Companion PR to mongodb/mongo-cxx-driver#1492.
To avoid potentially breaking downstream users, no include directives are removed by changes in this PR. However, component header includes are reordered to the top, with necessary fixes applied to impacted downstream components. These include:
<bson/bson.h>: missing<bson/bson_t.h>and<bson/error.h>(see: [CDRIVER-4153] Beginning of Header Hygiene & Verification #2053)<bson/bson-vector.h>: missing<bson/bson_t.h>and<bson/bson-types.h><mongoc/mongoc-topology-description.h>: missing<mongoc/mongoc-server-description.h>.<mongoc/mongoc-stream-tls-secure-transport.h>: missing<mongoc/mongoc-ssl.h>and<mongoc/mongoc-stream.h>.(Aside:
bson-private.hshould probably be renamed tobson-types-private.hfor consistency?)Additionally, the
bson-config.hheader is exported bybson-macros.handbson-compat.h, andbson-macros.his exported bybson-compat.h. This is due to the global nature of these headers in providing system-defined entities (types, functions, macros, etc.). The various stdlib and system includes inbson-compat.hwhich are currently marked as "unused" by IWYU are left as-is (to avoid potentially breaking downstream users) and do not have the IWYU export pragma applied.Note
Although IWYU supports the "private" pragma to denote private component headers which require the separate inclusion of the corresponding public header, this PR proposes we avoid this pattern in favor of supporting standalone-includable headers whenever able, even for private headers, by ensuring the corresponding public header is first included by the private header.
With the changes in this PR, the IWYU tool (via clangd or otherwise) may be used to start properly addressing "Condition 1" in CDRIVER-6085 via missing-header and unused-header diagnostics.