Skip to content

Commit 98b3191

Browse files
[libc][docgen] regen docgen via cmake (#119628)
Now, `ninja docs-libc-html` will re-run docgen. Previously, we would run docgen offline, and commit the result. Now we no longer need to do that; docgen is invoked from the dependencies of the `docs-libc-html` target on demand. This commit removes the dynamically generated .rst files (keeping the static ones that haven't been converted to docgen), and fixes up some mistakes I failed to cleanup recently since I didn't have such automation in place to catch such bugs.
1 parent 21edac2 commit 98b3191

24 files changed

+136
-3050
lines changed

libc/docs/CMakeLists.txt

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,72 @@
1-
21
if (LLVM_ENABLE_SPHINX)
32
include(AddSphinxTarget)
43
if (SPHINX_FOUND)
54
if (${SPHINX_OUTPUT_HTML})
6-
add_sphinx_target(html libc)
5+
# Similar to clang, we copy our static .rst files from libc/docs/ to the
6+
# $build_dir/libc/docs/. That way, we can have a mix of both static
7+
# (committed) .rst files, and dynamically generated .rst files. We don't
8+
# want the dynamically generated .rst files to pollute the source tree.
9+
add_custom_target(copy-libc-rst-docs
10+
COMMAND "${CMAKE_COMMAND}" -E copy_directory
11+
"${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
12+
13+
# For headers that are nested in directories, we need to
14+
# `mkdir $build_dir/libc/docs/headers/$dir` since the above copy_directory
15+
# command does not create such copies. Otherwise, the invocation of docgen
16+
# below will fail since the output file would be placed in a directory that
17+
# does not exist, leading to a `No such file or directory` error from the
18+
# shell.
19+
file(MAKE_DIRECTORY
20+
"${CMAKE_CURRENT_BINARY_DIR}/headers/arpa/"
21+
"${CMAKE_CURRENT_BINARY_DIR}/headers/sys/"
22+
)
23+
24+
# Change sphinx to build from $build_dir/libc/docs/ rather than
25+
# llvm-project/libc/docs/.
26+
add_sphinx_target(html libc SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
27+
# Depend on the copy target.
28+
add_dependencies(docs-libc-html copy-libc-rst-docs)
29+
30+
# Maintain a list of headers for which we dynamically generate html docs
31+
# for via docgen. For more complex docs (such as per arch support, a la
32+
# math.h), those should be omitted and exist statically in
33+
# libc/docs/headers/.
34+
list(APPEND docgen_list
35+
arpa/inet
36+
assert
37+
ctype
38+
errno
39+
fenv
40+
float
41+
inttypes
42+
locale
43+
setjmp
44+
signal
45+
stdbit
46+
stdio
47+
stdlib
48+
string
49+
strings
50+
sys/mman
51+
threads
52+
uchar
53+
wchar
54+
wctype
55+
)
56+
57+
foreach(stem IN LISTS docgen_list)
58+
# It is an error in cmake to have a target name that contains a "/", but
59+
# docgen relies on the "/" to find headers nested under directories.
60+
# Replace with underscore.
61+
string(REPLACE "/" "_" stem_rst ${stem})
62+
63+
# docgen invocation.
64+
add_custom_target(${stem_rst}
65+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../utils/docgen/docgen.py ${stem}.h >
66+
${CMAKE_CURRENT_BINARY_DIR}/headers/${stem}.rst)
67+
# depend on the docgen invocation.
68+
add_dependencies(docs-libc-html ${stem_rst})
69+
endforeach()
770
endif()
871
endif()
972
endif()

libc/docs/headers/arpa/inet.rst

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

libc/docs/headers/assert.rst

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

libc/docs/headers/ctype.rst

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

libc/docs/headers/errno.rst

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

0 commit comments

Comments
 (0)