[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 updated
https://github.com/llvm/llvm-project/pull/149589
>From bc443f0743080af8102372da7e844d599586e250 Mon Sep 17 00:00:00 2001
From: Erick Velez
Date: Fri, 18 Jul 2025 13:59:44 -0700
Subject: [PATCH] [clang-doc] integrate JSON as the source for Mustache
templates
---
.../clang-doc/HTMLMustacheGenerator.cpp | 489 +++---
.../clang-doc/assets/class-template.mustache | 62 +--
.../clang-doc/assets/enum-template.mustache | 12 +-
.../assets/function-template.mustache | 2 +-
.../assets/namespace-template.mustache| 45 +-
.../clang-doc/basic-project.mustache.test | 70 +--
.../test/clang-doc/mustache-index.cpp | 10 +-
.../clang-doc/mustache-separate-namespace.cpp | 8 +-
.../clang-doc/HTMLMustacheGeneratorTest.cpp | 129 -
9 files changed, 173 insertions(+), 654 deletions(-)
diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
index 7aeaa1b7cf67d..a64cb5ea26a79 100644
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -27,6 +27,9 @@ using namespace llvm::mustache;
namespace clang {
namespace doc {
+static Error generateDocForJSON(json::Value &JSON, StringRef Filename,
+StringRef Path, raw_fd_ostream &OS,
+const ClangDocContext &CDCtx);
static Error createFileOpenError(StringRef FileName, std::error_code EC) {
return createFileError("cannot open file " + FileName, EC);
@@ -132,404 +135,68 @@ Error MustacheHTMLGenerator::generateDocs(
return Err;
}
- // Track which directories we already tried to create.
- StringSet<> CreatedDirs;
- // Collect all output by file name and create the necessary directories.
- StringMap> FileToInfos;
- for (const auto &Group : Infos) {
-llvm::TimeTraceScope TS("setup directories");
-doc::Info *Info = Group.getValue().get();
-
-SmallString<128> Path;
-sys::path::native(RootDir, Path);
-sys::path::append(Path, Info->getRelativeFilePath(""));
-if (!CreatedDirs.contains(Path)) {
- if (std::error_code EC = sys::fs::create_directories(Path))
-return createStringError(EC, "failed to create directory '%s'.",
- Path.c_str());
- CreatedDirs.insert(Path);
-}
-
-sys::path::append(Path, Info->getFileBaseName() + ".html");
-FileToInfos[Path].push_back(Info);
+ {
+llvm::TimeTraceScope TS("Generate JSON for Mustache");
+if (auto JSONGenerator = findGeneratorByName("json")) {
+ if (Error Err = JSONGenerator.get()->generateDocs(
+ RootDir, std::move(Infos), CDCtx))
+return Err;
+} else
+ return JSONGenerator.takeError();
}
+ StringMap JSONFileMap;
{
-llvm::TimeTraceScope TS("Generate Docs");
-for (const auto &Group : FileToInfos) {
- llvm::TimeTraceScope TS("Info to Doc");
+llvm::TimeTraceScope TS("Iterate JSON files");
+std::error_code EC;
+sys::fs::directory_iterator JSONIter(RootDir, EC);
+std::vector JSONFiles;
+JSONFiles.reserve(Infos.size());
+if (EC)
+ return createStringError("Failed to create directory iterator.");
+
+while (JSONIter != sys::fs::directory_iterator()) {
+ if (EC)
+return createFileError("Failed to iterate: " + JSONIter->path(), EC);
+
+ auto Path = StringRef(JSONIter->path());
+ if (!Path.ends_with(".json")) {
+JSONIter.increment(EC);
+continue;
+ }
+
+ auto File = MemoryBuffer::getFile(Path);
+ if (EC = File.getError(); EC)
+// TODO: Buffer errors to report later, look into using Clang
+// diagnostics.
+llvm::errs() << "Failed to open file: " << Path << " " << EC.message()
+ << '\n';
+
+ auto Parsed = json::parse((*File)->getBuffer());
+ if (!Parsed)
+return Parsed.takeError();
+
std::error_code FileErr;
- raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None);
+ SmallString<16> HTMLPath(Path.begin(), Path.end());
+ sys::path::replace_extension(HTMLPath, "html");
+ raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None);
if (FileErr)
-return createFileOpenError(Group.getKey(), FileErr);
+return createFileOpenError(Path, FileErr);
- for (const auto &Info : Group.getValue())
-if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx))
- return Err;
+ if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath),
+ HTMLPath, InfoOS, CDCtx))
+return Err;
+ JSONIter.increment(EC);
}
}
- return Error::success();
-}
-
-static json::Value
-extractValue(const Location &L,
- std::optional RepositoryUrl = std::nullopt) {
- Object Obj = Object();
- // TODO: Consider using both Start/End line n
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 updated
https://github.com/llvm/llvm-project/pull/149589
>From bc443f0743080af8102372da7e844d599586e250 Mon Sep 17 00:00:00 2001
From: Erick Velez
Date: Fri, 18 Jul 2025 13:59:44 -0700
Subject: [PATCH] [clang-doc] integrate JSON as the source for Mustache
templates
---
.../clang-doc/HTMLMustacheGenerator.cpp | 489 +++---
.../clang-doc/assets/class-template.mustache | 62 +--
.../clang-doc/assets/enum-template.mustache | 12 +-
.../assets/function-template.mustache | 2 +-
.../assets/namespace-template.mustache| 45 +-
.../clang-doc/basic-project.mustache.test | 70 +--
.../test/clang-doc/mustache-index.cpp | 10 +-
.../clang-doc/mustache-separate-namespace.cpp | 8 +-
.../clang-doc/HTMLMustacheGeneratorTest.cpp | 129 -
9 files changed, 173 insertions(+), 654 deletions(-)
diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
index 7aeaa1b7cf67d..a64cb5ea26a79 100644
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -27,6 +27,9 @@ using namespace llvm::mustache;
namespace clang {
namespace doc {
+static Error generateDocForJSON(json::Value &JSON, StringRef Filename,
+StringRef Path, raw_fd_ostream &OS,
+const ClangDocContext &CDCtx);
static Error createFileOpenError(StringRef FileName, std::error_code EC) {
return createFileError("cannot open file " + FileName, EC);
@@ -132,404 +135,68 @@ Error MustacheHTMLGenerator::generateDocs(
return Err;
}
- // Track which directories we already tried to create.
- StringSet<> CreatedDirs;
- // Collect all output by file name and create the necessary directories.
- StringMap> FileToInfos;
- for (const auto &Group : Infos) {
-llvm::TimeTraceScope TS("setup directories");
-doc::Info *Info = Group.getValue().get();
-
-SmallString<128> Path;
-sys::path::native(RootDir, Path);
-sys::path::append(Path, Info->getRelativeFilePath(""));
-if (!CreatedDirs.contains(Path)) {
- if (std::error_code EC = sys::fs::create_directories(Path))
-return createStringError(EC, "failed to create directory '%s'.",
- Path.c_str());
- CreatedDirs.insert(Path);
-}
-
-sys::path::append(Path, Info->getFileBaseName() + ".html");
-FileToInfos[Path].push_back(Info);
+ {
+llvm::TimeTraceScope TS("Generate JSON for Mustache");
+if (auto JSONGenerator = findGeneratorByName("json")) {
+ if (Error Err = JSONGenerator.get()->generateDocs(
+ RootDir, std::move(Infos), CDCtx))
+return Err;
+} else
+ return JSONGenerator.takeError();
}
+ StringMap JSONFileMap;
{
-llvm::TimeTraceScope TS("Generate Docs");
-for (const auto &Group : FileToInfos) {
- llvm::TimeTraceScope TS("Info to Doc");
+llvm::TimeTraceScope TS("Iterate JSON files");
+std::error_code EC;
+sys::fs::directory_iterator JSONIter(RootDir, EC);
+std::vector JSONFiles;
+JSONFiles.reserve(Infos.size());
+if (EC)
+ return createStringError("Failed to create directory iterator.");
+
+while (JSONIter != sys::fs::directory_iterator()) {
+ if (EC)
+return createFileError("Failed to iterate: " + JSONIter->path(), EC);
+
+ auto Path = StringRef(JSONIter->path());
+ if (!Path.ends_with(".json")) {
+JSONIter.increment(EC);
+continue;
+ }
+
+ auto File = MemoryBuffer::getFile(Path);
+ if (EC = File.getError(); EC)
+// TODO: Buffer errors to report later, look into using Clang
+// diagnostics.
+llvm::errs() << "Failed to open file: " << Path << " " << EC.message()
+ << '\n';
+
+ auto Parsed = json::parse((*File)->getBuffer());
+ if (!Parsed)
+return Parsed.takeError();
+
std::error_code FileErr;
- raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None);
+ SmallString<16> HTMLPath(Path.begin(), Path.end());
+ sys::path::replace_extension(HTMLPath, "html");
+ raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None);
if (FileErr)
-return createFileOpenError(Group.getKey(), FileErr);
+return createFileOpenError(Path, FileErr);
- for (const auto &Info : Group.getValue())
-if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx))
- return Err;
+ if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath),
+ HTMLPath, InfoOS, CDCtx))
+return Err;
+ JSONIter.increment(EC);
}
}
- return Error::success();
-}
-
-static json::Value
-extractValue(const Location &L,
- std::optional RepositoryUrl = std::nullopt) {
- Object Obj = Object();
- // TODO: Consider using both Start/End line n
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 updated
https://github.com/llvm/llvm-project/pull/149589
>From c9f121abb503e121a6ab346e992a2f5673a3b235 Mon Sep 17 00:00:00 2001
From: Erick Velez
Date: Fri, 18 Jul 2025 13:59:44 -0700
Subject: [PATCH] [clang-doc] integrate JSON as the source for Mustache
templates
---
.../clang-doc/HTMLMustacheGenerator.cpp | 487 +++---
.../clang-doc/assets/class-template.mustache | 62 +--
.../clang-doc/assets/enum-template.mustache | 12 +-
.../assets/function-template.mustache | 2 +-
.../assets/namespace-template.mustache| 45 +-
.../clang-doc/basic-project.mustache.test | 70 +--
.../test/clang-doc/mustache-index.cpp | 10 +-
.../clang-doc/mustache-separate-namespace.cpp | 8 +-
.../clang-doc/HTMLMustacheGeneratorTest.cpp | 129 -
9 files changed, 171 insertions(+), 654 deletions(-)
diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
index 7aeaa1b7cf67d..98e2935a8aada 100644
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -27,6 +27,9 @@ using namespace llvm::mustache;
namespace clang {
namespace doc {
+static Error generateDocForJSON(json::Value &JSON, StringRef Filename,
+StringRef Path, raw_fd_ostream &OS,
+const ClangDocContext &CDCtx);
static Error createFileOpenError(StringRef FileName, std::error_code EC) {
return createFileError("cannot open file " + FileName, EC);
@@ -132,404 +135,65 @@ Error MustacheHTMLGenerator::generateDocs(
return Err;
}
- // Track which directories we already tried to create.
- StringSet<> CreatedDirs;
- // Collect all output by file name and create the necessary directories.
- StringMap> FileToInfos;
- for (const auto &Group : Infos) {
-llvm::TimeTraceScope TS("setup directories");
-doc::Info *Info = Group.getValue().get();
-
-SmallString<128> Path;
-sys::path::native(RootDir, Path);
-sys::path::append(Path, Info->getRelativeFilePath(""));
-if (!CreatedDirs.contains(Path)) {
- if (std::error_code EC = sys::fs::create_directories(Path))
-return createStringError(EC, "failed to create directory '%s'.",
- Path.c_str());
- CreatedDirs.insert(Path);
-}
-
-sys::path::append(Path, Info->getFileBaseName() + ".html");
-FileToInfos[Path].push_back(Info);
+ {
+llvm::TimeTraceScope TS("Generate JSON for Mustache");
+if (auto JSONGenerator = findGeneratorByName("json")) {
+ if (Error Err = JSONGenerator.get()->generateDocs(
+ RootDir, std::move(Infos), CDCtx))
+return Err;
+} else
+ return JSONGenerator.takeError();
}
+ StringMap JSONFileMap;
{
-llvm::TimeTraceScope TS("Generate Docs");
-for (const auto &Group : FileToInfos) {
- llvm::TimeTraceScope TS("Info to Doc");
+llvm::TimeTraceScope TS("Iterate JSON files");
+std::error_code EC;
+sys::fs::directory_iterator JSONIter(RootDir, EC);
+std::vector JSONFiles;
+JSONFiles.reserve(Infos.size());
+if (EC)
+ return createStringError("Failed to create directory iterator.");
+
+while (JSONIter != sys::fs::directory_iterator()) {
+ if (EC)
+return createStringError(EC, "Failed to iterate directory");
+
+ auto Path = StringRef(JSONIter->path());
+ if (!Path.ends_with(".json")) {
+JSONIter.increment(EC);
+continue;
+ }
+
+ auto File = MemoryBuffer::getFile(Path);
+ if ((EC = File.getError()))
+continue;
+
+ auto Parsed = json::parse((*File)->getBuffer());
+ if (!Parsed)
+return Parsed.takeError();
+
std::error_code FileErr;
- raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None);
+ SmallString<16> HTMLPath(Path.begin(), Path.end());
+ sys::path::replace_extension(HTMLPath, "html");
+ raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None);
if (FileErr)
-return createFileOpenError(Group.getKey(), FileErr);
+return createFileOpenError(Path, FileErr);
- for (const auto &Info : Group.getValue())
-if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx))
- return Err;
+ if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath),
+ HTMLPath, InfoOS, CDCtx))
+return Err;
+ JSONIter.increment(EC);
}
}
- return Error::success();
-}
-
-static json::Value
-extractValue(const Location &L,
- std::optional RepositoryUrl = std::nullopt) {
- Object Obj = Object();
- // TODO: Consider using both Start/End line numbers to improve location
report
- Obj.insert({"LineNumber", L.StartLineNumber});
- Obj.insert({"Filename", L.Filename});
-
- if (!L.IsFileInRootDir || !RepositoryUrl)
-return Obj;
- SmallS
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
llvmbot wrote:
@llvm/pr-subscribers-clang-tools-extra
Author: Erick Velez (evelez7)
Changes
This patch integrates JSON as the source to generate HTML Mustache templates.
The Mustache generator calls the JSON generator and reads JSON files on the
disk to produce HTML serially.
---
Patch is 48.74 KiB, truncated to 20.00 KiB below, full version:
https://github.com/llvm/llvm-project/pull/149589.diff
9 Files Affected:
- (modified) clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp (+78-409)
- (modified) clang-tools-extra/clang-doc/assets/class-template.mustache
(+32-30)
- (modified) clang-tools-extra/clang-doc/assets/enum-template.mustache (+9-3)
- (modified) clang-tools-extra/clang-doc/assets/function-template.mustache
(+1-1)
- (modified) clang-tools-extra/clang-doc/assets/namespace-template.mustache
(+25-20)
- (modified) clang-tools-extra/test/clang-doc/basic-project.mustache.test
(+13-57)
- (modified) clang-tools-extra/test/clang-doc/mustache-index.cpp (+9-5)
- (modified) clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp
(+6-2)
- (modified)
clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp (-129)
``diff
diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
index 7aeaa1b7cf67d..98e2935a8aada 100644
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -27,6 +27,9 @@ using namespace llvm::mustache;
namespace clang {
namespace doc {
+static Error generateDocForJSON(json::Value &JSON, StringRef Filename,
+StringRef Path, raw_fd_ostream &OS,
+const ClangDocContext &CDCtx);
static Error createFileOpenError(StringRef FileName, std::error_code EC) {
return createFileError("cannot open file " + FileName, EC);
@@ -132,404 +135,65 @@ Error MustacheHTMLGenerator::generateDocs(
return Err;
}
- // Track which directories we already tried to create.
- StringSet<> CreatedDirs;
- // Collect all output by file name and create the necessary directories.
- StringMap> FileToInfos;
- for (const auto &Group : Infos) {
-llvm::TimeTraceScope TS("setup directories");
-doc::Info *Info = Group.getValue().get();
-
-SmallString<128> Path;
-sys::path::native(RootDir, Path);
-sys::path::append(Path, Info->getRelativeFilePath(""));
-if (!CreatedDirs.contains(Path)) {
- if (std::error_code EC = sys::fs::create_directories(Path))
-return createStringError(EC, "failed to create directory '%s'.",
- Path.c_str());
- CreatedDirs.insert(Path);
-}
-
-sys::path::append(Path, Info->getFileBaseName() + ".html");
-FileToInfos[Path].push_back(Info);
+ {
+llvm::TimeTraceScope TS("Generate JSON for Mustache");
+if (auto JSONGenerator = findGeneratorByName("json")) {
+ if (Error Err = JSONGenerator.get()->generateDocs(
+ RootDir, std::move(Infos), CDCtx))
+return Err;
+} else
+ return JSONGenerator.takeError();
}
+ StringMap JSONFileMap;
{
-llvm::TimeTraceScope TS("Generate Docs");
-for (const auto &Group : FileToInfos) {
- llvm::TimeTraceScope TS("Info to Doc");
+llvm::TimeTraceScope TS("Iterate JSON files");
+std::error_code EC;
+sys::fs::directory_iterator JSONIter(RootDir, EC);
+std::vector JSONFiles;
+JSONFiles.reserve(Infos.size());
+if (EC)
+ return createStringError("Failed to create directory iterator.");
+
+while (JSONIter != sys::fs::directory_iterator()) {
+ if (EC)
+return createStringError(EC, "Failed to iterate directory");
+
+ auto Path = StringRef(JSONIter->path());
+ if (!Path.ends_with(".json")) {
+JSONIter.increment(EC);
+continue;
+ }
+
+ auto File = MemoryBuffer::getFile(Path);
+ if ((EC = File.getError()))
+continue;
+
+ auto Parsed = json::parse((*File)->getBuffer());
+ if (!Parsed)
+return Parsed.takeError();
+
std::error_code FileErr;
- raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None);
+ SmallString<16> HTMLPath(Path.begin(), Path.end());
+ sys::path::replace_extension(HTMLPath, "html");
+ raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None);
if (FileErr)
-return createFileOpenError(Group.getKey(), FileErr);
+return createFileOpenError(Path, FileErr);
- for (const auto &Info : Group.getValue())
-if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx))
- return Err;
+ if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath),
+ HTMLPath, InfoOS, CDCtx))
+return Err;
+ JSONIter.increment(EC);
}
}
- return Error::success();
-}
-
-static json::Value
-extractValue(const Location &L,
- std::
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/149589 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/149589 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149589** https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#149588** https://app.graphite.dev/github/pr/llvm/llvm-project/149588?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149589 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 created
https://github.com/llvm/llvm-project/pull/149589
None
>From b36a2d4bc00eee19dae7bd0eaaf08a3b4d8a70a2 Mon Sep 17 00:00:00 2001
From: Erick Velez
Date: Fri, 18 Jul 2025 13:59:44 -0700
Subject: [PATCH] [clang-doc] integrate JSON as the source for Mustache
templates
---
.../clang-doc/HTMLMustacheGenerator.cpp | 487 +++---
.../clang-doc/assets/class-template.mustache | 62 +--
.../clang-doc/assets/enum-template.mustache | 12 +-
.../assets/function-template.mustache | 2 +-
.../assets/namespace-template.mustache| 45 +-
.../clang-doc/basic-project.mustache.test | 70 +--
.../test/clang-doc/mustache-index.cpp | 14 +-
.../clang-doc/mustache-separate-namespace.cpp | 8 +-
.../clang-doc/HTMLMustacheGeneratorTest.cpp | 129 -
9 files changed, 173 insertions(+), 656 deletions(-)
diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
index 7aeaa1b7cf67d..98e2935a8aada 100644
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -27,6 +27,9 @@ using namespace llvm::mustache;
namespace clang {
namespace doc {
+static Error generateDocForJSON(json::Value &JSON, StringRef Filename,
+StringRef Path, raw_fd_ostream &OS,
+const ClangDocContext &CDCtx);
static Error createFileOpenError(StringRef FileName, std::error_code EC) {
return createFileError("cannot open file " + FileName, EC);
@@ -132,404 +135,65 @@ Error MustacheHTMLGenerator::generateDocs(
return Err;
}
- // Track which directories we already tried to create.
- StringSet<> CreatedDirs;
- // Collect all output by file name and create the necessary directories.
- StringMap> FileToInfos;
- for (const auto &Group : Infos) {
-llvm::TimeTraceScope TS("setup directories");
-doc::Info *Info = Group.getValue().get();
-
-SmallString<128> Path;
-sys::path::native(RootDir, Path);
-sys::path::append(Path, Info->getRelativeFilePath(""));
-if (!CreatedDirs.contains(Path)) {
- if (std::error_code EC = sys::fs::create_directories(Path))
-return createStringError(EC, "failed to create directory '%s'.",
- Path.c_str());
- CreatedDirs.insert(Path);
-}
-
-sys::path::append(Path, Info->getFileBaseName() + ".html");
-FileToInfos[Path].push_back(Info);
+ {
+llvm::TimeTraceScope TS("Generate JSON for Mustache");
+if (auto JSONGenerator = findGeneratorByName("json")) {
+ if (Error Err = JSONGenerator.get()->generateDocs(
+ RootDir, std::move(Infos), CDCtx))
+return Err;
+} else
+ return JSONGenerator.takeError();
}
+ StringMap JSONFileMap;
{
-llvm::TimeTraceScope TS("Generate Docs");
-for (const auto &Group : FileToInfos) {
- llvm::TimeTraceScope TS("Info to Doc");
+llvm::TimeTraceScope TS("Iterate JSON files");
+std::error_code EC;
+sys::fs::directory_iterator JSONIter(RootDir, EC);
+std::vector JSONFiles;
+JSONFiles.reserve(Infos.size());
+if (EC)
+ return createStringError("Failed to create directory iterator.");
+
+while (JSONIter != sys::fs::directory_iterator()) {
+ if (EC)
+return createStringError(EC, "Failed to iterate directory");
+
+ auto Path = StringRef(JSONIter->path());
+ if (!Path.ends_with(".json")) {
+JSONIter.increment(EC);
+continue;
+ }
+
+ auto File = MemoryBuffer::getFile(Path);
+ if ((EC = File.getError()))
+continue;
+
+ auto Parsed = json::parse((*File)->getBuffer());
+ if (!Parsed)
+return Parsed.takeError();
+
std::error_code FileErr;
- raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None);
+ SmallString<16> HTMLPath(Path.begin(), Path.end());
+ sys::path::replace_extension(HTMLPath, "html");
+ raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None);
if (FileErr)
-return createFileOpenError(Group.getKey(), FileErr);
+return createFileOpenError(Path, FileErr);
- for (const auto &Info : Group.getValue())
-if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx))
- return Err;
+ if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath),
+ HTMLPath, InfoOS, CDCtx))
+return Err;
+ JSONIter.increment(EC);
}
}
- return Error::success();
-}
-
-static json::Value
-extractValue(const Location &L,
- std::optional RepositoryUrl = std::nullopt) {
- Object Obj = Object();
- // TODO: Consider using both Start/End line numbers to improve location
report
- Obj.insert({"LineNumber", L.StartLineNumber});
- Obj.insert({"Filename", L.Filename});
-
- if (!L.IsFileInRootDir || !RepositoryUrl)
-return Obj;
-
