X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FProcess.cpp;h=0d42e0e35b92e7e3691d7b6eb7092375efe03978;hb=540b4f6c08a089f487edad2befb7caf98c127ac5;hp=0380ed955dd5547d8e21cbdf306fe0f6c5ddb932;hpb=d8ceb275c2d3c0f09cb3bf814ad32c23deb93e10;p=oota-llvm.git diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 0380ed955dd..0d42e0e35b9 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -7,13 +7,16 @@ // //===----------------------------------------------------------------------===// // -// This header file implements the operating system Process concept. +// This file implements the operating system Process concept. // //===----------------------------------------------------------------------===// +#include "llvm/ADT/StringExtras.h" #include "llvm/Config/config.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Process.h" +#include "llvm/Support/Program.h" using namespace llvm; using namespace sys; @@ -66,6 +69,33 @@ TimeValue self_process::get_wall_time() const { return getElapsedWallTime(); } +Optional Process::FindInEnvPath(const std::string& EnvName, + const std::string& FileName) +{ + Optional FoundPath; + Optional OptPath = Process::GetEnv(EnvName); + if (!OptPath.hasValue()) + return FoundPath; + + const char EnvPathSeparatorStr[] = {EnvPathSeparator, '\0'}; + SmallVector Dirs; + SplitString(OptPath.getValue(), Dirs, EnvPathSeparatorStr); + + for (const auto &Dir : Dirs) { + if (Dir.empty()) + continue; + + SmallString<128> FilePath(Dir); + path::append(FilePath, FileName); + if (fs::exists(Twine(FilePath))) { + FoundPath = FilePath.str(); + break; + } + } + + return FoundPath; +} + #define COLOR(FGBG, CODE, BOLD) "\033[0;" BOLD FGBG CODE "m"