From e45b0fff87f3b508e535a85c9a6185a9454e03b4 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 1 Jul 2025 19:04:46 -0600 Subject: [PATCH 01/17] Prepare some core header files for public use. This change starts a new pattern for public API headers: Headers that omit the "bson-" or "mongoc-" prefix are intended for public `#include` directives, allowing users to selectively import the APIs that they want. This change required minimal modification of the existing code, as the few headers that have been modified are very basic and have very few dependencies. --- .evergreen/scripts/check-preludes.py | 2 +- src/common/src/common-thread-private.h | 8 +-- src/libbson/.gitignore | 1 - src/libbson/CMakeLists.txt | 8 +-- src/libbson/libbson.rc.in | 2 +- src/libbson/src/bson/.gitignore | 2 - src/libbson/src/bson/bcon.c | 2 +- src/libbson/src/bson/bson-clock.c | 4 +- src/libbson/src/bson/bson-clock.h | 4 +- src/libbson/src/bson/bson-context.c | 4 +- src/libbson/src/bson/bson-context.h | 2 +- src/libbson/src/bson/bson-decimal128.c | 2 +- src/libbson/src/bson/bson-decimal128.h | 4 +- src/libbson/src/bson/bson-endian.h | 6 +- src/libbson/src/bson/bson-error-private.h | 4 +- src/libbson/src/bson/bson-error.h | 47 --------------- src/libbson/src/bson/bson-iso8601-private.h | 4 +- src/libbson/src/bson/bson-iso8601.c | 6 +- src/libbson/src/bson/bson-iter.c | 2 +- src/libbson/src/bson/bson-iter.h | 2 +- src/libbson/src/bson/bson-json.c | 2 +- src/libbson/src/bson/bson-keys.h | 2 +- src/libbson/src/bson/bson-oid.c | 2 +- src/libbson/src/bson/bson-oid.h | 2 +- src/libbson/src/bson/bson-private.h | 4 +- src/libbson/src/bson/bson-reader.c | 2 +- src/libbson/src/bson/bson-reader.h | 2 +- src/libbson/src/bson/bson-string.c | 6 +- src/libbson/src/bson/bson-string.h | 2 +- src/libbson/src/bson/bson-timegm-private.h | 4 +- src/libbson/src/bson/bson-timegm.c | 4 +- src/libbson/src/bson/bson-types.h | 60 ++----------------- src/libbson/src/bson/bson-utf8.c | 2 +- src/libbson/src/bson/bson-utf8.h | 2 +- src/libbson/src/bson/bson-value.c | 2 +- src/libbson/src/bson/bson-value.h | 2 +- src/libbson/src/bson/bson-vector-private.h | 4 +- src/libbson/src/bson/bson-vector.h | 4 +- src/libbson/src/bson/bson-version-functions.c | 2 +- src/libbson/src/bson/bson-writer.h | 10 +--- src/libbson/src/bson/bson.c | 2 +- src/libbson/src/bson/bson.h | 12 ++-- src/libbson/src/bson/bson_t.h | 45 ++++++++++++++ .../src/bson/{bson-compat.h => compat.h} | 9 +-- .../bson/{bson-config.h.in => config.h.in} | 4 -- .../src/bson/{bson-error.c => error.c} | 6 +- src/libbson/src/bson/error.h | 36 +++++++++++ .../src/bson/{bson-macros.h => macros.h} | 6 +- .../src/bson/{bson-memory.c => memory.c} | 4 +- .../src/bson/{bson-memory.h => memory.h} | 32 ++-------- .../bson/{bson-version.h.in => version.h.in} | 5 -- src/libbson/src/jsonsl/jsonsl.c | 2 +- src/libbson/src/jsonsl/jsonsl.h | 4 +- .../tests/test-mongoc-retryability-helpers.c | 2 +- 54 files changed, 170 insertions(+), 235 deletions(-) delete mode 100644 src/libbson/src/bson/bson-error.h create mode 100644 src/libbson/src/bson/bson_t.h rename src/libbson/src/bson/{bson-compat.h => compat.h} (97%) rename src/libbson/src/bson/{bson-config.h.in => config.h.in} (95%) rename src/libbson/src/bson/{bson-error.c => error.c} (98%) create mode 100644 src/libbson/src/bson/error.h rename src/libbson/src/bson/{bson-macros.h => macros.h} (99%) rename src/libbson/src/bson/{bson-memory.c => memory.c} (99%) rename src/libbson/src/bson/{bson-memory.h => memory.h} (63%) rename src/libbson/src/bson/{bson-version.h.in => version.h.in} (95%) diff --git a/.evergreen/scripts/check-preludes.py b/.evergreen/scripts/check-preludes.py index cd0fb8c8b09..3b5807f3707 100644 --- a/.evergreen/scripts/check-preludes.py +++ b/.evergreen/scripts/check-preludes.py @@ -39,7 +39,7 @@ }, { "name": "libbson", - "headers": list(BSON_PREFIX.glob("*.h")), + "headers": list(BSON_PREFIX.glob("bson-*.h")), "exclusions": [ BSON_PREFIX / "bson-prelude.h", BSON_PREFIX / "bson.h", diff --git a/src/common/src/common-thread-private.h b/src/common/src/common-thread-private.h index dbbb7f4839f..7247c56076f 100644 --- a/src/common/src/common-thread-private.h +++ b/src/common/src/common-thread-private.h @@ -21,11 +21,9 @@ #ifndef MONGO_C_DRIVER_COMMON_THREAD_PRIVATE_H #define MONGO_C_DRIVER_COMMON_THREAD_PRIVATE_H -#define BSON_INSIDE -#include -#include -#include -#undef BSON_INSIDE +#include +#include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/.gitignore b/src/libbson/.gitignore index d1b5f611844..14a7bfd860f 100644 --- a/src/libbson/.gitignore +++ b/src/libbson/.gitignore @@ -7,7 +7,6 @@ ChangeLog CMakeFiles CMakeCache.txt compile -config.* !config.yml configure depcomp diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index 47713afbd0d..5004d67a0bb 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -116,13 +116,13 @@ else () endif () configure_file ( - "${PROJECT_SOURCE_DIR}/src/bson/bson-config.h.in" - "${PROJECT_BINARY_DIR}/src/bson/bson-config.h" + "${PROJECT_SOURCE_DIR}/src/bson/config.h.in" + "${PROJECT_BINARY_DIR}/src/bson/config.h" ) configure_file ( - "${PROJECT_SOURCE_DIR}/src/bson/bson-version.h.in" - "${PROJECT_BINARY_DIR}/src/bson/bson-version.h" + "${PROJECT_SOURCE_DIR}/src/bson/version.h.in" + "${PROJECT_BINARY_DIR}/src/bson/version.h" ) # 8888888b. .d888 d8b d8b 888 d8b diff --git a/src/libbson/libbson.rc.in b/src/libbson/libbson.rc.in index 9015243d19d..e8f08a6d10a 100644 --- a/src/libbson/libbson.rc.in +++ b/src/libbson/libbson.rc.in @@ -2,7 +2,7 @@ // Refer: https://learn.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource #include // Defines VS_VERSION_INFO -#include // Defines BSON_MAJOR_VERSION and other version macros. +#include // Defines BSON_MAJOR_VERSION and other version macros. #define BSON_OUTPUT_BASENAME "@BSON_OUTPUT_BASENAME@" diff --git a/src/libbson/src/bson/.gitignore b/src/libbson/src/bson/.gitignore index d151f69a799..12228a2e100 100644 --- a/src/libbson/src/bson/.gitignore +++ b/src/libbson/src/bson/.gitignore @@ -1,4 +1,2 @@ -bson-config.h bson-stdint.h -bson-version.h .dirstamp diff --git a/src/libbson/src/bson/bcon.c b/src/libbson/src/bson/bcon.c index 45d19877912..dd377c47385 100644 --- a/src/libbson/src/bson/bcon.c +++ b/src/libbson/src/bson/bcon.c @@ -22,7 +22,7 @@ #include #include -#include +#include /* These stack manipulation macros are used to manage append recursion in * bcon_append_ctx_va(). They take care of some awkward dereference rules (the diff --git a/src/libbson/src/bson/bson-clock.c b/src/libbson/src/bson/bson-clock.c index 959cbe13322..1dfe6cf8fd3 100644 --- a/src/libbson/src/bson/bson-clock.c +++ b/src/libbson/src/bson/bson-clock.c @@ -14,8 +14,8 @@ * limitations under the License. */ -#include -#include +#include +#include #if defined(BSON_HAVE_CLOCK_GETTIME) diff --git a/src/libbson/src/bson/bson-clock.h b/src/libbson/src/bson/bson-clock.h index 4179152772a..e6a7cf976ab 100644 --- a/src/libbson/src/bson/bson-clock.h +++ b/src/libbson/src/bson/bson-clock.h @@ -21,8 +21,8 @@ #define BSON_CLOCK_H -#include -#include +#include +#include #include diff --git a/src/libbson/src/bson/bson-context.c b/src/libbson/src/bson/bson-context.c index b41583dd94a..1c3a7893a60 100644 --- a/src/libbson/src/bson/bson-context.c +++ b/src/libbson/src/bson/bson-context.c @@ -15,7 +15,7 @@ */ #include -#include +#include #include #include @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include diff --git a/src/libbson/src/bson/bson-context.h b/src/libbson/src/bson/bson-context.h index 882d080bbcb..67c307f3052 100644 --- a/src/libbson/src/bson/bson-context.h +++ b/src/libbson/src/bson/bson-context.h @@ -21,7 +21,7 @@ #define BSON_CONTEXT_H -#include +#include #include diff --git a/src/libbson/src/bson/bson-decimal128.c b/src/libbson/src/bson/bson-decimal128.c index 412e6b7a2af..4263295894e 100644 --- a/src/libbson/src/bson/bson-decimal128.c +++ b/src/libbson/src/bson/bson-decimal128.c @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/libbson/src/bson/bson-decimal128.h b/src/libbson/src/bson/bson-decimal128.h index 48d5f29ae98..9a4828e7956 100644 --- a/src/libbson/src/bson/bson-decimal128.h +++ b/src/libbson/src/bson/bson-decimal128.h @@ -23,8 +23,8 @@ #include -#include -#include +#include +#include #include diff --git a/src/libbson/src/bson/bson-endian.h b/src/libbson/src/bson/bson-endian.h index 8ea44153275..9c997fcaf27 100644 --- a/src/libbson/src/bson/bson-endian.h +++ b/src/libbson/src/bson/bson-endian.h @@ -20,9 +20,9 @@ #ifndef BSON_ENDIAN_H #define BSON_ENDIAN_H -#include -#include -#include +#include +#include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-error-private.h b/src/libbson/src/bson/bson-error-private.h index 0d858840122..92c11f54302 100644 --- a/src/libbson/src/bson/bson-error-private.h +++ b/src/libbson/src/bson/bson-error-private.h @@ -19,8 +19,8 @@ #ifndef BSON_ERROR_PRIVATE_H #define BSON_ERROR_PRIVATE_H -#include -#include +#include +#include #define BSON_ERROR_CATEGORY 1 diff --git a/src/libbson/src/bson/bson-error.h b/src/libbson/src/bson/bson-error.h deleted file mode 100644 index 154800f2a18..00000000000 --- a/src/libbson/src/bson/bson-error.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2009-present MongoDB, Inc. - * - * 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. - */ - -#include - - -#ifndef BSON_ERROR_H -#define BSON_ERROR_H - - -#include -#include -#include - - -BSON_BEGIN_DECLS - - -#define BSON_ERROR_JSON 1 -#define BSON_ERROR_READER 2 -#define BSON_ERROR_INVALID 3 -#define BSON_ERROR_VECTOR 4 - - -BSON_EXPORT (void) -bson_set_error (bson_error_t *error, uint32_t domain, uint32_t code, const char *format, ...) BSON_GNUC_PRINTF (4, 5); -BSON_EXPORT (char *) -bson_strerror_r (int err_code, char *buf, size_t buflen); - - -BSON_END_DECLS - - -#endif /* BSON_ERROR_H */ diff --git a/src/libbson/src/bson/bson-iso8601-private.h b/src/libbson/src/bson/bson-iso8601-private.h index 1f010419fbb..18e27b19f9a 100644 --- a/src/libbson/src/bson/bson-iso8601-private.h +++ b/src/libbson/src/bson/bson-iso8601-private.h @@ -21,8 +21,8 @@ #define BSON_ISO8601_PRIVATE_H -#include -#include +#include +#include #include diff --git a/src/libbson/src/bson/bson-iso8601.c b/src/libbson/src/bson/bson-iso8601.c index cf86cf9a1d3..3e6527f5edb 100644 --- a/src/libbson/src/bson/bson-iso8601.c +++ b/src/libbson/src/bson/bson-iso8601.c @@ -15,9 +15,9 @@ */ -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/src/libbson/src/bson/bson-iter.c b/src/libbson/src/bson/bson-iter.c index 0870396e153..586f3a459f7 100644 --- a/src/libbson/src/bson/bson-iter.c +++ b/src/libbson/src/bson/bson-iter.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/libbson/src/bson/bson-iter.h b/src/libbson/src/bson/bson-iter.h index 65b74594979..7b065cf545d 100644 --- a/src/libbson/src/bson/bson-iter.h +++ b/src/libbson/src/bson/bson-iter.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include diff --git a/src/libbson/src/bson/bson-json.c b/src/libbson/src/bson/bson-json.c index 4c394219328..094aef7ef5a 100644 --- a/src/libbson/src/bson/bson-json.c +++ b/src/libbson/src/bson/bson-json.c @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/libbson/src/bson/bson-keys.h b/src/libbson/src/bson/bson-keys.h index 08f14e8ba38..597d155c3b7 100644 --- a/src/libbson/src/bson/bson-keys.h +++ b/src/libbson/src/bson/bson-keys.h @@ -21,7 +21,7 @@ #define BSON_KEYS_H -#include +#include #include diff --git a/src/libbson/src/bson/bson-oid.c b/src/libbson/src/bson/bson-oid.c index 7f734061409..2cdc77f15e5 100644 --- a/src/libbson/src/bson/bson-oid.c +++ b/src/libbson/src/bson/bson-oid.c @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include #include diff --git a/src/libbson/src/bson/bson-oid.h b/src/libbson/src/bson/bson-oid.h index 1db8b3ea41c..efdf5f5e669 100644 --- a/src/libbson/src/bson/bson-oid.h +++ b/src/libbson/src/bson/bson-oid.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include diff --git a/src/libbson/src/bson/bson-private.h b/src/libbson/src/bson/bson-private.h index ac3d4f1ad94..ab6cd1c14d8 100644 --- a/src/libbson/src/bson/bson-private.h +++ b/src/libbson/src/bson/bson-private.h @@ -21,8 +21,8 @@ #define BSON_PRIVATE_H -#include -#include +#include +#include #include diff --git a/src/libbson/src/bson/bson-reader.c b/src/libbson/src/bson/bson-reader.c index df18232c7aa..266d9ac6957 100644 --- a/src/libbson/src/bson/bson-reader.c +++ b/src/libbson/src/bson/bson-reader.c @@ -29,7 +29,7 @@ #include #include -#include +#include typedef enum { diff --git a/src/libbson/src/bson/bson-reader.h b/src/libbson/src/bson/bson-reader.h index ab2c0a6931a..a3edbfd73f1 100644 --- a/src/libbson/src/bson/bson-reader.h +++ b/src/libbson/src/bson/bson-reader.h @@ -21,7 +21,7 @@ #define BSON_READER_H -#include +#include #include #include diff --git a/src/libbson/src/bson/bson-string.c b/src/libbson/src/bson/bson-string.c index 97f9da202d3..7a79948d821 100644 --- a/src/libbson/src/bson/bson-string.c +++ b/src/libbson/src/bson/bson-string.c @@ -18,12 +18,12 @@ #include #include -#include -#include +#include +#include #include #include #include -#include +#include #include #ifdef BSON_HAVE_STRINGS_H diff --git a/src/libbson/src/bson/bson-string.h b/src/libbson/src/bson/bson-string.h index ced4e9d2354..265186ef29a 100644 --- a/src/libbson/src/bson/bson-string.h +++ b/src/libbson/src/bson/bson-string.h @@ -23,7 +23,7 @@ #include -#include +#include #include diff --git a/src/libbson/src/bson/bson-timegm-private.h b/src/libbson/src/bson/bson-timegm-private.h index 0490d012a83..21d2784ecfa 100644 --- a/src/libbson/src/bson/bson-timegm-private.h +++ b/src/libbson/src/bson/bson-timegm-private.h @@ -21,8 +21,8 @@ #define BSON_TIMEGM_PRIVATE_H -#include -#include +#include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-timegm.c b/src/libbson/src/bson/bson-timegm.c index 8ac072500bb..e6778fac830 100644 --- a/src/libbson/src/bson/bson-timegm.c +++ b/src/libbson/src/bson/bson-timegm.c @@ -10,8 +10,8 @@ ** and struct tm by A. Jesse Jiryu Davis for MongoDB, Inc. */ -#include -#include +#include +#include #include #include diff --git a/src/libbson/src/bson/bson-types.h b/src/libbson/src/bson/bson-types.h index 57dc64c5fbd..89d709412ca 100644 --- a/src/libbson/src/bson/bson-types.h +++ b/src/libbson/src/bson/bson-types.h @@ -24,10 +24,12 @@ #include #include -#include -#include -#include +#include +#include +#include #include +#include +#include BSON_BEGIN_DECLS @@ -103,45 +105,6 @@ typedef struct _bson_context_t bson_context_t; typedef struct _bson_json_opts_t bson_json_opts_t; -/** - * bson_t: - * - * This structure manages a buffer whose contents are a properly formatted - * BSON document. You may perform various transforms on the BSON documents. - * Additionally, it can be iterated over using bson_iter_t. - * - * See bson_iter_init() for iterating the contents of a bson_t. - * - * When building a bson_t structure using the various append functions, - * memory allocations may occur. That is performed using power of two - * allocations and realloc(). - * - * See http://bsonspec.org for the BSON document spec. - * - * This structure is meant to fit in two sequential 64-byte cachelines. - */ -BSON_ALIGNED_BEGIN (BSON_ALIGN_OF_PTR) typedef struct _bson_t { - uint32_t flags; /* Internal flags for the bson_t. */ - uint32_t len; /* Length of BSON data. */ - uint8_t padding[120]; /* Padding for stack allocation. */ -} bson_t BSON_ALIGNED_END (BSON_ALIGN_OF_PTR); - -/** - * BSON_INITIALIZER: - * - * This macro can be used to initialize a #bson_t structure on the stack - * without calling bson_init(). - * - * |[ - * bson_t b = BSON_INITIALIZER; - * ]| - */ -#define BSON_INITIALIZER {3, 5, {5}} - - -BSON_STATIC_ASSERT2 (bson_t, sizeof (bson_t) == 128); - - /** * bson_oid_t: * @@ -469,19 +432,6 @@ typedef struct { void *padding[7]; } bson_visitor_t; -#define BSON_ERROR_BUFFER_SIZE 503 - -BSON_ALIGNED_BEGIN (BSON_ALIGN_OF_PTR) // Aligned for backwards-compatibility. -typedef struct _bson_error_t { - uint32_t domain; - uint32_t code; - char message[BSON_ERROR_BUFFER_SIZE]; - uint8_t reserved; // For internal use only! -} bson_error_t BSON_ALIGNED_END (BSON_ALIGN_OF_PTR); - - -BSON_STATIC_ASSERT2 (error_t, sizeof (bson_error_t) == 512); - /** * bson_next_power_of_two: diff --git a/src/libbson/src/bson/bson-utf8.c b/src/libbson/src/bson/bson-utf8.c index 921e3538894..3df77a5f8e7 100644 --- a/src/libbson/src/bson/bson-utf8.c +++ b/src/libbson/src/bson/bson-utf8.c @@ -17,7 +17,7 @@ #include -#include +#include #include #include #include diff --git a/src/libbson/src/bson/bson-utf8.h b/src/libbson/src/bson/bson-utf8.h index fc58d3c5a72..591784fcd7f 100644 --- a/src/libbson/src/bson/bson-utf8.h +++ b/src/libbson/src/bson/bson-utf8.h @@ -21,7 +21,7 @@ #define BSON_UTF8_H -#include +#include #include diff --git a/src/libbson/src/bson/bson-value.c b/src/libbson/src/bson/bson-value.c index 3917de4bde1..3a5eee91e62 100644 --- a/src/libbson/src/bson/bson-value.c +++ b/src/libbson/src/bson/bson-value.c @@ -15,7 +15,7 @@ */ -#include +#include #include #include #include diff --git a/src/libbson/src/bson/bson-value.h b/src/libbson/src/bson/bson-value.h index afb11a5006b..25c4ae7fac9 100644 --- a/src/libbson/src/bson/bson-value.h +++ b/src/libbson/src/bson/bson-value.h @@ -21,7 +21,7 @@ #define BSON_VALUE_H -#include +#include #include diff --git a/src/libbson/src/bson/bson-vector-private.h b/src/libbson/src/bson/bson-vector-private.h index 0882dead92d..19c68c55596 100644 --- a/src/libbson/src/bson/bson-vector-private.h +++ b/src/libbson/src/bson/bson-vector-private.h @@ -19,8 +19,8 @@ #ifndef BSON_VECTOR_PRIVATE_H #define BSON_VECTOR_PRIVATE_H -#include -#include +#include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-vector.h b/src/libbson/src/bson/bson-vector.h index 5363bf0fdcb..0d855f7b379 100644 --- a/src/libbson/src/bson/bson-vector.h +++ b/src/libbson/src/bson/bson-vector.h @@ -19,8 +19,8 @@ #ifndef BSON_VECTOR_H #define BSON_VECTOR_H -#include -#include +#include +#include #include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-version-functions.c b/src/libbson/src/bson/bson-version-functions.c index 55de41026c9..5efb6c780c5 100644 --- a/src/libbson/src/bson/bson-version-functions.c +++ b/src/libbson/src/bson/bson-version-functions.c @@ -15,7 +15,7 @@ */ -#include +#include #include diff --git a/src/libbson/src/bson/bson-writer.h b/src/libbson/src/bson/bson-writer.h index 6308ee279ba..830e6ae3980 100644 --- a/src/libbson/src/bson/bson-writer.h +++ b/src/libbson/src/bson/bson-writer.h @@ -16,17 +16,16 @@ #include - #ifndef BSON_WRITER_H #define BSON_WRITER_H +#include +#include -#include - +#include BSON_BEGIN_DECLS - /** * bson_writer_t: * @@ -40,7 +39,6 @@ BSON_BEGIN_DECLS */ typedef struct _bson_writer_t bson_writer_t; - BSON_EXPORT (bson_writer_t *) bson_writer_new (uint8_t **buf, size_t *buflen, size_t offset, bson_realloc_func realloc_func, void *realloc_func_ctx); BSON_EXPORT (void) @@ -54,8 +52,6 @@ bson_writer_end (bson_writer_t *writer); BSON_EXPORT (void) bson_writer_rollback (bson_writer_t *writer); - BSON_END_DECLS - #endif /* BSON_WRITER_H */ diff --git a/src/libbson/src/bson/bson.c b/src/libbson/src/bson/bson.c index eb96252c2ff..41e30f7299e 100644 --- a/src/libbson/src/bson/bson.c +++ b/src/libbson/src/bson/bson.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/libbson/src/bson/bson.h b/src/libbson/src/bson/bson.h index 0cc4eb6308c..b90610606b4 100644 --- a/src/libbson/src/bson/bson.h +++ b/src/libbson/src/bson/bson.h @@ -20,21 +20,20 @@ #define BSON_INSIDE -#include +#include #include #include -#include -#include +#include +#include #include #include #include -#include +#include #include #include #include -#include #include #include #include @@ -42,10 +41,11 @@ #include #include #include -#include #include #include #include +#include +#include #undef BSON_INSIDE diff --git a/src/libbson/src/bson/bson_t.h b/src/libbson/src/bson/bson_t.h new file mode 100644 index 00000000000..2095ccf2b78 --- /dev/null +++ b/src/libbson/src/bson/bson_t.h @@ -0,0 +1,45 @@ +#ifndef BSON_BSON_T_H_INCLUDED +#define BSON_BSON_T_H_INCLUDED + +#include + +#include + +/** + * bson_t: + * + * This structure manages a buffer whose contents are a properly formatted + * BSON document. You may perform various transforms on the BSON documents. + * Additionally, it can be iterated over using bson_iter_t. + * + * See bson_iter_init() for iterating the contents of a bson_t. + * + * When building a bson_t structure using the various append functions, + * memory allocations may occur. That is performed using power of two + * allocations and realloc(). + * + * See http://bsonspec.org for the BSON document spec. + * + * This structure is meant to fit in two sequential 64-byte cachelines. + */ +BSON_ALIGNED_BEGIN (BSON_ALIGN_OF_PTR) typedef struct _bson_t { + uint32_t flags; /* Internal flags for the bson_t. */ + uint32_t len; /* Length of BSON data. */ + uint8_t padding[120]; /* Padding for stack allocation. */ +} bson_t BSON_ALIGNED_END (BSON_ALIGN_OF_PTR); + +/** + * BSON_INITIALIZER: + * + * This macro can be used to initialize a #bson_t structure on the stack + * without calling bson_init(). + * + * |[ + * bson_t b = BSON_INITIALIZER; + * ]| + */ +#define BSON_INITIALIZER {3, 5, {5}} + +BSON_STATIC_ASSERT2 (bson_t, sizeof (bson_t) == 128); + +#endif // BSON_BSON_T_H_INCLUDED diff --git a/src/libbson/src/bson/bson-compat.h b/src/libbson/src/bson/compat.h similarity index 97% rename from src/libbson/src/bson/bson-compat.h rename to src/libbson/src/bson/compat.h index 1a719cc359b..50420a92ecc 100644 --- a/src/libbson/src/bson/bson-compat.h +++ b/src/libbson/src/bson/compat.h @@ -14,9 +14,6 @@ * limitations under the License. */ -#include - - #ifndef BSON_COMPAT_H #define BSON_COMPAT_H @@ -31,8 +28,8 @@ #endif #endif -#include -#include +#include +#include #ifdef BSON_OS_WIN32 @@ -64,7 +61,7 @@ #endif -#include +#include #include diff --git a/src/libbson/src/bson/bson-config.h.in b/src/libbson/src/bson/config.h.in similarity index 95% rename from src/libbson/src/bson/bson-config.h.in rename to src/libbson/src/bson/config.h.in index e9011549bf2..306d35c11e7 100644 --- a/src/libbson/src/bson/bson-config.h.in +++ b/src/libbson/src/bson/config.h.in @@ -14,10 +14,6 @@ * limitations under the License. */ -#if !defined(BSON_INSIDE) && !defined(BSON_COMPILATION) -#error "Only can be included directly." -#endif - #ifndef BSON_CONFIG_H #define BSON_CONFIG_H diff --git a/src/libbson/src/bson/bson-error.c b/src/libbson/src/bson/error.c similarity index 98% rename from src/libbson/src/bson/bson-error.c rename to src/libbson/src/bson/error.c index acefa7b5958..ffdbe89685f 100644 --- a/src/libbson/src/bson/bson-error.c +++ b/src/libbson/src/bson/error.c @@ -18,10 +18,10 @@ #include #include -#include -#include +#include +#include #include -#include +#include #include #include diff --git a/src/libbson/src/bson/error.h b/src/libbson/src/bson/error.h new file mode 100644 index 00000000000..cdcf105fa82 --- /dev/null +++ b/src/libbson/src/bson/error.h @@ -0,0 +1,36 @@ +#ifndef BSON_ERROR_T_INCLUDED +#define BSON_ERROR_T_INCLUDED + +#include +#include + +BSON_BEGIN_DECLS + +#define BSON_ERROR_BUFFER_SIZE 503 + +BSON_ALIGNED_BEGIN (BSON_ALIGN_OF_PTR) // Aligned for backwards-compatibility. +typedef struct _bson_error_t { + uint32_t domain; + uint32_t code; + char message[BSON_ERROR_BUFFER_SIZE]; + uint8_t reserved; // For internal use only! +} bson_error_t BSON_ALIGNED_END (BSON_ALIGN_OF_PTR); + + +BSON_STATIC_ASSERT2 (error_t, sizeof (bson_error_t) == 512); + +#define BSON_ERROR_JSON 1 +#define BSON_ERROR_READER 2 +#define BSON_ERROR_INVALID 3 +#define BSON_ERROR_VECTOR 4 + +BSON_EXPORT (void) +bson_set_error (bson_error_t *error, uint32_t domain, uint32_t code, const char *format, ...) BSON_GNUC_PRINTF (4, 5); + +BSON_EXPORT (char *) +bson_strerror_r (int err_code, char *buf, size_t buflen); + +BSON_END_DECLS + + +#endif // BSON_ERROR_T_INCLUDED diff --git a/src/libbson/src/bson/bson-macros.h b/src/libbson/src/bson/macros.h similarity index 99% rename from src/libbson/src/bson/bson-macros.h rename to src/libbson/src/bson/macros.h index 65b3ab36e57..d47d2307b2e 100644 --- a/src/libbson/src/bson/bson-macros.h +++ b/src/libbson/src/bson/macros.h @@ -14,12 +14,10 @@ * limitations under the License. */ -#include - - #ifndef BSON_MACROS_H #define BSON_MACROS_H +#include #include #include @@ -28,8 +26,6 @@ #include #endif -#include - #if BSON_OS == 1 #define BSON_OS_UNIX diff --git a/src/libbson/src/bson/bson-memory.c b/src/libbson/src/bson/memory.c similarity index 99% rename from src/libbson/src/bson/bson-memory.c rename to src/libbson/src/bson/memory.c index 71ec4610127..b719a8d8e60 100644 --- a/src/libbson/src/bson/bson-memory.c +++ b/src/libbson/src/bson/memory.c @@ -20,8 +20,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/src/libbson/src/bson/bson-memory.h b/src/libbson/src/bson/memory.h similarity index 63% rename from src/libbson/src/bson/bson-memory.h rename to src/libbson/src/bson/memory.h index 1d8e2e0d50a..4100d793be4 100644 --- a/src/libbson/src/bson/bson-memory.h +++ b/src/libbson/src/bson/memory.h @@ -1,28 +1,7 @@ -/* - * Copyright 2009-present MongoDB, Inc. - * - * 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. - */ +#ifndef BSON_MEMORY_H_INCLUDED +#define BSON_MEMORY_H_INCLUDED -#include - - -#ifndef BSON_MEMORY_H -#define BSON_MEMORY_H - - -#include -#include +#include BSON_BEGIN_DECLS @@ -30,7 +9,6 @@ BSON_BEGIN_DECLS typedef void *(BSON_CALL *bson_realloc_func) (void *mem, size_t num_bytes, void *ctx); - typedef struct _bson_mem_vtable_t { void *(BSON_CALL *malloc) (size_t num_bytes); void *(BSON_CALL *calloc) (size_t n_members, size_t num_bytes); @@ -66,8 +44,6 @@ bson_zero_free (void *mem, size_t size); #define BSON_ALIGNED_ALLOC(T) ((T *) (bson_aligned_alloc (BSON_ALIGNOF (T), sizeof (T)))) #define BSON_ALIGNED_ALLOC0(T) ((T *) (bson_aligned_alloc0 (BSON_ALIGNOF (T), sizeof (T)))) - BSON_END_DECLS - -#endif /* BSON_MEMORY_H */ +#endif // BSON_MEMORY_H_INCLUDED diff --git a/src/libbson/src/bson/bson-version.h.in b/src/libbson/src/bson/version.h.in similarity index 95% rename from src/libbson/src/bson/bson-version.h.in rename to src/libbson/src/bson/version.h.in index 4d9fcac4893..8b4c248eaa3 100644 --- a/src/libbson/src/bson/bson-version.h.in +++ b/src/libbson/src/bson/version.h.in @@ -14,11 +14,6 @@ * limitations under the License. */ - -#if !defined(BSON_INSIDE) && !defined(BSON_COMPILATION) -#error "Only can be included directly." -#endif - // clang-format off #ifndef BSON_VERSION_H diff --git a/src/libbson/src/jsonsl/jsonsl.c b/src/libbson/src/jsonsl/jsonsl.c index 730c3166ae6..2fbdb5dcbb1 100644 --- a/src/libbson/src/jsonsl/jsonsl.c +++ b/src/libbson/src/jsonsl/jsonsl.c @@ -4,7 +4,7 @@ */ #include -#include +#include #include #include diff --git a/src/libbson/src/jsonsl/jsonsl.h b/src/libbson/src/jsonsl/jsonsl.h index 4c3fbbfd62e..e6058674010 100644 --- a/src/libbson/src/jsonsl/jsonsl.h +++ b/src/libbson/src/jsonsl/jsonsl.h @@ -12,8 +12,8 @@ #ifndef JSONSL_H_ #define JSONSL_H_ -#include -#include +#include +#include #include diff --git a/src/libmongoc/tests/test-mongoc-retryability-helpers.c b/src/libmongoc/tests/test-mongoc-retryability-helpers.c index f6407528228..4f2532b9f9a 100644 --- a/src/libmongoc/tests/test-mongoc-retryability-helpers.c +++ b/src/libmongoc/tests/test-mongoc-retryability-helpers.c @@ -1,6 +1,6 @@ #include "test-mongoc-retryability-helpers.h" -#include +#include #include From ab7c733312fd8456a68ec53b1d181b99471dfaf5 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 1 Jul 2025 19:06:46 -0600 Subject: [PATCH 02/17] Fix C++ and C compatibility in some header files --- src/common/src/common-string-private.h | 2 +- src/common/src/mlib/config.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/common/src/common-string-private.h b/src/common/src/common-string-private.h index fd066c15a47..1015bd0de77 100644 --- a/src/common/src/common-string-private.h +++ b/src/common/src/common-string-private.h @@ -483,7 +483,7 @@ mcommon_string_append_overflow (mcommon_string_append_t *append) */ bool mcommon_string_append_selected_chars (mcommon_string_append_t *append, - const char *template, + const char *template_, const char *selector, size_t selector_len); diff --git a/src/common/src/mlib/config.h b/src/common/src/mlib/config.h index 2b7ed9045d2..6a1e45275bf 100644 --- a/src/common/src/mlib/config.h +++ b/src/common/src/mlib/config.h @@ -256,24 +256,24 @@ #define mlib_diagnostic_push() \ MLIB_IF_GNU_LIKE (mlib_pragma (GCC diagnostic push);) \ MLIB_IF_MSVC (mlib_pragma (warning (push));) \ - mlib_static_assert (true, "") + mlib_static_assert (1, "") #define mlib_diagnostic_pop() \ MLIB_IF_GNU_LIKE (mlib_pragma (GCC diagnostic pop);) \ MLIB_IF_MSVC (mlib_pragma (warning (pop));) \ - mlib_static_assert (true, "") + mlib_static_assert (1, "") #define mlib_gcc_warning_disable(Warning) \ MLIB_IF_GCC (mlib_pragma (GCC diagnostic ignored Warning);) \ - mlib_static_assert (true, "") + mlib_static_assert (1, "") #define mlib_gnu_warning_disable(Warning) \ MLIB_IF_GNU_LIKE (mlib_pragma (GCC diagnostic ignored Warning);) \ - mlib_static_assert (true, "") + mlib_static_assert (1, "") #define mlib_msvc_warning(...) \ MLIB_IF_MSVC (mlib_pragma (warning (__VA_ARGS__));) \ - mlib_static_assert (true, "") + mlib_static_assert (1, "") /** * @brief Attribute macro that forces the function to be inlined at all call sites. @@ -366,6 +366,6 @@ */ #define mlib_disable_unused_parameter_warnings() \ MLIB_IF_GNU_LIKE (mlib_gnu_warning_disable ("-Wunused-parameter");) \ - MLIB_IF_MSVC (mlib_msvc_warning (disable : 4100);) mlib_static_assert (true, "") + MLIB_IF_MSVC (mlib_msvc_warning (disable : 4100);) mlib_static_assert (1, "") #endif // MLIB_CONFIG_H_INCLUDED From 3f9d51ba4e8c938ec9284ce34b8fb29e384a5832 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 1 Jul 2025 19:08:34 -0600 Subject: [PATCH 03/17] Add CMake code for header verification. This adds a CMake utility based around VERIFY_INTERFACE_HEADER_SETS to check that certain headers can be included directly in a translation unit without any prerequesits, in either C or C++ code. This verification only concerns itself with headers that we have already made part of the public API. Private header files and header files that are not-yet-sanitized are not checked by this process. The verification does not yet happen automatically. It is only enabled for CMake 3.24 or newer, and requires the dev/CI to build the special linting target the CMake generates. --- CMakeLists.txt | 1 + build/cmake/VerifyHeaders.cmake | 99 +++++++++++++++++++++++++++++++++ build/cmake/empty.c | 2 + build/cmake/empty.cpp | 2 + src/libbson/CMakeLists.txt | 19 +++++++ src/libmongoc/CMakeLists.txt | 17 ++++++ 6 files changed, 140 insertions(+) create mode 100644 build/cmake/VerifyHeaders.cmake create mode 100644 build/cmake/empty.c create mode 100644 build/cmake/empty.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b2f926510e5..a044cfb0b65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ include(FeatureSummary) include (MongoSettings) include (MongoPlatform) include (GeneratePkgConfig) +include (VerifyHeaders) # Subcomponents: mongo_bool_setting(ENABLE_MONGOC "Enable the build of libmongoc libraries (The MongoDB C database driver)") diff --git a/build/cmake/VerifyHeaders.cmake b/build/cmake/VerifyHeaders.cmake new file mode 100644 index 00000000000..59bf957e7dc --- /dev/null +++ b/build/cmake/VerifyHeaders.cmake @@ -0,0 +1,99 @@ +#[==[ +Add header verification targets for given headers: + + mongo_verify_headers( + + [USES_LIBRARIES [ ...]] + [HEADERS [ ...]] + [EXCLUDE_REGEX [ ...]] + ) + +Here `` is an arbitrary string that is used to qualify the internal target +created for the verification. The `` expressions are used to automatically +collect sources files (relative to the current source directory). All files +collected by `` must live within the current source directory. + +After collecting sources according to the `` patterns, sources are +excluded if they filepath contains any substring that matches any regular +expression in the `` list. Each `` is tested against the +relative path to the header file that was found by ``, and not the +absolute path to the file file. + +The header verification targets are compiled according to the usage requirements +from all `` arguments. + +]==] +function(mongo_verify_headers tag) + list(APPEND CMAKE_MESSAGE_CONTEXT "${CMAKE_CURRENT_FUNCTION}(${tag})") + cmake_parse_arguments( + PARSE_ARGV 1 arg + "" # No flags + "" # No args + "HEADERS;EXCLUDE_REGEX;USE_LIBRARIES" # List args + ) + if(arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unknown arguments: ${arg_UNPARSED_ARGUMENTS}") + endif() + + # Collect headers according to our patterns + set(headers_to_verify) + foreach(pattern IN LISTS arg_HEADERS) + # Use a recursive glob from the current source dir: + file(GLOB_RECURSE more + # Make the paths relative to the calling dir to prevent parent paths + # from interfering with the exclusion regex logic below + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" + # We need to re-run configuration if any files are added/removed + CONFIGURE_DEPENDS + "${pattern}" + ) + # Warn if this pattern didn't match anything. It is probably a mistake + # in the caller's argument list. + if(NOT more) + message(WARNING "Globbing pattern “${pattern}” did not match any files") + endif() + list(APPEND headers_to_verify ${more}) + endforeach() + + # Excluce anything that matches any exclusion regex + foreach(pattern IN LISTS arg_EXCLUDE_REGEX) + list(FILTER headers_to_verify EXCLUDE REGEX "${pattern}") + endforeach() + + # Drop duplicates since globs may grab a file more than once + list(REMOVE_DUPLICATES headers_to_verify) + list(SORT headers_to_verify) + foreach(file IN LISTS headers_to_verify) + message(DEBUG "Verify header file: ${file}") + endforeach() + + # We create two targets: One for C and one for C++ + set(c_target ${tag}-verify-headers-c) + set(cxx_target ${tag}-verify-headers-cxx) + message(DEBUG "Defining header verification targets “${c_target}” and “${cxx_target}”") + # Create object libraries. They will only have one empty compiled source file. + # The source file language will tell CMake how to verify the associated header files. + add_library(${c_target} OBJECT "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/empty.c") + add_library(${cxx_target} OBJECT "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/empty.cpp") + # Define the file set + target_sources(${c_target} PUBLIC FILE_SET HEADERS) + target_sources(${cxx_target} PUBLIC FILE_SET HEADERS) + # Populate the properies and file sets + set_target_properties(${c_target} ${cxx_target} PROPERTIES + # The main header file set: + HEADER_SET "${headers_to_verify}" + # Enable header verification: + VERIFY_INTERFACE_HEADER_SETS TRUE + # Add the usage requirements that propagate to the generated compilation + # rules: + INTERFACE_LINK_LIBRARIES "${arg_USE_LIBRARIES}" + ) +endfunction() + +#[[ +Variable set to TRUE if-and-only-if CMake supports header verification. +]] +set(MONGO_CAN_VERIFY_HEADERS FALSE) +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24") + set(MONGO_CAN_VERIFY_HEADERS TRUE) +endif() diff --git a/build/cmake/empty.c b/build/cmake/empty.c new file mode 100644 index 00000000000..f0c06f6c738 --- /dev/null +++ b/build/cmake/empty.c @@ -0,0 +1,2 @@ +/* This is an empty placeholder file use for miscellaneous build system tasks */ +#include diff --git a/build/cmake/empty.cpp b/build/cmake/empty.cpp new file mode 100644 index 00000000000..40b0c6decdf --- /dev/null +++ b/build/cmake/empty.cpp @@ -0,0 +1,2 @@ +// This is an empty placeholder file use for miscellaneous build system tasks +#include diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index 5004d67a0bb..efed858a7b7 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -173,6 +173,25 @@ if(ENABLE_STATIC) # User wants static libs to use PIC code. set_property(TARGET bson_static PROPERTY POSITION_INDEPENDENT_CODE TRUE) endif() + + if(MONGO_CAN_VERIFY_HEADERS) + mongo_verify_headers( + bson + USE_LIBRARIES bson::static + HEADERS + # Grab all headers + "src/*.h" + EXCLUDE_REGEX + # No -private headers + "-private\\.h" + # Ignore all headers that start with "bson-", as they have not + # been sanitized for direct inclusion. + "bson/bson-.*\\.h" + # Don't check jsonsl.h or bcon.h either + "jsonsl\\.h" + "bcon\\.h" + ) + endif() endif() if(ENABLE_SHARED) diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 1a0a8333285..a1c25e9904d 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -971,6 +971,23 @@ if (MONGOC_ENABLE_STATIC_BUILD) if(MONGOC_ENABLE_STATIC_INSTALL) mongo_generate_pkg_config (mongoc_static FILENAME mongoc${PROJECT_VERSION_MAJOR}-static.pc INSTALL) endif() + + if(MONGO_CAN_VERIFY_HEADERS) + mongo_verify_headers( + mongoc + USE_LIBRARIES mongoc::static + HEADERS "src/*.h" + EXCLUDE_REGEX + # Ignore all headers that start with "mongoc-", as they have not + # been sanitized for direct inclusion. + "mongoc/mongoc-.*\\.h" + # Other private headers that aren't for public consumption: + "/mcd-" + "service-gcp\\.h" + "uthash\\.h" + "utlist\\.h" + ) + endif() endif () From 38bad5d4ece0676a687eaf873b432297ec83ff08 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 1 Jul 2025 19:42:51 -0600 Subject: [PATCH 04/17] Earthly target and EVG tasks to run header verification --- .../config_generator/components/earthly.py | 9 +- .../generated_configs/legacy-config.yml | 1 + .evergreen/generated_configs/tasks.yml | 16 ++++ .../evergreen_config_lib/variants.py | 7 +- Earthfile | 87 ++++++++++++++----- docs/dev/earthly.rst | 15 ++++ tools/build.earth | 6 ++ 7 files changed, 116 insertions(+), 25 deletions(-) diff --git a/.evergreen/config_generator/components/earthly.py b/.evergreen/config_generator/components/earthly.py index 4dac11f31dc..67dfd739ac7 100644 --- a/.evergreen/config_generator/components/earthly.py +++ b/.evergreen/config_generator/components/earthly.py @@ -38,7 +38,7 @@ "Valid options for the SASL configuration parameter" TLSOption = Literal["OpenSSL", "off"] "Options for the TLS backend configuration parameter (AKA 'ENABLE_SSL')" -CxxVersion = Literal["none"] # TODO: Once CXX-3103 is released, add latest C++ release tag. +CxxVersion = Literal["none"] # TODO: Once CXX-3103 is released, add latest C++ release tag. "C++ driver refs that are under CI test" # A separator character, since we cannot use whitespace @@ -266,6 +266,13 @@ def tasks() -> Iterable[EvgTask]: if task is not None: yield task + yield EvgTask( + name="verify-headers", + commands=[earthly_exec(kind="test", target="verify-headers")], + tags=["pr-merge-gate"], + run_on=CONTAINER_RUN_DISTROS, + ) + def variants() -> Iterable[BuildVariant]: yield from (ev.as_evg_variant() for ev in all_possible(EarthlyVariant)) diff --git a/.evergreen/generated_configs/legacy-config.yml b/.evergreen/generated_configs/legacy-config.yml index 69393956836..09180173e74 100644 --- a/.evergreen/generated_configs/legacy-config.yml +++ b/.evergreen/generated_configs/legacy-config.yml @@ -16243,6 +16243,7 @@ buildvariants: - link-with-cmake - link-with-cmake-ssl - link-with-cmake-snappy + - verify-headers - name: link-with-cmake-mac distros: - macos-14-arm64 diff --git a/.evergreen/generated_configs/tasks.yml b/.evergreen/generated_configs/tasks.yml index b5abdbc7d7f..fddb7425014 100644 --- a/.evergreen/generated_configs/tasks.yml +++ b/.evergreen/generated_configs/tasks.yml @@ -6420,3 +6420,19 @@ tasks: - func: bootstrap-mongo-orchestration - func: run-simple-http-server - func: run-tests + - name: verify-headers + run_on: + - amazon2 + - debian11-large + - debian12-large + - ubuntu2204-large + - ubuntu2404-large + tags: [pr-merge-gate] + commands: + - command: subprocess.exec + type: test + params: + binary: ./tools/earthly.sh + working_dir: mongoc + args: + - +verify-headers diff --git a/.evergreen/legacy_config_generator/evergreen_config_lib/variants.py b/.evergreen/legacy_config_generator/evergreen_config_lib/variants.py index f6a65e62e80..1f0318d5841 100644 --- a/.evergreen/legacy_config_generator/evergreen_config_lib/variants.py +++ b/.evergreen/legacy_config_generator/evergreen_config_lib/variants.py @@ -50,6 +50,7 @@ def days(n: int) -> int: "link-with-cmake", "link-with-cmake-ssl", "link-with-cmake-snappy", + "verify-headers", OD([("name", "link-with-cmake-mac"), ("distros", ["macos-14-arm64"])]), OD([("name", "link-with-cmake-windows"), ("distros", ["windows-vsCurrent-large"])]), OD([("name", "link-with-cmake-windows-ssl"), ("distros", ["windows-vsCurrent-large"])]), @@ -84,7 +85,7 @@ def days(n: int) -> int: "build-and-run-authentication-tests-openssl-1.0.1", "build-and-run-authentication-tests-openssl-1.0.2", "build-and-run-authentication-tests-openssl-1.1.0", - "build-and-run-authentication-tests-openssl-1.0.1-fips" + "build-and-run-authentication-tests-openssl-1.0.1-fips", ], {}, ), @@ -363,7 +364,7 @@ def days(n: int) -> int: "name": "ocsp-openssl-1.0.1", "execution_tasks": [".ocsp-openssl-1.0.1"], }, - ] + ], ), Variant( "packaging", @@ -387,7 +388,7 @@ def days(n: int) -> int: ".versioned-api .5.0", ".versioned-api .6.0", ".versioned-api .7.0", - ".versioned-api .8.0" + ".versioned-api .8.0", ], {}, ), diff --git a/Earthfile b/Earthfile index 6d668088f7a..b527e21ffba 100644 --- a/Earthfile +++ b/Earthfile @@ -6,25 +6,11 @@ IMPORT ./tools/ AS tools # For target names, descriptions, and build parameters, run the "doc" Earthly subcommand. # Example use: +build --env=u22 --sasl=off --tls=OpenSSL --c_compiler=gcc -# build : -# Build libmongoc and libbson using the specified environment. -# -# The --env argument specifies the build environment among the `+env.xyz` environment -# targets, using --purpose=build for the build environment. Refer to the target -# list for a list of available build environments. -build: - # env is an argument - ARG --required env - FROM --pass-args +env.$env --purpose=build - # The configuration to be built - ARG config=RelWithDebInfo - # The prefix at which to install the built result - ARG install_prefix=/opt/mongo-c-driver - # Build configuration parameters. Will be case-normalized for CMake usage. - ARG --required sasl - ARG --required tls - LET source_dir=/opt/mongoc/source - LET build_dir=/opt/mongoc/build +# COPY_SOURCE : +# Copy source files required for the build into the specified "--into" directory +COPY_SOURCE: + COMMAND + ARG --required into COPY --dir \ build/ \ CMakeLists.txt \ @@ -34,8 +20,16 @@ build: src/ \ THIRD_PARTY_NOTICES \ VERSION_CURRENT \ - "$source_dir" - ENV CCACHE_HOME=/root/.cache/ccache + "$into" + +# CONFIGURE : +# Configure the project in $source_dir into $build_dir with a common set of configuration options +CONFIGURE: + COMMAND + ARG --required source_dir + ARG --required build_dir + ARG --required tls + ARG --required sasl RUN cmake -S "$source_dir" -B "$build_dir" -G "Ninja Multi-Config" \ -D ENABLE_MAINTAINER_FLAGS=ON \ -D ENABLE_SHM_COUNTERS=ON \ @@ -47,6 +41,29 @@ build: -D ENABLE_COVERAGE=ON \ -D ENABLE_DEBUG_ASSERTIONS=ON \ -Werror + +# build : +# Build libmongoc and libbson using the specified environment. +# +# The --env argument specifies the build environment among the `+env.xyz` environment +# targets, using --purpose=build for the build environment. Refer to the target +# list for a list of available build environments. +build: + # env is an argument + ARG --required env + FROM --pass-args +env.$env --purpose=build + # The configuration to be built + ARG config=RelWithDebInfo + # The prefix at which to install the built result + ARG install_prefix=/opt/mongo-c-driver + # Build configuration parameters. Will be case-normalized for CMake usage. + ARG --required sasl + ARG --required tls + LET source_dir=/opt/mongoc/source + LET build_dir=/opt/mongoc/build + DO +COPY_SOURCE --into=$source_dir + ENV CCACHE_HOME=/root/.cache/ccache + DO +CONFIGURE --source_dir=$source_dir --build_dir=$build_dir RUN --mount=type=cache,target=$CCACHE_HOME \ env CCACHE_BASE="$source_dir" \ cmake --build $build_dir --config $config @@ -396,6 +413,34 @@ vcpkg-base: COPY src/libmongoc/examples/cmake/vcpkg/ $src_dir WORKDIR $src_dir +# verify-headers : +# Execute CMake header verification on the sources +# +# See `earthly.rst` for more details. +verify-headers: + # We test against multiple different platforms, because glibc/musl versions may + # rearrange their header contents and requirements, so we want to check against as + # many as possible. + BUILD +do-verify-headers-impl \ + --from +env.alpine3.19 \ + --from +env.u22 \ + --from +env.centos7 \ + --sasl=off --tls=off --cxx_compiler=gcc --c_compiler=gcc + +do-verify-headers-impl: + ARG --required from + # We don't really care about the specifics of the build env/settings, so set some + # reasonable defaults so the caller doesn't need to specify. In the future, it is + # possible that we will need to test other environments and build settings. + FROM --pass-args "$from" --purpose=build + # Add C++ so we can test as C++ headers + DO --pass-args tools+ADD_CXX_COMPILER + DO +COPY_SOURCE --into=/s + DO --pass-args +CONFIGURE --source_dir /s --build_dir /s/_build + # The "all_verify_interface_header_sets" target is created automatically + # by CMake for the VERIFY_INTERFACE_HEADER_SETS target property. + RUN cmake --build /s/_build --target all_verify_interface_header_sets + # run : # Run one or more targets simultaneously. # diff --git a/docs/dev/earthly.rst b/docs/dev/earthly.rst index d216fc81c47..dc1144d5b93 100644 --- a/docs/dev/earthly.rst +++ b/docs/dev/earthly.rst @@ -284,6 +284,21 @@ enumerated using ``earthly ls`` or ``earthly doc`` in the root of the repository See: `SNYK_TOKEN` +.. program:: +verify-headers +.. earthly-target:: +verify-headers + + This runs `CMake's header verification`__ on the library sources, to ensure + that the public API headers can be ``#include``\ 'd directly in a C++ + compiler. + + __ https://cmake.org/cmake/help/latest/prop_tgt/VERIFY_INTERFACE_HEADER_SETS.html + + This target does not produce any output artifacts. This only checks that our + public API headers are valid. This checks against a variety of environments + to test that we are including the necessary standard library headers in our + public API headers. + + .. _earthly.secrets: Setting Earthly Secrets diff --git a/tools/build.earth b/tools/build.earth index 7c60cb044a6..470864bb037 100644 --- a/tools/build.earth +++ b/tools/build.earth @@ -83,6 +83,12 @@ ADD_CXX_COMPILER: # Old Alpine 3.16 bundles libstdc++ in g++, so we need to pull GCC along anyway LET cxx_pkg = clang g++ END + ELSE IF test -f /etc/redhat-release + IF test "$cxx_compiler" = g++ + LET cxx_pkg = "gcc-c++" + ELSE IF test "$cxx_cmopiler" = clang++ + LET cxx_pkg = clang gcc-c++ + END END IF test "$cxx_pkg" = "" RUN __fail "Unable to infer package name for --cxx_compiler “%s” on this platform (check spelling or pass a “--cxx_pkg” argument)" "$cxx_compiler" From 5cee4bb06016f2acbf4b59a4c137a1f0cb7e1ce9 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Wed, 2 Jul 2025 08:54:59 -0600 Subject: [PATCH 05/17] Don't require C++ for VerifyHeaders --- build/cmake/VerifyHeaders.cmake | 34 +++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/build/cmake/VerifyHeaders.cmake b/build/cmake/VerifyHeaders.cmake index 59bf957e7dc..27276cf06cb 100644 --- a/build/cmake/VerifyHeaders.cmake +++ b/build/cmake/VerifyHeaders.cmake @@ -1,3 +1,5 @@ +include_guard(DIRECTORY) + #[==[ Add header verification targets for given headers: @@ -21,7 +23,6 @@ absolute path to the file file. The header verification targets are compiled according to the usage requirements from all `` arguments. - ]==] function(mongo_verify_headers tag) list(APPEND CMAKE_MESSAGE_CONTEXT "${CMAKE_CURRENT_FUNCTION}(${tag})") @@ -68,24 +69,33 @@ function(mongo_verify_headers tag) endforeach() # We create two targets: One for C and one for C++ + set(targets) + # C target set(c_target ${tag}-verify-headers-c) - set(cxx_target ${tag}-verify-headers-cxx) - message(DEBUG "Defining header verification targets “${c_target}” and “${cxx_target}”") + message(DEBUG "Defining header verification target “${c_target}” (C)") # Create object libraries. They will only have one empty compiled source file. # The source file language will tell CMake how to verify the associated header files. add_library(${c_target} OBJECT "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/empty.c") - add_library(${cxx_target} OBJECT "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/empty.cpp") # Define the file set target_sources(${c_target} PUBLIC FILE_SET HEADERS) - target_sources(${cxx_target} PUBLIC FILE_SET HEADERS) - # Populate the properies and file sets + # Conditionally do the same thing for C++ + if(CMAKE_CXX_COMPILER) + # C++ is available. define it + set(cxx_target ${tag}-verify-headers-cxx) + message(DEBUG "Defining header verification targets “${cxx_target}” (C++)") + add_library(${cxx_target} OBJECT "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/empty.cpp") + target_sources(${cxx_target} PUBLIC FILE_SET HEADERS) + else() + message(AUTHOR_WARNING "No C++ compiler is available, so the header-check C++ targets won't be defined") + unset(cxx_target) + endif() + # Populate the properies and file sets. set_target_properties(${c_target} ${cxx_target} PROPERTIES # The main header file set: HEADER_SET "${headers_to_verify}" # Enable header verification: VERIFY_INTERFACE_HEADER_SETS TRUE - # Add the usage requirements that propagate to the generated compilation - # rules: + # Add the usage requirements that propagate to the generated compilation rules: INTERFACE_LINK_LIBRARIES "${arg_USE_LIBRARIES}" ) endfunction() @@ -97,3 +107,11 @@ set(MONGO_CAN_VERIFY_HEADERS FALSE) if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24") set(MONGO_CAN_VERIFY_HEADERS TRUE) endif() + +# Try to enable C++, but don't require it. This will be used to conditionally +# define the C++ header-check tests +include(CheckLanguage) +check_language(CXX) +if(CMAKE_CXX_COMPILER) + enable_language(CXX) +endif() From f338ea12626c467a989f5e40e99895303bcfae79 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Wed, 2 Jul 2025 09:43:16 -0600 Subject: [PATCH 06/17] Missing pass-thru of Earthly config args --- Earthfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Earthfile b/Earthfile index b527e21ffba..5652e55291e 100644 --- a/Earthfile +++ b/Earthfile @@ -63,7 +63,7 @@ build: LET build_dir=/opt/mongoc/build DO +COPY_SOURCE --into=$source_dir ENV CCACHE_HOME=/root/.cache/ccache - DO +CONFIGURE --source_dir=$source_dir --build_dir=$build_dir + DO --pass-args +CONFIGURE --source_dir=$source_dir --build_dir=$build_dir RUN --mount=type=cache,target=$CCACHE_HOME \ env CCACHE_BASE="$source_dir" \ cmake --build $build_dir --config $config From 9d0d43bb1375778040077d2450e1950ddf91f867 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 8 Jul 2025 10:09:37 -0600 Subject: [PATCH 07/17] Minor speeling and grammars fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Roberto C. Sánchez --- build/cmake/VerifyHeaders.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/cmake/VerifyHeaders.cmake b/build/cmake/VerifyHeaders.cmake index 27276cf06cb..2942bc4b1b2 100644 --- a/build/cmake/VerifyHeaders.cmake +++ b/build/cmake/VerifyHeaders.cmake @@ -16,10 +16,10 @@ collect sources files (relative to the current source directory). All files collected by `` must live within the current source directory. After collecting sources according to the `` patterns, sources are -excluded if they filepath contains any substring that matches any regular +excluded if the filepath contains any substring that matches any regular expression in the `` list. Each `` is tested against the relative path to the header file that was found by ``, and not the -absolute path to the file file. +absolute path to the file. The header verification targets are compiled according to the usage requirements from all `` arguments. @@ -56,7 +56,7 @@ function(mongo_verify_headers tag) list(APPEND headers_to_verify ${more}) endforeach() - # Excluce anything that matches any exclusion regex + # Exclude anything that matches any exclusion regex foreach(pattern IN LISTS arg_EXCLUDE_REGEX) list(FILTER headers_to_verify EXCLUDE REGEX "${pattern}") endforeach() @@ -89,7 +89,7 @@ function(mongo_verify_headers tag) message(AUTHOR_WARNING "No C++ compiler is available, so the header-check C++ targets won't be defined") unset(cxx_target) endif() - # Populate the properies and file sets. + # Populate the properties and file sets. set_target_properties(${c_target} ${cxx_target} PROPERTIES # The main header file set: HEADER_SET "${headers_to_verify}" From b12a44b1917b286886cdc27c01da8877b44a84ed Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 8 Jul 2025 10:12:39 -0600 Subject: [PATCH 08/17] Remove bad includes following merge --- src/libbson/src/bson/bson-version-functions.c | 4 ---- src/libbson/src/bson/bson.h | 1 - 2 files changed, 5 deletions(-) diff --git a/src/libbson/src/bson/bson-version-functions.c b/src/libbson/src/bson/bson-version-functions.c index ebe2096d6dc..a4896f6369d 100644 --- a/src/libbson/src/bson/bson-version-functions.c +++ b/src/libbson/src/bson/bson-version-functions.c @@ -14,13 +14,10 @@ * limitations under the License. */ - #include -#include #include - /** * bson_get_major_version: * @@ -32,7 +29,6 @@ bson_get_major_version (void) return BSON_MAJOR_VERSION; } - /** * bson_get_minor_version: * diff --git a/src/libbson/src/bson/bson.h b/src/libbson/src/bson/bson.h index 519b8de7f77..287bda929c0 100644 --- a/src/libbson/src/bson/bson.h +++ b/src/libbson/src/bson/bson.h @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include From d83ed79e8faa8d798f5d4895e419a08e95d11baf Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 8 Jul 2025 19:56:28 -0600 Subject: [PATCH 09/17] Missing license header --- src/libbson/src/bson/bson_t.h | 16 ++++++++++++++++ src/libbson/src/bson/error.h | 16 ++++++++++++++++ src/libbson/src/bson/memory.h | 16 ++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/libbson/src/bson/bson_t.h b/src/libbson/src/bson/bson_t.h index 2095ccf2b78..cf68a87a589 100644 --- a/src/libbson/src/bson/bson_t.h +++ b/src/libbson/src/bson/bson_t.h @@ -1,3 +1,19 @@ +/* + * Copyright 2009-present MongoDB, Inc. + * + * 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. + */ + #ifndef BSON_BSON_T_H_INCLUDED #define BSON_BSON_T_H_INCLUDED diff --git a/src/libbson/src/bson/error.h b/src/libbson/src/bson/error.h index d682303b31a..bc427d3d503 100644 --- a/src/libbson/src/bson/error.h +++ b/src/libbson/src/bson/error.h @@ -1,3 +1,19 @@ +/* + * Copyright 2009-present MongoDB, Inc. + * + * 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. + */ + #ifndef BSON_ERROR_T_INCLUDED #define BSON_ERROR_T_INCLUDED diff --git a/src/libbson/src/bson/memory.h b/src/libbson/src/bson/memory.h index 4100d793be4..b670fba5bf6 100644 --- a/src/libbson/src/bson/memory.h +++ b/src/libbson/src/bson/memory.h @@ -1,3 +1,19 @@ +/* + * Copyright 2009-present MongoDB, Inc. + * + * 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. + */ + #ifndef BSON_MEMORY_H_INCLUDED #define BSON_MEMORY_H_INCLUDED From 8a2dcc808537a5a1a52f903f2e18d1f728b0826a Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Tue, 8 Jul 2025 19:58:08 -0600 Subject: [PATCH 10/17] Minor header verification cleanup --- build/cmake/VerifyHeaders.cmake | 1 - build/cmake/empty.c | 5 +++-- build/cmake/empty.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build/cmake/VerifyHeaders.cmake b/build/cmake/VerifyHeaders.cmake index 2942bc4b1b2..89407127878 100644 --- a/build/cmake/VerifyHeaders.cmake +++ b/build/cmake/VerifyHeaders.cmake @@ -69,7 +69,6 @@ function(mongo_verify_headers tag) endforeach() # We create two targets: One for C and one for C++ - set(targets) # C target set(c_target ${tag}-verify-headers-c) message(DEBUG "Defining header verification target “${c_target}” (C)") diff --git a/build/cmake/empty.c b/build/cmake/empty.c index f0c06f6c738..deb1f24d152 100644 --- a/build/cmake/empty.c +++ b/build/cmake/empty.c @@ -1,2 +1,3 @@ -/* This is an empty placeholder file use for miscellaneous build system tasks */ -#include +/* This is an empty placeholder file used for miscellaneous build system tasks + */ +#include diff --git a/build/cmake/empty.cpp b/build/cmake/empty.cpp index 40b0c6decdf..3c896c8708a 100644 --- a/build/cmake/empty.cpp +++ b/build/cmake/empty.cpp @@ -1,2 +1,2 @@ -// This is an empty placeholder file use for miscellaneous build system tasks -#include +// This is an empty placeholder file used for miscellaneous build system tasks +#include From f8331b5b7d8e7674e5f991837cb348b51cf8ec43 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Wed, 9 Jul 2025 10:55:54 -0600 Subject: [PATCH 11/17] Conditionally add verification by `ENABLE_TESTS` --- src/libbson/CMakeLists.txt | 2 +- src/libmongoc/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index efed858a7b7..6ba064d5dbf 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -174,7 +174,7 @@ if(ENABLE_STATIC) set_property(TARGET bson_static PROPERTY POSITION_INDEPENDENT_CODE TRUE) endif() - if(MONGO_CAN_VERIFY_HEADERS) + if(MONGO_CAN_VERIFY_HEADERS AND ENABLE_TESTS) mongo_verify_headers( bson USE_LIBRARIES bson::static diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 073a01556fd..4fd14dbeea7 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -972,7 +972,7 @@ if (MONGOC_ENABLE_STATIC_BUILD) mongo_generate_pkg_config (mongoc_static FILENAME mongoc${PROJECT_VERSION_MAJOR}-static.pc INSTALL) endif() - if(MONGO_CAN_VERIFY_HEADERS) + if(MONGO_CAN_VERIFY_HEADERS AND ENABLE_TESTS) mongo_verify_headers( mongoc USE_LIBRARIES mongoc::static From 310f23a3304087fd8d29d4772a571534f0c28dd6 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Wed, 9 Jul 2025 10:57:56 -0600 Subject: [PATCH 12/17] Spelling in Earthfile --- tools/build.earth | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build.earth b/tools/build.earth index 470864bb037..a72f2215aa7 100644 --- a/tools/build.earth +++ b/tools/build.earth @@ -86,7 +86,7 @@ ADD_CXX_COMPILER: ELSE IF test -f /etc/redhat-release IF test "$cxx_compiler" = g++ LET cxx_pkg = "gcc-c++" - ELSE IF test "$cxx_cmopiler" = clang++ + ELSE IF test "$cxx_compiler" = clang++ LET cxx_pkg = clang gcc-c++ END END From 5b5da27d0a81635ab7ec93dc3d46acbe3a790086 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Wed, 9 Jul 2025 12:28:51 -0600 Subject: [PATCH 13/17] Missing inclusion for snprintf --- src/libbson/src/bson/bson-oid.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libbson/src/bson/bson-oid.c b/src/libbson/src/bson/bson-oid.c index 28bb2976d08..85328d32fcd 100644 --- a/src/libbson/src/bson/bson-oid.c +++ b/src/libbson/src/bson/bson-oid.c @@ -19,6 +19,7 @@ #include #include +#include #include #include From ab8cd675afa611358051399c4e829f72cdd46586 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Wed, 23 Jul 2025 11:02:18 -0600 Subject: [PATCH 14/17] Remove unused old script --- .evergreen/scripts/check-files.py | 67 ------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 .evergreen/scripts/check-files.py diff --git a/.evergreen/scripts/check-files.py b/.evergreen/scripts/check-files.py deleted file mode 100644 index 36023203667..00000000000 --- a/.evergreen/scripts/check-files.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2009-present MongoDB, Inc. -# -# 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 that there are no missing .c or .h files in the release tarball. -""" -import os -import re -import sys - -if len(sys.argv) != 3: - print("Usage: python check_files.py" - " " - " ") - sys.exit(1) - -REPO_SRC_DIR = sys.argv[1] -TAR_SRC_DIR = sys.argv[2] - -pattern = re.compile(r".*\.(c|h)$") - -repo_src_files = set() -tar_src_files = set() - -# Files that are generated by cmake are expected not to be in the repository. -cmake_produced = [ - "libbson/src/bson/bson-version.h", - "libmongoc/src/mongoc/mongoc-version.h", - "zlib-1.2.13/zconf.h", -] - -for root, dirs, files in os.walk(REPO_SRC_DIR): - for file in files: - relpath = os.path.relpath(os.path.join(root, file), REPO_SRC_DIR) - - if pattern.match(relpath): - repo_src_files.add(relpath) - -for root, dirs, files in os.walk(TAR_SRC_DIR): - for file in files: - relpath = os.path.relpath(os.path.join(root, file), TAR_SRC_DIR) - if relpath in cmake_produced: - continue - if pattern.match(relpath): - tar_src_files.add(relpath) - -if tar_src_files != repo_src_files: - print("Files produced from tarball differ from repository") - print("Tarball produced the following files NOT in repository") - for file in sorted(tar_src_files.difference(repo_src_files)): - print(" " + file) - print("Repository has the following files NOT in tarball") - for file in sorted(repo_src_files.difference(tar_src_files)): - print(" " + file) - sys.exit(1) From 3486d465eb77b8757b9f322d3077e39cef9f5bf9 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Wed, 23 Jul 2025 11:03:12 -0600 Subject: [PATCH 15/17] Update old config mention --- src/libbson/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index d5500c98d2a..df006e3a3e5 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -69,7 +69,7 @@ mongo_bool_setting( # Configure-time platform checks. These start as regular CMake booleans, but are # converted to 0/1 values (with mongo_bool01) so that they can be inserted into -# bson-config.h as preprocessor values. We cannot use #cmakedefine01, as we need +# bson/config.h as preprocessor values. We cannot use #cmakedefine01, as we need # to keep compatibility with an external Autotools-generated library configuration include (CheckFunctionExists) From 59365ee827d06fdf86e7d175e9e2183767b57be3 Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Wed, 23 Jul 2025 11:06:40 -0600 Subject: [PATCH 16/17] Rename bson.h -> bson-bcon.h --- src/libbson/CMakeLists.txt | 3 +-- src/libbson/src/bson/{bcon.c => bson-bcon.c} | 2 +- src/libbson/src/bson/{bcon.h => bson-bcon.h} | 0 src/libbson/src/bson/bson.h | 2 +- src/libbson/tests/test-bcon-basic.c | 2 +- src/libbson/tests/test-bcon-extract.c | 2 +- src/libbson/tests/test-bson.c | 2 +- src/libbson/tests/test-value.c | 2 +- src/libmongoc/tests/test-mongoc-collection.c | 2 +- src/libmongoc/tests/test-mongoc-find-and-modify.c | 2 +- src/libmongoc/tests/test-mongoc-write-commands.c | 2 +- 11 files changed, 10 insertions(+), 11 deletions(-) rename src/libbson/src/bson/{bcon.c => bson-bcon.c} (99%) rename src/libbson/src/bson/{bcon.h => bson-bcon.h} (100%) diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index df006e3a3e5..47bb0bd72ff 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -187,9 +187,8 @@ if(ENABLE_STATIC) # Ignore all headers that start with "bson-", as they have not # been sanitized for direct inclusion. "bson/bson-.*\\.h" - # Don't check jsonsl.h or bcon.h either + # Don't check jsonsl.h either "jsonsl\\.h" - "bcon\\.h" ) endif() endif() diff --git a/src/libbson/src/bson/bcon.c b/src/libbson/src/bson/bson-bcon.c similarity index 99% rename from src/libbson/src/bson/bcon.c rename to src/libbson/src/bson/bson-bcon.c index d9a6d12412f..15712dd8348 100644 --- a/src/libbson/src/bson/bcon.c +++ b/src/libbson/src/bson/bson-bcon.c @@ -19,7 +19,7 @@ */ -#include +#include #include diff --git a/src/libbson/src/bson/bcon.h b/src/libbson/src/bson/bson-bcon.h similarity index 100% rename from src/libbson/src/bson/bcon.h rename to src/libbson/src/bson/bson-bcon.h diff --git a/src/libbson/src/bson/bson.h b/src/libbson/src/bson/bson.h index 287bda929c0..408489576c3 100644 --- a/src/libbson/src/bson/bson.h +++ b/src/libbson/src/bson/bson.h @@ -20,7 +20,7 @@ #define BSON_INSIDE -#include +#include #include #include #include diff --git a/src/libbson/tests/test-bcon-basic.c b/src/libbson/tests/test-bcon-basic.c index a6c9a8168e8..5b02fb7bd2f 100644 --- a/src/libbson/tests/test-bcon-basic.c +++ b/src/libbson/tests/test-bcon-basic.c @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/src/libbson/tests/test-bcon-extract.c b/src/libbson/tests/test-bcon-extract.c index db1156e768b..6b40b5ff1a6 100644 --- a/src/libbson/tests/test-bcon-extract.c +++ b/src/libbson/tests/test-bcon-extract.c @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/src/libbson/tests/test-bson.c b/src/libbson/tests/test-bson.c index 09b9b9c5e9b..5f2bc49ebcf 100644 --- a/src/libbson/tests/test-bson.c +++ b/src/libbson/tests/test-bson.c @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include diff --git a/src/libbson/tests/test-value.c b/src/libbson/tests/test-value.c index 0484417aa75..5999a488e55 100644 --- a/src/libbson/tests/test-value.c +++ b/src/libbson/tests/test-value.c @@ -15,7 +15,7 @@ */ -#include +#include #include #include diff --git a/src/libmongoc/tests/test-mongoc-collection.c b/src/libmongoc/tests/test-mongoc-collection.c index 1c0d9fe049c..49e80191086 100644 --- a/src/libmongoc/tests/test-mongoc-collection.c +++ b/src/libmongoc/tests/test-mongoc-collection.c @@ -9,7 +9,7 @@ #include -#include +#include #include #include diff --git a/src/libmongoc/tests/test-mongoc-find-and-modify.c b/src/libmongoc/tests/test-mongoc-find-and-modify.c index 3044bfb7c99..be225e8300b 100644 --- a/src/libmongoc/tests/test-mongoc-find-and-modify.c +++ b/src/libmongoc/tests/test-mongoc-find-and-modify.c @@ -4,7 +4,7 @@ #include -#include +#include #include #include diff --git a/src/libmongoc/tests/test-mongoc-write-commands.c b/src/libmongoc/tests/test-mongoc-write-commands.c index 04676f9f662..ecd1ff66831 100644 --- a/src/libmongoc/tests/test-mongoc-write-commands.c +++ b/src/libmongoc/tests/test-mongoc-write-commands.c @@ -5,7 +5,7 @@ #include -#include +#include #include #include From f9f3b1daf7dd7bac3aa1d307a6d3d274b6d756ba Mon Sep 17 00:00:00 2001 From: vector-of-bool Date: Wed, 23 Jul 2025 11:29:35 -0600 Subject: [PATCH 17/17] Update Earthfile post-merge --- Earthfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Earthfile b/Earthfile index 7710a276b94..b4c344562e9 100644 --- a/Earthfile +++ b/Earthfile @@ -12,7 +12,7 @@ IMPORT ./tools/ AS tools # COPY_SOURCE : # Copy source files required for the build into the specified "--into" directory COPY_SOURCE: - COMMAND + FUNCTION ARG --required into COPY --dir \ build/ \ @@ -28,7 +28,7 @@ COPY_SOURCE: # CONFIGURE : # Configure the project in $source_dir into $build_dir with a common set of configuration options CONFIGURE: - COMMAND + FUNCTION ARG --required source_dir ARG --required build_dir ARG --required tls