diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 |
commit | 044eb2f6afba375a914ac9d8024f8f5142bb912e (patch) | |
tree | 1475247dc9f9fe5be155ebd4c9069c75aadf8c20 /lib/Support/Process.cpp | |
parent | eb70dddbd77e120e5d490bd8fbe7ff3f8fa81c6b (diff) |
Notes
Diffstat (limited to 'lib/Support/Process.cpp')
-rw-r--r-- | lib/Support/Process.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index caec993ee165..1c8cc6e83ad1 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Process.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" @@ -26,9 +27,14 @@ using namespace sys; //=== independent code. //===----------------------------------------------------------------------===// -Optional<std::string> Process::FindInEnvPath(const std::string& EnvName, - const std::string& FileName) -{ +Optional<std::string> Process::FindInEnvPath(StringRef EnvName, + StringRef FileName) { + return FindInEnvPath(EnvName, FileName, {}); +} + +Optional<std::string> Process::FindInEnvPath(StringRef EnvName, + StringRef FileName, + ArrayRef<std::string> IgnoreList) { assert(!path::is_absolute(FileName)); Optional<std::string> FoundPath; Optional<std::string> OptPath = Process::GetEnv(EnvName); @@ -39,10 +45,13 @@ Optional<std::string> Process::FindInEnvPath(const std::string& EnvName, SmallVector<StringRef, 8> Dirs; SplitString(OptPath.getValue(), Dirs, EnvPathSeparatorStr); - for (const auto &Dir : Dirs) { + for (StringRef Dir : Dirs) { if (Dir.empty()) continue; + if (any_of(IgnoreList, [&](StringRef S) { return fs::equivalent(S, Dir); })) + continue; + SmallString<128> FilePath(Dir); path::append(FilePath, FileName); if (fs::exists(Twine(FilePath))) { |