| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1 | //===--- InitHeaderSearch.cpp - Initialize header search paths ----------*-===// | 
|  | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 | // | 
|  | 10 | // This file implements the InitHeaderSearch class. | 
|  | 11 | // | 
|  | 12 | //===----------------------------------------------------------------------===// | 
|  | 13 |  | 
|  | 14 | #include "clang/Driver/InitHeaderSearch.h" | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 15 | #include "clang/Lex/HeaderSearch.h" | 
|  | 16 | #include "clang/Basic/FileManager.h" | 
|  | 17 | #include "clang/Basic/LangOptions.h" | 
|  | 18 | #include "llvm/ADT/SmallString.h" | 
|  | 19 | #include "llvm/ADT/SmallPtrSet.h" | 
|  | 20 | #include "llvm/System/Path.h" | 
| Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 21 | #include "llvm/Config/config.h" | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 22 | #include <vector> | 
|  | 23 |  | 
|  | 24 | using namespace clang; | 
|  | 25 |  | 
|  | 26 | void InitHeaderSearch::AddPath(const std::string &Path, IncludeDirGroup Group, | 
|  | 27 | bool isCXXAware, bool isUserSupplied, | 
|  | 28 | bool isFramework) { | 
|  | 29 | assert(!Path.empty() && "can't handle empty path here"); | 
|  | 30 | FileManager &FM = Headers.getFileMgr(); | 
|  | 31 |  | 
|  | 32 | // Compute the actual path, taking into consideration -isysroot. | 
|  | 33 | llvm::SmallString<256> MappedPath; | 
|  | 34 |  | 
|  | 35 | // Handle isysroot. | 
|  | 36 | if (Group == System) { | 
|  | 37 | // FIXME: Portability.  This should be a sys::Path interface, this doesn't | 
|  | 38 | // handle things like C:\ right, nor win32 \\network\device\blah. | 
|  | 39 | if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present. | 
|  | 40 | MappedPath.append(isysroot.begin(), isysroot.end()); | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | MappedPath.append(Path.begin(), Path.end()); | 
|  | 44 |  | 
|  | 45 | // Compute the DirectoryLookup type. | 
| Chris Lattner | 9d72851 | 2008-10-27 01:19:25 +0000 | [diff] [blame] | 46 | SrcMgr::CharacteristicKind Type; | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 47 | if (Group == Quoted || Group == Angled) | 
| Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 48 | Type = SrcMgr::C_User; | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 49 | else if (isCXXAware) | 
| Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 50 | Type = SrcMgr::C_System; | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 51 | else | 
| Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 52 | Type = SrcMgr::C_ExternCSystem; | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 53 |  | 
|  | 54 |  | 
|  | 55 | // If the directory exists, add it. | 
|  | 56 | if (const DirectoryEntry *DE = FM.getDirectory(&MappedPath[0], | 
|  | 57 | &MappedPath[0]+ | 
|  | 58 | MappedPath.size())) { | 
|  | 59 | IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied, | 
|  | 60 | isFramework)); | 
|  | 61 | return; | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | // Check to see if this is an apple-style headermap (which are not allowed to | 
|  | 65 | // be frameworks). | 
|  | 66 | if (!isFramework) { | 
|  | 67 | if (const FileEntry *FE = FM.getFile(&MappedPath[0], | 
|  | 68 | &MappedPath[0]+MappedPath.size())) { | 
|  | 69 | if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { | 
|  | 70 | // It is a headermap, add it to the search path. | 
|  | 71 | IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied)); | 
|  | 72 | return; | 
|  | 73 | } | 
|  | 74 | } | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | if (Verbose) | 
|  | 78 | fprintf(stderr, "ignoring nonexistent directory \"%s\"\n", Path.c_str()); | 
|  | 79 | } | 
|  | 80 |  | 
|  | 81 |  | 
|  | 82 | void InitHeaderSearch::AddEnvVarPaths(const char *Name) { | 
|  | 83 | const char* at = getenv(Name); | 
| Daniel Dunbar | bb95255 | 2008-10-04 20:58:18 +0000 | [diff] [blame] | 84 | if (!at || *at == 0) // Empty string should not add '.' path. | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 85 | return; | 
|  | 86 |  | 
|  | 87 | const char* delim = strchr(at, llvm::sys::PathSeparator); | 
|  | 88 | while (delim != 0) { | 
|  | 89 | if (delim-at == 0) | 
|  | 90 | AddPath(".", Angled, false, true, false); | 
|  | 91 | else | 
|  | 92 | AddPath(std::string(at, std::string::size_type(delim-at)), Angled, false, | 
| Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 93 | true, false); | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 94 | at = delim + 1; | 
|  | 95 | delim = strchr(at, llvm::sys::PathSeparator); | 
|  | 96 | } | 
|  | 97 | if (*at == 0) | 
|  | 98 | AddPath(".", Angled, false, true, false); | 
|  | 99 | else | 
|  | 100 | AddPath(at, Angled, false, true, false); | 
|  | 101 | } | 
|  | 102 |  | 
|  | 103 |  | 
|  | 104 | void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang) { | 
|  | 105 | // FIXME: temporary hack: hard-coded paths. | 
|  | 106 | // FIXME: get these from the target? | 
| Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 107 |  | 
|  | 108 | #ifdef LLVM_ON_WIN32 | 
|  | 109 | if (Lang.CPlusPlus) { | 
|  | 110 | // Mingw32 GCC version 4 | 
|  | 111 | AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++", System, true, false, false); | 
|  | 112 | AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/mingw32", System, true, false, false); | 
|  | 113 | AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/backward", System, true, false, false); | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | // Mingw32 GCC version 4 | 
|  | 117 | AddPath("C:/mingw/lib/gcc/mingw32/4.3.0/include", System, false, false, false); | 
|  | 118 | AddPath("C:/mingw/include", System, false, false, false); | 
|  | 119 | #else | 
|  | 120 |  | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 121 | if (Lang.CPlusPlus) { | 
|  | 122 | AddPath("/usr/include/c++/4.2.1", System, true, false, false); | 
|  | 123 | AddPath("/usr/include/c++/4.2.1/i686-apple-darwin10", System, true, false, | 
|  | 124 | false); | 
|  | 125 | AddPath("/usr/include/c++/4.2.1/backward", System, true, false, false); | 
|  | 126 |  | 
|  | 127 | AddPath("/usr/include/c++/4.0.0", System, true, false, false); | 
|  | 128 | AddPath("/usr/include/c++/4.0.0/i686-apple-darwin8", System, true, false, | 
|  | 129 | false); | 
|  | 130 | AddPath("/usr/include/c++/4.0.0/backward", System, true, false, false); | 
|  | 131 |  | 
|  | 132 | // Ubuntu 7.10 - Gutsy Gibbon | 
|  | 133 | AddPath("/usr/include/c++/4.1.3", System, true, false, false); | 
|  | 134 | AddPath("/usr/include/c++/4.1.3/i486-linux-gnu", System, true, false, | 
|  | 135 | false); | 
|  | 136 | AddPath("/usr/include/c++/4.1.3/backward", System, true, false, false); | 
|  | 137 |  | 
|  | 138 | // Fedora 8 | 
|  | 139 | AddPath("/usr/include/c++/4.1.2", System, true, false, false); | 
|  | 140 | AddPath("/usr/include/c++/4.1.2/i386-redhat-linux", System, true, false, | 
|  | 141 | false); | 
|  | 142 | AddPath("/usr/include/c++/4.1.2/backward", System, true, false, false); | 
|  | 143 |  | 
|  | 144 | // Fedora 9 | 
|  | 145 | AddPath("/usr/include/c++/4.3.0", System, true, false, false); | 
|  | 146 | AddPath("/usr/include/c++/4.3.0/i386-redhat-linux", System, true, false, | 
|  | 147 | false); | 
|  | 148 | AddPath("/usr/include/c++/4.3.0/backward", System, true, false, false); | 
|  | 149 |  | 
| Zhongxing Xu | 776caef | 2008-12-25 09:28:01 +0000 | [diff] [blame] | 150 | // Fedora 10 | 
|  | 151 | AddPath("/usr/include/c++/4.3.2", System, true, false, false); | 
|  | 152 | AddPath("/usr/include/c++/4.3.2/i386-redhat-linux", System, true, false, | 
|  | 153 | false); | 
|  | 154 | AddPath("/usr/include/c++/4.3.2/backward", System, true, false, false); | 
|  | 155 |  | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 156 | // Arch Linux 2008-06-24 | 
|  | 157 | AddPath("/usr/include/c++/4.3.1", System, true, false, false); | 
|  | 158 | AddPath("/usr/include/c++/4.3.1/i686-pc-linux-gnu", System, true, false, | 
|  | 159 | false); | 
|  | 160 | AddPath("/usr/include/c++/4.3.1/backward", System, true, false, false); | 
|  | 161 | AddPath("/usr/include/c++/4.3.1/x86_64-unknown-linux-gnu", System, true, | 
|  | 162 | false, false); | 
| Chris Lattner | 5654ffd | 2008-08-23 18:25:07 +0000 | [diff] [blame] | 163 |  | 
| Nuno Lopes | a3d783b | 2008-12-07 12:11:37 +0000 | [diff] [blame] | 164 | // Gentoo x86 stable | 
|  | 165 | AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", System, | 
|  | 166 | true, false, false); | 
|  | 167 | AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/" | 
|  | 168 | "i686-pc-linux-gnu", System, true, false, false); | 
|  | 169 | AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/backward", | 
|  | 170 | System, true, false, false); | 
|  | 171 |  | 
|  | 172 |  | 
| Chris Lattner | 5654ffd | 2008-08-23 18:25:07 +0000 | [diff] [blame] | 173 | // DragonFly | 
|  | 174 | AddPath("/usr/include/c++/4.1", System, true, false, false); | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 175 | } | 
|  | 176 |  | 
|  | 177 | AddPath("/usr/local/include", System, false, false, false); | 
|  | 178 |  | 
|  | 179 | AddPath("/usr/lib/gcc/i686-apple-darwin10/4.2.1/include", System, | 
|  | 180 | false, false, false); | 
|  | 181 | AddPath("/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/include", | 
|  | 182 | System, false, false, false); | 
|  | 183 |  | 
|  | 184 | // leopard | 
|  | 185 | AddPath("/usr/lib/gcc/i686-apple-darwin9/4.0.1/include", System, | 
|  | 186 | false, false, false); | 
|  | 187 | AddPath("/usr/lib/gcc/powerpc-apple-darwin9/4.0.1/include", | 
|  | 188 | System, false, false, false); | 
|  | 189 | AddPath("/usr/lib/gcc/powerpc-apple-darwin9/" | 
|  | 190 | "4.0.1/../../../../powerpc-apple-darwin0/include", | 
|  | 191 | System, false, false, false); | 
|  | 192 |  | 
|  | 193 | // tiger | 
|  | 194 | AddPath("/usr/lib/gcc/i686-apple-darwin8/4.0.1/include", System, | 
|  | 195 | false, false, false); | 
|  | 196 | AddPath("/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/include", | 
|  | 197 | System, false, false, false); | 
|  | 198 | AddPath("/usr/lib/gcc/powerpc-apple-darwin8/" | 
|  | 199 | "4.0.1/../../../../powerpc-apple-darwin8/include", | 
|  | 200 | System, false, false, false); | 
|  | 201 |  | 
|  | 202 | // Ubuntu 7.10 - Gutsy Gibbon | 
|  | 203 | AddPath("/usr/lib/gcc/i486-linux-gnu/4.1.3/include", System, | 
|  | 204 | false, false, false); | 
|  | 205 |  | 
|  | 206 | // Fedora 8 | 
|  | 207 | AddPath("/usr/lib/gcc/i386-redhat-linux/4.1.2/include", System, | 
|  | 208 | false, false, false); | 
|  | 209 |  | 
|  | 210 | // Fedora 9 | 
|  | 211 | AddPath("/usr/lib/gcc/i386-redhat-linux/4.3.0/include", System, | 
|  | 212 | false, false, false); | 
|  | 213 |  | 
| Zhongxing Xu | 776caef | 2008-12-25 09:28:01 +0000 | [diff] [blame] | 214 | // Fedora 10 | 
|  | 215 | AddPath("/usr/lib/gcc/i386-redhat-linux/4.3.2/include", System, | 
|  | 216 | false, false, false); | 
|  | 217 |  | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 218 | //Debian testing/lenny x86 | 
|  | 219 | AddPath("/usr/lib/gcc/i486-linux-gnu/4.2.3/include", System, | 
|  | 220 | false, false, false); | 
|  | 221 |  | 
|  | 222 | //Debian testing/lenny amd64 | 
|  | 223 | AddPath("/usr/lib/gcc/x86_64-linux-gnu/4.2.3/include", System, | 
|  | 224 | false, false, false); | 
|  | 225 |  | 
| Torok Edwin | f7ea67a | 2009-02-05 18:12:45 +0000 | [diff] [blame] | 226 | // Debian sid amd64 | 
|  | 227 | AddPath("/usr/lib/gcc/x86_64-linux-gnu/4.3/include", System, | 
|  | 228 | false, false, false); | 
|  | 229 | AddPath("/usr/lib/gcc/x86_64-linux-gnu/4.3/include-fixed", | 
|  | 230 | System, false, false, false); | 
|  | 231 |  | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 232 | // Arch Linux 2008-06-24 | 
|  | 233 | AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.3.1/include", System, | 
|  | 234 | false, false, false); | 
|  | 235 | AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.3.1/include-fixed", System, | 
|  | 236 | false, false, false); | 
|  | 237 | AddPath("/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.1/include", System, | 
|  | 238 | false, false, false); | 
|  | 239 | AddPath("/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.1/include-fixed", | 
|  | 240 | System, false, false, false); | 
|  | 241 |  | 
|  | 242 | // Debian testing/lenny ppc32 | 
|  | 243 | AddPath("/usr/lib/gcc/powerpc-linux-gnu/4.2.3/include", System, | 
|  | 244 | false, false, false); | 
|  | 245 |  | 
|  | 246 | // Gentoo x86 stable | 
|  | 247 | AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include", System, | 
|  | 248 | false, false, false); | 
|  | 249 |  | 
| Chris Lattner | 5654ffd | 2008-08-23 18:25:07 +0000 | [diff] [blame] | 250 | // DragonFly | 
|  | 251 | AddPath("/usr/libdata/gcc41", System, true, false, false); | 
|  | 252 |  | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 253 | AddPath("/usr/include", System, false, false, false); | 
|  | 254 | AddPath("/System/Library/Frameworks", System, true, false, true); | 
|  | 255 | AddPath("/Library/Frameworks", System, true, false, true); | 
| Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 256 |  | 
|  | 257 | #endif | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 258 | } | 
|  | 259 |  | 
|  | 260 | void InitHeaderSearch::AddDefaultEnvVarPaths(const LangOptions &Lang) { | 
|  | 261 | AddEnvVarPaths("CPATH"); | 
|  | 262 | if (Lang.CPlusPlus && Lang.ObjC1) | 
|  | 263 | AddEnvVarPaths("OBJCPLUS_INCLUDE_PATH"); | 
|  | 264 | else if (Lang.CPlusPlus) | 
|  | 265 | AddEnvVarPaths("CPLUS_INCLUDE_PATH"); | 
|  | 266 | else if (Lang.ObjC1) | 
|  | 267 | AddEnvVarPaths("OBJC_INCLUDE_PATH"); | 
|  | 268 | else | 
|  | 269 | AddEnvVarPaths("C_INCLUDE_PATH"); | 
|  | 270 | } | 
|  | 271 |  | 
|  | 272 |  | 
|  | 273 | /// RemoveDuplicates - If there are duplicate directory entries in the specified | 
|  | 274 | /// search list, remove the later (dead) ones. | 
|  | 275 | static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, | 
|  | 276 | bool Verbose) { | 
|  | 277 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; | 
|  | 278 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; | 
|  | 279 | llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; | 
|  | 280 | for (unsigned i = 0; i != SearchList.size(); ++i) { | 
| Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 281 | unsigned DirToRemove = i; | 
|  | 282 |  | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 283 | const DirectoryLookup &CurEntry = SearchList[i]; | 
|  | 284 |  | 
|  | 285 | if (CurEntry.isNormalDir()) { | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 286 | // If this isn't the first time we've seen this dir, remove it. | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 287 | if (SeenDirs.insert(CurEntry.getDir())) | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 288 | continue; | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 289 | } else if (CurEntry.isFramework()) { | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 290 | // If this isn't the first time we've seen this framework dir, remove it. | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 291 | if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 292 | continue; | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 293 | } else { | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 294 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 295 | // If this isn't the first time we've seen this headermap, remove it. | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 296 | if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 297 | continue; | 
| Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 298 | } | 
|  | 299 |  | 
|  | 300 | // If we have a normal #include dir/framework/headermap that is shadowed | 
|  | 301 | // later in the chain by a system include location, we actually want to | 
|  | 302 | // ignore the user's request and drop the user dir... keeping the system | 
|  | 303 | // dir.  This is weird, but required to emulate GCC's search path correctly. | 
|  | 304 | // | 
|  | 305 | // Since dupes of system dirs are rare, just rescan to find the original | 
|  | 306 | // that we're nuking instead of using a DenseMap. | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 307 | if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { | 
| Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 308 | // Find the dir that this is the same of. | 
|  | 309 | unsigned FirstDir; | 
|  | 310 | for (FirstDir = 0; ; ++FirstDir) { | 
|  | 311 | assert(FirstDir != i && "Didn't find dupe?"); | 
|  | 312 |  | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 313 | const DirectoryLookup &SearchEntry = SearchList[FirstDir]; | 
|  | 314 |  | 
| Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 315 | // If these are different lookup types, then they can't be the dupe. | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 316 | if (SearchEntry.getLookupType() != CurEntry.getLookupType()) | 
| Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 317 | continue; | 
|  | 318 |  | 
|  | 319 | bool isSame; | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 320 | if (CurEntry.isNormalDir()) | 
|  | 321 | isSame = SearchEntry.getDir() == CurEntry.getDir(); | 
|  | 322 | else if (CurEntry.isFramework()) | 
|  | 323 | isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); | 
| Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 324 | else { | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 325 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); | 
|  | 326 | isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); | 
| Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 327 | } | 
|  | 328 |  | 
|  | 329 | if (isSame) | 
|  | 330 | break; | 
|  | 331 | } | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 332 |  | 
| Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 333 | // If the first dir in the search path is a non-system dir, zap it | 
|  | 334 | // instead of the system one. | 
|  | 335 | if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) | 
|  | 336 | DirToRemove = FirstDir; | 
|  | 337 | } | 
|  | 338 |  | 
|  | 339 | if (Verbose) { | 
| Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 340 | fprintf(stderr, "ignoring duplicate directory \"%s\"\n", | 
|  | 341 | CurEntry.getName()); | 
| Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 342 | if (DirToRemove != i) | 
|  | 343 | fprintf(stderr, "  as it is a non-system directory that duplicates" | 
|  | 344 | " a system directory\n"); | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 345 | } | 
|  | 346 |  | 
| Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 347 | // This is reached if the current entry is a duplicate.  Remove the | 
|  | 348 | // DirToRemove (usually the current dir). | 
|  | 349 | SearchList.erase(SearchList.begin()+DirToRemove); | 
| Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 350 | --i; | 
|  | 351 | } | 
|  | 352 | } | 
|  | 353 |  | 
|  | 354 |  | 
|  | 355 | void InitHeaderSearch::Realize() { | 
|  | 356 | // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. | 
|  | 357 | std::vector<DirectoryLookup> SearchList; | 
|  | 358 | SearchList = IncludeGroup[Angled]; | 
|  | 359 | SearchList.insert(SearchList.end(), IncludeGroup[System].begin(), | 
|  | 360 | IncludeGroup[System].end()); | 
|  | 361 | SearchList.insert(SearchList.end(), IncludeGroup[After].begin(), | 
|  | 362 | IncludeGroup[After].end()); | 
|  | 363 | RemoveDuplicates(SearchList, Verbose); | 
|  | 364 | RemoveDuplicates(IncludeGroup[Quoted], Verbose); | 
|  | 365 |  | 
|  | 366 | // Prepend QUOTED list on the search list. | 
|  | 367 | SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(), | 
|  | 368 | IncludeGroup[Quoted].end()); | 
|  | 369 |  | 
|  | 370 |  | 
|  | 371 | bool DontSearchCurDir = false;  // TODO: set to true if -I- is set? | 
|  | 372 | Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(), | 
|  | 373 | DontSearchCurDir); | 
|  | 374 |  | 
|  | 375 | // If verbose, print the list of directories that will be searched. | 
|  | 376 | if (Verbose) { | 
|  | 377 | fprintf(stderr, "#include \"...\" search starts here:\n"); | 
|  | 378 | unsigned QuotedIdx = IncludeGroup[Quoted].size(); | 
|  | 379 | for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { | 
|  | 380 | if (i == QuotedIdx) | 
|  | 381 | fprintf(stderr, "#include <...> search starts here:\n"); | 
|  | 382 | const char *Name = SearchList[i].getName(); | 
|  | 383 | const char *Suffix; | 
|  | 384 | if (SearchList[i].isNormalDir()) | 
|  | 385 | Suffix = ""; | 
|  | 386 | else if (SearchList[i].isFramework()) | 
|  | 387 | Suffix = " (framework directory)"; | 
|  | 388 | else { | 
|  | 389 | assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); | 
|  | 390 | Suffix = " (headermap)"; | 
|  | 391 | } | 
|  | 392 | fprintf(stderr, " %s%s\n", Name, Suffix); | 
|  | 393 | } | 
|  | 394 | fprintf(stderr, "End of search list.\n"); | 
|  | 395 | } | 
|  | 396 | } | 
|  | 397 |  |