1 //===--- InitHeaderSearch.cpp - Initialize header search paths ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the InitHeaderSearch class.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Frontend/Utils.h"
15 #include "clang/Basic/FileManager.h"
16 #include "clang/Basic/LangOptions.h"
17 #include "clang/Config/config.h" // C_INCLUDE_DIRS
18 #include "clang/Lex/HeaderSearch.h"
19 #include "clang/Lex/HeaderSearchOptions.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringExtras.h"
24 #include "llvm/ADT/Triple.h"
25 #include "llvm/ADT/Twine.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/FileSystem.h"
28 #include "llvm/Support/Path.h"
29 #include "llvm/Support/raw_ostream.h"
31 using namespace clang;
32 using namespace clang::frontend;
36 /// InitHeaderSearch - This class makes it easier to set the search paths of
37 /// a HeaderSearch object. InitHeaderSearch stores several search path lists
38 /// internally, which can be sent to a HeaderSearch object in one swoop.
39 class InitHeaderSearch {
40 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
41 typedef std::vector<std::pair<IncludeDirGroup,
42 DirectoryLookup> >::const_iterator path_iterator;
43 std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
44 HeaderSearch &Headers;
46 std::string IncludeSysroot;
51 InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
52 : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
53 HasSysroot(!(sysroot.empty() || sysroot == "/")) {
56 /// AddPath - Add the specified path to the specified group list, prefixing
57 /// the sysroot if used.
58 void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
60 /// AddUnmappedPath - Add the specified path to the specified group list,
61 /// without performing any sysroot remapping.
62 void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
65 /// AddSystemHeaderPrefix - Add the specified prefix to the system header
67 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
68 SystemHeaderPrefixes.push_back(std::make_pair(Prefix, IsSystemHeader));
71 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
73 void AddGnuCPlusPlusIncludePaths(StringRef Base,
77 const llvm::Triple &triple);
79 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
81 void AddMinGWCPlusPlusIncludePaths(StringRef Base,
85 /// AddMinGW64CXXPaths - Add the necessary paths to support
86 /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
87 void AddMinGW64CXXPaths(StringRef Base,
90 // AddDefaultCIncludePaths - Add paths that should always be searched.
91 void AddDefaultCIncludePaths(const llvm::Triple &triple,
92 const HeaderSearchOptions &HSOpts);
94 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
96 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
97 const HeaderSearchOptions &HSOpts);
99 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
100 /// that e.g. stdio.h is found.
101 void AddDefaultIncludePaths(const LangOptions &Lang,
102 const llvm::Triple &triple,
103 const HeaderSearchOptions &HSOpts);
105 /// Realize - Merges all search path lists into one list and send it to
107 void Realize(const LangOptions &Lang);
110 } // end anonymous namespace.
112 static bool CanPrefixSysroot(StringRef Path) {
113 #if defined(LLVM_ON_WIN32)
114 return !Path.empty() && llvm::sys::path::is_separator(Path[0]);
116 return llvm::sys::path::is_absolute(Path);
120 void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
122 // Add the path with sysroot prepended, if desired and this is a system header
125 SmallString<256> MappedPathStorage;
126 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
127 if (CanPrefixSysroot(MappedPathStr)) {
128 AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
133 AddUnmappedPath(Path, Group, isFramework);
136 void InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
138 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
140 FileManager &FM = Headers.getFileMgr();
141 SmallString<256> MappedPathStorage;
142 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
144 // Compute the DirectoryLookup type.
145 SrcMgr::CharacteristicKind Type;
146 if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) {
147 Type = SrcMgr::C_User;
148 } else if (Group == ExternCSystem) {
149 Type = SrcMgr::C_ExternCSystem;
151 Type = SrcMgr::C_System;
154 // If the directory exists, add it.
155 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
156 IncludePath.push_back(
157 std::make_pair(Group, DirectoryLookup(DE, Type, isFramework)));
161 // Check to see if this is an apple-style headermap (which are not allowed to
164 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
165 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
166 // It is a headermap, add it to the search path.
167 IncludePath.push_back(
168 std::make_pair(Group,
169 DirectoryLookup(HM, Type, Group == IndexHeaderMap)));
176 llvm::errs() << "ignoring nonexistent directory \""
177 << MappedPathStr << "\"\n";
180 void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
184 const llvm::Triple &triple) {
186 AddPath(Base, CXXSystem, false);
188 // Add the multilib dirs
189 llvm::Triple::ArchType arch = triple.getArch();
190 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
192 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, false);
194 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, false);
196 // Add the backward dir
197 AddPath(Base + "/backward", CXXSystem, false);
200 void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
203 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
205 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
207 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
211 void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,
213 // Assumes Base is HeaderSearchOpts' ResourceDir
214 AddPath(Base + "/../../../include/c++/" + Version,
216 AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",
218 AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",
220 AddPath(Base + "/../../../include/c++/" + Version + "/backward",
224 void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
225 const HeaderSearchOptions &HSOpts) {
226 llvm::Triple::OSType os = triple.getOS();
228 if (HSOpts.UseStandardSystemIncludes) {
230 case llvm::Triple::CloudABI:
231 case llvm::Triple::FreeBSD:
232 case llvm::Triple::NetBSD:
233 case llvm::Triple::OpenBSD:
234 case llvm::Triple::Bitrig:
235 case llvm::Triple::NaCl:
238 // FIXME: temporary hack: hard-coded paths.
239 AddPath("/usr/local/include", System, false);
244 // Builtin includes use #include_next directives and should be positioned
245 // just prior C include dirs.
246 if (HSOpts.UseBuiltinIncludes) {
247 // Ignore the sys root, we *always* look for clang headers relative to
249 SmallString<128> P = StringRef(HSOpts.ResourceDir);
250 llvm::sys::path::append(P, "include");
251 AddUnmappedPath(P, ExternCSystem, false);
254 // All remaining additions are for system include directories, early exit if
255 // we aren't using them.
256 if (!HSOpts.UseStandardSystemIncludes)
259 // Add dirs specified via 'configure --with-c-include-dirs'.
260 StringRef CIncludeDirs(C_INCLUDE_DIRS);
261 if (CIncludeDirs != "") {
262 SmallVector<StringRef, 5> dirs;
263 CIncludeDirs.split(dirs, ":");
264 for (SmallVectorImpl<StringRef>::iterator i = dirs.begin();
267 AddPath(*i, ExternCSystem, false);
272 case llvm::Triple::Linux:
273 llvm_unreachable("Include management is handled in the driver.");
275 case llvm::Triple::CloudABI: {
276 // <sysroot>/<triple>/include
277 SmallString<128> P = StringRef(HSOpts.ResourceDir);
278 llvm::sys::path::append(P, "../../..", triple.str(), "include");
279 AddPath(P, System, false);
283 case llvm::Triple::Haiku:
284 AddPath("/boot/common/include", System, false);
285 AddPath("/boot/develop/headers/os", System, false);
286 AddPath("/boot/develop/headers/os/app", System, false);
287 AddPath("/boot/develop/headers/os/arch", System, false);
288 AddPath("/boot/develop/headers/os/device", System, false);
289 AddPath("/boot/develop/headers/os/drivers", System, false);
290 AddPath("/boot/develop/headers/os/game", System, false);
291 AddPath("/boot/develop/headers/os/interface", System, false);
292 AddPath("/boot/develop/headers/os/kernel", System, false);
293 AddPath("/boot/develop/headers/os/locale", System, false);
294 AddPath("/boot/develop/headers/os/mail", System, false);
295 AddPath("/boot/develop/headers/os/media", System, false);
296 AddPath("/boot/develop/headers/os/midi", System, false);
297 AddPath("/boot/develop/headers/os/midi2", System, false);
298 AddPath("/boot/develop/headers/os/net", System, false);
299 AddPath("/boot/develop/headers/os/storage", System, false);
300 AddPath("/boot/develop/headers/os/support", System, false);
301 AddPath("/boot/develop/headers/os/translation", System, false);
302 AddPath("/boot/develop/headers/os/add-ons/graphics", System, false);
303 AddPath("/boot/develop/headers/os/add-ons/input_server", System, false);
304 AddPath("/boot/develop/headers/os/add-ons/screen_saver", System, false);
305 AddPath("/boot/develop/headers/os/add-ons/tracker", System, false);
306 AddPath("/boot/develop/headers/os/be_apps/Deskbar", System, false);
307 AddPath("/boot/develop/headers/os/be_apps/NetPositive", System, false);
308 AddPath("/boot/develop/headers/os/be_apps/Tracker", System, false);
309 AddPath("/boot/develop/headers/cpp", System, false);
310 AddPath("/boot/develop/headers/cpp/i586-pc-haiku", System, false);
311 AddPath("/boot/develop/headers/3rdparty", System, false);
312 AddPath("/boot/develop/headers/bsd", System, false);
313 AddPath("/boot/develop/headers/glibc", System, false);
314 AddPath("/boot/develop/headers/posix", System, false);
315 AddPath("/boot/develop/headers", System, false);
317 case llvm::Triple::RTEMS:
319 case llvm::Triple::Win32:
320 switch (triple.getEnvironment()) {
321 default: llvm_unreachable("Include management is handled in the driver.");
322 case llvm::Triple::Cygnus:
323 AddPath("/usr/include/w32api", System, false);
325 case llvm::Triple::GNU:
326 // mingw-w64 crt include paths
327 // <sysroot>/i686-w64-mingw32/include
328 SmallString<128> P = StringRef(HSOpts.ResourceDir);
329 llvm::sys::path::append(P, "../../../i686-w64-mingw32/include");
330 AddPath(P, System, false);
332 // <sysroot>/x86_64-w64-mingw32/include
333 P.resize(HSOpts.ResourceDir.size());
334 llvm::sys::path::append(P, "../../../x86_64-w64-mingw32/include");
335 AddPath(P, System, false);
337 // mingw.org crt include paths
339 P.resize(HSOpts.ResourceDir.size());
340 llvm::sys::path::append(P, "../../../include");
341 AddPath(P, System, false);
342 AddPath("/mingw/include", System, false);
343 #if defined(LLVM_ON_WIN32)
344 AddPath("c:/mingw/include", System, false);
354 case llvm::Triple::CloudABI:
355 case llvm::Triple::RTEMS:
356 case llvm::Triple::NaCl:
359 AddPath("/usr/include", ExternCSystem, false);
364 void InitHeaderSearch::
365 AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
366 llvm::Triple::OSType os = triple.getOS();
367 // FIXME: temporary hack: hard-coded paths.
369 if (triple.isOSDarwin()) {
370 switch (triple.getArch()) {
373 case llvm::Triple::ppc:
374 case llvm::Triple::ppc64:
375 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
376 "powerpc-apple-darwin10", "", "ppc64",
378 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
379 "powerpc-apple-darwin10", "", "ppc64",
383 case llvm::Triple::x86:
384 case llvm::Triple::x86_64:
385 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
386 "i686-apple-darwin10", "", "x86_64", triple);
387 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
388 "i686-apple-darwin8", "", "", triple);
391 case llvm::Triple::arm:
392 case llvm::Triple::thumb:
393 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
394 "arm-apple-darwin10", "v7", "", triple);
395 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
396 "arm-apple-darwin10", "v6", "", triple);
399 case llvm::Triple::aarch64:
400 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
401 "arm64-apple-darwin10", "", "", triple);
408 case llvm::Triple::Linux:
409 llvm_unreachable("Include management is handled in the driver.");
411 case llvm::Triple::Win32:
412 switch (triple.getEnvironment()) {
413 default: llvm_unreachable("Include management is handled in the driver.");
414 case llvm::Triple::Cygnus:
416 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.7.3");
417 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
418 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
419 // g++-4 / Cygwin-1.5
420 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
422 case llvm::Triple::GNU:
423 // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
424 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
425 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.1");
426 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.2");
427 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.3");
428 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.8.0");
429 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.8.1");
430 AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.8.2");
431 // mingw.org C++ include paths
432 #if defined(LLVM_ON_WIN32)
433 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.0");
434 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.1");
435 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.2");
436 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.3");
437 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.8.0");
438 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.8.1");
439 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.8.2");
443 case llvm::Triple::DragonFly:
444 if (llvm::sys::fs::exists("/usr/lib/gcc47"))
445 AddPath("/usr/include/c++/4.7", CXXSystem, false);
447 AddPath("/usr/include/c++/4.4", CXXSystem, false);
449 case llvm::Triple::OpenBSD: {
450 std::string t = triple.getTriple();
451 if (t.substr(0, 6) == "x86_64")
452 t.replace(0, 6, "amd64");
453 AddGnuCPlusPlusIncludePaths("/usr/include/g++",
457 case llvm::Triple::Minix:
458 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
461 case llvm::Triple::Solaris:
462 AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/",
463 "i386-pc-solaris2.11", "", "", triple);
470 void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
471 const llvm::Triple &triple,
472 const HeaderSearchOptions &HSOpts) {
473 // NB: This code path is going away. All of the logic is moving into the
474 // driver which has the information necessary to do target-specific
475 // selections of default include paths. Each target which moves there will be
476 // exempted from this logic here until we can delete the entire pile of code.
477 switch (triple.getOS()) {
479 break; // Everything else continues to use this routine's logic.
481 case llvm::Triple::Linux:
484 case llvm::Triple::Win32:
485 if (triple.getEnvironment() == llvm::Triple::MSVC ||
486 triple.getEnvironment() == llvm::Triple::Itanium ||
487 triple.isOSBinFormatMachO())
492 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
493 HSOpts.UseStandardSystemIncludes) {
494 if (HSOpts.UseLibcxx) {
495 if (triple.isOSDarwin()) {
496 // On Darwin, libc++ may be installed alongside the compiler in
498 if (!HSOpts.ResourceDir.empty()) {
499 // Remove version from foo/lib/clang/version
500 StringRef NoVer = llvm::sys::path::parent_path(HSOpts.ResourceDir);
501 // Remove clang from foo/lib/clang
502 StringRef Lib = llvm::sys::path::parent_path(NoVer);
503 // Remove lib from foo/lib
504 SmallString<128> P = llvm::sys::path::parent_path(Lib);
506 // Get foo/include/c++/v1
507 llvm::sys::path::append(P, "include", "c++", "v1");
508 AddUnmappedPath(P, CXXSystem, false);
511 // On Solaris, include the support directory for things like xlocale and
512 // fudged system headers.
513 if (triple.getOS() == llvm::Triple::Solaris)
514 AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, false);
516 AddPath("/usr/include/c++/v1", CXXSystem, false);
518 AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
522 AddDefaultCIncludePaths(triple, HSOpts);
524 // Add the default framework include paths on Darwin.
525 if (HSOpts.UseStandardSystemIncludes) {
526 if (triple.isOSDarwin()) {
527 AddPath("/System/Library/Frameworks", System, true);
528 AddPath("/Library/Frameworks", System, true);
533 /// RemoveDuplicates - If there are duplicate directory entries in the specified
534 /// search list, remove the later (dead) ones. Returns the number of non-system
535 /// headers removed, which is used to update NumAngled.
536 static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
537 unsigned First, bool Verbose) {
538 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
539 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
540 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
541 unsigned NonSystemRemoved = 0;
542 for (unsigned i = First; i != SearchList.size(); ++i) {
543 unsigned DirToRemove = i;
545 const DirectoryLookup &CurEntry = SearchList[i];
547 if (CurEntry.isNormalDir()) {
548 // If this isn't the first time we've seen this dir, remove it.
549 if (SeenDirs.insert(CurEntry.getDir()).second)
551 } else if (CurEntry.isFramework()) {
552 // If this isn't the first time we've seen this framework dir, remove it.
553 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()).second)
556 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
557 // If this isn't the first time we've seen this headermap, remove it.
558 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()).second)
562 // If we have a normal #include dir/framework/headermap that is shadowed
563 // later in the chain by a system include location, we actually want to
564 // ignore the user's request and drop the user dir... keeping the system
565 // dir. This is weird, but required to emulate GCC's search path correctly.
567 // Since dupes of system dirs are rare, just rescan to find the original
568 // that we're nuking instead of using a DenseMap.
569 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
570 // Find the dir that this is the same of.
572 for (FirstDir = 0; ; ++FirstDir) {
573 assert(FirstDir != i && "Didn't find dupe?");
575 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
577 // If these are different lookup types, then they can't be the dupe.
578 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
582 if (CurEntry.isNormalDir())
583 isSame = SearchEntry.getDir() == CurEntry.getDir();
584 else if (CurEntry.isFramework())
585 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
587 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
588 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
595 // If the first dir in the search path is a non-system dir, zap it
596 // instead of the system one.
597 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
598 DirToRemove = FirstDir;
602 llvm::errs() << "ignoring duplicate directory \""
603 << CurEntry.getName() << "\"\n";
604 if (DirToRemove != i)
605 llvm::errs() << " as it is a non-system directory that duplicates "
606 << "a system directory\n";
608 if (DirToRemove != i)
611 // This is reached if the current entry is a duplicate. Remove the
612 // DirToRemove (usually the current dir).
613 SearchList.erase(SearchList.begin()+DirToRemove);
616 return NonSystemRemoved;
620 void InitHeaderSearch::Realize(const LangOptions &Lang) {
621 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
622 std::vector<DirectoryLookup> SearchList;
623 SearchList.reserve(IncludePath.size());
625 // Quoted arguments go first.
626 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
628 if (it->first == Quoted)
629 SearchList.push_back(it->second);
631 // Deduplicate and remember index.
632 RemoveDuplicates(SearchList, 0, Verbose);
633 unsigned NumQuoted = SearchList.size();
635 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
637 if (it->first == Angled || it->first == IndexHeaderMap)
638 SearchList.push_back(it->second);
641 RemoveDuplicates(SearchList, NumQuoted, Verbose);
642 unsigned NumAngled = SearchList.size();
644 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
646 if (it->first == System || it->first == ExternCSystem ||
647 (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) ||
648 (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) ||
649 (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) ||
650 (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem))
651 SearchList.push_back(it->second);
654 for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
656 if (it->first == After)
657 SearchList.push_back(it->second);
660 // Remove duplicates across both the Angled and System directories. GCC does
661 // this and failing to remove duplicates across these two groups breaks
663 unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
664 NumAngled -= NonSystemRemoved;
666 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
667 Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
669 Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes);
671 // If verbose, print the list of directories that will be searched.
673 llvm::errs() << "#include \"...\" search starts here:\n";
674 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
676 llvm::errs() << "#include <...> search starts here:\n";
677 const char *Name = SearchList[i].getName();
679 if (SearchList[i].isNormalDir())
681 else if (SearchList[i].isFramework())
682 Suffix = " (framework directory)";
684 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
685 Suffix = " (headermap)";
687 llvm::errs() << " " << Name << Suffix << "\n";
689 llvm::errs() << "End of search list.\n";
693 void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
694 const HeaderSearchOptions &HSOpts,
695 const LangOptions &Lang,
696 const llvm::Triple &Triple) {
697 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
699 // Add the user defined entries.
700 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
701 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
702 if (E.IgnoreSysRoot) {
703 Init.AddUnmappedPath(E.Path, E.Group, E.IsFramework);
705 Init.AddPath(E.Path, E.Group, E.IsFramework);
709 Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
711 for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i)
712 Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix,
713 HSOpts.SystemHeaderPrefixes[i].IsSystemHeader);
715 if (HSOpts.UseBuiltinIncludes) {
716 // Set up the builtin include directory in the module map.
717 SmallString<128> P = StringRef(HSOpts.ResourceDir);
718 llvm::sys::path::append(P, "include");
719 if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P))
720 HS.getModuleMap().setBuiltinIncludeDir(Dir);