]> granicus.if.org Git - clang/commitdiff
Driver: Support ToolChain specific path lists to search for files and
authorDaniel Dunbar <daniel@zuster.org>
Wed, 18 Mar 2009 20:26:19 +0000 (20:26 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 18 Mar 2009 20:26:19 +0000 (20:26 +0000)
programs.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67229 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/ToolChain.h
lib/Driver/Driver.cpp

index 3a07a325bd47dcd2088b45278acbe3877f43e680..5c00538f886e39ed3c6c8bf0258615a88527bb2c 100644 (file)
@@ -10,6 +10,7 @@
 #ifndef CLANG_DRIVER_TOOLCHAIN_H_
 #define CLANG_DRIVER_TOOLCHAIN_H_
 
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/System/Path.h"
 #include <string>
 
@@ -23,9 +24,21 @@ namespace driver {
 
 /// ToolChain - Access to tools for a single platform.
 class ToolChain {
+public:
+  typedef llvm::SmallVector<std::string, 4> path_list;
+
+private:
   const HostInfo &Host;
   std::string Arch, Platform, OS;
 
+  /// The list of toolchain specific path prefixes to search for
+  /// files.
+  path_list FilePaths;
+
+  /// The list of toolchain specific path prefixes to search for
+  /// programs.
+  path_list ProgramPaths;
+
 protected:
   ToolChain(const HostInfo &Host, const char *_Arch, const char *_Platform, 
             const char *_OS);
@@ -40,6 +53,12 @@ public:
   const std::string &getPlatform() const { return Platform; }
   const std::string &getOS() const { return OS; }
 
+  path_list getFilePaths() { return FilePaths; }
+  const path_list getFilePaths() const { return FilePaths; }
+
+  path_list getProgramPaths() { return ProgramPaths; }
+  const path_list getProgramPaths() const { return ProgramPaths; }
+
   // Tool access.
 
   /// TranslateArgs - Create a new derived argument list for any
index 9d913a1601dd28bad11c0f87a6b8b0fe0c40c85a..f3d241017ed5a486f7b84d319f592415ecd0a565 100644 (file)
@@ -849,13 +849,36 @@ const char *Driver::GetNamedOutputPath(Compilation &C,
 
 llvm::sys::Path Driver::GetFilePath(const char *Name,
                                     const ToolChain &TC) const {
-  // FIXME: Implement.
+  const ToolChain::path_list &List = TC.getFilePaths();
+  for (ToolChain::path_list::const_iterator 
+         it = List.begin(), ie = List.end(); it != ie; ++it) {
+    llvm::sys::Path P(*it);
+    P.appendComponent(Name);
+    if (P.exists())
+      return P;
+  }
+
   return llvm::sys::Path(Name);
 }
 
 llvm::sys::Path Driver::GetProgramPath(const char *Name, 
                                        const ToolChain &TC) const {
-  // FIXME: Implement.
+  const ToolChain::path_list &List = TC.getProgramPaths();
+  for (ToolChain::path_list::const_iterator 
+         it = List.begin(), ie = List.end(); it != ie; ++it) {
+    llvm::sys::Path P(*it);
+    P.appendComponent(Name);
+    if (P.exists())
+      return P;
+  }
+
+  // As a last resort, always search in our directory before pulling
+  // from the path.
+  llvm::sys::Path P(Dir);
+  P.appendComponent(Name);
+  if (P.exists())
+    return P;
+
   return llvm::sys::Path(Name);
 }