[PATCH] Use the newly added FindInEnvPath helper in clang
Ehsan Akhgari
ehsan.akhgari at gmail.com
Wed Jun 18 17:18:03 PDT 2014
Hi hans,
http://reviews.llvm.org/D4202
Files:
lib/Driver/Driver.cpp
lib/Driver/Tools.cpp
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -932,30 +932,9 @@
/// \brief Check whether the file referenced by Value exists in the LIB
/// environment variable.
static bool ExistsInLibDir(StringRef Value) {
- llvm::Optional<std::string> OptPath = llvm::sys::Process::GetEnv("LIB");
- if (!OptPath.hasValue())
- return false;
-
-#ifdef LLVM_ON_WIN32
- const StringRef PathSeparators = ";";
-#else
- const StringRef PathSeparators = ":";
-#endif
-
- SmallVector<StringRef, 8> LibDirs;
- llvm::SplitString(OptPath.getValue(), LibDirs, PathSeparators);
-
- for (const auto &LibDir : LibDirs) {
- if (LibDir.empty())
- continue;
-
- SmallString<128> FilePath(LibDir);
- llvm::sys::path::append(FilePath, Value);
- if (llvm::sys::fs::exists(Twine(FilePath)))
- return true;
- }
-
- return false;
+ llvm::Optional<std::string> FilePath =
+ llvm::sys::FindInEnvPath("LIB", Value);
+ return FilePath.hasValue();
}
/// \brief Check that the file referenced by Value exists. If it doesn't,
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -7532,30 +7532,13 @@
// if it's available as cl.exe on the path.
static std::string FindFallback(const char *FallbackName,
const char *ClangProgramPath) {
- llvm::Optional<std::string> OptPath = llvm::sys::Process::GetEnv("PATH");
- if (!OptPath.hasValue())
- return FallbackName;
+ llvm::Optional<std::string> FilePath =
+ llvm::sys::FindInEnvPath("PATH", FallbackName);
-#ifdef LLVM_ON_WIN32
- const StringRef PathSeparators = ";";
-#else
- const StringRef PathSeparators = ":";
-#endif
-
- SmallVector<StringRef, 8> PathSegments;
- llvm::SplitString(OptPath.getValue(), PathSegments, PathSeparators);
-
- for (size_t i = 0, e = PathSegments.size(); i != e; ++i) {
- const StringRef &PathSegment = PathSegments[i];
- if (PathSegment.empty())
- continue;
-
- SmallString<128> FilePath(PathSegment);
- llvm::sys::path::append(FilePath, FallbackName);
- if (llvm::sys::fs::can_execute(Twine(FilePath)) &&
- !llvm::sys::fs::equivalent(Twine(FilePath), ClangProgramPath))
- return FilePath.str();
- }
+ if (FilePath.hasValue() &&
+ llvm::sys::fs::can_execute(Twine(FilePath.getValue())) &&
+ !llvm::sys::fs::equivalent(Twine(FilePath.getValue()), ClangProgramPath))
+ return FilePath.getValue();
return FallbackName;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4202.10598.patch
Type: text/x-patch
Size: 2601 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140619/f0c53f48/attachment.bin>
More information about the cfe-commits
mailing list