From dc30049cb36089e80901e49815a8d51f470246b6 Mon Sep 17 00:00:00 2001 From: Diego Astiazaran Date: Fri, 9 Aug 2019 20:52:28 +0000 Subject: [PATCH] [clang-doc] Generate an HTML index file clang-doc now generates a file that contains only an index to all the infos that can be used as the landing page for the generated website. Differential Revision: https://reviews.llvm.org/D65918 llvm-svn: 368484 --- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index 546d7d208d73..3987f23e783f 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -813,6 +813,24 @@ static bool SerializeIndex(ClangDocContext &CDCtx) { return true; } +static bool GenIndex(const ClangDocContext &CDCtx) { + std::error_code FileErr, OK; + llvm::SmallString<128> IndexPath; + llvm::sys::path::native(CDCtx.OutDirectory, IndexPath); + llvm::sys::path::append(IndexPath, "index.html"); + llvm::raw_fd_ostream IndexOS(IndexPath, FileErr, llvm::sys::fs::F_None); + if (FileErr != OK) { + llvm::errs() << "Error creating main index: " << FileErr.message() << "\n"; + return false; + } + HTMLFile F; + std::vector> BasicNodes = + genCommonFileNodes("Index", "", CDCtx); + AppendVector(std::move(BasicNodes), F.Children); + F.Render(IndexOS); + return true; +} + static bool CopyFile(StringRef FilePath, StringRef OutDirectory) { llvm::SmallString<128> PathWrite; llvm::sys::path::native(OutDirectory, PathWrite); @@ -831,7 +849,7 @@ static bool CopyFile(StringRef FilePath, StringRef OutDirectory) { } bool HTMLGenerator::createResources(ClangDocContext &CDCtx) { - if (!SerializeIndex(CDCtx)) + if (!SerializeIndex(CDCtx) || !GenIndex(CDCtx)) return false; for (const auto &FilePath : CDCtx.UserStylesheets) if (!CopyFile(FilePath, CDCtx.OutDirectory))