Skip to content

Commit c7490ab

Browse files
committed
[clang-doc] address pr comments
1 parent bb407e7 commit c7490ab

File tree

9 files changed

+52
-20
lines changed

9 files changed

+52
-20
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,18 @@ genStylesheetsHTML(StringRef InfoPath, const ClangDocContext &CDCtx) {
289289
static std::vector<std::unique_ptr<TagNode>>
290290
genJsScriptsHTML(StringRef InfoPath, const ClangDocContext &CDCtx) {
291291
std::vector<std::unique_ptr<TagNode>> Out;
292+
293+
// index_json.js is part of every generated HTML file
294+
SmallString<128> IndexJSONPath = computeRelativePath("", InfoPath);
295+
auto IndexJSONNode = std::make_unique<TagNode>(HTMLTag::TAG_SCRIPT);
296+
llvm::sys::path::append(IndexJSONPath, "index_json.js");
297+
llvm::sys::path::native(IndexJSONPath, llvm::sys::path::Style::posix);
298+
IndexJSONNode->Attributes.emplace_back("src", std::string(IndexJSONPath));
299+
Out.emplace_back(std::move(IndexJSONNode));
300+
292301
for (const auto &FilePath : CDCtx.JsScripts) {
293-
auto ScriptNode = std::make_unique<TagNode>(HTMLTag::TAG_SCRIPT);
294302
SmallString<128> ScriptPath = computeRelativePath("", InfoPath);
303+
auto ScriptNode = std::make_unique<TagNode>(HTMLTag::TAG_SCRIPT);
295304
llvm::sys::path::append(ScriptPath, llvm::sys::path::filename(FilePath));
296305
// Paths in HTML must be in posix-style
297306
llvm::sys::path::native(ScriptPath, llvm::sys::path::Style::posix);
@@ -1069,7 +1078,7 @@ llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
10691078
if (Err)
10701079
return Err;
10711080
}
1072-
for (const auto &FilePath : CDCtx.FilesToCopy) {
1081+
for (const auto &FilePath : CDCtx.JsScripts) {
10731082
Err = CopyFile(FilePath, CDCtx.OutDirectory);
10741083
if (Err)
10751084
return Err;

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,9 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
368368
StringRef ProjectName, bool PublicOnly,
369369
StringRef OutDirectory, StringRef SourceRoot,
370370
StringRef RepositoryUrl,
371-
std::vector<std::string> UserStylesheets,
372-
std::vector<std::string> JsScripts)
371+
std::vector<std::string> UserStylesheets)
373372
: ECtx(ECtx), ProjectName(ProjectName), PublicOnly(PublicOnly),
374-
OutDirectory(OutDirectory), UserStylesheets(UserStylesheets),
375-
JsScripts(JsScripts) {
373+
OutDirectory(OutDirectory), UserStylesheets(UserStylesheets) {
376374
llvm::SmallString<128> SourceRootDir(SourceRoot);
377375
if (SourceRoot.empty())
378376
// If no SourceRoot was provided the current path is used as the default

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,7 @@ struct ClangDocContext {
482482
ClangDocContext(tooling::ExecutionContext *ECtx, StringRef ProjectName,
483483
bool PublicOnly, StringRef OutDirectory, StringRef SourceRoot,
484484
StringRef RepositoryUrl,
485-
std::vector<std::string> UserStylesheets,
486-
std::vector<std::string> JsScripts);
485+
std::vector<std::string> UserStylesheets);
487486
tooling::ExecutionContext *ECtx;
488487
std::string ProjectName; // Name of project clang-doc is documenting.
489488
bool PublicOnly; // Indicates if only public declarations are documented.
@@ -498,8 +497,6 @@ struct ClangDocContext {
498497
std::vector<std::string> UserStylesheets;
499498
// JavaScript files that will be imported in allHTML file.
500499
std::vector<std::string> JsScripts;
501-
// Other files that should be copied to OutDirectory, besides UserStylesheets.
502-
std::vector<std::string> FilesToCopy;
503500
Index Idx;
504501
};
505502

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) {
150150
CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
151151
std::string(FilePath));
152152
else if (llvm::sys::path::extension(FilePath) == ".js")
153-
CDCtx.FilesToCopy.emplace_back(FilePath.str());
153+
CDCtx.JsScripts.emplace_back(FilePath.str());
154154
}
155155
}
156156
if (FileErr)
@@ -176,8 +176,6 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
176176
llvm::sys::path::native(AssetsPath, IndexJS);
177177
llvm::sys::path::append(IndexJS, "index.js");
178178

179-
llvm::outs() << "Using default asset: " << AssetsPath << "\n";
180-
181179
if (!llvm::sys::fs::is_regular_file(IndexJS))
182180
return llvm::createStringError(llvm::inconvertibleErrorCode(),
183181
"default index.js file missing at " +
@@ -191,7 +189,7 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
191189

192190
CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
193191
std::string(DefaultStylesheet));
194-
CDCtx.FilesToCopy.emplace_back(IndexJS.str());
192+
CDCtx.JsScripts.emplace_back(IndexJS.str());
195193

196194
return llvm::Error::success();
197195
}
@@ -254,12 +252,13 @@ Example usage for a project using a compile commands database:
254252
OutDirectory,
255253
SourceRoot,
256254
RepositoryUrl,
257-
{UserStylesheets.begin(), UserStylesheets.end()},
258-
{"index.js", "index_json.js"}};
255+
{UserStylesheets.begin(), UserStylesheets.end()}
256+
};
259257

260258
if (Format == "html") {
261259
if (auto Err = getHtmlAssetFiles(argv[0], CDCtx)) {
262-
llvm::outs() << "warning: " << toString(std::move(Err)) << "\n";
260+
llvm::errs() << toString(std::move(Err)) << "\n";
261+
return 1;
263262
}
264263
}
265264

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
padding: 0;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello, world!");
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: rm -rf %t && mkdir %t
2+
// RUN: clang-doc --format=html --output=%t --asset=%S/Inputs/test-assets --executor=standalone %s --output=%t/docs
3+
// RUN: FileCheck %s -input-file=%t/index.html -check-prefix=INDEX
4+
// RUN: FileCheck %s -input-file=%t/test.css -check-prefix=CSS
5+
// RUN: FileCheck %s -input-file=%t/test.js -check-prefix=JS
6+
7+
// INDEX: <!DOCTYPE html>
8+
// INDEX-NEXT: <meta charset="utf-8"/>
9+
// INDEX-NEXT: <title>Index</title>
10+
// INDEX-NEXT: <link rel="stylesheet" href="test.css"/>
11+
// INDEX-NEXT: <script src="index_json.js"></script>
12+
// INDEX-NEXT: <script src="test.js"></script>
13+
// INDEX-NEXT: <header id="project-title"></header>
14+
// INDEX-NEXT: <main>
15+
// INDEX-NEXT: <div id="sidebar-left" path="" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left" style="flex: 0 100%;"></div>
16+
// INDEX-NEXT: </main>
17+
18+
// CSS: body {
19+
// CSS-NEXT: padding: 0;
20+
// CSS-NEXT: }
21+
22+
// JS: console.log("Hello, world!");

clang-tools-extra/test/clang-doc/single-source-html.cpp

Lines changed: 0 additions & 2 deletions
This file was deleted.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ClangDocContext
3030
getClangDocContext(std::vector<std::string> UserStylesheets = {},
3131
StringRef RepositoryUrl = "") {
3232
ClangDocContext CDCtx{
33-
{}, "test-project", {}, {}, {}, RepositoryUrl, UserStylesheets, {}};
33+
{}, "test-project", {}, {}, {}, RepositoryUrl, UserStylesheets};
3434
CDCtx.UserStylesheets.insert(
3535
CDCtx.UserStylesheets.begin(),
3636
"../share/clang/clang-doc-default-stylesheet.css");
@@ -66,6 +66,7 @@ TEST(HTMLGeneratorTest, emitNamespaceHTML) {
6666
<title>namespace Namespace</title>
6767
<link rel="stylesheet" href="../clang-doc-default-stylesheet.css"/>
6868
<link rel="stylesheet" href="../user-provided-stylesheet.css"/>
69+
<script src="../index_json.js"></script>
6970
<script src="../index.js"></script>
7071
<header id="project-title">test-project</header>
7172
<main>
@@ -176,6 +177,7 @@ TEST(HTMLGeneratorTest, emitRecordHTML) {
176177
<meta charset="utf-8"/>
177178
<title>class r</title>
178179
<link rel="stylesheet" href="../../../clang-doc-default-stylesheet.css"/>
180+
<script src="../../../index_json.js"></script>
179181
<script src="../../../index.js"></script>
180182
<header id="project-title">test-project</header>
181183
<main>
@@ -290,6 +292,7 @@ TEST(HTMLGeneratorTest, emitFunctionHTML) {
290292
<meta charset="utf-8"/>
291293
<title></title>
292294
<link rel="stylesheet" href="clang-doc-default-stylesheet.css"/>
295+
<script src="index_json.js"></script>
293296
<script src="index.js"></script>
294297
<header id="project-title">test-project</header>
295298
<main>
@@ -337,6 +340,7 @@ TEST(HTMLGeneratorTest, emitEnumHTML) {
337340
<meta charset="utf-8"/>
338341
<title></title>
339342
<link rel="stylesheet" href="clang-doc-default-stylesheet.css"/>
343+
<script src="index_json.js"></script>
340344
<script src="index.js"></script>
341345
<header id="project-title">test-project</header>
342346
<main>
@@ -422,6 +426,7 @@ TEST(HTMLGeneratorTest, emitCommentHTML) {
422426
<meta charset="utf-8"/>
423427
<title></title>
424428
<link rel="stylesheet" href="clang-doc-default-stylesheet.css"/>
429+
<script src="index_json.js"></script>
425430
<script src="index.js"></script>
426431
<header id="project-title">test-project</header>
427432
<main>

0 commit comments

Comments
 (0)