Skip to content
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

CDRIVER-5635 Exclude tests and examples from ALL target #1675

Merged
merged 7 commits into from
Jul 19, 2024

Conversation

eramongodb
Copy link
Collaborator

Summary

Resolves CDRIVER-5635. Verified by this patch.

The ALL Target and Installation

Although tests and examples are correctly disabled via ENABLE_TESTS and ENABLE_EXAMPLES, they are not being correctly excluded from the ALL target when enabled. The ALL target should only build targets which are required by the install target (that is, targets which produce artifacts intended to be installed, with the exception of excluded components, which does not apply to our project. This is the same in spirit to the make && make install pattern).

Grepping the CMake build output for "Linking" is an approximate means of identifying the list of executable/library targets being built. The base commit currently emits the following list of artifacts for a simple cmake --build <binary-dir> (ALL target) configured with tests and examples enabled:

C shared library src/libbson/libbson-1.0.so.0.0.0
C static library src/libbson/libbson-static-1.0.a
C static library src/libmongoc/libmongoc-static-1.0.a
CXX static library src/libmongoc-cxx-check.a
C executable src/libmongoc/test-awsauth
C executable src/libmongoc/test-gcpkms
C executable src/libmongoc/test-azurekms
C executable src/libmongoc/test-mongoc-cache
C executable src/libmongoc/test-mongoc-gssapi
C static library src/libmongoc/libtest-libmongoc-lib.a
C shared library src/libmongoc/libmongoc-1.0.so.0.0.0
C executable src/libbson/creating
C executable src/libbson/bson-check-depth
C executable src/libbson/json-to-bson
C executable src/libbson/bson-validate
C executable src/libbson/bson-to-json
C executable src/libbson/bson-streaming-reader
C executable src/libbson/bson-metrics
C executable src/libbson/bcon-speed
C executable src/libbson/bcon-col-view
C executable src/libmongoc/test-atlas-executor
C executable src/libmongoc/test-libmongoc
C executable src/libmongoc/appending
C executable src/libmongoc/executing
C executable src/libmongoc/fam
C executable src/libmongoc/common-operations
C executable src/libmongoc/bulk6
C executable src/libmongoc/bulk5
C executable src/libmongoc/bulk4
C executable src/libmongoc/bulk3
C executable src/libmongoc/bulk2
C executable src/libmongoc/bulk1
C executable src/libmongoc/bulk-collation
C executable src/libmongoc/basic-aggregation
C executable src/libmongoc/aggregation1
C executable src/libmongoc/example-bulkwrite
C executable src/libmongoc/example-collection-command
C executable src/libmongoc/mongoc-tail
C executable src/libmongoc/mongoc-ping
C executable src/libmongoc/mongoc-dump
C executable src/libmongoc/hello_mongoc
C executable src/libmongoc/find-and-modify
C executable src/libmongoc/example-update
C executable src/libmongoc/example-transaction
C executable src/libmongoc/example-session
C executable src/libmongoc/example-sdam-monitoring
C executable src/libmongoc/example-scram
C executable src/libmongoc/example-pool
C executable src/libmongoc/example-gridfs-bucket
C executable src/libmongoc/example-gridfs
C executable src/libmongoc/example-manage-search-indexes
C executable src/libmongoc/example-manage-collection-indexes
C executable src/libmongoc/example-command-with-opts
C executable src/libmongoc/example-command-monitoring
C executable src/libmongoc/example-start-at-optime
C executable src/libmongoc/example-resume
C executable src/libmongoc/example-collection-watch
C executable src/libmongoc/example-client
C executable src/libmongoc/mongoc-stat

This PR proposes reducing the list to only the following:

Linking C shared library src/libbson/libbson-1.0.so.0.0.0
Linking C static library src/libbson/libbson-static-1.0.a
Linking C static library src/libmongoc/libmongoc-static-1.0.a
Linking C shared library src/libmongoc/libmongoc-1.0.so.0.0.0
Linking C executable src/libmongoc/mongoc-stat

Note: man pages and html docs are not excluded, as they are also installed artifacts under share/.

The new tests and examples custom targets are defined as a convenient means of compiling all test and example targets. The if (NOT TARGET) pattern is used to ensure compatibility with parent projects (where C Driver is imported via add_subdirectory()) which may have already defined the tests or examples target. The new tests target is used by the updated EVG scripts to ensure test binaries are available for use by test tasks.

Miscellaneous

  • Use CMAKE_BUILD_PARALLEL_LEVEL instead of --parallel, -- -j, or /m.
  • Set UseMultiToolTask and EnforceProcessCountAcrossBuilds for better MSBuild parallelism with VS2019+.
  • Changed mongoc-cxx-check from STATIC to OBJECT to avoid the unnecessary "Linking" step.
  • Remove unused EXAMPLES variable (incorrect for its entire existence?).

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.

LGTM with minor comments.

The if (NOT TARGET) pattern is used to ensure compatibility with parent projects (where C Driver is imported via add_subdirectory()) which may have already defined the tests or examples target.

I would like to eventually consider prefixing target names (e.g. with mongoc or similar) to avoid collisions. But I think that is outside of the scope of this PR.

@@ -97,30 +97,43 @@ fi

"${cmake_binary:?}" --version

if [[ "${OSTYPE}" == darwin* ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggest removing if-block since script is Windows-specific.

declare compile_flags=(
"/m" # Number of concurrent processes. No value=# of cpus
)
# MSBUild needs additional assistance.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# MSBUild needs additional assistance.
# MSBuild needs additional assistance.

@eramongodb
Copy link
Collaborator Author

Good call on prefixing target names. The CXX Driver may not be the only users using add_subdirectory() to import the C Driver; they may also define their own tests or examples target (a common pattern).

Renamed to use the mongo_c_driver_* prefix and unconditionally defined them as top-level targets for use by both libbson and libmongoc, removing the need for the tests target existence check+workaround in scripts.

@eramongodb eramongodb requested a review from kevinAlbs July 19, 2024 18:49
@eramongodb eramongodb merged commit ef17740 into mongodb:master Jul 19, 2024
1 check was pending
@eramongodb eramongodb deleted the cdriver-5635 branch July 19, 2024 19:13
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