Coverage Report

Created: 2019-07-24 05:18

/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
55
std::string lld::relativeToRoot(StringRef path) {
25
55
  SmallString<128> abs = path;
26
55
  if (fs::make_absolute(abs))
27
0
    return path;
28
55
  path::remove_dots(abs, /*remove_dot_dot=*/true);
29
55
30
55
  // This is Windows specific. root_name() returns a drive letter
31
55
  // (e.g. "c:") or a UNC name (//net). We want to keep it as part
32
55
  // of the result.
33
55
  SmallString<128> res;
34
55
  StringRef root = path::root_name(abs);
35
55
  if (root.endswith(":"))
36
0
    res = root.drop_back();
37
55
  else if (root.startswith("//"))
38
0
    res = root.substr(2);
39
55
40
55
  path::append(res, path::relative_path(abs));
41
55
  return path::convert_to_slash(res);
42
55
}
43
44
// Quote a given string if it contains a space character.
45
54
std::string lld::quote(StringRef s) {
46
54
  if (s.contains(' '))
47
7
    return ("\"" + s + "\"").str();
48
47
  return s;
49
47
}
50
51
// Converts an Arg to a string representation suitable for a response file.
52
// To show an Arg in a diagnostic, use Arg::getAsString() instead.
53
22
std::string lld::toString(const opt::Arg &arg) {
54
22
  std::string k = arg.getSpelling();
55
22
  if (arg.getNumValues() == 0)
56
7
    return k;
57
15
  std::string v = quote(arg.getValue());
58
15
  if (arg.getOption().getRenderStyle() == opt::Option::RenderJoinedStyle)
59
9
    return k + v;
60
6
  return k + " " + v;
61
6
}