diff options
author | Zachary Turner <zturner@google.com> | 2017-10-11 20:12:09 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-10-11 20:12:09 +0000 |
commit | fa0ca6cbd01c6289ef4073073a84200a883eb3c5 (patch) | |
tree | 2abc3114b64d579879e5787ea6a3e9cb9adbce79 /llvm/lib/Support/Process.cpp | |
parent | 210d9f43a33e98bb60231972c618482de1fdc0d6 (diff) | |
download | bcm5719-llvm-fa0ca6cbd01c6289ef4073073a84200a883eb3c5.tar.gz bcm5719-llvm-fa0ca6cbd01c6289ef4073073a84200a883eb3c5.zip |
[llvm-rc] Use proper search algorithm for finding resources.
Previously we would only look in the current directory for a
resource, which might not be the same as the directory of the
rc file. Furthermore, MSVC rc supports a /I option, and can
also look in the system environment. This patch adds support
for this search algorithm.
Differential Revision: https://reviews.llvm.org/D38740
llvm-svn: 315499
Diffstat (limited to 'llvm/lib/Support/Process.cpp')
-rw-r--r-- | llvm/lib/Support/Process.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp index caec993ee16..1c8cc6e83ad 100644 --- a/llvm/lib/Support/Process.cpp +++ b/llvm/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))) { |