================
@@ -83,34 +106,50 @@ LogLine::~LogLine() {
DroppedLines->fetch_add(1, std::memory_order_relaxed);
}
-AtomicLineLogger::AtomicLineLogger(StringRef LogFilePath)
- : LogPath(LogFilePath.str()) {
-#ifndef _WIN32
+void AtomicLineLogger::setFD(StringRef Path) {
+ LogPath = Path.str();
+ FD.store(openLogFile(Path), std::memory_order_release);
+ log() << "logging_start";
+}
+
+AtomicLineLogger::AtomicLineLogger(StringRef LogFilePath) {
if (LogFilePath.empty())
return;
+ setFD(LogFilePath);
+}
- std::error_code EC = llvm::sys::fs::openFileForWrite(
- LogFilePath, FD, llvm::sys::fs::CD_OpenAlways, llvm::sys::fs::OF_Append);
- if (EC) {
- llvm::errs() << "warning: unable to open log file '" << LogFilePath
- << "': " << EC.message() << "\n";
- FD = -1;
+void AtomicLineLogger::enable(StringRef LogFilePath) {
+ if (LogFilePath.empty())
+ return;
+ std::lock_guard<std::mutex> Lock(EnableMtx);
+ if (FD.load(std::memory_order_relaxed) != -1) {
+ if (LogFilePath != LogPath && !WarnedConflict) {
+ llvm::errs() << "warning: dependency scanning log path '" << LogFilePath
+ << "' ignored; already logging to '" << LogPath << "'\n";
+ WarnedConflict = true;
+ }
return;
}
-#endif
- // Write to files opened with OF_Append may not be guaranteed to be atomic
- // on Windows, so we do not enable logging on Windows.
+
+ int NewFD = openLogFile(LogFilePath);
+ if (NewFD == -1)
+ return;
+ setFD(LogFilePath);
----------------
cyndyishida wrote:
`setFD` calls `openLogFile` but it's also already called on line 134. If NewFD
is valid, shouldn't it just be reused?
https://github.com/llvm/llvm-project/pull/211966
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits