Skip to content

Commit 3589489

Browse files
committed
[clang-doc] Add Mustache case to test for DR 131697
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.
1 parent fdf9479 commit 3589489

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

clang-tools-extra/clang-doc/Generators.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,30 @@ Error MustacheGenerator::generateDocumentation(
8484
return JSONGenerator.takeError();
8585
}
8686

87-
SmallString<128> JSONPath;
88-
sys::path::native(RootDir.str() + "/json", JSONPath);
87+
SmallString<128> JSONDirPath(RootDir);
88+
sys::path::append(JSONDirPath, "json");
89+
if (auto EC = sys::fs::create_directories(JSONDirPath))
90+
return createFileError(JSONDirPath, EC);
91+
SmallString<128> DocsDirPath(RootDir);
92+
sys::path::append(DocsDirPath, DirName);
93+
if (auto EC = sys::fs::create_directories(DocsDirPath))
94+
return createFileError(DocsDirPath, EC);
8995

9096
{
9197
llvm::TimeTraceScope TS("Iterate JSON files");
9298
std::error_code EC;
93-
sys::fs::recursive_directory_iterator JSONIter(JSONPath, EC);
99+
sys::fs::recursive_directory_iterator JSONIter(JSONDirPath, EC);
94100
std::vector<json::Value> JSONFiles;
95101
JSONFiles.reserve(Infos.size());
96102
if (EC)
97103
return createStringError("Failed to create directory iterator.");
98104

99-
SmallString<128> DocsDirPath(RootDir.str() + '/' + DirName);
100-
sys::path::native(DocsDirPath);
101-
if (auto EC = sys::fs::create_directories(DocsDirPath))
102-
return createFileError(DocsDirPath, EC);
103105
while (JSONIter != sys::fs::recursive_directory_iterator()) {
104106
// create the same directory structure in the docs format dir
105107
if (JSONIter->type() == sys::fs::file_type::directory_file) {
106108
SmallString<128> DocsClonedPath(JSONIter->path());
107-
sys::path::replace_path_prefix(DocsClonedPath, JSONPath, DocsDirPath);
109+
sys::path::replace_path_prefix(DocsClonedPath, JSONDirPath,
110+
DocsDirPath);
108111
if (auto EC = sys::fs::create_directories(DocsClonedPath)) {
109112
return createFileError(DocsClonedPath, EC);
110113
}
@@ -134,7 +137,7 @@ Error MustacheGenerator::generateDocumentation(
134137

135138
std::error_code FileErr;
136139
SmallString<128> DocsFilePath(JSONIter->path());
137-
sys::path::replace_path_prefix(DocsFilePath, JSONPath, DocsDirPath);
140+
sys::path::replace_path_prefix(DocsFilePath, JSONDirPath, DocsDirPath);
138141
sys::path::replace_extension(DocsFilePath, DirName);
139142
raw_fd_ostream InfoOS(DocsFilePath, FileErr, sys::fs::OF_None);
140143
if (FileErr)

clang-tools-extra/test/clang-doc/DR-131697.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: rm -rf %t && mkdir -p %t
22
// RUN: split-file %s %t
33
// RUN: clang-doc -format=html %t/compile_commands.json %t/main.cpp
4+
// RUN: clang-doc -format=mustache %t/compile_commands.json %t/main.cpp
45

56
//--- main.cpp
67

0 commit comments

Comments
 (0)