Skip to content

[Batch mode] Restore -### functionality for batch-mode by extending OutputLevel. #14961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/Driver/Compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ namespace driver {
enum class OutputLevel {
/// Indicates that normal output should be produced.
Normal,

/// Indicates that only jobs should be printed and not run. (-###)
PrintJobs,

/// Indicates that verbose output should be produced. (-v)
Verbose,
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,6 @@ class Driver {
/// Print the list of Actions in a Compilation.
void printActions(const Compilation &C) const;

/// Print the list of Jobs in a Compilation.
void printJobs(const Compilation &C) const;

/// Print the driver version.
void printVersion(const ToolChain &TC, raw_ostream &OS) const;

Expand Down
46 changes: 36 additions & 10 deletions lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,21 @@ namespace driver {
DriverTimers[BeganCmd]->startTimer();
}

// For verbose output, print out each command as it begins execution.
if (Comp.Level == OutputLevel::Verbose)
switch (Comp.Level) {
case OutputLevel::Normal:
break;
// For command line or verbose output, print out each command as it
// begins execution.
case OutputLevel::PrintJobs:
BeganCmd->printCommandLineAndEnvironment(llvm::outs());
break;
case OutputLevel::Verbose:
BeganCmd->printCommandLine(llvm::errs());
else if (Comp.Level == OutputLevel::Parseable)
break;
case OutputLevel::Parseable:
parseable_output::emitBeganMessage(llvm::errs(), *BeganCmd, Pid);
break;
}
}

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

if (Comp.Level == OutputLevel::Parseable) {
// Parseable output was requested.
parseable_output::emitFinishedMessage(llvm::errs(), *FinishedCmd, Pid,
ReturnCode, Output);
} else {
// Otherwise, send the buffered output to stderr, though only if we
switch (Comp.Level) {
case OutputLevel::PrintJobs:
// Only print the jobs, not the outputs
break;
case OutputLevel::Normal:
case OutputLevel::Verbose:
// Send the buffered output to stderr, though only if we
// support getting buffered output.
if (TaskQueue::supportsBufferingOutput())
llvm::errs() << Output;
break;
case OutputLevel::Parseable:
// Parseable output was requested.
parseable_output::emitFinishedMessage(llvm::errs(), *FinishedCmd, Pid,
ReturnCode, Output);
break;
}
}

Expand Down Expand Up @@ -1109,8 +1126,17 @@ int Compilation::performSingleCommand(const Job *Cmd) {
if (!writeFilelistIfNecessary(Cmd, Diags))
return 1;

if (Level == OutputLevel::Verbose)
switch (Level) {
case OutputLevel::Normal:
case OutputLevel::Parseable:
break;
case OutputLevel::PrintJobs:
Cmd->printCommandLineAndEnvironment(llvm::outs());
return 0;
case OutputLevel::Verbose:
Cmd->printCommandLine(llvm::errs());
break;
}

SmallVector<const char *, 128> Argv;
Argv.push_back(Cmd->getExecutable());
Expand Down
23 changes: 8 additions & 15 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,9 @@ Driver::buildCompilation(const ToolChain &TC,
bool DriverPrintDerivedOutputFileMap =
ArgList->hasArg(options::OPT_driver_print_derived_output_file_map);
DriverPrintBindings = ArgList->hasArg(options::OPT_driver_print_bindings);
bool DriverPrintJobs = ArgList->hasArg(options::OPT_driver_print_jobs);
bool DriverSkipExecution =
ArgList->hasArg(options::OPT_driver_skip_execution);
ArgList->hasArg(options::OPT_driver_skip_execution,
options::OPT_driver_print_jobs);
bool ShowIncrementalBuildDecisions =
ArgList->hasArg(options::OPT_driver_show_incremental);
bool ShowJobLifecycle =
Expand Down Expand Up @@ -679,9 +679,12 @@ Driver::buildCompilation(const ToolChain &TC,
}

OutputLevel Level = OutputLevel::Normal;
if (const Arg *A = ArgList->getLastArg(options::OPT_v,
options::OPT_parseable_output)) {
if (A->getOption().matches(options::OPT_v))
if (const Arg *A =
ArgList->getLastArg(options::OPT_driver_print_jobs, options::OPT_v,
options::OPT_parseable_output)) {
if (A->getOption().matches(options::OPT_driver_print_jobs))
Level = OutputLevel::PrintJobs;
else if (A->getOption().matches(options::OPT_v))
Level = OutputLevel::Verbose;
else if (A->getOption().matches(options::OPT_parseable_output))
Level = OutputLevel::Parseable;
Expand Down Expand Up @@ -754,11 +757,6 @@ Driver::buildCompilation(const ToolChain &TC,
if (DriverPrintBindings)
return nullptr;

if (DriverPrintJobs) {
printJobs(*C);
return nullptr;
}

return C;
}

Expand Down Expand Up @@ -2622,11 +2620,6 @@ void Driver::printActions(const Compilation &C) const {
}
}

void Driver::printJobs(const Compilation &C) const {
for (const Job *J : C.getJobs())
J->printCommandLineAndEnvironment(llvm::outs());
}

void Driver::printVersion(const ToolChain &TC, raw_ostream &OS) const {
OS << version::getSwiftFullVersion(
version::Version::getCurrentLanguageVersion()) << '\n';
Expand Down
18 changes: 18 additions & 0 deletions test/Driver/batch_mode_print_jobs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Ensure that the -### and -driver-print-jobs options work properly in batch
// mode. They should each do the same thing, so test them both.
//
// Test be sure that the output does reflect the batching, in other words
// multiple primary files. Also test to be sure that the output is on
// stdout, and NOT stderr.


// RUN: %empty-directory(%t)
// RUN: touch %t/file-01.swift %t/file-02.swift %t/file-03.swift
// RUN: echo 'public func main() {}' >%t/main.swift
//
// 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
// 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
// RUN: test -z "`cat %t/shouldBeEmpty1`"
// RUN: test -z "`cat %t/shouldBeEmpty2`"
//
// CHECK-COMBINED: -primary-file {{.*}}/file-01.swift -primary-file {{.*}}/file-02.swift {{.*}}/file-03.swift {{.*}}/main.swift
4 changes: 2 additions & 2 deletions test/Driver/embed-bitcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@
// CHECK-LIB: -emit-bc
// CHECK-LIB: -primary-file
// CHECK-LIB: swift -frontend
// CHECK-LIB: -emit-module
// CHECK-LIB: swift -frontend
// CHECK-LIB: -c
// CHECK-LIB: -embed-bitcode
// CHECK-LIB: -disable-llvm-optzns
// CHECK-LIB: swift -frontend
// CHECK-LIB: -c
// CHECK-LIB: -embed-bitcode
// CHECK-LIB: -disable-llvm-optzns
// CHECK-LIB: swift -frontend
// CHECK-LIB: -emit-module
// CHECK-LIB-NOT: swift -frontend

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