[clang-tools-extra] Clang doc async (PR #93276)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 23 23:47:59 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: None (PeterChou1)
<details>
<summary>Changes</summary>
relevant issue: https://github.com/llvm/llvm-project/issues/93273
---
Full diff: https://github.com/llvm/llvm-project/pull/93276.diff
5 Files Affected:
- (modified) clang-tools-extra/clang-doc/HTMLGenerator.cpp (+13-12)
- (modified) clang-tools-extra/clang-doc/Representation.h (+1)
- (modified) clang-tools-extra/clang-doc/Serialize.cpp (+1)
- (modified) clang-tools-extra/clang-doc/assets/index.js (+5-2)
- (modified) clang-tools-extra/clang-doc/tool/ClangDocMain.cpp (+6-1)
``````````diff
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index c0faf5f7e8fd9..fd3807014fd09 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -964,7 +964,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) {
std::error_code FileErr;
llvm::SmallString<128> FilePath;
llvm::sys::path::native(CDCtx.OutDirectory, FilePath);
- llvm::sys::path::append(FilePath, "index_json.js");
+ llvm::sys::path::append(FilePath, "index.json");
llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None);
if (FileErr != OK) {
return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -985,9 +985,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) {
});
});
};
- OS << "var JsonIndex = `\n";
IndexToJSON(CDCtx.Idx);
- OS << "`;\n";
return llvm::Error::success();
}
@@ -1050,30 +1048,33 @@ static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) {
if (FileErr != OK) {
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"error creating file " +
- llvm::sys::path::filename(FilePath) +
+ FilePath +
": " + FileErr.message() + "\n");
}
return llvm::Error::success();
}
llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
- auto Err = SerializeIndex(CDCtx);
- if (Err)
+ if (auto Err = SerializeIndex(CDCtx)) {
return Err;
- Err = GenIndex(CDCtx);
- if (Err)
+ }
+
+ if (auto Err = GenIndex(CDCtx)) {
return Err;
+ }
for (const auto &FilePath : CDCtx.UserStylesheets) {
- Err = CopyFile(FilePath, CDCtx.OutDirectory);
- if (Err)
+ if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
return Err;
+ }
}
+
for (const auto &FilePath : CDCtx.FilesToCopy) {
- Err = CopyFile(FilePath, CDCtx.OutDirectory);
- if (Err)
+ if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) {
return Err;
+ }
}
+
return llvm::Error::success();
}
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index a6b144eb7fa2a..23323f1cbdf46 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -491,6 +491,7 @@ struct ClangDocContext {
std::string SourceRoot; // Directory where processed files are stored. Links
// to definition locations will only be generated if
// the file is in this dir.
+
// URL of repository that hosts code used for links to definition locations.
std::optional<std::string> RepositoryUrl;
// Path of CSS stylesheets that will be copied to OutDirectory and used to
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 3b074d849e8a9..49062af637ea0 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -32,6 +32,7 @@ populateParentNamespaces(llvm::SmallVector<Reference, 4> &Namespaces,
static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D);
+
// A function to extract the appropriate relative path for a given info's
// documentation. The path returned is a composite of the parent namespaces.
//
diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..b659b20069ac5 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -82,6 +82,9 @@ function createIndex(Index) {
document.addEventListener("DOMContentLoaded", function() {
// JsonIndex is a variable from another file that contains the index
// in JSON format
- var Index = JSON.parse(JsonIndex);
- createIndex(Index);
+ fetch("/index.json")
+ .then((response) => response.json())
+ .then((Index) => {
+ createIndex(Index);
+ });
});
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 21b581fa6df2e..af892b5402092 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -155,6 +155,10 @@ Example usage for a project using a compile commands database:
return 1;
}
+ // add option to customize url fragment
+ // such as https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-doc/ClangDocMain.cpp#L1
+
+
// Fail early if an invalid format was provided.
std::string Format = getFormatString();
llvm::outs() << "Emiting docs in " << Format << " format.\n";
@@ -179,7 +183,7 @@ Example usage for a project using a compile commands database:
SourceRoot,
RepositoryUrl,
{UserStylesheets.begin(), UserStylesheets.end()},
- {"index.js", "index_json.js"}};
+ {"index.js"}};
if (Format == "html") {
void *MainAddr = (void *)(intptr_t)GetExecutablePath;
@@ -201,6 +205,7 @@ Example usage for a project using a compile commands database:
CDCtx.FilesToCopy.emplace_back(IndexJS.str());
}
+
// Mapping phase
llvm::outs() << "Mapping decls...\n";
auto Err =
``````````
</details>
https://github.com/llvm/llvm-project/pull/93276
More information about the cfe-commits
mailing list