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 | |
Daniel Dunbar | e1bd4e6 | 2009-03-02 06:16:29 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/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" |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 22 | #include <cstdio> |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 23 | #include <vector> |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | |
| 26 | void InitHeaderSearch::AddPath(const std::string &Path, IncludeDirGroup Group, |
| 27 | bool isCXXAware, bool isUserSupplied, |
Chris Lattner | 6858dd3 | 2009-02-19 06:48:28 +0000 | [diff] [blame] | 28 | bool isFramework, bool IgnoreSysRoot) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 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. |
Chris Lattner | 6858dd3 | 2009-02-19 06:48:28 +0000 | [diff] [blame] | 36 | if (Group == System && !IgnoreSysRoot) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 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) |
Chris Lattner | 50b587d | 2009-02-19 04:48:57 +0000 | [diff] [blame] | 78 | fprintf(stderr, "ignoring nonexistent directory \"%s\"\n", |
| 79 | MappedPath.c_str()); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
| 83 | void InitHeaderSearch::AddEnvVarPaths(const char *Name) { |
| 84 | const char* at = getenv(Name); |
Daniel Dunbar | bb95255 | 2008-10-04 20:58:18 +0000 | [diff] [blame] | 85 | if (!at || *at == 0) // Empty string should not add '.' path. |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 86 | return; |
| 87 | |
| 88 | const char* delim = strchr(at, llvm::sys::PathSeparator); |
| 89 | while (delim != 0) { |
| 90 | if (delim-at == 0) |
| 91 | AddPath(".", Angled, false, true, false); |
| 92 | else |
| 93 | AddPath(std::string(at, std::string::size_type(delim-at)), Angled, false, |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 94 | true, false); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 95 | at = delim + 1; |
| 96 | delim = strchr(at, llvm::sys::PathSeparator); |
| 97 | } |
| 98 | if (*at == 0) |
| 99 | AddPath(".", Angled, false, true, false); |
| 100 | else |
| 101 | AddPath(at, Angled, false, true, false); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang) { |
| 106 | // FIXME: temporary hack: hard-coded paths. |
| 107 | // FIXME: get these from the target? |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 108 | |
| 109 | #ifdef LLVM_ON_WIN32 |
| 110 | if (Lang.CPlusPlus) { |
| 111 | // Mingw32 GCC version 4 |
Chris Lattner | 6f54102 | 2009-02-18 00:25:15 +0000 | [diff] [blame] | 112 | AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++", |
| 113 | System, true, false, false); |
| 114 | AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/mingw32", |
| 115 | System, true, false, false); |
| 116 | AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/backward", |
| 117 | System, true, false, false); |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | // Mingw32 GCC version 4 |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 121 | AddPath("C:/mingw/include", System, false, false, false); |
| 122 | #else |
| 123 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 124 | if (Lang.CPlusPlus) { |
| 125 | AddPath("/usr/include/c++/4.2.1", System, true, false, false); |
| 126 | AddPath("/usr/include/c++/4.2.1/i686-apple-darwin10", System, true, false, |
| 127 | false); |
| 128 | AddPath("/usr/include/c++/4.2.1/backward", System, true, false, false); |
| 129 | |
| 130 | AddPath("/usr/include/c++/4.0.0", System, true, false, false); |
| 131 | AddPath("/usr/include/c++/4.0.0/i686-apple-darwin8", System, true, false, |
| 132 | false); |
| 133 | AddPath("/usr/include/c++/4.0.0/backward", System, true, false, false); |
| 134 | |
| 135 | // Ubuntu 7.10 - Gutsy Gibbon |
| 136 | AddPath("/usr/include/c++/4.1.3", System, true, false, false); |
| 137 | AddPath("/usr/include/c++/4.1.3/i486-linux-gnu", System, true, false, |
| 138 | false); |
| 139 | AddPath("/usr/include/c++/4.1.3/backward", System, true, false, false); |
| 140 | |
Douglas Gregor | 15e9232 | 2009-06-17 21:18:36 +0000 | [diff] [blame] | 141 | // Ubuntu 9.04 |
| 142 | AddPath("/usr/include/c++/4.3.3", System, true, false, false); |
| 143 | AddPath("/usr/include/c++/4.3.3/x86_64-linux-gnu/", System, true, false, |
| 144 | false); |
| 145 | AddPath("/usr/include/c++/4.3.3/backward", System, true, false, false); |
| 146 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 147 | // Fedora 8 |
| 148 | AddPath("/usr/include/c++/4.1.2", System, true, false, false); |
| 149 | AddPath("/usr/include/c++/4.1.2/i386-redhat-linux", System, true, false, |
| 150 | false); |
| 151 | AddPath("/usr/include/c++/4.1.2/backward", System, true, false, false); |
| 152 | |
| 153 | // Fedora 9 |
| 154 | AddPath("/usr/include/c++/4.3.0", System, true, false, false); |
| 155 | AddPath("/usr/include/c++/4.3.0/i386-redhat-linux", System, true, false, |
| 156 | false); |
| 157 | AddPath("/usr/include/c++/4.3.0/backward", System, true, false, false); |
| 158 | |
Zhongxing Xu | 776caef | 2008-12-25 09:28:01 +0000 | [diff] [blame] | 159 | // Fedora 10 |
| 160 | AddPath("/usr/include/c++/4.3.2", System, true, false, false); |
| 161 | AddPath("/usr/include/c++/4.3.2/i386-redhat-linux", System, true, false, |
| 162 | false); |
| 163 | AddPath("/usr/include/c++/4.3.2/backward", System, true, false, false); |
| 164 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 165 | // Arch Linux 2008-06-24 |
| 166 | AddPath("/usr/include/c++/4.3.1", System, true, false, false); |
| 167 | AddPath("/usr/include/c++/4.3.1/i686-pc-linux-gnu", System, true, false, |
| 168 | false); |
| 169 | AddPath("/usr/include/c++/4.3.1/backward", System, true, false, false); |
| 170 | AddPath("/usr/include/c++/4.3.1/x86_64-unknown-linux-gnu", System, true, |
| 171 | false, false); |
Chris Lattner | 5654ffd | 2008-08-23 18:25:07 +0000 | [diff] [blame] | 172 | |
Nuno Lopes | ec9fd76 | 2009-07-26 16:14:05 +0000 | [diff] [blame] | 173 | // Gentoo x86 2009.0 stable |
| 174 | AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4", System, |
| 175 | true, false, false); |
| 176 | AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/" |
| 177 | "i686-pc-linux-gnu", System, true, false, false); |
| 178 | AddPath(" /usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/backward", |
| 179 | System, true, false, false); |
| 180 | |
| 181 | // Gentoo x86 2008.0 stable |
Nuno Lopes | a3d783b | 2008-12-07 12:11:37 +0000 | [diff] [blame] | 182 | AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", System, |
| 183 | true, false, false); |
| 184 | AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/" |
| 185 | "i686-pc-linux-gnu", System, true, false, false); |
| 186 | AddPath("/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/backward", |
| 187 | System, true, false, false); |
| 188 | |
Sebastian Redl | 4d374d4 | 2009-07-01 18:59:43 +0000 | [diff] [blame] | 189 | // Gentoo amd64 stable |
| 190 | AddPath("/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", System, |
| 191 | true, false, false); |
| 192 | AddPath("/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/" |
| 193 | "i686-pc-linux-gnu", System, true, false, false); |
| 194 | AddPath("/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/backward", |
| 195 | System, true, false, false); |
| 196 | |
Chris Lattner | 5654ffd | 2008-08-23 18:25:07 +0000 | [diff] [blame] | 197 | // DragonFly |
| 198 | AddPath("/usr/include/c++/4.1", System, true, false, false); |
Chris Lattner | 01e4b5c | 2009-02-25 18:06:37 +0000 | [diff] [blame] | 199 | |
| 200 | // FreeBSD |
| 201 | AddPath("/usr/include/c++/4.2", System, true, false, false); |
Eli Friedman | 868d016 | 2009-08-01 17:10:21 +0000 | [diff] [blame] | 202 | |
| 203 | // AuroraUX |
| 204 | AddPath("/opt/gcc4/include/c++/4.2.4", System, true, false, false); |
Eli Friedman | 2ef398c | 2009-08-01 21:46:03 +0000 | [diff] [blame^] | 205 | AddPath("/opt/gcc4/include/c++/4.2.4/i386-pc-solaris2.11", System, true, false, false); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | AddPath("/usr/local/include", System, false, false, false); |
| 209 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 210 | AddPath("/usr/include", System, false, false, false); |
| 211 | AddPath("/System/Library/Frameworks", System, true, false, true); |
| 212 | AddPath("/Library/Frameworks", System, true, false, true); |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 213 | #endif |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void InitHeaderSearch::AddDefaultEnvVarPaths(const LangOptions &Lang) { |
| 217 | AddEnvVarPaths("CPATH"); |
| 218 | if (Lang.CPlusPlus && Lang.ObjC1) |
| 219 | AddEnvVarPaths("OBJCPLUS_INCLUDE_PATH"); |
| 220 | else if (Lang.CPlusPlus) |
| 221 | AddEnvVarPaths("CPLUS_INCLUDE_PATH"); |
| 222 | else if (Lang.ObjC1) |
| 223 | AddEnvVarPaths("OBJC_INCLUDE_PATH"); |
| 224 | else |
| 225 | AddEnvVarPaths("C_INCLUDE_PATH"); |
| 226 | } |
| 227 | |
| 228 | |
| 229 | /// RemoveDuplicates - If there are duplicate directory entries in the specified |
| 230 | /// search list, remove the later (dead) ones. |
| 231 | static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, |
| 232 | bool Verbose) { |
| 233 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; |
| 234 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; |
| 235 | llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; |
| 236 | for (unsigned i = 0; i != SearchList.size(); ++i) { |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 237 | unsigned DirToRemove = i; |
| 238 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 239 | const DirectoryLookup &CurEntry = SearchList[i]; |
| 240 | |
| 241 | if (CurEntry.isNormalDir()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 242 | // 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] | 243 | if (SeenDirs.insert(CurEntry.getDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 244 | continue; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 245 | } else if (CurEntry.isFramework()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 246 | // 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] | 247 | if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 248 | continue; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 249 | } else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 250 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 251 | // 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] | 252 | if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 253 | continue; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | // If we have a normal #include dir/framework/headermap that is shadowed |
| 257 | // later in the chain by a system include location, we actually want to |
| 258 | // ignore the user's request and drop the user dir... keeping the system |
| 259 | // dir. This is weird, but required to emulate GCC's search path correctly. |
| 260 | // |
| 261 | // Since dupes of system dirs are rare, just rescan to find the original |
| 262 | // that we're nuking instead of using a DenseMap. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 263 | if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 264 | // Find the dir that this is the same of. |
| 265 | unsigned FirstDir; |
| 266 | for (FirstDir = 0; ; ++FirstDir) { |
| 267 | assert(FirstDir != i && "Didn't find dupe?"); |
| 268 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 269 | const DirectoryLookup &SearchEntry = SearchList[FirstDir]; |
| 270 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 271 | // 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] | 272 | if (SearchEntry.getLookupType() != CurEntry.getLookupType()) |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 273 | continue; |
| 274 | |
| 275 | bool isSame; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 276 | if (CurEntry.isNormalDir()) |
| 277 | isSame = SearchEntry.getDir() == CurEntry.getDir(); |
| 278 | else if (CurEntry.isFramework()) |
| 279 | isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 280 | else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 281 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
| 282 | isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | if (isSame) |
| 286 | break; |
| 287 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 288 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 289 | // If the first dir in the search path is a non-system dir, zap it |
| 290 | // instead of the system one. |
| 291 | if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) |
| 292 | DirToRemove = FirstDir; |
| 293 | } |
| 294 | |
| 295 | if (Verbose) { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 296 | fprintf(stderr, "ignoring duplicate directory \"%s\"\n", |
| 297 | CurEntry.getName()); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 298 | if (DirToRemove != i) |
| 299 | fprintf(stderr, " as it is a non-system directory that duplicates" |
| 300 | " a system directory\n"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 303 | // This is reached if the current entry is a duplicate. Remove the |
| 304 | // DirToRemove (usually the current dir). |
| 305 | SearchList.erase(SearchList.begin()+DirToRemove); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 306 | --i; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | |
| 311 | void InitHeaderSearch::Realize() { |
| 312 | // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. |
| 313 | std::vector<DirectoryLookup> SearchList; |
| 314 | SearchList = IncludeGroup[Angled]; |
| 315 | SearchList.insert(SearchList.end(), IncludeGroup[System].begin(), |
| 316 | IncludeGroup[System].end()); |
| 317 | SearchList.insert(SearchList.end(), IncludeGroup[After].begin(), |
| 318 | IncludeGroup[After].end()); |
| 319 | RemoveDuplicates(SearchList, Verbose); |
| 320 | RemoveDuplicates(IncludeGroup[Quoted], Verbose); |
| 321 | |
| 322 | // Prepend QUOTED list on the search list. |
| 323 | SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(), |
| 324 | IncludeGroup[Quoted].end()); |
| 325 | |
| 326 | |
| 327 | bool DontSearchCurDir = false; // TODO: set to true if -I- is set? |
| 328 | Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(), |
| 329 | DontSearchCurDir); |
| 330 | |
| 331 | // If verbose, print the list of directories that will be searched. |
| 332 | if (Verbose) { |
| 333 | fprintf(stderr, "#include \"...\" search starts here:\n"); |
| 334 | unsigned QuotedIdx = IncludeGroup[Quoted].size(); |
| 335 | for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { |
| 336 | if (i == QuotedIdx) |
| 337 | fprintf(stderr, "#include <...> search starts here:\n"); |
| 338 | const char *Name = SearchList[i].getName(); |
| 339 | const char *Suffix; |
| 340 | if (SearchList[i].isNormalDir()) |
| 341 | Suffix = ""; |
| 342 | else if (SearchList[i].isFramework()) |
| 343 | Suffix = " (framework directory)"; |
| 344 | else { |
| 345 | assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); |
| 346 | Suffix = " (headermap)"; |
| 347 | } |
| 348 | fprintf(stderr, " %s%s\n", Name, Suffix); |
| 349 | } |
| 350 | fprintf(stderr, "End of search list.\n"); |
| 351 | } |
| 352 | } |
| 353 | |