]> granicus.if.org Git - clang/commitdiff
Use the newly added FindInEnvPath helper in clang
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Mon, 30 Jun 2014 19:56:37 +0000 (19:56 +0000)
committerEhsan Akhgari <ehsan.akhgari@gmail.com>
Mon, 30 Jun 2014 19:56:37 +0000 (19:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212058 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Driver.cpp
lib/Driver/Tools.cpp

index a18312a84fa08ca4c1c18e3bf87d2362640b64b6..08dcc11d62e3e1c2ad228a2ff2496a005b1833e9 100644 (file)
@@ -939,35 +939,6 @@ void Driver::BuildUniversalActions(const ToolChain &TC,
   }
 }
 
-/// \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;
-}
-
 /// \brief Check that the file referenced by Value exists. If it doesn't,
 /// issue a diagnostic and return false.
 static bool DiagnoseInputExistence(const Driver &D, const DerivedArgList &Args,
@@ -991,7 +962,7 @@ static bool DiagnoseInputExistence(const Driver &D, const DerivedArgList &Args,
   if (llvm::sys::fs::exists(Twine(Path)))
     return true;
 
-  if (D.IsCLMode() && ExistsInLibDir(Value))
+  if (D.IsCLMode() && llvm::sys::Process::FindInEnvPath("LIB", Value))
     return true;
 
   D.Diag(clang::diag::err_drv_no_such_file) << Path.str();
index 3587bbb2f5fafad1f2cf147ee8ed66d4cfe51657..f5d79941363ae13d9774388c971a6803a5795b9d 100644 (file)
@@ -7651,14 +7651,9 @@ static std::string FindFallback(const char *FallbackName,
   if (!OptPath.hasValue())
     return FallbackName;
 
-#ifdef LLVM_ON_WIN32
-  const StringRef PathSeparators = ";";
-#else
-  const StringRef PathSeparators = ":";
-#endif
-
+  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
   SmallVector<StringRef, 8> PathSegments;
-  llvm::SplitString(OptPath.getValue(), PathSegments, PathSeparators);
+  llvm::SplitString(OptPath.getValue(), PathSegments, EnvPathSeparatorStr);
 
   for (size_t i = 0, e = PathSegments.size(); i != e; ++i) {
     const StringRef &PathSegment = PathSegments[i];