[clang-tools-extra] [clang-doc] fix CSS, JS paths for HTML Mustache generation (PR #160360)

Erick Velez via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 23 11:39:09 PDT 2025


https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/160360

>From 4e6e429090a7e7050be6e92c78a5cd7d7d039e68 Mon Sep 17 00:00:00 2001
From: Erick Velez <erickvelez7 at gmail.com>
Date: Tue, 23 Sep 2025 09:34:27 -0700
Subject: [PATCH] [clang-doc] fix CSS, JS paths for HTML Mustache generation

Resource creation not using the correct path after the patch that placed
HTML files into their own directory.
---
 .../clang-doc/HTMLMustacheGenerator.cpp       |  5 +-
 .../unittests/clang-doc/CMakeLists.txt        |  1 -
 .../clang-doc/HTMLMustacheGeneratorTest.cpp   | 88 -------------------
 3 files changed, 3 insertions(+), 91 deletions(-)
 delete mode 100644 clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp

diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
index 1ab40aacbfe09..b37dc272ea156 100644
--- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp
@@ -274,11 +274,12 @@ Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
 }
 
 Error MustacheHTMLGenerator::createResources(ClangDocContext &CDCtx) {
+  std::string ResourcePath(CDCtx.OutDirectory + "/html");
   for (const auto &FilePath : CDCtx.UserStylesheets)
-    if (Error Err = copyFile(FilePath, CDCtx.OutDirectory))
+    if (Error Err = copyFile(FilePath, ResourcePath))
       return Err;
   for (const auto &FilePath : CDCtx.JsScripts)
-    if (Error Err = copyFile(FilePath, CDCtx.OutDirectory))
+    if (Error Err = copyFile(FilePath, ResourcePath))
       return Err;
   return Error::success();
 }
diff --git a/clang-tools-extra/unittests/clang-doc/CMakeLists.txt b/clang-tools-extra/unittests/clang-doc/CMakeLists.txt
index 18166acf9bbca..01b34ec9a791e 100644
--- a/clang-tools-extra/unittests/clang-doc/CMakeLists.txt
+++ b/clang-tools-extra/unittests/clang-doc/CMakeLists.txt
@@ -26,7 +26,6 @@ add_extra_unittest(ClangDocTests
   ClangDocTest.cpp
   GeneratorTest.cpp
   HTMLGeneratorTest.cpp
-  HTMLMustacheGeneratorTest.cpp
   MDGeneratorTest.cpp
   MergeTest.cpp
   SerializeTest.cpp
diff --git a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
deleted file mode 100644
index 602058f5d9eb8..0000000000000
--- a/clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-//===-- clang-doc/HTMLMustacheGeneratorTest.cpp ---------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "ClangDocTest.h"
-#include "Generators.h"
-#include "Representation.h"
-#include "config.h"
-#include "support/Utils.h"
-#include "clang/Basic/Version.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Testing/Support/Error.h"
-#include "llvm/Testing/Support/SupportHelpers.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-using namespace testing;
-using namespace clang;
-using namespace clang::doc;
-
-// FIXME: Don't enable unit tests that can read files. Remove once we can use
-// lit to test these properties.
-#define ENABLE_LOCAL_TEST 0
-
-static const std::string ClangDocVersion = getClangToolFullVersion("clang-doc");
-
-static std::unique_ptr<Generator> getHTMLMustacheGenerator() {
-  auto G = findGeneratorByName("mustache");
-  if (!G)
-    return nullptr;
-  return std::move(G.get());
-}
-
-static ClangDocContext
-getClangDocContext(std::vector<std::string> UserStylesheets = {},
-                   StringRef RepositoryUrl = "",
-                   StringRef RepositoryLinePrefix = "", StringRef Base = "") {
-  ClangDocContext CDCtx{
-      {},   "test-project", {}, {}, {}, RepositoryUrl, RepositoryLinePrefix,
-      Base, UserStylesheets};
-  CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), "");
-  CDCtx.JsScripts.emplace_back("");
-  return CDCtx;
-}
-
-static void verifyFileContents(const Twine &Path, StringRef Contents) {
-  auto Buffer = MemoryBuffer::getFile(Path);
-  ASSERT_TRUE((bool)Buffer);
-  StringRef Data = Buffer.get()->getBuffer();
-  ASSERT_EQ(Data, Contents);
-}
-
-TEST(HTMLMustacheGeneratorTest, createResources) {
-  auto G = getHTMLMustacheGenerator();
-  ASSERT_THAT(G, NotNull()) << "Could not find HTMLMustacheGenerator";
-  ClangDocContext CDCtx = getClangDocContext();
-  EXPECT_THAT_ERROR(G->createResources(CDCtx), Failed())
-      << "Empty UserStylesheets or JsScripts should fail!";
-
-  unittest::TempDir RootTestDirectory("createResourcesTest", /*Unique=*/true);
-  CDCtx.OutDirectory = RootTestDirectory.path();
-
-  unittest::TempFile CSS("clang-doc-mustache", "css", "CSS");
-  unittest::TempFile JS("mustache", "js", "JavaScript");
-
-  CDCtx.UserStylesheets[0] = CSS.path();
-  CDCtx.JsScripts[0] = JS.path();
-
-  EXPECT_THAT_ERROR(G->createResources(CDCtx), Succeeded())
-      << "Failed to create resources with valid UserStylesheets and JsScripts";
-  {
-    SmallString<256> PathBuf;
-    llvm::sys::path::append(PathBuf, RootTestDirectory.path(),
-                            "clang-doc-mustache.css");
-    verifyFileContents(PathBuf, "CSS");
-  }
-
-  {
-    SmallString<256> PathBuf;
-    llvm::sys::path::append(PathBuf, RootTestDirectory.path(), "mustache.js");
-    verifyFileContents(PathBuf, "JavaScript");
-  }
-}



More information about the cfe-commits mailing list