Skip to content

Commit d0d4362

Browse files
committed
[clang-doc] add option to delete JSON residuals
This new option defaults to delete the json dir after HTML generation.
1 parent 4f00704 commit d0d4362

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ Error MustacheHTMLGenerator::generateDocs(
196196
}
197197
}
198198

199+
if (!CDCtx.KeepJSON)
200+
sys::fs::remove_directories(JSONPath);
201+
199202
return Error::success();
200203
}
201204

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
481481
StringRef RepositoryUrl,
482482
StringRef RepositoryLinePrefix, StringRef Base,
483483
std::vector<std::string> UserStylesheets,
484-
bool FTimeTrace)
484+
bool KeepJSON, bool FTimeTrace)
485485
: ECtx(ECtx), ProjectName(ProjectName), PublicOnly(PublicOnly),
486-
FTimeTrace(FTimeTrace), OutDirectory(OutDirectory),
486+
FTimeTrace(FTimeTrace), KeepJSON(KeepJSON), OutDirectory(OutDirectory),
487487
UserStylesheets(UserStylesheets), Base(Base) {
488488
llvm::SmallString<128> SourceRootDir(SourceRoot);
489489
if (SourceRoot.empty())

clang-tools-extra/clang-doc/Representation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,12 @@ struct ClangDocContext {
610610
bool PublicOnly, StringRef OutDirectory, StringRef SourceRoot,
611611
StringRef RepositoryUrl, StringRef RepositoryCodeLinePrefix,
612612
StringRef Base, std::vector<std::string> UserStylesheets,
613-
bool FTimeTrace = false);
613+
bool KeepJSON, bool FTimeTrace = false);
614614
tooling::ExecutionContext *ECtx;
615615
std::string ProjectName; // Name of project clang-doc is documenting.
616616
bool PublicOnly; // Indicates if only public declarations are documented.
617617
bool FTimeTrace; // Indicates if ftime trace is turned on
618+
bool KeepJSON; // Indicates if JSON files should be kept after HTML generation
618619
int Granularity; // Granularity of ftime trace
619620
std::string OutDirectory; // Directory for outputting generated files.
620621
std::string SourceRoot; // Directory where processed files are stored. Links

clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ Turn on time profiler. Generates clang-doc-tracing.json)"),
110110
llvm::cl::init(false),
111111
llvm::cl::cat(ClangDocCategory));
112112

113+
static llvm::cl::opt<bool>
114+
KeepJSON("keep-json",
115+
llvm::cl::desc("Keep JSON residuals after processing."),
116+
llvm::cl::init(false), llvm::cl::cat(ClangDocCategory));
117+
113118
enum OutputFormatTy { md, yaml, html, mustache, json };
114119

115120
static llvm::cl::opt<OutputFormatTy> FormatEnum(
@@ -325,6 +330,7 @@ Example usage for a project using a compile commands database:
325330
RepositoryCodeLinePrefix,
326331
BaseDirectory,
327332
{UserStylesheets.begin(), UserStylesheets.end()},
333+
KeepJSON,
328334
FTimeTrace};
329335

330336
if (Format == "html") {

clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ getClangDocContext(std::vector<std::string> UserStylesheets = {},
3030
StringRef RepositoryUrl = "",
3131
StringRef RepositoryLinePrefix = "", StringRef Base = "") {
3232
ClangDocContext CDCtx{
33-
{}, "test-project", {}, {}, {}, RepositoryUrl, RepositoryLinePrefix,
34-
Base, UserStylesheets};
33+
{}, "test-project", {}, {}, {}, RepositoryUrl, RepositoryLinePrefix,
34+
Base, UserStylesheets, {}};
3535
CDCtx.UserStylesheets.insert(
3636
CDCtx.UserStylesheets.begin(),
3737
"../share/clang/clang-doc-default-stylesheet.css");

clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ getClangDocContext(std::vector<std::string> UserStylesheets = {},
4141
StringRef RepositoryUrl = "",
4242
StringRef RepositoryLinePrefix = "", StringRef Base = "") {
4343
ClangDocContext CDCtx{
44-
{}, "test-project", {}, {}, {}, RepositoryUrl, RepositoryLinePrefix,
45-
Base, UserStylesheets};
44+
{}, "test-project", {}, {}, {}, RepositoryUrl, RepositoryLinePrefix,
45+
Base, UserStylesheets, {}};
4646
CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), "");
4747
CDCtx.JsScripts.emplace_back("");
4848
return CDCtx;

0 commit comments

Comments
 (0)