Skip to content

Commit 99dc81f

Browse files
authored
CXX-3199 Generate API documentation with generated headers (#1301)
1 parent d26e355 commit 99dc81f

File tree

20 files changed

+370
-539
lines changed

20 files changed

+370
-539
lines changed

CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,20 +283,33 @@ add_custom_target(hugo-deploy
283283
VERBATIM
284284
)
285285

286-
add_custom_target(docs_dir_current
287-
COMMAND ${CMAKE_COMMAND} -E make_directory docs/api/current
286+
add_custom_target(doxygen-install-headers
287+
VERBATIM
288+
289+
# Clear any existing files in the target directory.
290+
COMMAND ${CMAKE_COMMAND} -E remove_directory
291+
${MONGO_CXX_DRIVER_SOURCE_DIR}/build/doxygen/install
292+
293+
# Manually "install" all headers without requiring compilation.
294+
COMMAND ${CMAKE_COMMAND} -E copy_directory
295+
${MONGO_CXX_DRIVER_SOURCE_DIR}/src/bsoncxx/include
296+
${MONGO_CXX_DRIVER_BINARY_DIR}/src/bsoncxx/lib
297+
${MONGO_CXX_DRIVER_SOURCE_DIR}/build/doxygen/install/include
298+
COMMAND ${CMAKE_COMMAND} -E copy_directory
299+
${MONGO_CXX_DRIVER_SOURCE_DIR}/src/mongocxx/include
300+
${MONGO_CXX_DRIVER_BINARY_DIR}/src/mongocxx/lib
301+
${MONGO_CXX_DRIVER_SOURCE_DIR}/build/doxygen/install/include
288302
)
289303

290304
add_custom_target(doxygen-current
291-
DEPENDS docs_dir_current
292305
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
293-
COMMAND doxygen ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
306+
COMMAND ${CMAKE_COMMAND} -E env DOXYGEN_USE_CURRENT=1 etc/generate-latest-apidocs.sh
294307
VERBATIM
295308
)
296309

297310
add_custom_target(doxygen-latest
298311
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
299-
COMMAND etc/generate-latest-apidocs.pl
312+
COMMAND etc/generate-latest-apidocs.sh
300313
VERBATIM
301314
)
302315

Doxyfile

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ FULL_PATH_NAMES = YES
181181
# This tag requires that the tag FULL_PATH_NAMES is set to YES.
182182

183183
STRIP_FROM_PATH = . \
184-
src/bsoncxx/include \
185-
src/mongocxx/include
184+
build/doxygen/install/include
186185

187186
# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
188187
# path mentioned in the documentation of a class, which tells the reader which
@@ -192,8 +191,7 @@ STRIP_FROM_PATH = . \
192191
# using the -I flag.
193192

194193
STRIP_FROM_INC_PATH = . \
195-
src/bsoncxx/include \
196-
src/mongocxx/include
194+
build/doxygen/install/include
197195

198196
# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
199197
# less readable) file names. This can be useful is your file systems doesn't
@@ -836,7 +834,7 @@ CITE_BIB_FILES =
836834
# messages are off.
837835
# The default value is: NO.
838836

839-
QUIET = NO
837+
QUIET = YES
840838

841839
# The WARNINGS tag can be used to turn on/off the warning messages that are
842840
# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES
@@ -943,8 +941,7 @@ WARN_LOGFILE =
943941
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
944942
# Note: If this tag is empty the current directory is searched.
945943

946-
INPUT = src/bsoncxx/include \
947-
src/mongocxx/include \
944+
INPUT = build/doxygen/install/include \
948945
etc/apidocmenu.md
949946

950947
# This tag can be used to specify the character encoding of the source files
@@ -2398,10 +2395,7 @@ SEARCH_INCLUDES = YES
23982395
# RECURSIVE has no effect here.
23992396
# This tag requires that the tag SEARCH_INCLUDES is set to YES.
24002397

2401-
INCLUDE_PATH = src/bsoncxx/include/bsoncxx/v_noabi \
2402-
src/mongocxx/include/mongocxx/v_noabi \
2403-
src/bsoncxx/include \
2404-
src/mongocxx/include
2398+
INCLUDE_PATH = build/doxygen/install/include
24052399

24062400
# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
24072401
# patterns (like *.h and *.hpp) to filter out the header-files in the

etc/generate-apidocs-from-tag.pl

Lines changed: 0 additions & 175 deletions
This file was deleted.

etc/generate-latest-apidocs.pl

Lines changed: 0 additions & 22 deletions
This file was deleted.

etc/generate-latest-apidocs.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env bash
2+
#
3+
# generate-latest-apidocs.sh
4+
#
5+
# Usage:
6+
# ./etc/generate-latest-apidocs.sh
7+
#
8+
# This script is meant to be run from the project root directory.
9+
10+
set -o errexit
11+
set -o pipefail
12+
13+
LATEST_VERSION="4.0.0"
14+
DOXYGEN_VERSION_REQUIRED="1.12.0"
15+
16+
# Permit using a custom Doxygen binary.
17+
: "${DOXYGEN_BINARY:=doxygen}"
18+
19+
# Use the current repository instead of a clean temporary repository.
20+
: "${DOXYGEN_USE_CURRENT:=0}"
21+
22+
# Permit using any Doxygen version.
23+
: "${DOXYGEN_ANY_VERSION:=0}"
24+
25+
command -v git >/dev/null
26+
command -v mktemp >/dev/null
27+
command -v sed >/dev/null
28+
29+
if [[ ! -d build ]]; then
30+
echo "missing build directory: this script must be run from the project root directory" 1>&2
31+
exit 1
32+
fi
33+
34+
# Validate Doxygen version.
35+
doxygen_version="$("${DOXYGEN_BINARY:?}" -v | perl -lne 'print $1 if m/^(\d+\.\d+\.\d+).*$/')"
36+
if [[ "${doxygen_version:-}" != "${DOXYGEN_VERSION_REQUIRED:?}" ]]; then
37+
if [[ "${DOXYGEN_ANY_VERSION:?}" == 1 ]]; then
38+
echo "using ${DOXYGEN_BINARY:?} version ${doxygen_version:-"unknown"} which does not equal ${DOXYGEN_VERSION_REQUIRED:?}" 1>&2
39+
else
40+
echo "${DOXYGEN_BINARY} version ${doxygen_version:-"unknown"} does not equal ${DOXYGEN_VERSION_REQUIRED:?}" 1>&2
41+
exit 1
42+
fi
43+
fi
44+
45+
working_dir="$(pwd)"
46+
apidocspath="${working_dir:?}/build/docs/api"
47+
48+
if [[ "${DOXYGEN_USE_CURRENT:?}" == 1 ]]; then
49+
# Use the current repository's build directory.
50+
output_directory="${apidocspath:?}/current"
51+
scratch_dir="$(pwd)"
52+
else
53+
# Use a clean copy of the repository.
54+
output_directory="${apidocspath:?}/mongocxx-${LATEST_VERSION:?}"
55+
scratch_dir="$(mktemp -d)"
56+
trap 'rm -rf "${scratch_dir:?}"' EXIT
57+
58+
git clone -q -c advice.detachedHead=false -b "r${LATEST_VERSION}" . "${scratch_dir:?}"
59+
60+
# Update the Doxyfile configuration file:
61+
# - set OUTPUT_DIRECTORY to `build/docs/api/mongocxx-<version>`.
62+
# - set PROJECT_NUMBER to `<version>`.
63+
sed -i'' \
64+
-e "s|^OUTPUT_DIRECTORY\s*=\s*.*$|OUTPUT_DIRECTORY = ${output_directory:?}|g" \
65+
-e "s|^PROJECT_NUMBER\s*=\s*.*$|PROJECT_NUMBER = ${LATEST_VERSION:?}|g" \
66+
"${scratch_dir:?}/Doxyfile"
67+
fi
68+
69+
mkdir -p "${output_directory:?}"
70+
71+
# Generate API documentation.
72+
(
73+
cd "${scratch_dir:?}"
74+
75+
set -o xtrace
76+
77+
cmake -S . -B build --log-level=WARNING
78+
cmake --build build --target doxygen-install-headers
79+
"${DOXYGEN_BINARY:?}"
80+
)

0 commit comments

Comments
 (0)