Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/lib/Core/Reproduce.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Reproduce.cpp - Utilities for creating reproducers -----------------===//
2
//
3
//                             The LLVM Linker
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#include "lld/Core/Reproduce.h"
11
#include "llvm/Option/Arg.h"
12
#include "llvm/Support/Error.h"
13
#include "llvm/Support/FileSystem.h"
14
#include "llvm/Support/Path.h"
15
16
using namespace lld;
17
using namespace llvm;
18
using namespace llvm::sys;
19
20
// Makes a given pathname an absolute path first, and then remove
21
// beginning /. For example, "../foo.o" is converted to "home/john/foo.o",
22
// assuming that the current directory is "/home/john/bar".
23
// Returned string is a forward slash separated path even on Windows to avoid
24
// a mess with backslash-as-escape and backslash-as-path-separator.
25
49
std::string lld::relativeToRoot(StringRef Path) {
26
49
  SmallString<128> Abs = Path;
27
49
  if (fs::make_absolute(Abs))
28
0
    return Path;
29
49
  path::remove_dots(Abs, /*remove_dot_dot=*/true);
30
49
31
49
  // This is Windows specific. root_name() returns a drive letter
32
49
  // (e.g. "c:") or a UNC name (//net). We want to keep it as part
33
49
  // of the result.
34
49
  SmallString<128> Res;
35
49
  StringRef Root = path::root_name(Abs);
36
49
  if (Root.endswith(":"))
37
0
    Res = Root.drop_back();
38
49
  else 
if (49
Root.startswith("//")49
)
39
0
    Res = Root.substr(2);
40
49
41
49
  path::append(Res, path::relative_path(Abs));
42
49
  return path::convert_to_slash(Res);
43
49
}
44
45
// Quote a given string if it contains a space character.
46
53
std::string lld::quote(StringRef S) {
47
53
  if (S.contains(' '))
48
5
    return ("\"" + S + "\"").str();
49
48
  return S;
50
48
}
51
52
18
std::string lld::rewritePath(StringRef S) {
53
18
  if (fs::exists(S))
54
17
    return relativeToRoot(S);
55
1
  return S;
56
1
}
57
58
37
std::string lld::toString(opt::Arg *Arg) {
59
37
  std::string K = Arg->getSpelling();
60
37
  if (Arg->getNumValues() == 0)
61
17
    return K;
62
20
  std::string V = quote(Arg->getValue());
63
20
  if (Arg->getOption().getRenderStyle() == opt::Option::RenderJoinedStyle)
64
9
    return K + V;
65
11
  return K + " " + V;
66
11
}