Skip to content

Commit 03ffb82

Browse files
authored
[Support] Make CleanupInstaller public (NFC) (#86758)
This can be used by others to automatically remove temp files.
1 parent d412047 commit 03ffb82

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

llvm/include/llvm/Support/ToolOutputFile.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818

1919
namespace llvm {
2020

21+
class CleanupInstaller {
22+
public:
23+
/// The name of the file.
24+
std::string Filename;
25+
26+
/// The flag which indicates whether we should not delete the file.
27+
bool Keep;
28+
29+
StringRef getFilename() { return Filename; }
30+
explicit CleanupInstaller(StringRef Filename);
31+
~CleanupInstaller();
32+
};
33+
2134
/// This class contains a raw_fd_ostream and adds a few extra features commonly
2235
/// needed for compiler-like tool output files:
2336
/// - The file is automatically deleted if the process is killed.
@@ -28,18 +41,7 @@ class ToolOutputFile {
2841
/// before the raw_fd_ostream is constructed and destructed after the
2942
/// raw_fd_ostream is destructed. It installs cleanups in its constructor and
3043
/// uninstalls them in its destructor.
31-
class CleanupInstaller {
32-
public:
33-
/// The name of the file.
34-
std::string Filename;
35-
36-
/// The flag which indicates whether we should not delete the file.
37-
bool Keep;
38-
39-
StringRef getFilename() { return Filename; }
40-
explicit CleanupInstaller(StringRef Filename);
41-
~CleanupInstaller();
42-
} Installer;
44+
CleanupInstaller Installer;
4345

4446
/// Storage for the stream, if we're owning our own stream. This is
4547
/// intentionally declared after Installer.

llvm/lib/Support/ToolOutputFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ using namespace llvm;
1717

1818
static bool isStdout(StringRef Filename) { return Filename == "-"; }
1919

20-
ToolOutputFile::CleanupInstaller::CleanupInstaller(StringRef Filename)
20+
CleanupInstaller::CleanupInstaller(StringRef Filename)
2121
: Filename(std::string(Filename)), Keep(false) {
2222
// Arrange for the file to be deleted if the process is killed.
2323
if (!isStdout(Filename))
2424
sys::RemoveFileOnSignal(Filename);
2525
}
2626

27-
ToolOutputFile::CleanupInstaller::~CleanupInstaller() {
27+
CleanupInstaller::~CleanupInstaller() {
2828
if (isStdout(Filename))
2929
return;
3030

0 commit comments

Comments
 (0)