Skip to content

CDRIVER-5866 Fix 2 includes #1836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2025
Merged

CDRIVER-5866 Fix 2 includes #1836

merged 1 commit into from
Jan 27, 2025

Conversation

jeroen
Copy link
Contributor

@jeroen jeroen commented Jan 27, 2025

This fixes two complication errors:

clang -arch arm64 -DNDEBUG -I. -Icommon -Ikms -Iutf8proc -DBSON_COMPILATION -DBSON_EXTRA_ALIGN -DMONGOC_COMPILATION -DMONGOC_HAVE_SASL_CLIENT_DONE -DMONGOC_ENABLE_SSL_SECURE_TRANSPORT -DMONGOC_ENABLE_CRYPTO_COMMON_CRYPTO -DKMS_MESSAGE_ENABLE_CRYPTO -DKMS_MESSAGE_ENABLE_CRYPTO_COMMON_CRYPTO -D_DARWIN_C_SOURCE  -I/opt/R/arm64/include   -mmacosx-version-min=10.8 -fPIC  -falign-functions=64 -Wall -g -O2  -c mongoc/mongoc-cluster.c -o mongoc/mongoc-cluster.o
In file included from mongoc/mongoc-cluster.c:55:
mongoc/utlist.h:20:10: error: 'mongoc-prelude.h' file not found with <angled> include; use "quotes" instead
   20 | #include <mongoc-prelude.h>
      |          ^~~~~~~~~~~~~~~~~~
      |          "mongoc-prelude.h"
1 error generated.

and

clang -arch arm64 -DNDEBUG -I. -Icommon -Ikms -Iutf8proc -DBSON_COMPILATION -DBSON_EXTRA_ALIGN -DMONGOC_COMPILATION -DMONGOC_HAVE_SASL_CLIENT_DONE -DMONGOC_ENABLE_SSL_SECURE_TRANSPORT -DMONGOC_ENABLE_CRYPTO_COMMON_CRYPTO -DKMS_MESSAGE_ENABLE_CRYPTO -DKMS_MESSAGE_ENABLE_CRYPTO_COMMON_CRYPTO -D_DARWIN_C_SOURCE  -I/opt/R/arm64/include   -mmacosx-version-min=10.8 -fPIC  -falign-functions=64 -Wall -g -O2  -c mongoc/mongoc-init.c -o mongoc/mongoc-init.o
mongoc/mongoc-init.c:55:10: error: 'mongoc-cyrus-private.h' file not found with <angled> include; use "quotes" instead
   55 | #include <mongoc-cyrus-private.h> // _mongoc_cyrus_verifyfile_cb
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
      |          "mongoc-cyrus-private.h"
1 error generated.

@ghost
Copy link

ghost commented Jan 27, 2025

Hi @jeroen, thanks for contributing a patch to mongodb!

I'm taking a look at this and while I agree the switch to quoted headers from angled might be an improvement, I'm not sure why the issue is coming up for you in these specific instances. In general there's a lot of inconsistency between header quoting styles, and this codebase assumes that header paths during compilation include the project source directories.

My assessment so far is that this would be best fixed at the build system level. A source level fix to change the header include style might be welcome but I suspect it would need to be more comprehensive in order to have its intended effect.

Could you share some more information about the build steps prior to the clang lines you've posted?

@jeroen
Copy link
Contributor Author

jeroen commented Jan 27, 2025

I maintain the R bindings and we vendor mongo-c-driver. We have a custom makefile so this might explain some subtle differences with your cmake config.

What makes the above lines a bug is that they use angled bracket notation but the path is not prefixed with <mongoc/..> as is done everywhere else in the code. These are the only two lines that assume the mongoc dir is on the include path, which I think is bad practice.

So you could either switch them to "quotes" as in this PR, or alternatively use #include <mongoc/....>. I think it would be good to adjust the cmake build system to not put mongoc directly in the include path as this increases chances of name conflicts with other random things, such as language bindings.

@kevinAlbs
Copy link
Collaborator

Thank you for reporting @jeroen. Filed CDRIVER-5865 to apply a consistent include pattern in the codebase.

or alternatively use #include <mongoc/....>

I would rather this PR be updated to use this form to avoid relative look-up.

@jeroen
Copy link
Contributor Author

jeroen commented Jan 27, 2025

@kevinAlbs it's fine by me but literally all other mongoc headers in this file use quotes so for consistency that seems to make more sense? The last line below is the only odd one out...

#include <bson/bson.h>
#include "mongoc-config.h"
#include "mongoc-counters-private.h"
#include "mongoc-init.h"
#include "mongoc-handshake-private.h"
#include "mongoc-cluster-aws-private.h"
#ifdef MONGOC_ENABLE_SSL_OPENSSL
#include "mongoc-openssl-private.h"
#elif defined(MONGOC_ENABLE_SSL_LIBRESSL)
#include "tls.h"
#endif
#include "mongoc-thread-private.h"
#include "common-b64-private.h"
#if defined(MONGOC_ENABLE_CRYPTO_CNG)
#include "mongoc-crypto-private.h"
#include "mongoc-crypto-cng-private.h"
#endif
#ifdef MONGOC_ENABLE_MONGODB_AWS_AUTH
#include "kms_message/kms_message.h"
#endif
#ifdef MONGOC_ENABLE_OCSP_OPENSSL
#include "mongoc-ocsp-cache-private.h"
#endif
#ifndef MONGOC_NO_AUTOMATIC_GLOBALS
#pragma message("Configure the driver with ENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF.\
Automatic cleanup is deprecated and will be removed in version 2.0.")
#endif
#ifdef MONGOC_ENABLE_SASL_CYRUS
#include <sasl/sasl.h>
#include <mongoc-cyrus-private.h> // _mongoc_cyrus_verifyfile_cb

@ghost
Copy link

ghost commented Jan 27, 2025

in this file

The problem is really larger than just a couple files. We have a more comprehensive solution in progress.

Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CDRIVER-5670 is expected to address this to the entire codebase. LGTM as a short-term fix (though it may be overwritten shortly).

@kevinAlbs kevinAlbs changed the title Fix 2 includes CDRIVER-5866 Fix 2 includes Jan 27, 2025
@kevinAlbs kevinAlbs merged commit 45cf893 into mongodb:master Jan 27, 2025
40 of 45 checks passed
@jeroen jeroen deleted the fix-includes branch January 27, 2025 21:21
eramongodb pushed a commit to eramongodb/mongo-c-driver that referenced this pull request Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants