Skip to content

Commit 251dbb9

Browse files
committed
[driver] Improve handling of supplementary outputs in createCompilerInvocation
Mark the relevant options in Options.td rather than hard-coding the list in code, and handle a few more options suggested during the review.
1 parent cccb21a commit 251dbb9

File tree

4 files changed

+51
-32
lines changed

4 files changed

+51
-32
lines changed

include/swift/Option/Options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace options {
3636
SwiftIndentOption = (1 << 11),
3737
ArgumentIsPath = (1 << 12),
3838
ModuleInterfaceOption = (1 << 13),
39+
SupplementaryOutput = (1 << 14),
3940
};
4041

4142
enum ID {

include/swift/Option/Options.td

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def ArgumentIsPath : OptionFlag;
5151
// and read/parsed from there when reconstituting a .swiftmodule from it.
5252
def ModuleInterfaceOption : OptionFlag;
5353

54+
// The option causes the output of a supplementary output, or is the path option
55+
// for a supplementary output. E.g., `-emit-module` and `-emit-module-path`.
56+
def SupplementaryOutput : OptionFlag;
57+
5458
/////////
5559
// Options
5660

@@ -314,49 +318,57 @@ def profile_stats_entities: Flag<["-"], "profile-stats-entities">,
314318
HelpText<"Profile changes to stats in -stats-output-dir, subdivided by source entity">;
315319

316320
def emit_dependencies : Flag<["-"], "emit-dependencies">,
317-
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>,
321+
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
322+
SupplementaryOutput]>,
318323
HelpText<"Emit basic Make-compatible dependencies files">;
319324
def track_system_dependencies : Flag<["-"], "track-system-dependencies">,
320325
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>,
321326
HelpText<"Track system dependencies while emitting Make-style dependencies">;
322327

323328
def emit_loaded_module_trace : Flag<["-"], "emit-loaded-module-trace">,
324-
Flags<[FrontendOption, NoInteractiveOption]>,
329+
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>,
325330
HelpText<"Emit a JSON file containing information about what modules were loaded">;
326331
def emit_loaded_module_trace_path : Separate<["-"], "emit-loaded-module-trace-path">,
327-
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath]>,
332+
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
333+
SupplementaryOutput]>,
328334
HelpText<"Emit the loaded module trace JSON to <path>">,
329335
MetaVarName<"<path>">;
330336
def emit_loaded_module_trace_path_EQ : Joined<["-"], "emit-loaded-module-trace-path=">,
331-
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath]>,
337+
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
338+
SupplementaryOutput]>,
332339
Alias<emit_loaded_module_trace_path>;
333340
def emit_cross_import_remarks : Flag<["-"], "Rcross-import">,
334341
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
335342
HelpText<"Emit a remark if a cross-import of a module is triggered.">;
336343

337344
def emit_tbd : Flag<["-"], "emit-tbd">,
338345
HelpText<"Emit a TBD file">,
339-
Flags<[FrontendOption, NoInteractiveOption]>;
346+
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>;
340347
def emit_tbd_path : Separate<["-"], "emit-tbd-path">,
341-
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath]>,
348+
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
349+
SupplementaryOutput]>,
342350
HelpText<"Emit the TBD file to <path>">,
343351
MetaVarName<"<path>">;
344352
def emit_tbd_path_EQ : Joined<["-"], "emit-tbd-path=">,
345-
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath]>,
353+
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath,
354+
SupplementaryOutput]>,
346355
Alias<emit_tbd_path>;
347356
def embed_tbd_for_module : Separate<["-"], "embed-tbd-for-module">,
348357
Flags<[FrontendOption]>,
349358
HelpText<"Embed symbols from the module in the emitted tbd file">;
350359

351360
def serialize_diagnostics : Flag<["-"], "serialize-diagnostics">,
352-
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>,
361+
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
362+
SupplementaryOutput]>,
353363
HelpText<"Serialize diagnostics in a binary format">;
354364
def serialize_diagnostics_path : Separate<["-"], "serialize-diagnostics-path">,
355-
Flags<[FrontendOption, NoBatchOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
365+
Flags<[FrontendOption, NoBatchOption, DoesNotAffectIncrementalBuild,
366+
ArgumentIsPath, SupplementaryOutput]>,
356367
HelpText<"Emit a serialized diagnostics file to <path>">,
357368
MetaVarName<"<path>">;
358369
def serialize_diagnostics_path_EQ: Joined<["-"], "serialize-diagnostics-path=">,
359-
Flags<[FrontendOption, NoBatchOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
370+
Flags<[FrontendOption, NoBatchOption, DoesNotAffectIncrementalBuild,
371+
ArgumentIsPath, SupplementaryOutput]>,
360372
Alias<serialize_diagnostics_path>;
361373
def color_diagnostics : Flag<["-"], "color-diagnostics">,
362374
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
@@ -403,32 +415,34 @@ def autolink_force_load : Flag<["-"], "autolink-force-load">,
403415
HelpText<"Force ld to link against this module even if no symbols are used">;
404416

405417
def emit_module : Flag<["-"], "emit-module">,
406-
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>,
418+
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
419+
SupplementaryOutput]>,
407420
HelpText<"Emit an importable module">;
408421
def emit_module_path : Separate<["-"], "emit-module-path">,
409422
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
410-
ArgumentIsPath]>,
423+
ArgumentIsPath, SupplementaryOutput]>,
411424
HelpText<"Emit an importable module to <path>">,
412425
MetaVarName<"<path>">;
413426
def emit_module_path_EQ : Joined<["-"], "emit-module-path=">,
414427
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
415-
ArgumentIsPath]>,
428+
ArgumentIsPath, SupplementaryOutput]>,
416429
Alias<emit_module_path>;
417430

418431
def emit_module_interface :
419432
Flag<["-"], "emit-module-interface">,
420-
Flags<[NoInteractiveOption, DoesNotAffectIncrementalBuild]>,
433+
Flags<[NoInteractiveOption, DoesNotAffectIncrementalBuild,
434+
SupplementaryOutput]>,
421435
HelpText<"Output module interface file">;
422436
def emit_module_interface_path :
423437
Separate<["-"], "emit-module-interface-path">,
424438
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
425-
ArgumentIsPath]>,
439+
ArgumentIsPath, SupplementaryOutput]>,
426440
MetaVarName<"<path>">, HelpText<"Output module interface file to <path>">;
427441

428442
def emit_private_module_interface_path :
429443
Separate<["-"], "emit-private-module-interface-path">,
430444
Flags<[FrontendOption, NoInteractiveOption, HelpHidden,
431-
DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
445+
DoesNotAffectIncrementalBuild, ArgumentIsPath, SupplementaryOutput]>,
432446
MetaVarName<"<path>">, HelpText<"Output private module interface file to <path>">;
433447

434448
def avoid_emit_module_source_info :
@@ -439,25 +453,27 @@ def avoid_emit_module_source_info :
439453
def emit_module_source_info_path :
440454
Separate<["-"], "emit-module-source-info-path">,
441455
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
442-
ArgumentIsPath]>,
456+
ArgumentIsPath, SupplementaryOutput]>,
443457
MetaVarName<"<path>">, HelpText<"Output module source info file to <path>">;
444458

445459
def emit_parseable_module_interface :
446460
Flag<["-"], "emit-parseable-module-interface">,
447461
Alias<emit_module_interface>,
448-
Flags<[NoInteractiveOption, HelpHidden, DoesNotAffectIncrementalBuild]>;
462+
Flags<[NoInteractiveOption, HelpHidden, DoesNotAffectIncrementalBuild,
463+
SupplementaryOutput]>;
449464
def emit_parseable_module_interface_path :
450465
Separate<["-"], "emit-parseable-module-interface-path">,
451466
Alias<emit_module_interface_path>,
452467
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
453-
HelpHidden, ArgumentIsPath]>;
468+
HelpHidden, ArgumentIsPath, SupplementaryOutput]>;
454469

455470
def emit_objc_header : Flag<["-"], "emit-objc-header">,
456-
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>,
471+
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
472+
SupplementaryOutput]>,
457473
HelpText<"Emit an Objective-C header file">;
458474
def emit_objc_header_path : Separate<["-"], "emit-objc-header-path">,
459475
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
460-
ArgumentIsPath]>,
476+
ArgumentIsPath, SupplementaryOutput]>,
461477
MetaVarName<"<path>">, HelpText<"Emit an Objective-C header file to <path>">;
462478

463479
def static : Flag<["-"], "static">,

lib/Driver/FrontendUtil.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,11 @@ bool swift::driver::getSingleFrontendInvocationFromDriverArguments(
5959
return true;
6060

6161
if (ForceNoOutputs) {
62-
// Clear existing output modes.
62+
// Clear existing output modes and supplementary outputs.
6363
ArgList->eraseArg(options::OPT_modes_Group);
64-
// Disable other output options that conflict with -typecheck.
65-
ArgList->eraseArg(options::OPT_emit_module);
66-
ArgList->eraseArg(options::OPT_emit_module_path);
67-
ArgList->eraseArg(options::OPT_emit_module_source_info_path);
68-
ArgList->eraseArg(options::OPT_emit_module_interface);
69-
ArgList->eraseArg(options::OPT_emit_module_interface_path);
70-
ArgList->eraseArg(options::OPT_emit_objc_header);
71-
ArgList->eraseArg(options::OPT_emit_objc_header_path);
64+
ArgList->eraseArgIf([](const llvm::opt::Arg *A) {
65+
return A && A->getOption().hasFlag(options::SupplementaryOutput);
66+
});
7267

7368
unsigned index = ArgList->MakeIndex("-typecheck");
7469
// Takes ownership of the Arg.

test/Driver/createCompilerInvocation.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// CHECK-FAIL: error: unable to create a CompilerInvocation
99
// CHECK-NOWARN-NOT: warning
1010

11-
// RUN: %swift-ide-test_plain -test-createCompilerInvocation -module-name foo -emit-module -emit-module-path %t/foo.swiftmodule -emit-objc-header -emit-objc-header-path %t/foo.h -enable-library-evolution -emit-module-interface -emit-module-interface-path %t/foo.swiftinterface -emit-library %s 2>&1 | %FileCheck %s --check-prefix=NORMAL_ARGS --implicit-check-not="error: "
11+
// RUN: %swift-ide-test_plain -test-createCompilerInvocation \
12+
// RUN: -module-name foo -emit-module -emit-module-path %t/foo.swiftmodule -emit-objc-header -emit-objc-header-path %t/foo.h -enable-library-evolution -emit-module-interface -emit-module-interface-path %t/foo.swiftinterface -emit-library -emit-tbd -emit-tbd-path %t/foo.tbd -emit-dependencies -serialize-diagnostics %s \
13+
// RUN: 2>&1 | %FileCheck %s --check-prefix=NORMAL_ARGS --implicit-check-not="error: "
1214
// NORMAL_ARGS: Frontend Arguments BEGIN
1315
// NORMAL_ARGS-DAG: -o{{$}}
1416
// NORMAL_ARGS-DAG: foo-{{[a-z0-9]+}}.o
@@ -19,15 +21,20 @@
1921
// NORMAL_ARGS-DAG: -emit-module-source-info-path
2022
// NORMAL_ARGS-DAG: -emit-module-interface-path
2123
// NORMAL_ARGS-DAG: -emit-objc-header-path
24+
// NORMAL_ARGS-DAG: -emit-tbd-path
25+
// NORMAL_ARGS-DAG: -serialize-diagnostics-path
2226
// NORMAL_ARGS: Frontend Arguments END
2327

24-
// RUN: %swift-ide-test_plain -test-createCompilerInvocation -force-no-outputs -module-name foo -emit-module -emit-module-path %t/foo.swiftmodule -emit-objc-header -emit-objc-header-path %t/foo.h -enable-library-evolution -emit-module-interface -emit-module-interface-path %t/foo.swiftinterface -emit-library %s 2>&1 > %t.nooutput_args
28+
// RUN: %swift-ide-test_plain -test-createCompilerInvocation -force-no-outputs \
29+
// RUN: -module-name foo -emit-module -emit-module-path %t/foo.swiftmodule -emit-objc-header -emit-objc-header-path %t/foo.h -enable-library-evolution -emit-module-interface -emit-module-interface-path %t/foo.swiftinterface -emit-library -emit-tbd -emit-tbd-path %t/foo.tbd -emit-dependencies -serialize-diagnostics %s \
30+
// RUN: 2>&1 > %t.nooutput_args
2531
// RUN: %FileCheck %s --check-prefix=NOOUTPUT_ARGS --implicit-check-not="error: " < %t.nooutput_args
2632
// RUN: %FileCheck %s --check-prefix=NOOUTPUT_ARGS_NEG --implicit-check-not="error: " < %t.nooutput_args
2733
// NOOUTPUT_ARGS_NEG-NOT: -o{{$}}
2834
// NOOUTPUT_ARGS_NEG-NOT: foo-{{[a-z0-9]+}}.o
2935
// NOOUTPUT_ARGS_NEG-NOT: -o{{$}}
3036
// NOOUTPUT_ARGS_NEG-NOT: -emit
37+
// NOOUTPUT_ARGS_NEG-NOT: -serialize-diagnostics
3138

3239
// NOOUTPUT_ARGS: Frontend Arguments BEGIN
3340
// NOOUTPUT_ARGS-DAG: -typecheck

0 commit comments

Comments
 (0)