================
@@ -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
----------------
cyndyishida wrote:

There should be a test for this scenario.

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

Reply via email to