This revision was automatically updated to reflect the committed changes.
Closed by commit rG72e1f7f960d5: [clang-doc] Switch Generator::CreateResources 
to use llvm::Error (authored by juliehockett).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66502/new/

https://reviews.llvm.org/D66502

Files:
  clang-tools-extra/clang-doc/Generators.cpp
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===================================================================
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -326,8 +326,11 @@
     return 1;
 
   llvm::outs() << "Generating assets for docs...\n";
-  if (!G->get()->createResources(CDCtx))
+  Err = G->get()->createResources(CDCtx);
+  if (Err) {
+    llvm::errs() << toString(std::move(Err)) << "\n";
     return 1;
+  }
 
   return 0;
 }
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===================================================================
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -829,7 +829,7 @@
 
   llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
                                  const ClangDocContext &CDCtx) override;
-  bool createResources(ClangDocContext &CDCtx) override;
+  llvm::Error createResources(ClangDocContext &CDCtx) override;
 };
 
 const char *HTMLGenerator::Format = "html";
@@ -883,7 +883,7 @@
   llvm_unreachable("Unknown InfoType");
 }
 
-static bool SerializeIndex(ClangDocContext &CDCtx) {
+static llvm::Error SerializeIndex(ClangDocContext &CDCtx) {
   std::error_code OK;
   std::error_code FileErr;
   llvm::SmallString<128> FilePath;
@@ -891,8 +891,9 @@
   llvm::sys::path::append(FilePath, "index_json.js");
   llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::F_None);
   if (FileErr != OK) {
-    llvm::errs() << "Error creating index file: " << FileErr.message() << "\n";
-    return false;
+    return llvm::make_error<llvm::StringError>(
+        "Error creating index file: " + FileErr.message() + "\n",
+        llvm::inconvertibleErrorCode());
   }
   CDCtx.Idx.sort();
   llvm::json::OStream J(OS, 2);
@@ -911,7 +912,7 @@
   OS << "var JsonIndex = `\n";
   IndexToJSON(CDCtx.Idx);
   OS << "`;\n";
-  return true;
+  return llvm::Error::success();
 }
 
 // Generates a main HTML node that has the main content of the file that shows
@@ -932,15 +933,16 @@
   return MainNode;
 }
 
-static bool GenIndex(const ClangDocContext &CDCtx) {
+static llvm::Error GenIndex(const ClangDocContext &CDCtx) {
   std::error_code FileErr, OK;
   llvm::SmallString<128> IndexPath;
   llvm::sys::path::native(CDCtx.OutDirectory, IndexPath);
   llvm::sys::path::append(IndexPath, "index.html");
   llvm::raw_fd_ostream IndexOS(IndexPath, FileErr, llvm::sys::fs::F_None);
   if (FileErr != OK) {
-    llvm::errs() << "Error creating main index: " << FileErr.message() << "\n";
-    return false;
+    return llvm::make_error<llvm::StringError>(
+        "Error creating main index: " + FileErr.message() + "\n",
+        llvm::inconvertibleErrorCode());
   }
 
   HTMLFile F;
@@ -958,10 +960,10 @@
 
   F.Render(IndexOS);
 
-  return true;
+  return llvm::Error::success();
 }
 
-static bool CopyFile(StringRef FilePath, StringRef OutDirectory) {
+static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) {
   llvm::SmallString<128> PathWrite;
   llvm::sys::path::native(OutDirectory, PathWrite);
   llvm::sys::path::append(PathWrite, llvm::sys::path::filename(FilePath));
@@ -970,24 +972,33 @@
   std::error_code OK;
   std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite);
   if (FileErr != OK) {
-    llvm::errs() << "Error creating file "
-                 << llvm::sys::path::filename(FilePath) << ": "
-                 << FileErr.message() << "\n";
-    return false;
+    return llvm::make_error<llvm::StringError>(
+        "Error creating file " + llvm::sys::path::filename(FilePath) + ": " +
+            FileErr.message() + "\n",
+        llvm::inconvertibleErrorCode());
   }
-  return true;
+  return llvm::Error::success();
 }
 
-bool HTMLGenerator::createResources(ClangDocContext &CDCtx) {
-  if (!SerializeIndex(CDCtx) || !GenIndex(CDCtx))
-    return false;
-  for (const auto &FilePath : CDCtx.UserStylesheets)
-    if (!CopyFile(FilePath, CDCtx.OutDirectory))
-      return false;
-  for (const auto &FilePath : CDCtx.FilesToCopy)
-    if (!CopyFile(FilePath, CDCtx.OutDirectory))
-      return false;
-  return true;
+llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
+  auto Err = SerializeIndex(CDCtx);
+  if (Err)
+    return Err;
+  Err = GenIndex(CDCtx);
+  if (Err)
+    return Err;
+
+  for (const auto &FilePath : CDCtx.UserStylesheets) {
+    Err = CopyFile(FilePath, CDCtx.OutDirectory);
+    if (Err)
+      return Err;
+  }
+  for (const auto &FilePath : CDCtx.FilesToCopy) {
+    Err = CopyFile(FilePath, CDCtx.OutDirectory);
+    if (Err)
+      return Err;
+  }
+  return llvm::Error::success();
 }
 
 static GeneratorRegistry::Add<HTMLGenerator> HTML(HTMLGenerator::Format,
Index: clang-tools-extra/clang-doc/Generators.h
===================================================================
--- clang-tools-extra/clang-doc/Generators.h
+++ clang-tools-extra/clang-doc/Generators.h
@@ -32,7 +32,7 @@
   // It can be overwritten by any of the inherited generators.
   // If the override method wants to run this it should call
   // Generator::createResources(CDCtx);
-  virtual bool createResources(ClangDocContext &CDCtx);
+  virtual llvm::Error createResources(ClangDocContext &CDCtx);
 
   static void addInfoToIndex(Index &Idx, const doc::Info *Info);
 };
Index: clang-tools-extra/clang-doc/Generators.cpp
===================================================================
--- clang-tools-extra/clang-doc/Generators.cpp
+++ clang-tools-extra/clang-doc/Generators.cpp
@@ -57,7 +57,9 @@
   llvm_unreachable("Unknown TagTypeKind");
 }
 
-bool Generator::createResources(ClangDocContext &CDCtx) { return true; }
+llvm::Error Generator::createResources(ClangDocContext &CDCtx) {
+  return llvm::Error::success();
+}
 
 // A function to add a reference to Info in Idx.
 // Given an Info X with the following namespaces: [B,A]; a reference to X will
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to