Skip to content

Commit e7515ee

Browse files
authored
[clang-doc] fix CSS, JS paths for HTML Mustache generation (llvm#160360)
Resource creation not using the correct path after the patch that placed HTML files into their own directory.
1 parent 89d2b7e commit e7515ee

File tree

2 files changed

+3
-35
lines changed

2 files changed

+3
-35
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,12 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
274274
}
275275

276276
Error MustacheHTMLGenerator::createResources(ClangDocContext &CDCtx) {
277+
std::string ResourcePath(CDCtx.OutDirectory + "/html");
277278
for (const auto &FilePath : CDCtx.UserStylesheets)
278-
if (Error Err = copyFile(FilePath, CDCtx.OutDirectory))
279+
if (Error Err = copyFile(FilePath, ResourcePath))
279280
return Err;
280281
for (const auto &FilePath : CDCtx.JsScripts)
281-
if (Error Err = copyFile(FilePath, CDCtx.OutDirectory))
282+
if (Error Err = copyFile(FilePath, ResourcePath))
282283
return Err;
283284
return Error::success();
284285
}

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
#include "config.h"
1313
#include "support/Utils.h"
1414
#include "clang/Basic/Version.h"
15-
#include "llvm/Support/Path.h"
1615
#include "llvm/Testing/Support/Error.h"
17-
#include "llvm/Testing/Support/SupportHelpers.h"
1816
#include "gmock/gmock.h"
1917
#include "gtest/gtest.h"
2018

@@ -48,41 +46,10 @@ getClangDocContext(std::vector<std::string> UserStylesheets = {},
4846
return CDCtx;
4947
}
5048

51-
static void verifyFileContents(const Twine &Path, StringRef Contents) {
52-
auto Buffer = MemoryBuffer::getFile(Path);
53-
ASSERT_TRUE((bool)Buffer);
54-
StringRef Data = Buffer.get()->getBuffer();
55-
ASSERT_EQ(Data, Contents);
56-
}
57-
5849
TEST(HTMLMustacheGeneratorTest, createResources) {
5950
auto G = getHTMLMustacheGenerator();
6051
ASSERT_THAT(G, NotNull()) << "Could not find HTMLMustacheGenerator";
6152
ClangDocContext CDCtx = getClangDocContext();
6253
EXPECT_THAT_ERROR(G->createResources(CDCtx), Failed())
6354
<< "Empty UserStylesheets or JsScripts should fail!";
64-
65-
unittest::TempDir RootTestDirectory("createResourcesTest", /*Unique=*/true);
66-
CDCtx.OutDirectory = RootTestDirectory.path();
67-
68-
unittest::TempFile CSS("clang-doc-mustache", "css", "CSS");
69-
unittest::TempFile JS("mustache", "js", "JavaScript");
70-
71-
CDCtx.UserStylesheets[0] = CSS.path();
72-
CDCtx.JsScripts[0] = JS.path();
73-
74-
EXPECT_THAT_ERROR(G->createResources(CDCtx), Succeeded())
75-
<< "Failed to create resources with valid UserStylesheets and JsScripts";
76-
{
77-
SmallString<256> PathBuf;
78-
llvm::sys::path::append(PathBuf, RootTestDirectory.path(),
79-
"clang-doc-mustache.css");
80-
verifyFileContents(PathBuf, "CSS");
81-
}
82-
83-
{
84-
SmallString<256> PathBuf;
85-
llvm::sys::path::append(PathBuf, RootTestDirectory.path(), "mustache.js");
86-
verifyFileContents(PathBuf, "JavaScript");
87-
}
8855
}

0 commit comments

Comments
 (0)