Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/Process.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- Process.cpp - Implement OS Process Concept --------------*- C++ -*-===//
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
//  This file implements the operating system Process concept.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "llvm/Support/Process.h"
14
#include "llvm/ADT/STLExtras.h"
15
#include "llvm/ADT/StringExtras.h"
16
#include "llvm/Config/llvm-config.h"
17
#include "llvm/Config/config.h"
18
#include "llvm/Support/FileSystem.h"
19
#include "llvm/Support/Path.h"
20
#include "llvm/Support/Program.h"
21
22
using namespace llvm;
23
using namespace sys;
24
25
//===----------------------------------------------------------------------===//
26
//=== WARNING: Implementation here must contain only TRULY operating system
27
//===          independent code.
28
//===----------------------------------------------------------------------===//
29
30
Optional<std::string> Process::FindInEnvPath(StringRef EnvName,
31
8
                                             StringRef FileName) {
32
8
  return FindInEnvPath(EnvName, FileName, {});
33
8
}
34
35
Optional<std::string> Process::FindInEnvPath(StringRef EnvName,
36
                                             StringRef FileName,
37
10
                                             ArrayRef<std::string> IgnoreList) {
38
10
  assert(!path::is_absolute(FileName));
39
10
  Optional<std::string> FoundPath;
40
10
  Optional<std::string> OptPath = Process::GetEnv(EnvName);
41
10
  if (!OptPath.hasValue())
42
6
    return FoundPath;
43
4
44
4
  const char EnvPathSeparatorStr[] = {EnvPathSeparator, '\0'};
45
4
  SmallVector<StringRef, 8> Dirs;
46
4
  SplitString(OptPath.getValue(), Dirs, EnvPathSeparatorStr);
47
4
48
4
  for (StringRef Dir : Dirs) {
49
4
    if (Dir.empty())
50
0
      continue;
51
4
52
4
    if (any_of(IgnoreList, [&](StringRef S) 
{ return fs::equivalent(S, Dir); }0
))
53
0
      continue;
54
4
55
4
    SmallString<128> FilePath(Dir);
56
4
    path::append(FilePath, FileName);
57
4
    if (fs::exists(Twine(FilePath))) {
58
3
      FoundPath = FilePath.str();
59
3
      break;
60
3
    }
61
4
  }
62
4
63
4
  return FoundPath;
64
4
}
65
66
67
#define COLOR(FGBG, CODE, BOLD) "\033[0;" BOLD FGBG CODE "m"
68
69
#define ALLCOLORS(FGBG,BOLD) {\
70
    COLOR(FGBG, "0", BOLD),\
71
    COLOR(FGBG, "1", BOLD),\
72
    COLOR(FGBG, "2", BOLD),\
73
    COLOR(FGBG, "3", BOLD),\
74
    COLOR(FGBG, "4", BOLD),\
75
    COLOR(FGBG, "5", BOLD),\
76
    COLOR(FGBG, "6", BOLD),\
77
    COLOR(FGBG, "7", BOLD)\
78
  }
79
80
static const char colorcodes[2][2][8][10] = {
81
 { ALLCOLORS("3",""), ALLCOLORS("3","1;") },
82
 { ALLCOLORS("4",""), ALLCOLORS("4","1;") }
83
};
84
85
// A CMake option controls wheter we emit core dumps by default. An application
86
// may disable core dumps by calling Process::PreventCoreFiles().
87
static bool coreFilesPrevented = !LLVM_ENABLE_CRASH_DUMPS;
88
89
0
bool Process::AreCoreFilesPrevented() { return coreFilesPrevented; }
90
91
// Include the platform-specific parts of this class.
92
#ifdef LLVM_ON_UNIX
93
#include "Unix/Process.inc"
94
#endif
95
#ifdef _WIN32
96
#include "Windows/Process.inc"
97
#endif