Skip to content

[clang-doc] place HTML/JSON output inside their own directories #150655

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,22 @@ Error MustacheHTMLGenerator::generateDocs(
} else
return JSONGenerator.takeError();
}
SmallString<128> JSONPath;
sys::path::native(RootDir.str() + "/json", JSONPath);

StringMap<json::Value> JSONFileMap;
{
llvm::TimeTraceScope TS("Iterate JSON files");
std::error_code EC;
sys::fs::directory_iterator JSONIter(RootDir, EC);
sys::fs::directory_iterator JSONIter(JSONPath, EC);
std::vector<json::Value> JSONFiles;
JSONFiles.reserve(Infos.size());
if (EC)
return createStringError("Failed to create directory iterator.");

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

std::error_code FileErr;
SmallString<16> HTMLPath(Path.begin(), Path.end());
sys::path::replace_extension(HTMLPath, "html");
raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None);
SmallString<128> HTMLFilePath(HTMLDirPath);
sys::path::append(HTMLFilePath, sys::path::filename(Path));
sys::path::replace_extension(HTMLFilePath, "html");
raw_fd_ostream InfoOS(HTMLFilePath, FileErr, sys::fs::OF_None);
if (FileErr)
return createFileOpenError(Path, FileErr);

if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath),
HTMLPath, InfoOS, CDCtx))
if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLFilePath),
HTMLFilePath, InfoOS, CDCtx))
return Err;
JSONIter.increment(EC);
}
Expand Down
4 changes: 3 additions & 1 deletion clang-tools-extra/clang-doc/JSONGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,9 @@ Error JSONGenerator::generateDocs(
Info *Info = Group.getValue().get();

SmallString<128> Path;
sys::path::native(RootDir, Path);
auto RootDirStr = RootDir.str() + "/json";
StringRef JSONDir = StringRef(RootDirStr);
sys::path::native(JSONDir, Path);
if (!CreatedDirs.contains(Path)) {
if (std::error_code Err = sys::fs::create_directories(Path);
Err != std::error_code())
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/test/clang-doc/basic-project.mustache.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// RUN: sed 's|$test_dir|%/S|g' %S/Inputs/basic-project/database_template.json > %t/build/compile_commands.json

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

HTML-SHAPE: <html lang="en-US">
HTML-SHAPE: <head>
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/test/clang-doc/json/class-requires.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/_ZTV7MyClass.json
// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json

template<typename T>
concept Addable = requires(T a, T b) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/_ZTV7MyClass.json --check-prefix=BASE
// RUN: FileCheck %s < %t/_ZTV7MyClassIiE.json --check-prefix=SPECIALIZATION
// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json --check-prefix=BASE
// RUN: FileCheck %s < %t/json/_ZTV7MyClassIiE.json --check-prefix=SPECIALIZATION

template<typename T> struct MyClass {};

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/test/clang-doc/json/class-template.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/_ZTV7MyClass.json
// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json

template<typename T> struct MyClass {
T MemberTemplate;
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/test/clang-doc/json/class.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/_ZTV7MyClass.json
// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json

struct Foo;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/index.json
// RUN: FileCheck %s < %t/json/index.json

template<typename T> concept Incrementable = requires (T a) {
a++;
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/test/clang-doc/json/concept.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/index.json
// RUN: FileCheck %s < %t/json/index.json

// Requires that T suports post and pre-incrementing.
template<typename T>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --extra-arg -std=c++20 --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/index.json
// RUN: FileCheck %s < %t/json/index.json

template<typename T>
concept Incrementable = requires(T x) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/index.json
// RUN: FileCheck %s < %t/json/index.json

static void myFunction() {}

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/test/clang-doc/json/method-template.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/_ZTV7MyClass.json
// RUN: FileCheck %s < %t/json/_ZTV7MyClass.json

struct MyClass {
template<class T> T methodTemplate(T param) {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/test/clang-doc/json/namespace.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/index.json
// RUN: FileCheck %s < %t/json/index.json

class MyClass {};

Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
// RUN: FileCheck %s < %t/nested.json --check-prefix=NESTED
// RUN: FileCheck %s < %t/inner.json --check-prefix=INNER
// RUN: FileCheck %s < %t/json/nested.json --check-prefix=NESTED
// RUN: FileCheck %s < %t/json/inner.json --check-prefix=INNER

namespace nested {
int Global;
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/test/clang-doc/mustache-index.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --format=mustache --output=%t --executor=standalone %s
// RUN: FileCheck %s < %t/index.html
// RUN: FileCheck %s < %t/html/index.html

enum Color {
RED,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: clang-doc --format=mustache --output=%t --executor=standalone %s
// RUN: FileCheck %s < %t/MyNamespace.html
// RUN: FileCheck %s < %t/html/MyNamespace.html

namespace MyNamespace {
class Foo;
Expand Down