https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/150655
Instead of just outputting everything into the designated root folder, HTML and JSON output will be placed in html/ and json/ directories. >From 3381022d14818288a7bb69334751c2474667d9a4 Mon Sep 17 00:00:00 2001 From: Erick Velez <erickvel...@gmail.com> Date: Thu, 24 Jul 2025 20:33:27 -0700 Subject: [PATCH] [clang-doc] place HTML/JSON output inside their own directories Instead of just outputting everything into the designated root folder, HTML and JSON output will be placed in html/ and json/ directories. --- .../clang-doc/HTMLMustacheGenerator.cpp | 18 ++++++++++++------ clang-tools-extra/clang-doc/JSONGenerator.cpp | 4 +++- .../test/clang-doc/basic-project.mustache.test | 8 ++++---- .../test/clang-doc/json/class-requires.cpp | 2 +- .../clang-doc/json/class-specialization.cpp | 4 ++-- .../test/clang-doc/json/class-template.cpp | 2 +- .../test/clang-doc/json/class.cpp | 2 +- .../clang-doc/json/compound-constraints.cpp | 2 +- .../test/clang-doc/json/concept.cpp | 2 +- .../test/clang-doc/json/function-requires.cpp | 2 +- .../clang-doc/json/function-specifiers.cpp | 2 +- .../test/clang-doc/json/method-template.cpp | 2 +- .../test/clang-doc/json/namespace.cpp | 2 +- .../test/clang-doc/json/nested-namespace.cpp | 4 ++-- .../test/clang-doc/mustache-index.cpp | 2 +- .../clang-doc/mustache-separate-namespace.cpp | 2 +- 16 files changed, 34 insertions(+), 26 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp index a64cb5ea26a79..1ab40aacbfe09 100644 --- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp @@ -144,17 +144,22 @@ Error MustacheHTMLGenerator::generateDocs( } else return JSONGenerator.takeError(); } + SmallString<128> JSONPath; + sys::path::native(RootDir.str() + "/json", JSONPath); StringMap<json::Value> JSONFileMap; { llvm::TimeTraceScope TS("Iterate JSON files"); std::error_code EC; - sys::fs::directory_iterator JSONIter(RootDir, EC); + sys::fs::directory_iterator JSONIter(JSONPath, EC); std::vector<json::Value> JSONFiles; JSONFiles.reserve(Infos.size()); if (EC) return createStringError("Failed to create directory iterator."); + SmallString<128> HTMLDirPath(RootDir.str() + "/html/"); + if (auto EC = sys::fs::create_directories(HTMLDirPath)) + return createFileError(HTMLDirPath, EC); while (JSONIter != sys::fs::directory_iterator()) { if (EC) return createFileError("Failed to iterate: " + JSONIter->path(), EC); @@ -177,14 +182,15 @@ Error MustacheHTMLGenerator::generateDocs( return Parsed.takeError(); std::error_code FileErr; - SmallString<16> HTMLPath(Path.begin(), Path.end()); - sys::path::replace_extension(HTMLPath, "html"); - raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None); + SmallString<128> HTMLFilePath(HTMLDirPath); + sys::path::append(HTMLFilePath, sys::path::filename(Path)); + sys::path::replace_extension(HTMLFilePath, "html"); + raw_fd_ostream InfoOS(HTMLFilePath, FileErr, sys::fs::OF_None); if (FileErr) return createFileOpenError(Path, FileErr); - if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath), - HTMLPath, InfoOS, CDCtx)) + if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLFilePath), + HTMLFilePath, InfoOS, CDCtx)) return Err; JSONIter.increment(EC); } diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 92a4117c4e534..49c66c51e8f3b 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -586,7 +586,9 @@ Error JSONGenerator::generateDocs( Info *Info = Group.getValue().get(); SmallString<128> Path; - sys::path::native(RootDir, Path); + auto RootDirStr = RootDir.str() + "/json"; + StringRef JSONDir = StringRef(RootDirStr); + sys::path::native(JSONDir, Path); if (!CreatedDirs.contains(Path)) { if (std::error_code Err = sys::fs::create_directories(Path); Err != std::error_code()) diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 4fb38e2b32fcb..30f51fb910659 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -2,10 +2,10 @@ // RUN: sed 's|$test_dir|%/S|g' %S/Inputs/basic-project/database_template.json > %t/build/compile_commands.json // RUN: clang-doc --format=mustache --output=%t/docs --executor=all-TUs %t/build/compile_commands.json -// RUN: FileCheck %s -input-file=%t/docs/_ZTV5Shape.html -check-prefix=HTML-SHAPE -// RUN: FileCheck %s -input-file=%t/docs/_ZTV10Calculator.html -check-prefix=HTML-CALC -// RUN: FileCheck %s -input-file=%t/docs/_ZTV9Rectangle.html -check-prefix=HTML-RECTANGLE -// RUN: FileCheck %s -input-file=%t/docs/_ZTV6Circle.html -check-prefix=HTML-CIRCLE +// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV5Shape.html -check-prefix=HTML-SHAPE +// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV10Calculator.html -check-prefix=HTML-CALC +// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV9Rectangle.html -check-prefix=HTML-RECTANGLE +// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV6Circle.html -check-prefix=HTML-CIRCLE HTML-SHAPE: <html lang="en-US"> HTML-SHAPE: <head> diff --git a/clang-tools-extra/test/clang-doc/json/class-requires.cpp b/clang-tools-extra/test/clang-doc/json/class-requires.cpp index bf6c889849a70..513961723990e 100644 --- a/clang-tools-extra/test/clang-doc/json/class-requires.cpp +++ b/clang-tools-extra/test/clang-doc/json/class-requires.cpp @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s -// RUN: FileCheck %s < %t/_ZTV7MyClass.json +// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json template<typename T> concept Addable = requires(T a, T b) { diff --git a/clang-tools-extra/test/clang-doc/json/class-specialization.cpp b/clang-tools-extra/test/clang-doc/json/class-specialization.cpp index e9259edad5cb8..d3ad6957e7851 100644 --- a/clang-tools-extra/test/clang-doc/json/class-specialization.cpp +++ b/clang-tools-extra/test/clang-doc/json/class-specialization.cpp @@ -1,7 +1,7 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --output=%t --format=json --executor=standalone %s -// RUN: FileCheck %s < %t/_ZTV7MyClass.json --check-prefix=BASE -// RUN: FileCheck %s < %t/_ZTV7MyClassIiE.json --check-prefix=SPECIALIZATION +// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json --check-prefix=BASE +// RUN: FileCheck %s < %t/json/_ZTV7MyClassIiE.json --check-prefix=SPECIALIZATION template<typename T> struct MyClass {}; diff --git a/clang-tools-extra/test/clang-doc/json/class-template.cpp b/clang-tools-extra/test/clang-doc/json/class-template.cpp index 149248c772055..5ef78f54854dd 100644 --- a/clang-tools-extra/test/clang-doc/json/class-template.cpp +++ b/clang-tools-extra/test/clang-doc/json/class-template.cpp @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --output=%t --format=json --executor=standalone %s -// RUN: FileCheck %s < %t/_ZTV7MyClass.json +// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json template<typename T> struct MyClass { T MemberTemplate; diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index 79b8fed0a0188..20a9f218b3d79 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --output=%t --format=json --executor=standalone %s -// RUN: FileCheck %s < %t/_ZTV7MyClass.json +// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json struct Foo; diff --git a/clang-tools-extra/test/clang-doc/json/compound-constraints.cpp b/clang-tools-extra/test/clang-doc/json/compound-constraints.cpp index bb2b4ca770fc0..1a73a0ddb722f 100644 --- a/clang-tools-extra/test/clang-doc/json/compound-constraints.cpp +++ b/clang-tools-extra/test/clang-doc/json/compound-constraints.cpp @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s -// RUN: FileCheck %s < %t/index.json +// RUN: FileCheck %s < %t/json/index.json template<typename T> concept Incrementable = requires (T a) { a++; diff --git a/clang-tools-extra/test/clang-doc/json/concept.cpp b/clang-tools-extra/test/clang-doc/json/concept.cpp index 4c810244ca41b..e96ec14d7dde4 100644 --- a/clang-tools-extra/test/clang-doc/json/concept.cpp +++ b/clang-tools-extra/test/clang-doc/json/concept.cpp @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s -// RUN: FileCheck %s < %t/index.json +// RUN: FileCheck %s < %t/json/index.json // Requires that T suports post and pre-incrementing. template<typename T> diff --git a/clang-tools-extra/test/clang-doc/json/function-requires.cpp b/clang-tools-extra/test/clang-doc/json/function-requires.cpp index 59ed39ee61fda..94271467cba63 100644 --- a/clang-tools-extra/test/clang-doc/json/function-requires.cpp +++ b/clang-tools-extra/test/clang-doc/json/function-requires.cpp @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s -// RUN: FileCheck %s < %t/index.json +// RUN: FileCheck %s < %t/json/index.json template<typename T> concept Incrementable = requires(T x) { diff --git a/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp index b194e3371bf76..faaccb7d4f63f 100644 --- a/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp +++ b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --output=%t --format=json --executor=standalone %s -// RUN: FileCheck %s < %t/index.json +// RUN: FileCheck %s < %t/json/index.json static void myFunction() {} diff --git a/clang-tools-extra/test/clang-doc/json/method-template.cpp b/clang-tools-extra/test/clang-doc/json/method-template.cpp index 14232d00e277a..87977f891a223 100644 --- a/clang-tools-extra/test/clang-doc/json/method-template.cpp +++ b/clang-tools-extra/test/clang-doc/json/method-template.cpp @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --output=%t --format=json --executor=standalone %s -// RUN: FileCheck %s < %t/_ZTV7MyClass.json +// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json struct MyClass { template<class T> T methodTemplate(T param) { diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp index 4b6b38869f714..dcf83236bae28 100644 --- a/clang-tools-extra/test/clang-doc/json/namespace.cpp +++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --output=%t --format=json --executor=standalone %s -// RUN: FileCheck %s < %t/index.json +// RUN: FileCheck %s < %t/json/index.json class MyClass {}; diff --git a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp index 255e540bd6c7c..b19afc1885104 100644 --- a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp +++ b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp @@ -1,7 +1,7 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --output=%t --format=json --executor=standalone %s -// RUN: FileCheck %s < %t/nested.json --check-prefix=NESTED -// RUN: FileCheck %s < %t/inner.json --check-prefix=INNER +// RUN: FileCheck %s < %t/json/nested.json --check-prefix=NESTED +// RUN: FileCheck %s < %t/json/inner.json --check-prefix=INNER namespace nested { int Global; diff --git a/clang-tools-extra/test/clang-doc/mustache-index.cpp b/clang-tools-extra/test/clang-doc/mustache-index.cpp index 910233b943666..f9aad193799b3 100644 --- a/clang-tools-extra/test/clang-doc/mustache-index.cpp +++ b/clang-tools-extra/test/clang-doc/mustache-index.cpp @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --format=mustache --output=%t --executor=standalone %s -// RUN: FileCheck %s < %t/index.html +// RUN: FileCheck %s < %t/html/index.html enum Color { RED, diff --git a/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp b/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp index 7d7d108e63873..a73a5ab6a843b 100644 --- a/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp +++ b/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp @@ -1,6 +1,6 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --format=mustache --output=%t --executor=standalone %s -// RUN: FileCheck %s < %t/MyNamespace.html +// RUN: FileCheck %s < %t/html/MyNamespace.html namespace MyNamespace { class Foo; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits