Coverage Report

Created: 2019-05-19 14:56

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