Page MenuHomePhabricator

[clang][cmake] Include generated rst files in html built by docs-clang-html target
ClosedPublic

Authored by tstellar on Jan 16 2020, 1:45 PM.

Details

Summary

This is an attempt to simply the process of building the clang
documentation, which should help avoid some of the recent issues we've
had generating the documentation for the website.

The html documentation for clang is generated by sphinx from the
reStructuredText (rst) files we have in the clang/docs directory.
There are also some rst files that need to be generated by TableGen,
before they can be passed to sphinx. Prior to this patch we were not
generating those rst files as part with the build system and they had to be
generated manually.

This patch enables the automatic generation of these rst files, but
since they are generated at build time the cannot be placed in the
clang/docs directory and must go into the cmake build directory.

Unfortunately sphinx does not currently support multiple source
directories[1], so in order to be able to generate the full
documentation, we need to work around this by copying the
rst files from the clang/docs into the build directory before
generating the html documentation.

[1] https://github.com/sphinx-doc/sphinx/issues/3132

Diff Detail

Event Timeline

tstellar created this revision.Jan 16 2020, 1:45 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 16 2020, 1:45 PM

Unit tests: pass. 61925 tests passed, 0 failed and 783 were skipped.

clang-tidy: unknown.

clang-format: pass.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Thank you for working on this, I think this is a great improvement. I am not super qualified to review the cmake, but it looks eminently reasonable to me.

mgorny accepted this revision.Jan 17 2020, 7:56 AM

Besides the mentioned misindent, the CMake code looks correct. Could you test whether it works with standalone (out-of-LLVM) builds as well?

clang/docs/CMakeLists.txt
116

Looks like misindent.

This revision is now accepted and ready to land.Jan 17 2020, 7:56 AM
tstellar updated this revision to Diff 238893.Jan 17 2020, 2:22 PM
  • Fix indentation.
  • Remove placeholder AttributeReference.rst. The install target was replacing the generated AttributeReference.rst with this which caused the html page to be empty.
  • Tested with stand-alone clang builds: cmake ../clang -G Ninja -DCLANG_INCLUDE_DOCS=ON -DLLVM_BUILD_DOCS=ON -DLLVM_ENABLE_SPHINX=ON -DSPHINX_WARNINGS_AS_ERRORS=OFF
tstellar marked an inline comment as done.Jan 17 2020, 2:23 PM

Unit tests: pass. 61925 tests passed, 0 failed and 783 were skipped.

clang-tidy: unknown.

clang-format: pass.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

delcypher added inline comments.
llvm/cmake/modules/AddSphinxTarget.cmake
33

@tstellar I'm not 100% sure about this but I think you probably want ${CMAKE_CURRENT_SOURCE_DIR} quoted. If it's not then if it contains spaces I think you might make ARG_SOURCE_DIR a list. Then we you go to print it you'll probably end up with list separators (i.e. ;) in the command you pass the the sphinx binary.

I've not tested this though so I could be wrong.

tstellar updated this revision to Diff 238914.Jan 17 2020, 3:48 PM
tstellar marked 2 inline comments as done.
  • Add quotes around ${CMAKE_CURRENT_SOURCE_DIR}

Unit tests: pass. 61925 tests passed, 0 failed and 783 were skipped.

clang-tidy: unknown.

clang-format: pass.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Any other commits before I commit this?

llvm/cmake/modules/AddSphinxTarget.cmake
33

There are quotes used when setting variables above, so I went ahead and changed this to match.

delcypher requested changes to this revision.Feb 11 2020, 1:11 PM
delcypher added inline comments.
clang/docs/CMakeLists.txt
93

gen_rst_file is a very ambiguous name. At call sites it might not be obvious what this function does. Something like gen_rst_file_from_td might be more helpful.

94

You might want to add a check that ${CMAKE_CURRENT_SOURCE_DIR}/${source} exists in this function and error if it does not exist.

97

This add_dependencies(...) command is very fragile and is creating an implicit coupling between:

  • The implementation of add_sphinx_target().
  • The declaration of the clang html sphinx target.
  • The implementation of gen_rst_file.

gen_rst_file should probably take an optional argument for the target (in this case docs-clang-html) to add a dependency to.

This does not completely fix the dependency on add_sphinx_target implementation but it does mean that gen_rst_file isn't also dependent.

107–120

Minor nit: You might want to quote uses of ${CMAKE_CURRENT_BINARY_DIR}, ${CMAKE_COMMAND}, and ${CMAKE_CURRENT_SOURCE_DIR}.

This revision now requires changes to proceed.Feb 11 2020, 1:11 PM
tstellar updated this revision to Diff 247123.Feb 27 2020, 3:34 PM
tstellar marked 4 inline comments as done.

Address most recent review comments.

delcypher accepted this revision.Mar 5 2020, 4:02 PM

LGTM. Thanks for addressing all the issues I raised.

This revision is now accepted and ready to land.Mar 5 2020, 4:02 PM
This revision was automatically updated to reflect the committed changes.