Skip to content

Commit ba2157b

Browse files
dingobyejrose-apple
authored andcommitted
[Driver] Accept -serialize-diagnostics-path for the interpret mode. (swiftlang#22113)
This patch allows `-serialize-diagnostics-path` for the interpret mode. There is one file compiled in such mode, so it makes sense to support this flag to specify an explicit output path for diagnostics emission. Resolves: SR-9670
1 parent 5bf6d3e commit ba2157b

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ def emit_reference_dependencies_path
5555
: Separate<["-"], "emit-reference-dependencies-path">, MetaVarName<"<path>">,
5656
HelpText<"Output Swift-style dependencies file to <path>">;
5757

58-
def serialize_diagnostics_path
59-
: Separate<["-"], "serialize-diagnostics-path">, MetaVarName<"<path>">,
60-
HelpText<"Output serialized diagnostics to <path>">;
61-
6258
def emit_fixits_path
6359
: Separate<["-"], "emit-fixits-path">, MetaVarName<"<path>">,
6460
HelpText<"Output compiler fixits as source edits to <path>">;

include/swift/Option/Options.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ def emit_tbd_path_EQ : Joined<["-"], "emit-tbd-path=">,
278278
def serialize_diagnostics : Flag<["-"], "serialize-diagnostics">,
279279
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>,
280280
HelpText<"Serialize diagnostics in a binary format">;
281+
def serialize_diagnostics_path : Separate<["-"], "serialize-diagnostics-path">,
282+
Flags<[FrontendOption, NoBatchOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
283+
HelpText<"Emit a serialized diagnostics file to <path>">,
284+
MetaVarName<"<path>">;
285+
def serialize_diagnostics_path_EQ: Joined<["-"], "serialize-diagnostics-path=">,
286+
Flags<[FrontendOption, NoBatchOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
287+
Alias<serialize_diagnostics_path>;
281288

282289
def module_cache_path : Separate<["-"], "module-cache-path">,
283290
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
222222
inputArgs.AddLastArg(arguments,
223223
options::OPT_enable_experimental_dependencies);
224224
inputArgs.AddLastArg(arguments, options::OPT_package_description_version);
225+
inputArgs.AddLastArg(arguments, options::OPT_serialize_diagnostics_path);
225226

226227
// Pass on any build config options
227228
inputArgs.AddAllArgs(arguments, options::OPT_D);

test/Misc/serialized-diagnostics-batch-mode.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// RUN: rm -f %t.*
22

3+
// The `-serialize-diagnostics-path` flag is not allowed for batch mode invoked by swiftc
4+
// RUN: not %target-swiftc_driver -serialize-diagnostics-path %t.notexpected.dia %s %S/Inputs/serialized-diagnostics-batch-mode-helper.swift -c -o %t.o 2>&1 | %FileCheck %s
5+
// CHECK: <unknown>:0: error: option '-serialize-diagnostics-path' is not supported by 'swiftc'; did you mean to use 'swift'?
6+
// RUN: not ls %t.notexpected.dia > /dev/null
7+
// RUN: not ls %t.o > /dev/null
8+
9+
310
// RUN: not %target-swift-frontend -typecheck -primary-file %s -serialize-diagnostics-path %t.main.dia -primary-file %S/Inputs/serialized-diagnostics-batch-mode-helper.swift -serialize-diagnostics-path %t.helper.dia %S/Inputs/serialized-diagnostics-batch-mode-other.swift 2> %t.stderr.txt
411
// RUN: %FileCheck -check-prefix=CHECK-STDERR %s < %t.stderr.txt
512
// RUN: %FileCheck -check-prefix=NEGATIVE-STDERR %s < %t.stderr.txt
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: rm -f %t.*
2+
3+
// REQUIRES: swift_interpreter
4+
5+
// RUN: %target-swift-frontend -typecheck -serialize-diagnostics-path %t.dia %s -verify
6+
// RUN: %target-swift-frontend -typecheck -serialize-diagnostics-path=%t_EQ.dia %s -verify
7+
// RUN: not %swift_driver -serialize-diagnostics-path %t_intepret_mode.dia %s
8+
// RUN: not %swift_driver -serialize-diagnostics-path=%t_EQ_intepret_mode.dia %s
9+
10+
// RUN: diff %t.dia %t_EQ.dia
11+
// RUN: diff %t.dia %t_intepret_mode.dia
12+
// RUN: diff %t.dia %t_EQ_intepret_mode.dia
13+
14+
var x = 1 x = 2 // expected-error {{consecutive statements on a line must be separated by ';'}} {{10-10=;}}

0 commit comments

Comments
 (0)