[clang-tools-extra] [clang-doc] Add --asset option to clang-doc (PR #94717)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 7 16:35:46 PDT 2024
================
@@ -131,12 +137,55 @@ std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
}
+void GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
+ std::error_code Code;
+ for (auto DirIt = llvm::sys::fs::directory_iterator(
+ std::string(UserAssetPath), Code),
+ dir_end = llvm::sys::fs::directory_iterator();
+ !Code && DirIt != dir_end; DirIt.increment(Code)) {
+ llvm::SmallString<128> filePath = llvm::SmallString<128>(DirIt->path());
+ if (llvm::sys::fs::is_regular_file(filePath)) {
+ if (filePath.ends_with(".css")) {
+ CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
+ std::string(filePath));
+ } else if (filePath.ends_with(".js")) {
+ CDCtx.FilesToCopy.emplace_back(filePath.str());
+ }
+ }
+ }
+}
+
+void GetDefaultAssetFiles(const char *Argv0,
+ clang::doc::ClangDocContext &CDCtx) {
+ void *MainAddr = (void *)(intptr_t)GetExecutablePath;
+ std::string ClangDocPath = GetExecutablePath(Argv0, MainAddr);
+ llvm::SmallString<128> NativeClangDocPath;
+ llvm::sys::path::native(ClangDocPath, NativeClangDocPath);
+
+ llvm::SmallString<128> AssetsPath;
+ AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
+ llvm::sys::path::append(AssetsPath, "..", "share", "clang");
+ llvm::SmallString<128> DefaultStylesheet;
+ llvm::sys::path::native(AssetsPath, DefaultStylesheet);
+ llvm::sys::path::append(DefaultStylesheet,
+ "clang-doc-default-stylesheet.css");
+ llvm::SmallString<128> IndexJS;
+ llvm::sys::path::native(AssetsPath, IndexJS);
+ llvm::sys::path::append(IndexJS, "index.js");
----------------
ilovepi wrote:
so we did need to check, and you've added one now
https://github.com/llvm/llvm-project/pull/94717
More information about the cfe-commits
mailing list