Skip to content

Revert "[clang-doc] Add --asset option to clang-doc" #96354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2024

Conversation

ilovepi
Copy link
Contributor

@ilovepi ilovepi commented Jun 21, 2024

Reverts #94717

This breaks on some buildbots: http://45.33.8.238/linux/141118/step_7.txt

@ilovepi ilovepi marked this pull request as ready for review June 21, 2024 20:18
@ilovepi ilovepi merged commit bf824d9 into main Jun 21, 2024
6 of 8 checks passed
@ilovepi ilovepi deleted the revert-94717-clang-doc-add-asset-option branch June 21, 2024 20:18
@llvmbot
Copy link
Member

llvmbot commented Jun 21, 2024

@llvm/pr-subscribers-clang-tools-extra

Author: Paul Kirth (ilovepi)

Changes

Reverts llvm/llvm-project#94717

This breaks on some buildbots: http://45.33.8.238/linux/141118/step_7.txt


Full diff: https://github.com/llvm/llvm-project/pull/96354.diff

2 Files Affected:

  • (modified) clang-tools-extra/clang-doc/tool/ClangDocMain.cpp (+19-81)
  • (removed) clang-tools-extra/test/clang-doc/single-source-html.cpp (-2)
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 5a43c70a5ebc3..5517522d7967d 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -81,12 +81,6 @@ 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> SourceRoot("source-root", llvm::cl::desc(R"(
 Directory where processed files are stored.
 Links to definition locations will only be
@@ -133,86 +127,16 @@ 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) {
-  using DirIt = llvm::sys::fs::directory_iterator;
-  std::error_code FileErr;
-  llvm::SmallString<128> FilePath(UserAssetPath);
-  for (DirIt DirStart = DirIt(UserAssetPath, FileErr),
-                   DirEnd;
-       !FileErr && DirStart != DirEnd; DirStart.increment(FileErr)) {
-    FilePath = DirStart->path();
-    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 (llvm::sys::path::extension(FilePath) == ".js")
-        CDCtx.FilesToCopy.emplace_back(FilePath.str());
-    }
-  }
-  if (FileErr)
-    return llvm::createFileError(FilePath, FileErr);
-  return llvm::Error::success();
-}
-
-llvm::Error 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");
-
-  llvm::outs() << "Using default asset: " << AssetsPath << "\n";
-
-  if (!llvm::sys::fs::is_regular_file(IndexJS))
-    return llvm::createStringError(llvm::inconvertibleErrorCode(),
-                                   "default index.js file missing at " +
-                                       IndexJS + "\n");
-
-  if (!llvm::sys::fs::is_regular_file(DefaultStylesheet))
-    return llvm::createStringError(
-        llvm::inconvertibleErrorCode(),
-        "default clang-doc-default-stylesheet.css file missing at " +
-            DefaultStylesheet + "\n");
-
-  CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
-                               std::string(DefaultStylesheet));
-  CDCtx.FilesToCopy.emplace_back(IndexJS.str());
-
-  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) {
   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):
 
@@ -258,9 +182,23 @@ Example usage for a project using a compile commands database:
       {"index.js", "index_json.js"}};
 
   if (Format == "html") {
-    if (auto Err = getHtmlAssetFiles(argv[0], CDCtx)) {
-      llvm::outs() << "warning: " <<  toString(std::move(Err)) << "\n";
-    }
+    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());
   }
 
   // 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
deleted file mode 100644
index 32f232b9c45a0..0000000000000
--- a/clang-tools-extra/test/clang-doc/single-source-html.cpp
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: clang-doc --format=html --executor=standalone %s -output=%t/docs | FileCheck %s
-// CHECK: Using default asset: {{.*}}{{[\/]}}share{{[\/]}}clang
\ No newline at end of file

PeterChou1 added a commit to PeterChou1/llvm-project that referenced this pull request Jun 21, 2024
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants