From fa0ca6cbd01c6289ef4073073a84200a883eb3c5 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Wed, 11 Oct 2017 20:12:09 +0000 Subject: [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 --- llvm/lib/Support/Process.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Support/Process.cpp') 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 Process::FindInEnvPath(const std::string& EnvName, - const std::string& FileName) -{ +Optional Process::FindInEnvPath(StringRef EnvName, + StringRef FileName) { + return FindInEnvPath(EnvName, FileName, {}); +} + +Optional Process::FindInEnvPath(StringRef EnvName, + StringRef FileName, + ArrayRef IgnoreList) { assert(!path::is_absolute(FileName)); Optional FoundPath; Optional OptPath = Process::GetEnv(EnvName); @@ -39,10 +45,13 @@ Optional Process::FindInEnvPath(const std::string& EnvName, SmallVector 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))) { -- cgit v1.2.3