[llvm] [llvm] Do not use Console API if the output isn't a console device (PR #90230)
Kacper Michajłow via llvm-commits
llvm-commits at lists.llvm.org
Sat May 25 05:40:46 PDT 2024
https://github.com/kasper93 updated https://github.com/llvm/llvm-project/pull/90230
>From 881a7fc9e557742ea43cbbd86c6c6eec9186cce8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <kasper93 at gmail.com>
Date: Thu, 2 Feb 2023 18:32:03 +0100
Subject: [PATCH] [llvm] Do not use Console API if the output isn't a console
device
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This fixes the `-fcolor-diagnostics` to properly enable color output
when not outputting to console devices, such as when using Ninja.
This affects only Windows.
Signed-off-by: Kacper Michajłow <kasper93 at gmail.com>
---
llvm/lib/Support/raw_ostream.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 8cb7b5ac68ea7..993d75536112a 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -645,6 +645,11 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered,
// Check if this is a console device. This is not equivalent to isatty.
IsWindowsConsole =
::GetFileType((HANDLE)::_get_osfhandle(fd)) == FILE_TYPE_CHAR;
+
+ // If this isn't a console device, don't try to use the API to set the color.
+ // Switch to ANSI escape codes instead.
+ if (!IsWindowsConsole)
+ llvm::sys::Process::UseANSIEscapeCodes(true);
#endif
// Get the starting position.
More information about the llvm-commits
mailing list