Skip to content

Commit 0ac6f3a

Browse files
committed
[Driver] Automatic -color-diagnostics flag is added *before* -Xfrontend
1 parent 0ed3bb1 commit 0ac6f3a

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

lib/Driver/ToolChains.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -172,6 +172,10 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
172172
arguments.push_back(inputArgs.MakeArgString(OI.SDKPath));
173173
}
174174

175+
if (llvm::sys::Process::StandardErrHasColors()) {
176+
arguments.push_back("-color-diagnostics");
177+
}
178+
175179
inputArgs.AddAllArgs(arguments, options::OPT_I);
176180
inputArgs.AddAllArgs(arguments, options::OPT_F, options::OPT_Fsystem);
177181

@@ -262,11 +266,6 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
262266
// Pass through any subsystem flags.
263267
inputArgs.AddAllArgs(arguments, options::OPT_Xllvm);
264268
inputArgs.AddAllArgs(arguments, options::OPT_Xcc);
265-
266-
if (!inputArgs.hasArg(options::OPT_color_diagnostics,
267-
options::OPT_no_color_diagnostics) &&
268-
llvm::sys::Process::StandardErrHasColors())
269-
arguments.push_back("-color-diagnostics");
270269
}
271270

272271
static void addRuntimeLibraryFlags(const OutputInfo &OI,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -26,6 +26,7 @@
2626
#include "llvm/Support/FileSystem.h"
2727
#include "llvm/Support/LineIterator.h"
2828
#include "llvm/Support/Path.h"
29+
#include "llvm/Support/Process.h"
2930

3031
using namespace swift;
3132
using namespace llvm::opt;
@@ -659,8 +660,10 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
659660
Opts.SkipDiagnosticPasses |= Args.hasArg(OPT_disable_diagnostic_passes);
660661
Opts.ShowDiagnosticsAfterFatalError |=
661662
Args.hasArg(OPT_show_diagnostics_after_fatal);
662-
Opts.UseColor |= Args.hasFlag(OPT_color_diagnostics,
663-
OPT_no_color_diagnostics);
663+
Opts.UseColor |=
664+
Args.hasFlag(OPT_color_diagnostics,
665+
OPT_no_color_diagnostics,
666+
/*Default=*/llvm::sys::Process::StandardErrHasColors());
664667
Opts.FixitCodeForAllDiagnostics |= Args.hasArg(OPT_fixit_all);
665668
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
666669
Opts.WarningsAsErrors |= Args.hasArg(OPT_warnings_as_errors);

lib/Frontend/PrintingDiagnosticConsumer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -112,9 +112,9 @@ void PrintingDiagnosticConsumer::handleDiagnostic(
112112
llvm::raw_svector_ostream Out(Text);
113113
DiagnosticEngine::formatDiagnosticText(Out, FormatString, FormatArgs);
114114
}
115-
115+
116116
auto Msg = SM.GetMessage(Loc, SMKind, Text, Ranges, FixIts);
117-
rawSM.PrintMessage(out, Msg);
117+
rawSM.PrintMessage(out, Msg, ForceColors);
118118
}
119119

120120
llvm::SMDiagnostic

0 commit comments

Comments
 (0)