[llvm] r194034 - llvm-cov: Added command-line option to change dir.

Yuchen Wu yuchenericwu at hotmail.com
Mon Nov 4 17:20:42 PST 2013


Author: ywu
Date: Mon Nov  4 19:20:41 2013
New Revision: 194034

URL: http://llvm.org/viewvc/llvm-project?rev=194034&view=rev
Log:
llvm-cov: Added command-line option to change dir.

This will allow for much easier testing when the input files are in a
different folder from the test script.

Modified:
    llvm/trunk/lib/IR/GCOV.cpp
    llvm/trunk/tools/llvm-cov/llvm-cov.cpp

Modified: llvm/trunk/lib/IR/GCOV.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/GCOV.cpp?rev=194034&r1=194033&r2=194034&view=diff
==============================================================================
--- llvm/trunk/lib/IR/GCOV.cpp (original)
+++ llvm/trunk/lib/IR/GCOV.cpp Mon Nov  4 19:20:41 2013
@@ -266,18 +266,20 @@ void FileInfo::print(raw_fd_ostream &OS,
   for (StringMap<LineCounts>::iterator I = LineInfo.begin(), E = LineInfo.end();
        I != E; ++I) {
     StringRef Filename = I->first();
-    OS << "        -:    0:Source:" << Filename << "\n";
-    OS << "        -:    0:Graph:" << gcnoFile << "\n";
-    OS << "        -:    0:Data:" << gcdaFile << "\n";
-    OS << "        -:    0:Runs:" << RunCount << "\n";
-    OS << "        -:    0:Programs:" << ProgramCount << "\n";
-    LineCounts &L = LineInfo[Filename];
     OwningPtr<MemoryBuffer> Buff;
     if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
       errs() << Filename << ": " << ec.message() << "\n";
       return;
     }
     StringRef AllLines = Buff.take()->getBuffer();
+
+    OS << "        -:    0:Source:" << Filename << "\n";
+    OS << "        -:    0:Graph:" << gcnoFile << "\n";
+    OS << "        -:    0:Data:" << gcdaFile << "\n";
+    OS << "        -:    0:Runs:" << RunCount << "\n";
+    OS << "        -:    0:Programs:" << ProgramCount << "\n";
+
+    LineCounts &L = LineInfo[Filename];
     uint32_t i = 0;
     while (!AllLines.empty()) {
       if (L.find(i) != L.end()) {

Modified: llvm/trunk/tools/llvm-cov/llvm-cov.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/llvm-cov.cpp?rev=194034&r1=194033&r2=194034&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/llvm-cov.cpp (original)
+++ llvm/trunk/tools/llvm-cov/llvm-cov.cpp Mon Nov  4 19:20:41 2013
@@ -20,6 +20,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/system_error.h"
+#include <unistd.h>
 using namespace llvm;
 
 static cl::opt<bool>
@@ -34,6 +35,9 @@ InputGCDA("gcda", cl::desc("<input gcda
 static cl::opt<std::string>
 OutputFile("o", cl::desc("<output llvm-cov file>"), cl::init("-"));
 
+static cl::opt<std::string>
+WorkingDir("C", cl::desc("change path of working directory"),
+           cl::init(""));
 
 //===----------------------------------------------------------------------===//
 int main(int argc, char **argv) {
@@ -44,6 +48,13 @@ int main(int argc, char **argv) {
 
   cl::ParseCommandLineOptions(argc, argv, "llvm coverage tool\n");
 
+  if (!WorkingDir.empty()) {
+    if (chdir(WorkingDir.c_str()) == -1) {
+      errs() << "Cannot change to directory: " << WorkingDir << ".\n";
+      return 1;
+    }
+  }
+
   std::string ErrorInfo;
   raw_fd_ostream OS(OutputFile.c_str(), ErrorInfo);
   if (!ErrorInfo.empty())
@@ -77,7 +88,6 @@ int main(int argc, char **argv) {
     }
   }
 
-
   if (DumpGCOV)
     GF.dump();
 





More information about the llvm-commits mailing list