Skip to content

Commit cf757ae

Browse files
authored
CDRIVER-4673 fix include of bson-dsl.h (#1388)
* move bson-dsl.h to src/common bson-dsl.h is not installed, but shared between libmongoc and libbson. Intended to resolve CDRIVER-4673. * format bson-dsl.h * add bson-dsl.h to dist tarball * remove bson-dsl.h from old dist list * add regression test
1 parent 2d7f957 commit cf757ae

23 files changed

+80
-47
lines changed

.evergreen/generated_configs/legacy-config.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,16 @@ tasks:
10941094
script: |-
10951095
set -o errexit
10961096
bash ./.evergreen/scripts/build-and-test-with-toolchain.sh
1097+
- name: install-libmongoc-after-libbson
1098+
commands:
1099+
- command: shell.exec
1100+
type: test
1101+
params:
1102+
working_dir: mongoc
1103+
shell: bash
1104+
script: |-
1105+
set -o errexit
1106+
bash ./.evergreen/scripts/install-libmongoc-after-libbson.sh
10971107
- name: test-coverage-latest-replica-set-auth-sasl-openssl
10981108
tags:
10991109
- latest
@@ -9287,6 +9297,7 @@ buildvariants:
92879297
- name: build-and-test-with-toolchain
92889298
distros:
92899299
- debian10-small
9300+
- install-libmongoc-after-libbson
92909301
- name: clang34ubuntu
92919302
display_name: clang 3.4 (Ubuntu 14.04)
92929303
expansions:

.evergreen/legacy_config_generator/evergreen_config_lib/tasks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ def __init__(
416416
shell_mongoc("bash ./.evergreen/scripts/build-and-test-with-toolchain.sh"),
417417
],
418418
),
419+
NamedTask(
420+
"install-libmongoc-after-libbson",
421+
commands=[shell_mongoc("bash ./.evergreen/scripts/install-libmongoc-after-libbson.sh"),],
422+
),
419423
]
420424

421425

.evergreen/legacy_config_generator/evergreen_config_lib/variants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def days(n: int) -> int:
7171
OD([("name", "install-uninstall-check-msvc"), ("distros", ["windows-vsCurrent-large"])]),
7272
"debug-compile-with-warnings",
7373
OD([("name", "build-and-test-with-toolchain"), ("distros", ["debian10-small"])]),
74+
"install-libmongoc-after-libbson",
7475
],
7576
{},
7677
),
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o nounset
6+
7+
# Install libbson only.
8+
EXTRA_CONFIGURE_FLAGS="-DENABLE_MONGOC=OFF" \
9+
./.evergreen/scripts/compile.sh
10+
11+
# Install libmongoc using the system installed libbson.
12+
EXTRA_CONFIGURE_FLAGS="-DENABLE_MONGOC=ON -DUSE_SYSTEM_LIBBSON=ON" \
13+
./.evergreen/scripts/compile.sh

src/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ configure_file (
1313
)
1414

1515
set (src_common_DIST_noinst_hs
16+
bson-dsl.h
1617
common-b64-private.h
1718
common-md5-private.h
1819
common-prelude.h

src/libbson/src/bson/bson-dsl.h renamed to src/common/bson-dsl.h

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "common-prelude.h"
2+
13
#ifndef BSON_BSON_DSL_H_INCLUDED
24
#define BSON_BSON_DSL_H_INCLUDED
35

@@ -22,10 +24,10 @@ enum {
2224
};
2325

2426
#define _bson_thread_local \
25-
BSON_IF_GNU_LIKE (__thread) BSON_IF_MSVC (__declspec(thread))
27+
BSON_IF_GNU_LIKE (__thread) BSON_IF_MSVC (__declspec (thread))
2628

27-
#define _bson_comdat \
28-
BSON_IF_WINDOWS (__declspec(selectany)) \
29+
#define _bson_comdat \
30+
BSON_IF_WINDOWS (__declspec (selectany)) \
2931
BSON_IF_POSIX (__attribute__ ((weak)))
3032

3133
#ifdef __GNUC__
@@ -89,7 +91,7 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
8991
#define _bsonDSL_end \
9092
--_bson_dsl_indent; \
9193
} \
92-
else((void) 0)
94+
else ((void) 0)
9395

9496
/**
9597
* @brief Expands to a call to bson_append_{Kind}, with the three first
@@ -286,7 +288,7 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
286288
const bool _bvHalt = false; /* Required for _bsonVisitEach() */ \
287289
_bsonVisitEach ( \
288290
OtherBSON, \
289-
if (Pred, then (do(_bsonDocOperation_iterElement (bsonVisitIter))))); \
291+
if (Pred, then (do (_bsonDocOperation_iterElement (bsonVisitIter))))); \
290292
_bsonDSL_end
291293

292294
#define _bsonDocOperation_insertFromIter(Iter, Pred) \
@@ -312,16 +314,16 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
312314

313315
/// Insert the given BSON document into the parent array. Keys of the given
314316
/// document are discarded and it is treated as an array of values.
315-
#define _bsonArrayOperation_insert(OtherArr, Pred) \
316-
_bsonDSL_begin ("Insert other array: [%s]", _bsonDSL_str (OtherArr)); \
317-
_bsonVisitEach ( \
318-
OtherArr, \
319-
if (Pred, then (do(_bsonArrayOperation_iterValue (bsonVisitIter))))); \
317+
#define _bsonArrayOperation_insert(OtherArr, Pred) \
318+
_bsonDSL_begin ("Insert other array: [%s]", _bsonDSL_str (OtherArr)); \
319+
_bsonVisitEach ( \
320+
OtherArr, \
321+
if (Pred, then (do (_bsonArrayOperation_iterValue (bsonVisitIter))))); \
320322
_bsonDSL_end
321323

322324
#define _bsonArrayAppendValue(ValueOperation) \
323325
_bsonDSL_begin ("[%d] => [%s]", \
324-
(int) bsonBuildContext.index, \
326+
(int) bsonBuildContext.index, \
325327
_bsonDSL_strElide (30, ValueOperation)); \
326328
/* Set the doc key to the array index as a string: */ \
327329
_bsonBuild_setKeyToArrayIndex (bsonBuildContext.index); \
@@ -396,9 +398,11 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
396398
_bsonValueOperationIf_##Else; \
397399
}
398400

399-
#define _bsonBuild_setKeyToArrayIndex(Idx) \
400-
_bbCtx.key_len = bson_snprintf ( \
401-
_bbCtx.index_key_str, sizeof _bbCtx.index_key_str, "%d",(int) _bbCtx.index); \
401+
#define _bsonBuild_setKeyToArrayIndex(Idx) \
402+
_bbCtx.key_len = bson_snprintf (_bbCtx.index_key_str, \
403+
sizeof _bbCtx.index_key_str, \
404+
"%d", \
405+
(int) _bbCtx.index); \
402406
_bbCtx.key = _bbCtx.index_key_str
403407

404408
/// Handle an element of array()
@@ -716,19 +720,19 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
716720
(NthInt < _bpNumVisitBitInts && \
717721
(_bpVisitBits[NthInt] & (UINT64_C (1) << NthBit)))
718722

719-
#define _bsonParseOperation_find(Predicate, ...) \
720-
_bsonDSL_begin ("find(%s)", _bsonDSL_str (Predicate)); \
721-
_bpFoundElement = false; \
722-
_bsonVisitEach ( \
723-
*_bpDoc, \
724-
if (Predicate, \
725-
then (do(_bsonParseMarkVisited (bsonVisitContext.index); \
726-
_bpFoundElement = true), \
727-
__VA_ARGS__, \
728-
break))); \
729-
if (!_bpFoundElement && !bsonParseError) { \
730-
_bsonDSLDebug ("[not found]"); \
731-
} \
723+
#define _bsonParseOperation_find(Predicate, ...) \
724+
_bsonDSL_begin ("find(%s)", _bsonDSL_str (Predicate)); \
725+
_bpFoundElement = false; \
726+
_bsonVisitEach ( \
727+
*_bpDoc, \
728+
if (Predicate, \
729+
then (do (_bsonParseMarkVisited (bsonVisitContext.index); \
730+
_bpFoundElement = true), \
731+
__VA_ARGS__, \
732+
break))); \
733+
if (!_bpFoundElement && !bsonParseError) { \
734+
_bsonDSLDebug ("[not found]"); \
735+
} \
732736
_bsonDSL_end
733737

734738
#define _bsonParseOperation_require(Predicate, ...) \
@@ -737,8 +741,8 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
737741
_bsonVisitEach ( \
738742
*_bpDoc, \
739743
if (Predicate, \
740-
then (do(_bsonParseMarkVisited (bsonVisitContext.index); \
741-
_bpFoundElement = true), \
744+
then (do (_bsonParseMarkVisited (bsonVisitContext.index); \
745+
_bpFoundElement = true), \
742746
__VA_ARGS__, \
743747
break))); \
744748
if (!_bpFoundElement && !bsonParseError) { \
@@ -1140,7 +1144,7 @@ _bson_dsl_dupPath (char **into)
11401144
char *prev = acc;
11411145
if (ctx->parent && BSON_ITER_HOLDS_ARRAY (&ctx->parent->iter)) {
11421146
// We're an array element
1143-
acc = bson_strdup_printf ("[%d]%s", (int)ctx->index, prev);
1147+
acc = bson_strdup_printf ("[%d]%s", (int) ctx->index, prev);
11441148
} else {
11451149
// We're a document element
11461150
acc = bson_strdup_printf (".%s%s", bson_iter_key (&ctx->iter), prev);

src/libbson/src/bson/bson-dsl.md renamed to src/common/bson-dsl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Using `bson-dsl.h`
22

3-
The header `<bson/bson-dsl.h>` exposes an embedded domain-specific language
3+
The header `<bson-dsl.h>` exposes an embedded domain-specific language
44
(DSL) built upon the C99 preprocessor. The DSL emits valid C99 and C++03 code
55
that can be used to inspect and construct `bson_t` objects.
66

src/libbson/src/bson/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ set (src_libbson_src_bson_DIST_hs
66
bson-compat.h
77
bson-context.h
88
bson-decimal128.h
9-
bson-dsl.h
109
bson-endian.h
1110
bson-error.h
1211
bson-iter.h

src/libbson/tests/test-bson.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <fcntl.h>
2222
#include <time.h>
2323

24-
#include <bson/bson-dsl.h>
24+
#include <bson-dsl.h>
2525

2626
#include "TestSuite.h"
2727
#include "test-conveniences.h"

src/libmongoc/src/mongoc/mongoc-aggregate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "mongoc-trace-private.h"
2424
#include "mongoc-util-private.h"
2525

26-
#include <bson/bson-dsl.h>
26+
#include <bson-dsl.h>
2727

2828
/*--------------------------------------------------------------------------
2929
*

0 commit comments

Comments
 (0)