Reapply "[llvm-cov] Add an -output-dir option for the show sub-command""

Passing -output-dir path/to/dir to llvm-cov show creates path/to/dir if
it doesn't already exist, and prints reports into that directory.

In function view mode, all views are written into
path/to/dir/functions.$EXTENSION. In file view mode, all views are
written into path/to/dir/coverage/$PATH.$EXTENSION.

Changes since the initial commit:

- Avoid accidentally closing stdout twice.

llvm-svn: 273985
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
index 0757a4e..6516951 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
@@ -37,6 +37,15 @@
 
 } // anonymous namespace
 
+Expected<SourceCoverageView::OwnedStream>
+SourceCoverageViewText::createOutputFile(StringRef Path, bool InToplevel) {
+  return createOutputStream(getOptions(), Path, "txt", InToplevel);
+}
+
+void SourceCoverageViewText::closeOutputFile(OwnedStream OS) {
+  OS->operator<<('\n');
+}
+
 void SourceCoverageViewText::renderSourceName(raw_ostream &OS) {
   getOptions().colored_ostream(OS, raw_ostream::CYAN) << getSourceName()
                                                       << ":\n";