[clang-doc] Default to Standalone executor and improve documentation

This should provide a more intuitive usage consistent with other tools.

Differential Revision: https://reviews.llvm.org/D130226
This commit is contained in:
Petr Hosek 2022-07-21 08:12:08 +00:00
parent 0eaecbbc23
commit ea50901aa9
3 changed files with 41 additions and 16 deletions

View File

@ -182,12 +182,23 @@ int main(int argc, const char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
std::error_code OK;
ExecutorName.setInitialValue("all-TUs");
auto Exec = clang::tooling::createExecutorFromCommandLineArgs(
argc, argv, ClangDocCategory);
const char *Overview =
R"(Generates documentation from source code and comments.
if (!Exec) {
llvm::errs() << toString(Exec.takeError()) << "\n";
Example usage for files without flags (default):
$ clang-doc File1.cpp File2.cpp ... FileN.cpp
Example usage for a project using a compile commands database:
$ clang-doc --executor=all-TUs compile_commands.json
)";
auto Executor = clang::tooling::createExecutorFromCommandLineArgs(
argc, argv, ClangDocCategory, Overview);
if (!Executor) {
llvm::errs() << toString(Executor.takeError()) << "\n";
return 1;
}
@ -208,7 +219,7 @@ int main(int argc, const char **argv) {
ArgAdjuster);
clang::doc::ClangDocContext CDCtx = {
Exec->get()->getExecutionContext(),
Executor->get()->getExecutionContext(),
ProjectName,
PublicOnly,
OutDirectory,
@ -239,7 +250,7 @@ int main(int argc, const char **argv) {
// Mapping phase
llvm::outs() << "Mapping decls...\n";
auto Err =
Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
Executor->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
if (Err) {
if (IgnoreMappingFailures)
llvm::errs() << "Error mapping decls in files. Clang-doc will ignore "
@ -256,7 +267,7 @@ int main(int argc, const char **argv) {
// bitcode-encoded representation of the Info object.
llvm::outs() << "Collecting infos...\n";
llvm::StringMap<std::vector<StringRef>> USRToBitcode;
Exec->get()->getToolResults()->forEachResult(
Executor->get()->getToolResults()->forEachResult(
[&](StringRef Key, StringRef Value) {
auto R = USRToBitcode.try_emplace(Key, std::vector<StringRef>());
R.first->second.emplace_back(Value);

View File

@ -81,7 +81,7 @@ Miscellaneous
Improvements to clang-doc
-------------------------
The improvements are...
- The default executor was changed to standalone to match other tools.
Improvements to clang-query
---------------------------

View File

@ -25,19 +25,23 @@ compile command database for your project (for an example of how to do this
see `How To Setup Tooling For LLVM
<https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html>`_).
By default, the tool will run on all files listed in the given compile commands
database:
The tool will process a list of files by default:
.. code-block:: console
$ clang-doc /path/to/compile_commands.json
$ clang-doc File1.cpp File2.cpp ... FileN.cpp
The tool can also be used on a single file or multiple files if a build path is
passed with the ``-p`` flag.
The tool can be also used with a compile commands database:
.. code-block:: console
$ clang-doc /path/to/file.cpp -p /path/to/build
$ clang-doc --executor=all-TUs compile_commands.json
To select only a subset of files from the database, use the ``--filter`` flag:
.. code-block:: console
$ clang-doc --executor=all-TUs --filter=File[0-9]+.cpp compile_commands.json
Output
======
@ -50,7 +54,7 @@ The top-level directory is configurable through the ``output`` flag:
.. code-block:: console
$ clang-doc -output=output/directory/ compile_commands.json
$ clang-doc --output=output/directory/ compile_commands.json
Configuration
=============
@ -67,6 +71,16 @@ Options
.. code-block:: console
$ clang-doc --help
OVERVIEW: Generates documentation from source code and comments.
Example usage for files without flags (default):
$ clang-doc File1.cpp File2.cpp ... FileN.cpp
Example usage for a project using a compile commands database:
$ clang-doc --executor=all-TUs compile_commands.json
USAGE: clang-doc [options] <source0> [... <sourceN>]
OPTIONS: