LCOV - code coverage report
Current view: top level - lib/Support - Process.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 13 17 76.5 %
Date: 2018-06-17 00:07:59 Functions: 2 4 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- Process.cpp - Implement OS Process Concept --------------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : //  This file implements the operating system Process concept.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/Support/Process.h"
      15             : #include "llvm/ADT/STLExtras.h"
      16             : #include "llvm/ADT/StringExtras.h"
      17             : #include "llvm/Config/llvm-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           7 : Optional<std::string> Process::FindInEnvPath(StringRef EnvName,
      31             :                                              StringRef FileName) {
      32           7 :   return FindInEnvPath(EnvName, FileName, {});
      33             : }
      34             : 
      35           9 : Optional<std::string> Process::FindInEnvPath(StringRef EnvName,
      36             :                                              StringRef FileName,
      37             :                                              ArrayRef<std::string> IgnoreList) {
      38             :   assert(!path::is_absolute(FileName));
      39             :   Optional<std::string> FoundPath;
      40           9 :   Optional<std::string> OptPath = Process::GetEnv(EnvName);
      41           9 :   if (!OptPath.hasValue())
      42             :     return FoundPath;
      43             : 
      44           4 :   const char EnvPathSeparatorStr[] = {EnvPathSeparator, '\0'};
      45             :   SmallVector<StringRef, 8> Dirs;
      46           4 :   SplitString(OptPath.getValue(), Dirs, EnvPathSeparatorStr);
      47             : 
      48           6 :   for (StringRef Dir : Dirs) {
      49           4 :     if (Dir.empty())
      50           0 :       continue;
      51             : 
      52           4 :     if (any_of(IgnoreList, [&](StringRef S) { return fs::equivalent(S, Dir); }))
      53           0 :       continue;
      54             : 
      55             :     SmallString<128> FilePath(Dir);
      56           4 :     path::append(FilePath, FileName);
      57           4 :     if (fs::exists(Twine(FilePath))) {
      58           3 :       FoundPath = FilePath.str();
      59             :       break;
      60             :     }
      61             :   }
      62             : 
      63             :   return FoundPath;
      64             : }
      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             : // This is set to true when Process::PreventCoreFiles() is called.
      86             : static bool coreFilesPrevented = false;
      87             : 
      88           0 : bool Process::AreCoreFilesPrevented() {
      89           0 :   return coreFilesPrevented;
      90             : }
      91             : 
      92             : // Include the platform-specific parts of this class.
      93             : #ifdef LLVM_ON_UNIX
      94             : #include "Unix/Process.inc"
      95             : #endif
      96             : #ifdef _WIN32
      97             : #include "Windows/Process.inc"
      98             : #endif

Generated by: LCOV version 1.13