Skip to content

Commit 90d2740

Browse files
author
David Ungar
authored
Merge pull request #14961 from davidungar/PR-18-10-HHH
[Batch mode] Restore -### functionality for batch-mode by extending OutputLevel.
2 parents a42c5ce + 1dd49c8 commit 90d2740

File tree

6 files changed

+67
-30
lines changed

6 files changed

+67
-30
lines changed

include/swift/Driver/Compilation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ namespace driver {
5151
enum class OutputLevel {
5252
/// Indicates that normal output should be produced.
5353
Normal,
54+
55+
/// Indicates that only jobs should be printed and not run. (-###)
56+
PrintJobs,
5457

5558
/// Indicates that verbose output should be produced. (-v)
5659
Verbose,

include/swift/Driver/Driver.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,6 @@ class Driver {
357357
/// Print the list of Actions in a Compilation.
358358
void printActions(const Compilation &C) const;
359359

360-
/// Print the list of Jobs in a Compilation.
361-
void printJobs(const Compilation &C) const;
362-
363360
/// Print the driver version.
364361
void printVersion(const ToolChain &TC, raw_ostream &OS) const;
365362

lib/Driver/Compilation.cpp

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,21 @@ namespace driver {
311311
DriverTimers[BeganCmd]->startTimer();
312312
}
313313

314-
// For verbose output, print out each command as it begins execution.
315-
if (Comp.Level == OutputLevel::Verbose)
314+
switch (Comp.Level) {
315+
case OutputLevel::Normal:
316+
break;
317+
// For command line or verbose output, print out each command as it
318+
// begins execution.
319+
case OutputLevel::PrintJobs:
320+
BeganCmd->printCommandLineAndEnvironment(llvm::outs());
321+
break;
322+
case OutputLevel::Verbose:
316323
BeganCmd->printCommandLine(llvm::errs());
317-
else if (Comp.Level == OutputLevel::Parseable)
324+
break;
325+
case OutputLevel::Parseable:
318326
parseable_output::emitBeganMessage(llvm::errs(), *BeganCmd, Pid);
327+
break;
328+
}
319329
}
320330

321331
/// Note that a .swiftdeps file failed to load and take corrective actions:
@@ -450,15 +460,22 @@ namespace driver {
450460
DriverTimers[FinishedCmd]->stopTimer();
451461
}
452462

453-
if (Comp.Level == OutputLevel::Parseable) {
454-
// Parseable output was requested.
455-
parseable_output::emitFinishedMessage(llvm::errs(), *FinishedCmd, Pid,
456-
ReturnCode, Output);
457-
} else {
458-
// Otherwise, send the buffered output to stderr, though only if we
463+
switch (Comp.Level) {
464+
case OutputLevel::PrintJobs:
465+
// Only print the jobs, not the outputs
466+
break;
467+
case OutputLevel::Normal:
468+
case OutputLevel::Verbose:
469+
// Send the buffered output to stderr, though only if we
459470
// support getting buffered output.
460471
if (TaskQueue::supportsBufferingOutput())
461472
llvm::errs() << Output;
473+
break;
474+
case OutputLevel::Parseable:
475+
// Parseable output was requested.
476+
parseable_output::emitFinishedMessage(llvm::errs(), *FinishedCmd, Pid,
477+
ReturnCode, Output);
478+
break;
462479
}
463480
}
464481

@@ -1156,8 +1173,17 @@ int Compilation::performSingleCommand(const Job *Cmd) {
11561173
if (!writeFilelistIfNecessary(Cmd, Diags))
11571174
return 1;
11581175

1159-
if (Level == OutputLevel::Verbose)
1176+
switch (Level) {
1177+
case OutputLevel::Normal:
1178+
case OutputLevel::Parseable:
1179+
break;
1180+
case OutputLevel::PrintJobs:
1181+
Cmd->printCommandLineAndEnvironment(llvm::outs());
1182+
return 0;
1183+
case OutputLevel::Verbose:
11601184
Cmd->printCommandLine(llvm::errs());
1185+
break;
1186+
}
11611187

11621188
SmallVector<const char *, 128> Argv;
11631189
Argv.push_back(Cmd->getExecutable());

lib/Driver/Driver.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,9 @@ Driver::buildCompilation(const ToolChain &TC,
518518
bool DriverPrintDerivedOutputFileMap =
519519
ArgList->hasArg(options::OPT_driver_print_derived_output_file_map);
520520
DriverPrintBindings = ArgList->hasArg(options::OPT_driver_print_bindings);
521-
bool DriverPrintJobs = ArgList->hasArg(options::OPT_driver_print_jobs);
522521
bool DriverSkipExecution =
523-
ArgList->hasArg(options::OPT_driver_skip_execution);
522+
ArgList->hasArg(options::OPT_driver_skip_execution,
523+
options::OPT_driver_print_jobs);
524524
bool ShowIncrementalBuildDecisions =
525525
ArgList->hasArg(options::OPT_driver_show_incremental);
526526
bool ShowJobLifecycle =
@@ -682,9 +682,12 @@ Driver::buildCompilation(const ToolChain &TC,
682682
}
683683

684684
OutputLevel Level = OutputLevel::Normal;
685-
if (const Arg *A = ArgList->getLastArg(options::OPT_v,
686-
options::OPT_parseable_output)) {
687-
if (A->getOption().matches(options::OPT_v))
685+
if (const Arg *A =
686+
ArgList->getLastArg(options::OPT_driver_print_jobs, options::OPT_v,
687+
options::OPT_parseable_output)) {
688+
if (A->getOption().matches(options::OPT_driver_print_jobs))
689+
Level = OutputLevel::PrintJobs;
690+
else if (A->getOption().matches(options::OPT_v))
688691
Level = OutputLevel::Verbose;
689692
else if (A->getOption().matches(options::OPT_parseable_output))
690693
Level = OutputLevel::Parseable;
@@ -757,11 +760,6 @@ Driver::buildCompilation(const ToolChain &TC,
757760
if (DriverPrintBindings)
758761
return nullptr;
759762

760-
if (DriverPrintJobs) {
761-
printJobs(*C);
762-
return nullptr;
763-
}
764-
765763
return C;
766764
}
767765

@@ -2625,11 +2623,6 @@ void Driver::printActions(const Compilation &C) const {
26252623
}
26262624
}
26272625

2628-
void Driver::printJobs(const Compilation &C) const {
2629-
for (const Job *J : C.getJobs())
2630-
J->printCommandLineAndEnvironment(llvm::outs());
2631-
}
2632-
26332626
void Driver::printVersion(const ToolChain &TC, raw_ostream &OS) const {
26342627
OS << version::getSwiftFullVersion(
26352628
version::Version::getCurrentLanguageVersion()) << '\n';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Ensure that the -### and -driver-print-jobs options work properly in batch
2+
// mode. They should each do the same thing, so test them both.
3+
//
4+
// Test be sure that the output does reflect the batching, in other words
5+
// multiple primary files. Also test to be sure that the output is on
6+
// stdout, and NOT stderr.
7+
8+
9+
// RUN: %empty-directory(%t)
10+
// RUN: touch %t/file-01.swift %t/file-02.swift %t/file-03.swift
11+
// RUN: echo 'public func main() {}' >%t/main.swift
12+
//
13+
// RUN: %swiftc_driver -enable-batch-mode -c -emit-module -module-name main -j 2 %t/file-01.swift %t/file-02.swift %t/file-03.swift %t/main.swift -driver-print-jobs 2>%t/shouldBeEmpty1 | %FileCheck %s -check-prefix=CHECK-COMBINED
14+
// RUN: %swiftc_driver -enable-batch-mode -c -emit-module -module-name main -j 2 %t/file-01.swift %t/file-02.swift %t/file-03.swift %t/main.swift -### 2>%t/shouldBeEmpty2 | %FileCheck %s -check-prefix=CHECK-COMBINED
15+
// RUN: test -z "`cat %t/shouldBeEmpty1`"
16+
// RUN: test -z "`cat %t/shouldBeEmpty2`"
17+
//
18+
// CHECK-COMBINED: -primary-file {{.*}}/file-01.swift -primary-file {{.*}}/file-02.swift {{.*}}/file-03.swift {{.*}}/main.swift

test/Driver/embed-bitcode.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@
9797
// CHECK-LIB: -emit-bc
9898
// CHECK-LIB: -primary-file
9999
// CHECK-LIB: swift -frontend
100-
// CHECK-LIB: -emit-module
101-
// CHECK-LIB: swift -frontend
102100
// CHECK-LIB: -c
103101
// CHECK-LIB: -embed-bitcode
104102
// CHECK-LIB: -disable-llvm-optzns
105103
// CHECK-LIB: swift -frontend
106104
// CHECK-LIB: -c
107105
// CHECK-LIB: -embed-bitcode
108106
// CHECK-LIB: -disable-llvm-optzns
107+
// CHECK-LIB: swift -frontend
108+
// CHECK-LIB: -emit-module
109109
// CHECK-LIB-NOT: swift -frontend
110110

111111
// RUN: %target-swiftc_driver -embed-bitcode -emit-module %s 2>&1 -### | %FileCheck %s -check-prefix=WARN-EMBED-BITCODE

0 commit comments

Comments
 (0)