[clang-tools-extra] [clang-doc] Add --asset option to clang-doc (PR #94717)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 11 13:29:35 PDT 2024


https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/94717

>From eeb334620df72c395a5ad27f44a864a6a0c194a5 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Thu, 6 Jun 2024 23:18:12 -0400
Subject: [PATCH 1/7] [clang][clang-doc] add asset path

---
 .../clang-doc/tool/ClangDocMain.cpp           | 73 ++++++++++++++-----
 1 file changed, 55 insertions(+), 18 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 21b581fa6df2e..df53c46b4a76e 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -81,6 +81,12 @@ static llvm::cl::list<std::string> UserStylesheets(
     llvm::cl::desc("CSS stylesheets to extend the default styles."),
     llvm::cl::cat(ClangDocCategory));
 
+static llvm::cl::opt<std::string>
+    UserAssetPath("asset",
+                  llvm::cl::desc("User supplied asset path for html output to "
+                                 "override the default css and js files"),
+                  llvm::cl::cat(ClangDocCategory));
+
 static llvm::cl::opt<std::string> SourceRoot("source-root", llvm::cl::desc(R"(
 Directory where processed files are stored.
 Links to definition locations will only be
@@ -131,12 +137,54 @@ 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.push_back(std::string(filePath));
+      } else if (filePath.ends_with(".js")) {
+        CDCtx.FilesToCopy.push_back(std::string(filePath));
+      }
+    }
+  }
+}
+
+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");
+  CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
+                               std::string(DefaultStylesheet));
+  CDCtx.FilesToCopy.emplace_back(IndexJS.str());
+
+  llvm::outs() << "No default asset path found using default asset path: "
+               << AssetsPath << "\n";
+}
+
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
 
   const char *Overview =
-    R"(Generates documentation from source code and comments.
+      R"(Generates documentation from source code and comments.
 
 Example usage for files without flags (default):
 
@@ -182,23 +230,12 @@ Example usage for a project using a compile commands database:
       {"index.js", "index_json.js"}};
 
   if (Format == "html") {
-    void *MainAddr = (void *)(intptr_t)GetExecutablePath;
-    std::string ClangDocPath = GetExecutablePath(argv[0], 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");
-    CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
-                                 std::string(DefaultStylesheet));
-    CDCtx.FilesToCopy.emplace_back(IndexJS.str());
+    if (!UserAssetPath.empty() &&
+        llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
+      GetAssetFiles(CDCtx);
+    } else {
+      GetDefaultAssetFiles(argv[0], CDCtx);
+    }
   }
 
   // Mapping phase

>From 85581ed2f05974eac5697f43ab95a34ce17742a0 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Fri, 7 Jun 2024 01:54:43 -0400
Subject: [PATCH 2/7] [clang][clang-doc] fixes bug caused by not passing by
 reference

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index df53c46b4a76e..b72767d201073 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -137,7 +137,7 @@ std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
   return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
 }
 
-void GetAssetFiles(clang::doc::ClangDocContext CDCtx) {
+void GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
   std::error_code Code;
   for (auto DirIt = llvm::sys::fs::directory_iterator(
                 std::string(UserAssetPath), Code),
@@ -146,16 +146,17 @@ void GetAssetFiles(clang::doc::ClangDocContext CDCtx) {
     llvm::SmallString<128> filePath = llvm::SmallString<128>(DirIt->path());
     if (llvm::sys::fs::is_regular_file(filePath)) {
       if (filePath.ends_with(".css")) {
-        CDCtx.UserStylesheets.push_back(std::string(filePath));
+        CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
+                                     std::string(filePath));
       } else if (filePath.ends_with(".js")) {
-        CDCtx.FilesToCopy.push_back(std::string(filePath));
+        CDCtx.FilesToCopy.emplace_back(filePath.str());
       }
     }
   }
 }
 
 void GetDefaultAssetFiles(const char *Argv0,
-                          clang::doc::ClangDocContext CDCtx) {
+                          clang::doc::ClangDocContext &CDCtx) {
   void *MainAddr = (void *)(intptr_t)GetExecutablePath;
   std::string ClangDocPath = GetExecutablePath(Argv0, MainAddr);
   llvm::SmallString<128> NativeClangDocPath;

>From 6fee7d067d2923d971186b7e505452abaa2b92f0 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Fri, 7 Jun 2024 17:30:19 -0400
Subject: [PATCH 3/7] [clang][clang-doc] address pr comments about --asset
 option

---
 .../clang-doc/tool/ClangDocMain.cpp           | 66 +++++++++++++------
 1 file changed, 45 insertions(+), 21 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index b72767d201073..c2439734960d4 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -83,8 +83,8 @@ static llvm::cl::list<std::string> UserStylesheets(
 
 static llvm::cl::opt<std::string>
     UserAssetPath("asset",
-                  llvm::cl::desc("User supplied asset path for html output to "
-                                 "override the default css and js files"),
+                  llvm::cl::desc("User supplied asset path to "
+                                 "override the default css and js files for html output"),
                   llvm::cl::cat(ClangDocCategory));
 
 static llvm::cl::opt<std::string> SourceRoot("source-root", llvm::cl::desc(R"(
@@ -137,25 +137,27 @@ std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
   return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
 }
 
-void GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
+llvm::Error 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")) {
+  for (auto DirIt = llvm::sys::fs::directory_iterator(UserAssetPath, Code),
+            DirEnd = llvm::sys::fs::directory_iterator();
+       !Code && DirIt != DirEnd; DirIt.increment(Code)) {
+    llvm::SmallString<128> FilePath = llvm::SmallString<128>(DirIt->path());
+    if (!Code) {
+        return llvm::createFileError(FilePath, Code);
+    }
+    if (llvm::sys::fs::is_regular_file(FilePath)) {
+      if (llvm::sys::path::extension(FilePath) == ".css") {
         CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
-                                     std::string(filePath));
-      } else if (filePath.ends_with(".js")) {
-        CDCtx.FilesToCopy.emplace_back(filePath.str());
+                                     std::string(FilePath));
+      } else if (llvm::sys::path::extension(FilePath) == ".js") {
+        CDCtx.FilesToCopy.emplace_back(FilePath.str());
       }
     }
   }
 }
 
-void GetDefaultAssetFiles(const char *Argv0,
+llvm::Error GetDefaultAssetFiles(const char *Argv0,
                           clang::doc::ClangDocContext &CDCtx) {
   void *MainAddr = (void *)(intptr_t)GetExecutablePath;
   std::string ClangDocPath = GetExecutablePath(Argv0, MainAddr);
@@ -172,12 +174,35 @@ void GetDefaultAssetFiles(const char *Argv0,
   llvm::SmallString<128> IndexJS;
   llvm::sys::path::native(AssetsPath, IndexJS);
   llvm::sys::path::append(IndexJS, "index.js");
+
+  if (!llvm::sys::fs::is_regular_file(IndexJS)) {
+    return llvm::createStringError(llvm::inconvertibleErrorCode(),
+                                   "error default index.js file at " + IndexJS + "\n");
+  }
+
+  if (!llvm::sys::fs::is_regular_file(DefaultStylesheet)) {
+      return llvm::createStringError(llvm::inconvertibleErrorCode(),
+                                     "error default clang-doc-default-stylesheet.css file at " + DefaultStylesheet + "\n");
+  }
+
   CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
                                std::string(DefaultStylesheet));
   CDCtx.FilesToCopy.emplace_back(IndexJS.str());
 
-  llvm::outs() << "No default asset path found using default asset path: "
+  llvm::outs() << "Using default asset: "
                << AssetsPath << "\n";
+
+  return llvm::Error::success();
+}
+
+llvm::Error GetHTMLAssetFiles(const char *Argv0, clang::doc::ClangDocContext &CDCtx) {
+    if (!UserAssetPath.empty() && !llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
+        llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath << " falling back to default\n";
+    }
+    if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
+        return GetAssetFiles(CDCtx);
+    }
+    return GetDefaultAssetFiles(Argv0, CDCtx);
 }
 
 int main(int argc, const char **argv) {
@@ -231,12 +256,11 @@ Example usage for a project using a compile commands database:
       {"index.js", "index_json.js"}};
 
   if (Format == "html") {
-    if (!UserAssetPath.empty() &&
-        llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
-      GetAssetFiles(CDCtx);
-    } else {
-      GetDefaultAssetFiles(argv[0], CDCtx);
-    }
+      auto Err = GetHTMLAssetFiles(argv[0], CDCtx);
+      if (Err) {
+          llvm::errs() << toString(std::move(Err)) << "\n";
+    return 1;
+  }
   }
 
   // Mapping phase

>From a8462150b7fa4f80e5a3db5e9c7edac221781f4f Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Fri, 7 Jun 2024 17:52:44 -0400
Subject: [PATCH 4/7] [clang][clang-doc] add a test case

---
 .../clang-doc/tool/ClangDocMain.cpp           | 55 ++++++++++---------
 .../test/clang-doc/single-source-html.cpp     | 14 +++++
 2 files changed, 44 insertions(+), 25 deletions(-)
 create mode 100644 clang-tools-extra/test/clang-doc/single-source-html.cpp

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index c2439734960d4..f64612f085c30 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -81,11 +81,11 @@ static llvm::cl::list<std::string> UserStylesheets(
     llvm::cl::desc("CSS stylesheets to extend the default styles."),
     llvm::cl::cat(ClangDocCategory));
 
-static llvm::cl::opt<std::string>
-    UserAssetPath("asset",
-                  llvm::cl::desc("User supplied asset path to "
-                                 "override the default css and js files for html output"),
-                  llvm::cl::cat(ClangDocCategory));
+static llvm::cl::opt<std::string> UserAssetPath(
+    "asset",
+    llvm::cl::desc("User supplied asset path to "
+                   "override the default css and js files for html output"),
+    llvm::cl::cat(ClangDocCategory));
 
 static llvm::cl::opt<std::string> SourceRoot("source-root", llvm::cl::desc(R"(
 Directory where processed files are stored.
@@ -144,7 +144,7 @@ llvm::Error GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
        !Code && DirIt != DirEnd; DirIt.increment(Code)) {
     llvm::SmallString<128> FilePath = llvm::SmallString<128>(DirIt->path());
     if (!Code) {
-        return llvm::createFileError(FilePath, Code);
+      return llvm::createFileError(FilePath, Code);
     }
     if (llvm::sys::fs::is_regular_file(FilePath)) {
       if (llvm::sys::path::extension(FilePath) == ".css") {
@@ -158,7 +158,7 @@ llvm::Error GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
 }
 
 llvm::Error GetDefaultAssetFiles(const char *Argv0,
-                          clang::doc::ClangDocContext &CDCtx) {
+                                 clang::doc::ClangDocContext &CDCtx) {
   void *MainAddr = (void *)(intptr_t)GetExecutablePath;
   std::string ClangDocPath = GetExecutablePath(Argv0, MainAddr);
   llvm::SmallString<128> NativeClangDocPath;
@@ -177,32 +177,37 @@ llvm::Error GetDefaultAssetFiles(const char *Argv0,
 
   if (!llvm::sys::fs::is_regular_file(IndexJS)) {
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
-                                   "error default index.js file at " + IndexJS + "\n");
+                                   "error default index.js file at " + IndexJS +
+                                       "\n");
   }
 
   if (!llvm::sys::fs::is_regular_file(DefaultStylesheet)) {
-      return llvm::createStringError(llvm::inconvertibleErrorCode(),
-                                     "error default clang-doc-default-stylesheet.css file at " + DefaultStylesheet + "\n");
+    return llvm::createStringError(
+        llvm::inconvertibleErrorCode(),
+        "error default clang-doc-default-stylesheet.css file at " +
+            DefaultStylesheet + "\n");
   }
 
   CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
                                std::string(DefaultStylesheet));
   CDCtx.FilesToCopy.emplace_back(IndexJS.str());
 
-  llvm::outs() << "Using default asset: "
-               << AssetsPath << "\n";
+  llvm::outs() << "Using default asset: " << AssetsPath << "\n";
 
   return llvm::Error::success();
 }
 
-llvm::Error GetHTMLAssetFiles(const char *Argv0, clang::doc::ClangDocContext &CDCtx) {
-    if (!UserAssetPath.empty() && !llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
-        llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath << " falling back to default\n";
-    }
-    if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
-        return GetAssetFiles(CDCtx);
-    }
-    return GetDefaultAssetFiles(Argv0, CDCtx);
+llvm::Error GetHTMLAssetFiles(const char *Argv0,
+                              clang::doc::ClangDocContext &CDCtx) {
+  if (!UserAssetPath.empty() &&
+      !llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
+    llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath
+                 << " falling back to default\n";
+  }
+  if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
+    return GetAssetFiles(CDCtx);
+  }
+  return GetDefaultAssetFiles(Argv0, CDCtx);
 }
 
 int main(int argc, const char **argv) {
@@ -256,11 +261,11 @@ Example usage for a project using a compile commands database:
       {"index.js", "index_json.js"}};
 
   if (Format == "html") {
-      auto Err = GetHTMLAssetFiles(argv[0], CDCtx);
-      if (Err) {
-          llvm::errs() << toString(std::move(Err)) << "\n";
-    return 1;
-  }
+    auto Err = GetHTMLAssetFiles(argv[0], CDCtx);
+    if (Err) {
+      llvm::errs() << toString(std::move(Err)) << "\n";
+      return 1;
+    }
   }
 
   // Mapping phase
diff --git a/clang-tools-extra/test/clang-doc/single-source-html.cpp b/clang-tools-extra/test/clang-doc/single-source-html.cpp
new file mode 100644
index 0000000000000..9720acbaae989
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/single-source-html.cpp
@@ -0,0 +1,14 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --format=html --executor=standalone -p %t %t/test.cpp -output=%t/docs > %t/output.txt
+// RUN: cat %t/output.txt | FileCheck %s --check-prefix=CHECK
+
+// CHECK: Emiting docs in html format.
+// CHECK-NEXT: Using default asset: {{.*}}..\share\clang
+// CHECK-NEXT: Mapping decls...
+// CHECK-NEXT: Collecting infos...
+// CHECK-NEXT: Reducing 0 infos...
+// CHECK-NEXT: Generating docs...
+// CHECK-NEXT: Generating assets for docs...
\ No newline at end of file

>From 39e06472bc2348971dd144a1cc2b3717cde29576 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Tue, 11 Jun 2024 15:45:15 -0400
Subject: [PATCH 5/7] [clang][clang-doc] PR comments

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp       | 1 +
 clang-tools-extra/test/clang-doc/single-source-html.cpp | 8 +-------
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index f64612f085c30..7b01b0b84857a 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -155,6 +155,7 @@ llvm::Error GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
       }
     }
   }
+  return llvm::Error::success();
 }
 
 llvm::Error GetDefaultAssetFiles(const char *Argv0,
diff --git a/clang-tools-extra/test/clang-doc/single-source-html.cpp b/clang-tools-extra/test/clang-doc/single-source-html.cpp
index 9720acbaae989..4f62c45f545fa 100644
--- a/clang-tools-extra/test/clang-doc/single-source-html.cpp
+++ b/clang-tools-extra/test/clang-doc/single-source-html.cpp
@@ -5,10 +5,4 @@
 // RUN: clang-doc --format=html --executor=standalone -p %t %t/test.cpp -output=%t/docs > %t/output.txt
 // RUN: cat %t/output.txt | FileCheck %s --check-prefix=CHECK
 
-// CHECK: Emiting docs in html format.
-// CHECK-NEXT: Using default asset: {{.*}}..\share\clang
-// CHECK-NEXT: Mapping decls...
-// CHECK-NEXT: Collecting infos...
-// CHECK-NEXT: Reducing 0 infos...
-// CHECK-NEXT: Generating docs...
-// CHECK-NEXT: Generating assets for docs...
\ No newline at end of file
+// CHECK: Using default asset: {{.*}}..\share\clang
\ No newline at end of file

>From 170856299c84d2ce05c56546e08689605605b73f Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Tue, 11 Jun 2024 15:46:38 -0400
Subject: [PATCH 6/7] [clang][clang-doc] PR comments

---
 .../clang-doc/tool/ClangDocMain.cpp            | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 7b01b0b84857a..3b8f77cbe220e 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -133,11 +133,11 @@ std::string getFormatString() {
 // GetMainExecutable (since some platforms don't support taking the
 // address of main, and some platforms can't implement GetMainExecutable
 // without being given the address of a function in the main executable).
-std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
+std::string getExecutablePath(const char *Argv0, void *MainAddr) {
   return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
 }
 
-llvm::Error GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
+llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) {
   std::error_code Code;
   for (auto DirIt = llvm::sys::fs::directory_iterator(UserAssetPath, Code),
             DirEnd = llvm::sys::fs::directory_iterator();
@@ -158,10 +158,10 @@ llvm::Error GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
   return llvm::Error::success();
 }
 
-llvm::Error GetDefaultAssetFiles(const char *Argv0,
+llvm::Error getDefaultAssetFiles(const char *Argv0,
                                  clang::doc::ClangDocContext &CDCtx) {
-  void *MainAddr = (void *)(intptr_t)GetExecutablePath;
-  std::string ClangDocPath = GetExecutablePath(Argv0, MainAddr);
+  void *MainAddr = (void *)(intptr_t)getExecutablePath;
+  std::string ClangDocPath = getExecutablePath(Argv0, MainAddr);
   llvm::SmallString<128> NativeClangDocPath;
   llvm::sys::path::native(ClangDocPath, NativeClangDocPath);
 
@@ -198,7 +198,7 @@ llvm::Error GetDefaultAssetFiles(const char *Argv0,
   return llvm::Error::success();
 }
 
-llvm::Error GetHTMLAssetFiles(const char *Argv0,
+llvm::Error getHtmlAssetFiles(const char *Argv0,
                               clang::doc::ClangDocContext &CDCtx) {
   if (!UserAssetPath.empty() &&
       !llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
@@ -206,9 +206,9 @@ llvm::Error GetHTMLAssetFiles(const char *Argv0,
                  << " falling back to default\n";
   }
   if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
-    return GetAssetFiles(CDCtx);
+    return getAssetFiles(CDCtx);
   }
-  return GetDefaultAssetFiles(Argv0, CDCtx);
+  return getDefaultAssetFiles(Argv0, CDCtx);
 }
 
 int main(int argc, const char **argv) {
@@ -262,7 +262,7 @@ Example usage for a project using a compile commands database:
       {"index.js", "index_json.js"}};
 
   if (Format == "html") {
-    auto Err = GetHTMLAssetFiles(argv[0], CDCtx);
+    auto Err = getHtmlAssetFiles(argv[0], CDCtx);
     if (Err) {
       llvm::errs() << toString(std::move(Err)) << "\n";
       return 1;

>From 5cba074bf1f7417f7c51d76e42410ea2e856ed1b Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.chou at mail.utoronto.ca>
Date: Tue, 11 Jun 2024 16:28:44 -0400
Subject: [PATCH 7/7] [clang][clang-doc] fix asset option

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 3b8f77cbe220e..fddef797516a5 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -141,9 +141,9 @@ llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) {
   std::error_code Code;
   for (auto DirIt = llvm::sys::fs::directory_iterator(UserAssetPath, Code),
             DirEnd = llvm::sys::fs::directory_iterator();
-       !Code && DirIt != DirEnd; DirIt.increment(Code)) {
+       DirIt != DirEnd; DirIt.increment(Code)) {
     llvm::SmallString<128> FilePath = llvm::SmallString<128>(DirIt->path());
-    if (!Code) {
+    if (Code) {
       return llvm::createFileError(FilePath, Code);
     }
     if (llvm::sys::fs::is_regular_file(FilePath)) {
@@ -178,14 +178,14 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
 
   if (!llvm::sys::fs::is_regular_file(IndexJS)) {
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
-                                   "error default index.js file at " + IndexJS +
+                                   "error default index.js file missing at " + IndexJS +
                                        "\n");
   }
 
   if (!llvm::sys::fs::is_regular_file(DefaultStylesheet)) {
     return llvm::createStringError(
         llvm::inconvertibleErrorCode(),
-        "error default clang-doc-default-stylesheet.css file at " +
+        "error default clang-doc-default-stylesheet.css file missing at " +
             DefaultStylesheet + "\n");
   }
 



More information about the cfe-commits mailing list