@@ -57,14 +57,6 @@ public struct BuildParameters {
5757 public var swiftCompilerFlags : [ String ] {
5858 var flags = self . flags. cCompilerFlags. flatMap ( { [ " -Xcc " , $0] } )
5959 flags += self . flags. swiftCompilerFlags
60-
61- let stream = stdoutStream as? LocalFileOutputByteStream
62- let terminalController = stream. flatMap ( { TerminalController ( stream: $0) } )
63- // Add extra flags if stdout is tty
64- if terminalController != nil {
65- flags += [ " -Xfrontend " , " -color-diagnostics " ]
66- }
67-
6860 flags += verbosity. ccArgs
6961 return flags
7062 }
@@ -80,6 +72,14 @@ public struct BuildParameters {
8072 /// If should link the Swift stdlib statically.
8173 public let shouldLinkStaticSwiftStdlib : Bool
8274
75+ /// Checks if stdout stream is tty.
76+ fileprivate let isTTY : Bool = {
77+ guard let stream = stdoutStream as? LocalFileOutputByteStream else {
78+ return false
79+ }
80+ return TerminalController . isTTY ( stream)
81+ } ( )
82+
8383 public init (
8484 dataPath: AbsolutePath ,
8585 configuration: Configuration ,
@@ -297,6 +297,11 @@ public final class SwiftTargetDescription {
297297 args += additionalFlags
298298 args += moduleCacheArgs
299299
300+ // Add arguments to colorize output if stdout is tty
301+ if buildParameters. isTTY {
302+ args += [ " -Xfrontend " , " -color-diagnostics " ]
303+ }
304+
300305 // User arguments (from -Xswiftc) should follow generated arguments to allow user overrides
301306 args += buildParameters. swiftCompilerFlags
302307 return args
0 commit comments