[clang-doc] place HTML/JSON output inside their own directories (#150655)

Instead of just outputting everything into the designated root folder,
HTML and JSON output will be placed in html/ and json/ directories.
This commit is contained in:
Erick Velez 2025-08-14 12:21:40 -07:00 committed by GitHub
parent cbfc22c06b
commit 4f007041a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 34 additions and 26 deletions

View File

@ -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);
}

View File

@ -600,7 +600,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())

View File

@ -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>

View File

@ -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) {

View File

@ -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 {};

View File

@ -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;

View File

@ -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;

View File

@ -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++;

View File

@ -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>

View File

@ -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) {

View File

@ -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() {}

View File

@ -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) {

View File

@ -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 {};

View File

@ -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;

View File

@ -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,

View File

@ -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;