[llvm] [Support] Make CleanupInstaller public (NFC) (PR #86758)
Haohai Wen via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 26 19:22:42 PDT 2024
https://github.com/HaohaiWen created https://github.com/llvm/llvm-project/pull/86758
This can be used by others to automatically remove temp files.
>From 8f87334b9b53aaaf42d8036394bd13d315e22cea Mon Sep 17 00:00:00 2001
From: Haohai Wen <haohai.wen at intel.com>
Date: Wed, 27 Mar 2024 10:13:27 +0800
Subject: [PATCH] [Support] Make CleanupInstaller public (NFC)
This can be used by others to automatically remove temp files.
---
llvm/include/llvm/Support/ToolOutputFile.h | 26 ++++++++++++----------
llvm/lib/Support/ToolOutputFile.cpp | 4 ++--
2 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/llvm/include/llvm/Support/ToolOutputFile.h b/llvm/include/llvm/Support/ToolOutputFile.h
index e3fb83fdfd2c3f..c16fb03d9b22b9 100644
--- a/llvm/include/llvm/Support/ToolOutputFile.h
+++ b/llvm/include/llvm/Support/ToolOutputFile.h
@@ -18,6 +18,19 @@
namespace llvm {
+class CleanupInstaller {
+public:
+ /// The name of the file.
+ std::string Filename;
+
+ /// The flag which indicates whether we should not delete the file.
+ bool Keep;
+
+ StringRef getFilename() { return Filename; }
+ explicit CleanupInstaller(StringRef Filename);
+ ~CleanupInstaller();
+};
+
/// This class contains a raw_fd_ostream and adds a few extra features commonly
/// needed for compiler-like tool output files:
/// - The file is automatically deleted if the process is killed.
@@ -28,18 +41,7 @@ class ToolOutputFile {
/// before the raw_fd_ostream is constructed and destructed after the
/// raw_fd_ostream is destructed. It installs cleanups in its constructor and
/// uninstalls them in its destructor.
- class CleanupInstaller {
- public:
- /// The name of the file.
- std::string Filename;
-
- /// The flag which indicates whether we should not delete the file.
- bool Keep;
-
- StringRef getFilename() { return Filename; }
- explicit CleanupInstaller(StringRef Filename);
- ~CleanupInstaller();
- } Installer;
+ CleanupInstaller Installer;
/// Storage for the stream, if we're owning our own stream. This is
/// intentionally declared after Installer.
diff --git a/llvm/lib/Support/ToolOutputFile.cpp b/llvm/lib/Support/ToolOutputFile.cpp
index 01f7095f3499d9..7a07286882fee0 100644
--- a/llvm/lib/Support/ToolOutputFile.cpp
+++ b/llvm/lib/Support/ToolOutputFile.cpp
@@ -17,14 +17,14 @@ using namespace llvm;
static bool isStdout(StringRef Filename) { return Filename == "-"; }
-ToolOutputFile::CleanupInstaller::CleanupInstaller(StringRef Filename)
+CleanupInstaller::CleanupInstaller(StringRef Filename)
: Filename(std::string(Filename)), Keep(false) {
// Arrange for the file to be deleted if the process is killed.
if (!isStdout(Filename))
sys::RemoveFileOnSignal(Filename);
}
-ToolOutputFile::CleanupInstaller::~CleanupInstaller() {
+CleanupInstaller::~CleanupInstaller() {
if (isStdout(Filename))
return;
More information about the llvm-commits
mailing list