aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-cov/llvm-cov.cpp
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-02-18 09:19:48 +0000
committerJustin Bogner <mail@justinbogner.com>2014-02-18 09:19:48 +0000
commite9a3e5a93e1c52844dfb122e45c2afb16121d5b7 (patch)
tree427299b08153cb6e4cadb6e382ee81c6aecdb441 /llvm/tools/llvm-cov/llvm-cov.cpp
parent67bf8bd124f39734c94a1ed81bb3804de51ca789 (diff)
downloadllvm-e9a3e5a93e1c52844dfb122e45c2afb16121d5b7.zip
llvm-e9a3e5a93e1c52844dfb122e45c2afb16121d5b7.tar.gz
llvm-e9a3e5a93e1c52844dfb122e45c2afb16121d5b7.tar.bz2
llvm-cov: Support gcov's extermely lenient treatment of -o
In gcov, the -o flag can accept either a directory or a file name. When given a directory, the gcda and gcno files are expected to be in that directory. When given a file, the gcda and gcno files are expected to be named based on the stem of that file. Non-existent paths are treated as files. This implements compatible behaviour. llvm-svn: 201555
Diffstat (limited to 'llvm/tools/llvm-cov/llvm-cov.cpp')
-rw-r--r--llvm/tools/llvm-cov/llvm-cov.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/llvm/tools/llvm-cov/llvm-cov.cpp b/llvm/tools/llvm-cov/llvm-cov.cpp
index d7162c4..ce59694 100644
--- a/llvm/tools/llvm-cov/llvm-cov.cpp
+++ b/llvm/tools/llvm-cov/llvm-cov.cpp
@@ -14,6 +14,7 @@
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/GCOV.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryObject.h"
@@ -43,9 +44,11 @@ static cl::opt<bool> FuncSummary("f", cl::init(false),
cl::desc("Show coverage for each function"));
static cl::alias FuncSummaryA("function-summaries", cl::aliasopt(FuncSummary));
-static cl::opt<std::string> ObjectDir("o", cl::value_desc("DIR"), cl::init(""),
- cl::desc("Search for objects in DIR"));
+static cl::opt<std::string>
+ObjectDir("o", cl::value_desc("DIR|FILE"), cl::init(""),
+ cl::desc("Find objects in DIR or based on FILE's path"));
static cl::alias ObjectDirA("object-directory", cl::aliasopt(ObjectDir));
+static cl::alias ObjectDirB("object-file", cl::aliasopt(ObjectDir));
static cl::opt<bool> PreservePaths("p", cl::init(false),
cl::desc("Preserve path components"));
@@ -75,9 +78,16 @@ int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
SmallString<128> CoverageFileStem(ObjectDir);
- if (CoverageFileStem.empty())
+ if (CoverageFileStem.empty()) {
+ // If no directory was specified with -o, look next to the source file.
CoverageFileStem = sys::path::parent_path(SourceFile);
- sys::path::append(CoverageFileStem, sys::path::stem(SourceFile));
+ sys::path::append(CoverageFileStem, sys::path::stem(SourceFile));
+ } else if (sys::fs::is_directory(ObjectDir))
+ // A directory name was given. Use it and the source file name.
+ sys::path::append(CoverageFileStem, sys::path::stem(SourceFile));
+ else
+ // A file was given. Ignore the source file and look next to this file.
+ sys::path::replace_extension(CoverageFileStem, "");
if (InputGCNO.empty())
InputGCNO = (CoverageFileStem.str() + ".gcno").str();