From ea50901aa9e58fe3750df3e38471e65b027317fc Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Thu, 21 Jul 2022 08:12:08 +0000 Subject: [PATCH] [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 --- .../clang-doc/tool/ClangDocMain.cpp | 27 ++++++++++++------ clang-tools-extra/docs/ReleaseNotes.rst | 2 +- clang-tools-extra/docs/clang-doc.rst | 28 ++++++++++++++----- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index 218e36d9d91e..fc22e55edfb1 100644 --- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp +++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp @@ -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> USRToBitcode; - Exec->get()->getToolResults()->forEachResult( + Executor->get()->getToolResults()->forEachResult( [&](StringRef Key, StringRef Value) { auto R = USRToBitcode.try_emplace(Key, std::vector()); R.first->second.emplace_back(Value); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index e645468016e0..840e3aac3257 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -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 --------------------------- diff --git a/clang-tools-extra/docs/clang-doc.rst b/clang-tools-extra/docs/clang-doc.rst index bd0a9cacaf01..d65b986c9016 100644 --- a/clang-tools-extra/docs/clang-doc.rst +++ b/clang-tools-extra/docs/clang-doc.rst @@ -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 `_). -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] [... ] OPTIONS: