1 //===-- Process.cpp - Implement OS Process Concept --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the operating system Process concept.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ADT/StringExtras.h"
15 #include "llvm/Config/config.h"
16 #include "llvm/Support/FileSystem.h"
17 #include "llvm/Support/Path.h"
18 #include "llvm/Support/Process.h"
19 #include "llvm/Support/Program.h"
24 //===----------------------------------------------------------------------===//
25 //=== WARNING: Implementation here must contain only TRULY operating system
26 //=== independent code.
27 //===----------------------------------------------------------------------===//
29 Optional<std::string> Process::FindInEnvPath(const std::string& EnvName,
30 const std::string& FileName)
32 Optional<std::string> FoundPath;
33 Optional<std::string> OptPath = Process::GetEnv(EnvName);
34 if (!OptPath.hasValue())
37 const char EnvPathSeparatorStr[] = {EnvPathSeparator, '\0'};
38 SmallVector<StringRef, 8> Dirs;
39 SplitString(OptPath.getValue(), Dirs, EnvPathSeparatorStr);
41 for (const auto &Dir : Dirs) {
45 SmallString<128> FilePath(Dir);
46 path::append(FilePath, FileName);
47 if (fs::exists(Twine(FilePath))) {
48 FoundPath = FilePath.str();
57 #define COLOR(FGBG, CODE, BOLD) "\033[0;" BOLD FGBG CODE "m"
59 #define ALLCOLORS(FGBG,BOLD) {\
60 COLOR(FGBG, "0", BOLD),\
61 COLOR(FGBG, "1", BOLD),\
62 COLOR(FGBG, "2", BOLD),\
63 COLOR(FGBG, "3", BOLD),\
64 COLOR(FGBG, "4", BOLD),\
65 COLOR(FGBG, "5", BOLD),\
66 COLOR(FGBG, "6", BOLD),\
67 COLOR(FGBG, "7", BOLD)\
70 static const char colorcodes[2][2][8][10] = {
71 { ALLCOLORS("3",""), ALLCOLORS("3","1;") },
72 { ALLCOLORS("4",""), ALLCOLORS("4","1;") }
75 // Include the platform-specific parts of this class.
77 #include "Unix/Process.inc"
80 #include "Windows/Process.inc"