================
@@ -1,265 +1,311 @@
-//===- Dtlto.cpp - Distributed ThinLTO implementation --------------------===//
+//===- DTLTO.cpp - Distributed ThinLTO implementation 
---------------------===//
 //
 // 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
 //
 
//===----------------------------------------------------------------------===//
-//
 // \file
 // This file implements support functions for Distributed ThinLTO, focusing on
-// preparing input files for distribution.
+// preparing complilation jobs for distribution.
 //
 
//===----------------------------------------------------------------------===//
 
 #include "llvm/DTLTO/DTLTO.h"
 
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/BinaryFormat/Magic.h"
 #include "llvm/LTO/LTO.h"
-#include "llvm/Object/Archive.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/Signals.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/raw_ostream.h"
-#ifdef _WIN32
-#include "llvm/Support/Windows/WindowsSupport.h"
-#endif
 
 #include <string>
 
 using namespace llvm;
 
-namespace {
-
-// Saves the content of Buffer to Path overwriting any existing file.
-Error save(StringRef Buffer, StringRef Path) {
-  std::error_code EC;
-  raw_fd_ostream OS(Path.str(), EC, sys::fs::OpenFlags::OF_None);
-  if (EC)
-    return createStringError(inconvertibleErrorCode(),
-                             "Failed to create file %s: %s", Path.data(),
-                             EC.message().c_str());
-  OS.write(Buffer.data(), Buffer.size());
-  if (OS.has_error())
-    return createStringError(inconvertibleErrorCode(),
-                             "Failed writing to file %s", Path.data());
-  return Error::success();
-}
+// Remove temporary files created to enable distribution.
+void lto::DTLTO::cleanup() {
+  if (!SaveTemps) {
+    // Remove one file, report error if any.
+    auto removeFile = [](StringRef FileName) -> void {
+      std::error_code EC = sys::fs::remove(FileName, true);
+      if (EC &&
+          EC != std::make_error_code(std::errc::no_such_file_or_directory))
+        errs() << "warning: could not remove the file '" << FileName
+               << "': " << EC.message() << "\n";
+    };
 
-// Saves the content of Input to Path overwriting any existing file.
-Error save(lto::InputFile *Input, StringRef Path) {
-  MemoryBufferRef MB = Input->getFileBuffer();
-  return save(MB.getBuffer(), Path);
+    TimeTraceScope JobScope("Remove DTLTO temporary files");
+    for (const auto &Name : CleanupList)
----------------
teresajohnson wrote:

Suggest clearing CleanupList after this loop for safety. It doesn't look like 
this should be called more than once but probably best to leave in a clean 
state.

https://github.com/llvm/llvm-project/pull/192629
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to