Skip to content

Implement SeparateErrors on Windows #22961

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 1 commit into from
Feb 28, 2019
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
40 changes: 23 additions & 17 deletions lib/Basic/Default/TaskQueue.inc
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ public:
/// the current process's environment will be used instead.
ArrayRef<const char *> Env;

/// True if the errors of the Task should be stored in Errors instead of Output.
bool SeparateErrors;

/// Context associated with this Task.
void *Context;

Task(const char *ExecPath, ArrayRef<const char *> Args,
ArrayRef<const char *> Env = llvm::None, void *Context = nullptr)
: ExecPath(ExecPath), Args(Args), Env(Env), Context(Context) {}
ArrayRef<const char *> Env = llvm::None, void *Context = nullptr, bool SeparateErrors = false)
: ExecPath(ExecPath), Args(Args), Env(Env), Context(Context), SeparateErrors(SeparateErrors) {}
};

} // end namespace sys
Expand All @@ -75,10 +78,7 @@ unsigned TaskQueue::getNumberOfParallelTasks() const {
void TaskQueue::addTask(const char *ExecPath, ArrayRef<const char *> Args,
ArrayRef<const char *> Env, void *Context,
bool SeparateErrors) {
// This implementation of TaskQueue ignores SeparateErrors.
// We need to reference SeparateErrors to avoid warnings, though.
(void)SeparateErrors;
std::unique_ptr<Task> T(new Task(ExecPath, Args, Env, Context));
std::unique_ptr<Task> T(new Task(ExecPath, Args, Env, Context, SeparateErrors));
QueuedTasks.push(std::move(T));
}

Expand All @@ -104,16 +104,18 @@ bool TaskQueue::execute(TaskBeganCallback Began, TaskFinishedCallback Finished,
: decltype(Envp)(llvm::toStringRefArray(T->Env.data()));

llvm::SmallString<64> stdoutPath;
llvm::SmallString<64> stderrPath;
if (fs::createTemporaryFile("stdout", "tmp", stdoutPath)
|| fs::createTemporaryFile("stderr", "tmp", stderrPath)) {
if (fs::createTemporaryFile("stdout", "tmp", stdoutPath))
return true;
}

llvm::sys::RemoveFileOnSignal(stdoutPath);
llvm::sys::RemoveFileOnSignal(stderrPath);

Optional<StringRef> redirects[] = {None, {stdoutPath}, {stderrPath}};
llvm::SmallString<64> stderrPath;
if (T->SeparateErrors) {
if (fs::createTemporaryFile("stderr", "tmp", stdoutPath))
return true;
llvm::sys::RemoveFileOnSignal(stderrPath);
}

Optional<StringRef> redirects[] = {None, {stdoutPath}, {T->SeparateErrors ? stderrPath : stdoutPath}};

bool ExecutionFailed = false;
ProcessInfo PI = ExecuteNoWait(T->ExecPath,
Expand All @@ -133,10 +135,13 @@ bool TaskQueue::execute(TaskBeganCallback Began, TaskFinishedCallback Finished,
int ReturnCode = PI.ReturnCode;

auto stdoutBuffer = llvm::MemoryBuffer::getFile(stdoutPath);
auto stderrBuffer = llvm::MemoryBuffer::getFile(stderrPath);

StringRef stdoutContents = stdoutBuffer.get()->getBuffer();
StringRef stderrContents = stderrBuffer.get()->getBuffer();

StringRef stderrContents;
if (T->SeparateErrors) {
auto stderrBuffer = llvm::MemoryBuffer::getFile(stderrPath);
stderrContents = stderrBuffer.get()->getBuffer();
}

if (ReturnCode == -2) {
// Wait() returning a return code of -2 indicates the process received
Expand All @@ -161,7 +166,8 @@ bool TaskQueue::execute(TaskBeganCallback Began, TaskFinishedCallback Finished,
}
}
llvm::sys::fs::remove(stdoutPath);
llvm::sys::fs::remove(stderrPath);
if (T->SeparateErrors)
llvm::sys::fs::remove(stderrPath);
}

return !ContinueExecution;
Expand Down
2 changes: 2 additions & 0 deletions test/Driver/assert.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Windows programs cannot fail due to a signal
// UNSUPPORTED: windows
// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-assert-immediately 2>&1 | %FileCheck %s
// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-assert-after-parse 2>&1 | %FileCheck %s

Expand Down
3 changes: 2 additions & 1 deletion test/Driver/crash.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// UNSUPPORTED: win32
// Windows programs cannot fail due to a signal
// UNSUPPORTED: windows
// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-crash-immediately 2>&1 | %FileCheck %s

// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-crash-after-parse 2>&1 | %FileCheck %s
Expand Down
4 changes: 2 additions & 2 deletions test/Frontend/crash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

// Check that we see the contents of the input file list in the crash log.
// CHECK-LABEL: Stack dump
// CHECK-NEXT: Program arguments: {{.*swift(c?)}} -frontend
// CHECK-NEXT: Program arguments: {{.*swift(c?)(.EXE)?}} -frontend
// CHECK-NEXT: Contents of {{.*}}.filelist.txt:
// CHECK-NEXT: ---
// CHECK-NEXT: test/Frontend/crash.swift{{$}}
// CHECK-NEXT: test{{[\\/]}}Frontend{{[\\/]}}crash.swift{{$}}
// CHECK-NEXT: ---

func anchor() {}
Expand Down