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