Skip to content

Commit b991717

Browse files
Austinateaciidgh
authored andcommitted
Moved colorization arguments to SwiftTargetDescription.
1 parent 5470726 commit b991717

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

Sources/Basic/TerminalController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,18 @@ public final class TerminalController {
6161
/// Constructs the instance if the stream is a tty.
6262
public init?(stream: LocalFileOutputByteStream) {
6363
// Make sure this file stream is tty.
64-
guard isatty(fileno(stream.filePointer)) != 0 else {
64+
guard TerminalController.isTTY(stream) else {
6565
return nil
6666
}
6767
width = TerminalController.terminalWidth() ?? 80 // Assume default if we are not able to determine.
6868
self.stream = stream
6969
}
7070

71+
/// Checks if passed file stream is tty.
72+
public static func isTTY(_ stream: LocalFileOutputByteStream) -> Bool {
73+
return isatty(fileno(stream.filePointer)) != 0
74+
}
75+
7176
/// Tries to get the terminal width first using COLUMNS env variable and
7277
/// if that fails ioctl method testing on stdout stream.
7378
///

Sources/Build/BuildPlan.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)