Skip to content

Conversation

@evelez7
Copy link
Member

@evelez7 evelez7 commented Dec 1, 2025

The test for DR 131697 only requires that clang-doc doesn't crash. There
is no documentation created. However, when using Mustache, clang-doc still expects certain
paths to exist, like the directory where assets are placed. In legacy
HTML, the docs directory is still created and assets are placed there
regardless of there being any Infos to document. Mustache didn't do
this, so now we create docs/json and docs/html even if there is
nothing to document.

Copy link
Member Author

evelez7 commented Dec 1, 2025

@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2025

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

Author: Erick Velez (evelez7)

Changes

The test for DR 131697 only requires that clang-doc doesn't crash. There
is no documentation created. However, when using Mustache, clang-doc still expects certain
paths to exist, like the directory where assets are placed. In legacy
HTML, the docs directory is still created and assets are placed there
regardless of there being any Infos to document. Mustache didn't do
this, so now we create docs/json and docs/html even if there is
nothing to document.


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

2 Files Affected:

  • (modified) clang-tools-extra/clang-doc/Generators.cpp (+12-9)
  • (modified) clang-tools-extra/test/clang-doc/DR-131697.cpp (+1)
diff --git a/clang-tools-extra/clang-doc/Generators.cpp b/clang-tools-extra/clang-doc/Generators.cpp
index 667e5d5a318f0..5d76901b95833 100644
--- a/clang-tools-extra/clang-doc/Generators.cpp
+++ b/clang-tools-extra/clang-doc/Generators.cpp
@@ -84,27 +84,30 @@ Error MustacheGenerator::generateDocumentation(
       return JSONGenerator.takeError();
   }
 
-  SmallString<128> JSONPath;
-  sys::path::native(RootDir.str() + "/json", JSONPath);
+  SmallString<128> JSONDirPath(RootDir);
+  sys::path::append(JSONDirPath, "json");
+  if (auto EC = sys::fs::create_directories(JSONDirPath))
+    return createFileError(JSONDirPath, EC);
+  SmallString<128> DocsDirPath(RootDir);
+  sys::path::append(DocsDirPath, DirName);
+  if (auto EC = sys::fs::create_directories(DocsDirPath))
+    return createFileError(DocsDirPath, EC);
 
   {
     llvm::TimeTraceScope TS("Iterate JSON files");
     std::error_code EC;
-    sys::fs::recursive_directory_iterator JSONIter(JSONPath, EC);
+    sys::fs::recursive_directory_iterator JSONIter(JSONDirPath, EC);
     std::vector<json::Value> JSONFiles;
     JSONFiles.reserve(Infos.size());
     if (EC)
       return createStringError("Failed to create directory iterator.");
 
-    SmallString<128> DocsDirPath(RootDir.str() + '/' + DirName);
-    sys::path::native(DocsDirPath);
-    if (auto EC = sys::fs::create_directories(DocsDirPath))
-      return createFileError(DocsDirPath, EC);
     while (JSONIter != sys::fs::recursive_directory_iterator()) {
       // create the same directory structure in the docs format dir
       if (JSONIter->type() == sys::fs::file_type::directory_file) {
         SmallString<128> DocsClonedPath(JSONIter->path());
-        sys::path::replace_path_prefix(DocsClonedPath, JSONPath, DocsDirPath);
+        sys::path::replace_path_prefix(DocsClonedPath, JSONDirPath,
+                                       DocsDirPath);
         if (auto EC = sys::fs::create_directories(DocsClonedPath)) {
           return createFileError(DocsClonedPath, EC);
         }
@@ -134,7 +137,7 @@ Error MustacheGenerator::generateDocumentation(
 
       std::error_code FileErr;
       SmallString<128> DocsFilePath(JSONIter->path());
-      sys::path::replace_path_prefix(DocsFilePath, JSONPath, DocsDirPath);
+      sys::path::replace_path_prefix(DocsFilePath, JSONDirPath, DocsDirPath);
       sys::path::replace_extension(DocsFilePath, DirName);
       raw_fd_ostream InfoOS(DocsFilePath, FileErr, sys::fs::OF_None);
       if (FileErr)
diff --git a/clang-tools-extra/test/clang-doc/DR-131697.cpp b/clang-tools-extra/test/clang-doc/DR-131697.cpp
index 9025bbf910813..06168e6642f62 100644
--- a/clang-tools-extra/test/clang-doc/DR-131697.cpp
+++ b/clang-tools-extra/test/clang-doc/DR-131697.cpp
@@ -1,6 +1,7 @@
 // RUN: rm -rf %t && mkdir -p %t
 // RUN: split-file %s %t
 // RUN: clang-doc -format=html %t/compile_commands.json %t/main.cpp
+// RUN: clang-doc -format=mustache %t/compile_commands.json %t/main.cpp
 
 //--- main.cpp
 

@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-fix-enum-indentation branch from 6705300 to fdf9479 Compare December 4, 2025 17:30
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-mustache-dr131697 branch from f55da9f to 3589489 Compare December 4, 2025 17:30
Base automatically changed from users/evelez7/clang-doc-fix-enum-indentation to main December 4, 2025 17:41
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-mustache-dr131697 branch from 3589489 to 45b366a Compare December 4, 2025 17:55
@evelez7 evelez7 merged commit 1d84c89 into main Dec 4, 2025
8 of 9 checks passed
@evelez7 evelez7 deleted the users/evelez7/clang-doc-mustache-dr131697 branch December 4, 2025 18:08
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.

4 participants