Skip to content

Commit 4f00704

Browse files
authored
[clang-doc] place HTML/JSON output inside their own directories (#150655)
Instead of just outputting everything into the designated root folder, HTML and JSON output will be placed in html/ and json/ directories.
1 parent cbfc22c commit 4f00704

16 files changed

+34
-26
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,22 @@ Error MustacheHTMLGenerator::generateDocs(
144144
} else
145145
return JSONGenerator.takeError();
146146
}
147+
SmallString<128> JSONPath;
148+
sys::path::native(RootDir.str() + "/json", JSONPath);
147149

148150
StringMap<json::Value> JSONFileMap;
149151
{
150152
llvm::TimeTraceScope TS("Iterate JSON files");
151153
std::error_code EC;
152-
sys::fs::directory_iterator JSONIter(RootDir, EC);
154+
sys::fs::directory_iterator JSONIter(JSONPath, EC);
153155
std::vector<json::Value> JSONFiles;
154156
JSONFiles.reserve(Infos.size());
155157
if (EC)
156158
return createStringError("Failed to create directory iterator.");
157159

160+
SmallString<128> HTMLDirPath(RootDir.str() + "/html/");
161+
if (auto EC = sys::fs::create_directories(HTMLDirPath))
162+
return createFileError(HTMLDirPath, EC);
158163
while (JSONIter != sys::fs::directory_iterator()) {
159164
if (EC)
160165
return createFileError("Failed to iterate: " + JSONIter->path(), EC);
@@ -177,14 +182,15 @@ Error MustacheHTMLGenerator::generateDocs(
177182
return Parsed.takeError();
178183

179184
std::error_code FileErr;
180-
SmallString<16> HTMLPath(Path.begin(), Path.end());
181-
sys::path::replace_extension(HTMLPath, "html");
182-
raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None);
185+
SmallString<128> HTMLFilePath(HTMLDirPath);
186+
sys::path::append(HTMLFilePath, sys::path::filename(Path));
187+
sys::path::replace_extension(HTMLFilePath, "html");
188+
raw_fd_ostream InfoOS(HTMLFilePath, FileErr, sys::fs::OF_None);
183189
if (FileErr)
184190
return createFileOpenError(Path, FileErr);
185191

186-
if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath),
187-
HTMLPath, InfoOS, CDCtx))
192+
if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLFilePath),
193+
HTMLFilePath, InfoOS, CDCtx))
188194
return Err;
189195
JSONIter.increment(EC);
190196
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,9 @@ Error JSONGenerator::generateDocs(
600600
Info *Info = Group.getValue().get();
601601

602602
SmallString<128> Path;
603-
sys::path::native(RootDir, Path);
603+
auto RootDirStr = RootDir.str() + "/json";
604+
StringRef JSONDir = StringRef(RootDirStr);
605+
sys::path::native(JSONDir, Path);
604606
if (!CreatedDirs.contains(Path)) {
605607
if (std::error_code Err = sys::fs::create_directories(Path);
606608
Err != std::error_code())

clang-tools-extra/test/clang-doc/basic-project.mustache.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// RUN: sed 's|$test_dir|%/S|g' %S/Inputs/basic-project/database_template.json > %t/build/compile_commands.json
33

44
// RUN: clang-doc --format=mustache --output=%t/docs --executor=all-TUs %t/build/compile_commands.json
5-
// RUN: FileCheck %s -input-file=%t/docs/_ZTV5Shape.html -check-prefix=HTML-SHAPE
6-
// RUN: FileCheck %s -input-file=%t/docs/_ZTV10Calculator.html -check-prefix=HTML-CALC
7-
// RUN: FileCheck %s -input-file=%t/docs/_ZTV9Rectangle.html -check-prefix=HTML-RECTANGLE
8-
// RUN: FileCheck %s -input-file=%t/docs/_ZTV6Circle.html -check-prefix=HTML-CIRCLE
5+
// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV5Shape.html -check-prefix=HTML-SHAPE
6+
// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV10Calculator.html -check-prefix=HTML-CALC
7+
// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV9Rectangle.html -check-prefix=HTML-RECTANGLE
8+
// RUN: FileCheck %s -input-file=%t/docs/html/_ZTV6Circle.html -check-prefix=HTML-CIRCLE
99

1010
HTML-SHAPE: <html lang="en-US">
1111
HTML-SHAPE: <head>

clang-tools-extra/test/clang-doc/json/class-requires.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: rm -rf %t && mkdir -p %t
22
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
3-
// RUN: FileCheck %s < %t/_ZTV7MyClass.json
3+
// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json
44

55
template<typename T>
66
concept Addable = requires(T a, T b) {

clang-tools-extra/test/clang-doc/json/class-specialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: rm -rf %t && mkdir -p %t
22
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
3-
// RUN: FileCheck %s < %t/_ZTV7MyClass.json --check-prefix=BASE
4-
// RUN: FileCheck %s < %t/_ZTV7MyClassIiE.json --check-prefix=SPECIALIZATION
3+
// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json --check-prefix=BASE
4+
// RUN: FileCheck %s < %t/json/_ZTV7MyClassIiE.json --check-prefix=SPECIALIZATION
55

66
template<typename T> struct MyClass {};
77

clang-tools-extra/test/clang-doc/json/class-template.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: rm -rf %t && mkdir -p %t
22
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
3-
// RUN: FileCheck %s < %t/_ZTV7MyClass.json
3+
// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json
44

55
template<typename T> struct MyClass {
66
T MemberTemplate;

clang-tools-extra/test/clang-doc/json/class.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: rm -rf %t && mkdir -p %t
22
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
3-
// RUN: FileCheck %s < %t/_ZTV7MyClass.json
3+
// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json
44

55
struct Foo;
66

clang-tools-extra/test/clang-doc/json/compound-constraints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: rm -rf %t && mkdir -p %t
22
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
3-
// RUN: FileCheck %s < %t/index.json
3+
// RUN: FileCheck %s < %t/json/index.json
44

55
template<typename T> concept Incrementable = requires (T a) {
66
a++;

clang-tools-extra/test/clang-doc/json/concept.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: rm -rf %t && mkdir -p %t
22
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
3-
// RUN: FileCheck %s < %t/index.json
3+
// RUN: FileCheck %s < %t/json/index.json
44

55
// Requires that T suports post and pre-incrementing.
66
template<typename T>

clang-tools-extra/test/clang-doc/json/function-requires.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: rm -rf %t && mkdir -p %t
22
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
3-
// RUN: FileCheck %s < %t/index.json
3+
// RUN: FileCheck %s < %t/json/index.json
44

55
template<typename T>
66
concept Incrementable = requires(T x) {

0 commit comments

Comments
 (0)