[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 2 18:45:00 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Joshua Batista (bob80905)

<details>
<summary>Changes</summary>

In `clang-tools-extra\clang-doc\tool\ClangDocMain.cpp`, there is a function, `getDefaultAssetFiles` that tries to find the location of 
`<build dir>\share\clang-doc\index.js`, but fails. This is because there are alternate configurations in setting up the llvm project, and executables in different locations may be run. In some cases, executables are built and run in this location:
`<build dir>\bin\<executables>`
and in other cases, this location:
`<build dir>\[Debug | Release]\bin\<executables>`

The locator assumed that the executable that is running was in the first example above, and in the case that an executable under Debug / Release was run, the index.js file wouldn't be found.
This PR adjusts the locator to be agnostic to either scenario described above, and ascends an extra directory if the Debug directory is detected.

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


1 Files Affected:

- (modified) clang-tools-extra/clang-doc/tool/ClangDocMain.cpp (+7-1) 


``````````diff
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 6198a6e0cdcc3..b97fa715f9e67 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -167,7 +167,13 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
 
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
-  llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
+  llvm::sys::path::append(AssetsPath, "..");
+  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::sys::path::append(tempCopyDbg, "Debug");
+  // index.js may be in the debug
+  if (!llvm::sys::fs::is_directory(tempCopyDbg))
+    llvm::sys::path::append(AssetsPath, "..");
+  llvm::sys::path::append(AssetsPath, "share", "clang-doc");
   llvm::SmallString<128> DefaultStylesheet;
   llvm::sys::path::native(AssetsPath, DefaultStylesheet);
   llvm::sys::path::append(DefaultStylesheet,

``````````

</details>


https://github.com/llvm/llvm-project/pull/97505


More information about the cfe-commits mailing list