Skip to content

[Support] Make CleanupInstaller public (NFC) #86758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions llvm/include/llvm/Support/ToolOutputFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Support/ToolOutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down