aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Velez <erickvelez7@gmail.com>2025-07-24 20:51:32 -0700
committerErick Velez <erickvelez7@gmail.com>2025-08-14 19:24:27 +0000
commitd0d436232ad48ae1f62b7970600036e697e67e41 (patch)
tree076be6eed3a428feaf7f8f73fbb4398e2e40c44a
parent4f007041a87b1b0c2686d1871ea6e35394545865 (diff)
downloadllvm-users/evelez7/clang-doc-delete-json-option.zip
llvm-users/evelez7/clang-doc-delete-json-option.tar.gz
llvm-users/evelez7/clang-doc-delete-json-option.tar.bz2
[clang-doc] add option to delete JSON residualsusers/evelez7/clang-doc-delete-json-option
This new option defaults to delete the json dir after HTML generation.
-rw-r--r--clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp3
-rw-r--r--clang-tools-extra/clang-doc/Representation.cpp4
-rw-r--r--clang-tools-extra/clang-doc/Representation.h3
-rw-r--r--clang-tools-extra/clang-doc/tool/ClangDocMain.cpp6
-rw-r--r--clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp4
-rw-r--r--clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp4
6 files changed, 17 insertions, 7 deletions
diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
index 1ab40aa..4e225f7 100644
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -196,6 +196,9 @@ Error MustacheHTMLGenerator::generateDocs(
}
}
+ if (!CDCtx.KeepJSON)
+ sys::fs::remove_directories(JSONPath);
+
return Error::success();
}
diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp
index 929112f..e3fad58 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -481,9 +481,9 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
StringRef RepositoryUrl,
StringRef RepositoryLinePrefix, StringRef Base,
std::vector<std::string> UserStylesheets,
- bool FTimeTrace)
+ bool KeepJSON, bool FTimeTrace)
: ECtx(ECtx), ProjectName(ProjectName), PublicOnly(PublicOnly),
- FTimeTrace(FTimeTrace), OutDirectory(OutDirectory),
+ FTimeTrace(FTimeTrace), KeepJSON(KeepJSON), OutDirectory(OutDirectory),
UserStylesheets(UserStylesheets), Base(Base) {
llvm::SmallString<128> SourceRootDir(SourceRoot);
if (SourceRoot.empty())
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index 2a75f89..ddb8f3a 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -610,11 +610,12 @@ struct ClangDocContext {
bool PublicOnly, StringRef OutDirectory, StringRef SourceRoot,
StringRef RepositoryUrl, StringRef RepositoryCodeLinePrefix,
StringRef Base, std::vector<std::string> UserStylesheets,
- bool FTimeTrace = false);
+ bool KeepJSON, bool FTimeTrace = false);
tooling::ExecutionContext *ECtx;
std::string ProjectName; // Name of project clang-doc is documenting.
bool PublicOnly; // Indicates if only public declarations are documented.
bool FTimeTrace; // Indicates if ftime trace is turned on
+ bool KeepJSON; // Indicates if JSON files should be kept after HTML generation
int Granularity; // Granularity of ftime trace
std::string OutDirectory; // Directory for outputting generated files.
std::string SourceRoot; // Directory where processed files are stored. Links
diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 3bb67ba..29a766d 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -110,6 +110,11 @@ Turn on time profiler. Generates clang-doc-tracing.json)"),
llvm::cl::init(false),
llvm::cl::cat(ClangDocCategory));
+static llvm::cl::opt<bool>
+ KeepJSON("keep-json",
+ llvm::cl::desc("Keep JSON residuals after processing."),
+ llvm::cl::init(false), llvm::cl::cat(ClangDocCategory));
+
enum OutputFormatTy { md, yaml, html, mustache, json };
static llvm::cl::opt<OutputFormatTy> FormatEnum(
@@ -325,6 +330,7 @@ Example usage for a project using a compile commands database:
RepositoryCodeLinePrefix,
BaseDirectory,
{UserStylesheets.begin(), UserStylesheets.end()},
+ KeepJSON,
FTimeTrace};
if (Format == "html") {
diff --git a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
index 14341435..cf4541c 100644
--- a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -30,8 +30,8 @@ getClangDocContext(std::vector<std::string> UserStylesheets = {},
StringRef RepositoryUrl = "",
StringRef RepositoryLinePrefix = "", StringRef Base = "") {
ClangDocContext CDCtx{
- {}, "test-project", {}, {}, {}, RepositoryUrl, RepositoryLinePrefix,
- Base, UserStylesheets};
+ {}, "test-project", {}, {}, {}, RepositoryUrl, RepositoryLinePrefix,
+ Base, UserStylesheets, {}};
CDCtx.UserStylesheets.insert(
CDCtx.UserStylesheets.begin(),
"../share/clang/clang-doc-default-stylesheet.css");
diff --git a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
index 602058f..a24598e 100644
--- a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
@@ -41,8 +41,8 @@ getClangDocContext(std::vector<std::string> UserStylesheets = {},
StringRef RepositoryUrl = "",
StringRef RepositoryLinePrefix = "", StringRef Base = "") {
ClangDocContext CDCtx{
- {}, "test-project", {}, {}, {}, RepositoryUrl, RepositoryLinePrefix,
- Base, UserStylesheets};
+ {}, "test-project", {}, {}, {}, RepositoryUrl, RepositoryLinePrefix,
+ Base, UserStylesheets, {}};
CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), "");
CDCtx.JsScripts.emplace_back("");
return CDCtx;