blob: d8f0881debd338727054698c99c0398ac5264e45 [file] [log] [blame]
Nick Lewyckye602efc2010-07-25 03:12:58 +00001//===--- InitHeaderSearch.cpp - Initialize header search paths ------------===//
Nico Webered9b4102008-08-22 09:25:22 +00002//
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 Dunbar4df9aa22009-11-09 23:02:47 +000014#include "clang/Frontend/Utils.h"
Nico Webered9b4102008-08-22 09:25:22 +000015#include "clang/Basic/FileManager.h"
16#include "clang/Basic/LangOptions.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "clang/Config/config.h" // C_INCLUDE_DIRS
Chandler Carruthaa36b892015-12-30 03:40:23 +000018#include "clang/Lex/HeaderMap.h"
Daniel Dunbar08d5669b2009-11-07 04:20:50 +000019#include "clang/Lex/HeaderSearch.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000020#include "clang/Lex/HeaderSearchOptions.h"
Nico Webered9b4102008-08-22 09:25:22 +000021#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000022#include "llvm/ADT/SmallString.h"
Rafael Espindola46129b02009-11-13 05:13:58 +000023#include "llvm/ADT/SmallVector.h"
Rafael Espindolaf401fa02009-11-12 05:48:41 +000024#include "llvm/ADT/StringExtras.h"
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000025#include "llvm/ADT/Triple.h"
Benjamin Kramerc6ad84c2009-12-08 12:38:20 +000026#include "llvm/ADT/Twine.h"
Chandler Carruthdf527832011-11-04 23:49:05 +000027#include "llvm/Support/ErrorHandling.h"
John McCall65b8da02013-04-11 22:55:55 +000028#include "llvm/Support/FileSystem.h"
Michael J. Spencer8aaf4992010-11-29 18:12:39 +000029#include "llvm/Support/Path.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000030#include "llvm/Support/raw_ostream.h"
Dylan Noblesmith86780e92012-02-01 14:25:28 +000031
Nico Webered9b4102008-08-22 09:25:22 +000032using namespace clang;
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000033using namespace clang::frontend;
34
35namespace {
36
37/// InitHeaderSearch - This class makes it easier to set the search paths of
38/// a HeaderSearch object. InitHeaderSearch stores several search path lists
39/// internally, which can be sent to a HeaderSearch object in one swoop.
40class InitHeaderSearch {
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +000041 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
42 typedef std::vector<std::pair<IncludeDirGroup,
43 DirectoryLookup> >::const_iterator path_iterator;
Richard Smith8acadcb2012-06-13 20:27:03 +000044 std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
Chris Lattner0c64f4b2011-06-16 22:56:45 +000045 HeaderSearch &Headers;
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000046 bool Verbose;
Michael J. Spencerbc7fcc22010-12-25 20:09:27 +000047 std::string IncludeSysroot;
Daniel Dunbar335a37b2013-01-29 23:59:43 +000048 bool HasSysroot;
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000049
50public:
51
Chris Lattner0e62c1c2011-07-23 10:55:15 +000052 InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
Michael J. Spencerbc7fcc22010-12-25 20:09:27 +000053 : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
Daniel Dunbar335a37b2013-01-29 23:59:43 +000054 HasSysroot(!(sysroot.empty() || sysroot == "/")) {
Chandler Carrutheb842002010-11-15 07:15:26 +000055 }
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000056
Daniel Dunbarc6c23752013-01-30 01:06:03 +000057 /// AddPath - Add the specified path to the specified group list, prefixing
58 /// the sysroot if used.
59 void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
60
61 /// AddUnmappedPath - Add the specified path to the specified group list,
62 /// without performing any sysroot remapping.
63 void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
64 bool isFramework);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000065
Richard Smith8acadcb2012-06-13 20:27:03 +000066 /// AddSystemHeaderPrefix - Add the specified prefix to the system header
67 /// prefix list.
68 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
Benjamin Kramer3204b152015-05-29 19:42:19 +000069 SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
Richard Smith8acadcb2012-06-13 20:27:03 +000070 }
71
mike-m6fa3cd22010-05-05 17:00:31 +000072 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000073 /// libstdc++.
Chris Lattner0e62c1c2011-07-23 10:55:15 +000074 void AddGnuCPlusPlusIncludePaths(StringRef Base,
75 StringRef ArchDir,
76 StringRef Dir32,
77 StringRef Dir64,
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000078 const llvm::Triple &triple);
79
Michael J. Spencerbc721822010-12-21 16:45:42 +000080 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000081 /// libstdc++.
Aaron Ballmaneceaddc2012-03-25 22:46:17 +000082 void AddMinGWCPlusPlusIncludePaths(StringRef Base,
83 StringRef Arch,
84 StringRef Version);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000085
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000086 // AddDefaultCIncludePaths - Add paths that should always be searched.
mike-mc6da2612010-05-16 19:03:52 +000087 void AddDefaultCIncludePaths(const llvm::Triple &triple,
88 const HeaderSearchOptions &HSOpts);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000089
90 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
91 // compiling c++.
Douglas Gregor7a200962011-06-27 15:47:15 +000092 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
93 const HeaderSearchOptions &HSOpts);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000094
95 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
96 /// that e.g. stdio.h is found.
Daniel Dunbarb25bfde2011-10-11 18:20:10 +000097 void AddDefaultIncludePaths(const LangOptions &Lang,
98 const llvm::Triple &triple,
99 const HeaderSearchOptions &HSOpts);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +0000100
101 /// Realize - Merges all search path lists into one list and send it to
102 /// HeaderSearch.
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000103 void Realize(const LangOptions &Lang);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +0000104};
105
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000106} // end anonymous namespace.
Nico Webered9b4102008-08-22 09:25:22 +0000107
Daniel Dunbar2e8eb012013-01-29 23:59:37 +0000108static bool CanPrefixSysroot(StringRef Path) {
Hans Wennborg501eadb2014-03-12 16:07:46 +0000109#if defined(LLVM_ON_WIN32)
Daniel Dunbar2e8eb012013-01-29 23:59:37 +0000110 return !Path.empty() && llvm::sys::path::is_separator(Path[0]);
111#else
112 return llvm::sys::path::is_absolute(Path);
113#endif
114}
115
Daniel Dunbar9f237452013-01-30 00:19:24 +0000116void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
Daniel Dunbarc6c23752013-01-30 01:06:03 +0000117 bool isFramework) {
118 // Add the path with sysroot prepended, if desired and this is a system header
119 // group.
120 if (HasSysroot) {
121 SmallString<256> MappedPathStorage;
122 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
123 if (CanPrefixSysroot(MappedPathStr)) {
124 AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
125 return;
126 }
127 }
Mike Stump11289f42009-09-09 15:08:12 +0000128
Daniel Dunbarc6c23752013-01-30 01:06:03 +0000129 AddUnmappedPath(Path, Group, isFramework);
130}
131
132void InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
133 bool isFramework) {
134 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
135
136 FileManager &FM = Headers.getFileMgr();
Dylan Noblesmith2c1dd272012-02-05 02:13:05 +0000137 SmallString<256> MappedPathStorage;
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000138 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
Mike Stump11289f42009-09-09 15:08:12 +0000139
Nico Webered9b4102008-08-22 09:25:22 +0000140 // Compute the DirectoryLookup type.
Chris Lattner66a740e2008-10-27 01:19:25 +0000141 SrcMgr::CharacteristicKind Type;
Daniel Dunbar9f237452013-01-30 00:19:24 +0000142 if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) {
Chris Lattnerb03dc762008-09-26 21:18:42 +0000143 Type = SrcMgr::C_User;
Daniel Dunbar9f237452013-01-30 00:19:24 +0000144 } else if (Group == ExternCSystem) {
Chris Lattnerb03dc762008-09-26 21:18:42 +0000145 Type = SrcMgr::C_ExternCSystem;
Daniel Dunbar9f237452013-01-30 00:19:24 +0000146 } else {
147 Type = SrcMgr::C_System;
148 }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Nico Webered9b4102008-08-22 09:25:22 +0000150 // If the directory exists, add it.
Chris Lattner5159f612010-11-23 08:35:12 +0000151 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
Daniel Dunbarae4feb62013-01-25 01:50:28 +0000152 IncludePath.push_back(
153 std::make_pair(Group, DirectoryLookup(DE, Type, isFramework)));
Nico Webered9b4102008-08-22 09:25:22 +0000154 return;
155 }
Mike Stump11289f42009-09-09 15:08:12 +0000156
Nico Webered9b4102008-08-22 09:25:22 +0000157 // Check to see if this is an apple-style headermap (which are not allowed to
158 // be frameworks).
159 if (!isFramework) {
Chris Lattner5159f612010-11-23 08:35:12 +0000160 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
Nico Webered9b4102008-08-22 09:25:22 +0000161 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
162 // It is a headermap, add it to the search path.
Daniel Dunbarae4feb62013-01-25 01:50:28 +0000163 IncludePath.push_back(
164 std::make_pair(Group,
165 DirectoryLookup(HM, Type, Group == IndexHeaderMap)));
Nico Webered9b4102008-08-22 09:25:22 +0000166 return;
167 }
168 }
169 }
Mike Stump11289f42009-09-09 15:08:12 +0000170
Nico Webered9b4102008-08-22 09:25:22 +0000171 if (Verbose)
Chandler Carruth03ac1b02010-11-15 00:48:13 +0000172 llvm::errs() << "ignoring nonexistent directory \""
173 << MappedPathStr << "\"\n";
Nico Webered9b4102008-08-22 09:25:22 +0000174}
175
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000176void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
177 StringRef ArchDir,
178 StringRef Dir32,
179 StringRef Dir64,
Rafael Espindola0a1ac332009-10-14 17:09:44 +0000180 const llvm::Triple &triple) {
Rafael Espindola962e5182009-11-23 16:31:19 +0000181 // Add the base dir
Daniel Dunbar9f237452013-01-30 00:19:24 +0000182 AddPath(Base, CXXSystem, false);
Rafael Espindolaabab8792009-11-16 19:49:37 +0000183
184 // Add the multilib dirs
Rafael Espindola0a1ac332009-10-14 17:09:44 +0000185 llvm::Triple::ArchType arch = triple.getArch();
186 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
Rafael Espindola0a1ac332009-10-14 17:09:44 +0000187 if (is64bit)
Daniel Dunbar9f237452013-01-30 00:19:24 +0000188 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, false);
Rafael Espindola0a1ac332009-10-14 17:09:44 +0000189 else
Daniel Dunbar9f237452013-01-30 00:19:24 +0000190 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, false);
Rafael Espindola962e5182009-11-23 16:31:19 +0000191
192 // Add the backward dir
Daniel Dunbar9f237452013-01-30 00:19:24 +0000193 AddPath(Base + "/backward", CXXSystem, false);
Rafael Espindolac3031a92009-10-06 01:33:02 +0000194}
Nico Webered9b4102008-08-22 09:25:22 +0000195
Aaron Ballman9345d682012-03-25 15:47:41 +0000196void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
Aaron Ballmaneceaddc2012-03-25 22:46:17 +0000197 StringRef Arch,
198 StringRef Version) {
199 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
Daniel Dunbar9f237452013-01-30 00:19:24 +0000200 CXXSystem, false);
Aaron Ballmaneceaddc2012-03-25 22:46:17 +0000201 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
Daniel Dunbar9f237452013-01-30 00:19:24 +0000202 CXXSystem, false);
Aaron Ballmaneceaddc2012-03-25 22:46:17 +0000203 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
Daniel Dunbar9f237452013-01-30 00:19:24 +0000204 CXXSystem, false);
Aaron Ballman9345d682012-03-25 15:47:41 +0000205}
206
mike-mc6da2612010-05-16 19:03:52 +0000207void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
208 const HeaderSearchOptions &HSOpts) {
Benjamin Kramer24f1d3e2011-02-02 18:59:27 +0000209 llvm::Triple::OSType os = triple.getOS();
210
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000211 if (HSOpts.UseStandardSystemIncludes) {
212 switch (os) {
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000213 case llvm::Triple::CloudABI:
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000214 case llvm::Triple::FreeBSD:
215 case llvm::Triple::NetBSD:
Hans Wennborgae298f22012-08-02 12:27:08 +0000216 case llvm::Triple::OpenBSD:
Eli Friedman9fa28852012-08-08 23:57:20 +0000217 case llvm::Triple::Bitrig:
Derek Schuff6ab52fa2015-03-30 20:31:33 +0000218 case llvm::Triple::NaCl:
Filipe Cabecinhasc888e192015-10-14 12:25:43 +0000219 case llvm::Triple::PS4:
Andrey Bokhanko0b135e02015-12-16 13:27:38 +0000220 case llvm::Triple::ELFIAMCU:
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000221 break;
Yaron Keren1c0070c2015-07-02 04:45:27 +0000222 case llvm::Triple::Win32:
223 if (triple.getEnvironment() != llvm::Triple::Cygnus)
224 break;
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000225 default:
226 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbar9f237452013-01-30 00:19:24 +0000227 AddPath("/usr/local/include", System, false);
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000228 break;
229 }
Benjamin Kramer24f1d3e2011-02-02 18:59:27 +0000230 }
mike-mc6da2612010-05-16 19:03:52 +0000231
232 // Builtin includes use #include_next directives and should be positioned
233 // just prior C include dirs.
234 if (HSOpts.UseBuiltinIncludes) {
235 // Ignore the sys root, we *always* look for clang headers relative to
236 // supplied path.
Benjamin Kramer33d43302013-06-13 14:26:04 +0000237 SmallString<128> P = StringRef(HSOpts.ResourceDir);
238 llvm::sys::path::append(P, "include");
Yaron Keren92e1b622015-03-18 10:17:07 +0000239 AddUnmappedPath(P, ExternCSystem, false);
mike-mc6da2612010-05-16 19:03:52 +0000240 }
241
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000242 // All remaining additions are for system include directories, early exit if
243 // we aren't using them.
244 if (!HSOpts.UseStandardSystemIncludes)
245 return;
246
mike-mc6da2612010-05-16 19:03:52 +0000247 // Add dirs specified via 'configure --with-c-include-dirs'.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000248 StringRef CIncludeDirs(C_INCLUDE_DIRS);
Daniel Dunbar71ed08b2009-11-12 07:28:29 +0000249 if (CIncludeDirs != "") {
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000250 SmallVector<StringRef, 5> dirs;
Rafael Espindola46129b02009-11-13 05:13:58 +0000251 CIncludeDirs.split(dirs, ":");
Yaron Keren54bb2152015-10-01 11:19:28 +0000252 for (StringRef dir : dirs)
253 AddPath(dir, ExternCSystem, false);
Rafael Espindolaf401fa02009-11-12 05:48:41 +0000254 return;
255 }
Benjamin Kramer24f1d3e2011-02-02 18:59:27 +0000256
Mike Stump904ad902009-10-08 23:29:47 +0000257 switch (os) {
Chandler Carrutha796f532011-11-05 20:17:13 +0000258 case llvm::Triple::Linux:
Chandler Carrutha796f532011-11-05 20:17:13 +0000259 llvm_unreachable("Include management is handled in the driver.");
Chandler Carruthdf527832011-11-04 23:49:05 +0000260
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000261 case llvm::Triple::CloudABI: {
262 // <sysroot>/<triple>/include
263 SmallString<128> P = StringRef(HSOpts.ResourceDir);
264 llvm::sys::path::append(P, "../../..", triple.str(), "include");
Yaron Keren92e1b622015-03-18 10:17:07 +0000265 AddPath(P, System, false);
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000266 break;
267 }
268
Chris Lattnerb986aba2010-04-11 19:29:39 +0000269 case llvm::Triple::Haiku:
Reid Kleckner330fb172016-05-11 16:19:05 +0000270 AddPath("/boot/system/non-packaged/develop/headers", System, false);
271 AddPath("/boot/system/develop/headers/os", System, false);
272 AddPath("/boot/system/develop/headers/os/app", System, false);
273 AddPath("/boot/system/develop/headers/os/arch", System, false);
274 AddPath("/boot/system/develop/headers/os/device", System, false);
275 AddPath("/boot/system/develop/headers/os/drivers", System, false);
276 AddPath("/boot/system/develop/headers/os/game", System, false);
277 AddPath("/boot/system/develop/headers/os/interface", System, false);
278 AddPath("/boot/system/develop/headers/os/kernel", System, false);
279 AddPath("/boot/system/develop/headers/os/locale", System, false);
280 AddPath("/boot/system/develop/headers/os/mail", System, false);
281 AddPath("/boot/system/develop/headers/os/media", System, false);
282 AddPath("/boot/system/develop/headers/os/midi", System, false);
283 AddPath("/boot/system/develop/headers/os/midi2", System, false);
284 AddPath("/boot/system/develop/headers/os/net", System, false);
285 AddPath("/boot/system/develop/headers/os/opengl", System, false);
286 AddPath("/boot/system/develop/headers/os/storage", System, false);
287 AddPath("/boot/system/develop/headers/os/support", System, false);
288 AddPath("/boot/system/develop/headers/os/translation", System, false);
289 AddPath("/boot/system/develop/headers/os/add-ons/graphics", System, false);
290 AddPath("/boot/system/develop/headers/os/add-ons/input_server", System, false);
291 AddPath("/boot/system/develop/headers/os/add-ons/mail_daemon", System, false);
292 AddPath("/boot/system/develop/headers/os/add-ons/registrar", System, false);
293 AddPath("/boot/system/develop/headers/os/add-ons/screen_saver", System, false);
294 AddPath("/boot/system/develop/headers/os/add-ons/tracker", System, false);
295 AddPath("/boot/system/develop/headers/os/be_apps/Deskbar", System, false);
296 AddPath("/boot/system/develop/headers/os/be_apps/NetPositive", System, false);
297 AddPath("/boot/system/develop/headers/os/be_apps/Tracker", System, false);
298 AddPath("/boot/system/develop/headers/3rdparty", System, false);
299 AddPath("/boot/system/develop/headers/bsd", System, false);
300 AddPath("/boot/system/develop/headers/glibc", System, false);
301 AddPath("/boot/system/develop/headers/posix", System, false);
302 AddPath("/boot/system/develop/headers", System, false);
Eli Friedman04831922010-08-22 01:00:03 +0000303 break;
Douglas Gregor9fabd852011-07-01 22:41:14 +0000304 case llvm::Triple::RTEMS:
305 break;
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000306 case llvm::Triple::Win32:
307 switch (triple.getEnvironment()) {
308 default: llvm_unreachable("Include management is handled in the driver.");
309 case llvm::Triple::Cygnus:
310 AddPath("/usr/include/w32api", System, false);
311 break;
312 case llvm::Triple::GNU:
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000313 break;
Douglas Gregor7a200962011-06-27 15:47:15 +0000314 }
Mike Stump904ad902009-10-08 23:29:47 +0000315 break;
316 default:
Mike Stump904ad902009-10-08 23:29:47 +0000317 break;
318 }
John Thompson4334ce62009-10-13 18:51:32 +0000319
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000320 switch (os) {
321 case llvm::Triple::CloudABI:
322 case llvm::Triple::RTEMS:
Derek Schuff6ab52fa2015-03-30 20:31:33 +0000323 case llvm::Triple::NaCl:
Andrey Bokhanko0b135e02015-12-16 13:27:38 +0000324 case llvm::Triple::ELFIAMCU:
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000325 break;
Filipe Cabecinhasc888e192015-10-14 12:25:43 +0000326 case llvm::Triple::PS4: {
327 // <isysroot> gets prepended later in AddPath().
328 std::string BaseSDKPath = "";
329 if (!HasSysroot) {
330 const char *envValue = getenv("SCE_PS4_SDK_DIR");
331 if (envValue)
332 BaseSDKPath = envValue;
333 else {
334 // HSOpts.ResourceDir variable contains the location of Clang's
335 // resource files.
336 // Assuming that Clang is configured for PS4 without
337 // --with-clang-resource-dir option, the location of Clang's resource
338 // files is <SDK_DIR>/host_tools/lib/clang
339 SmallString<128> P = StringRef(HSOpts.ResourceDir);
340 llvm::sys::path::append(P, "../../..");
341 BaseSDKPath = P.str();
342 }
343 }
344 AddPath(BaseSDKPath + "/target/include", System, false);
345 if (triple.isPS4CPU())
346 AddPath(BaseSDKPath + "/target/include_common", System, false);
347 }
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000348 default:
Daniel Dunbar9f237452013-01-30 00:19:24 +0000349 AddPath("/usr/include", ExternCSystem, false);
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000350 break;
351 }
Rafael Espindola177f1d92009-10-27 14:47:31 +0000352}
353
Chris Lattner5561bf32010-05-05 05:28:39 +0000354void InitHeaderSearch::
Douglas Gregor7a200962011-06-27 15:47:15 +0000355AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
Rafael Espindola177f1d92009-10-27 14:47:31 +0000356 llvm::Triple::OSType os = triple.getOS();
357 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbar14ad22f2011-04-19 21:43:27 +0000358
359 if (triple.isOSDarwin()) {
Daniel Dunbareaff5fa2010-05-28 01:54:31 +0000360 switch (triple.getArch()) {
361 default: break;
362
NAKAMURA Takumi029d74b2011-02-17 08:50:50 +0000363 case llvm::Triple::ppc:
Douglas Gregoreb0bdf02010-05-29 01:15:12 +0000364 case llvm::Triple::ppc64:
Douglas Gregor117ef272010-05-29 01:21:11 +0000365 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
NAKAMURA Takumi029d74b2011-02-17 08:50:50 +0000366 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor117ef272010-05-29 01:21:11 +0000367 triple);
Douglas Gregoreb0bdf02010-05-29 01:15:12 +0000368 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
NAKAMURA Takumi029d74b2011-02-17 08:50:50 +0000369 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregoreb0bdf02010-05-29 01:15:12 +0000370 triple);
371 break;
372
Daniel Dunbareaff5fa2010-05-28 01:54:31 +0000373 case llvm::Triple::x86:
374 case llvm::Triple::x86_64:
375 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
376 "i686-apple-darwin10", "", "x86_64", triple);
377 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
378 "i686-apple-darwin8", "", "", triple);
379 break;
380
381 case llvm::Triple::arm:
382 case llvm::Triple::thumb:
383 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
384 "arm-apple-darwin10", "v7", "", triple);
385 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
386 "arm-apple-darwin10", "v6", "", triple);
387 break;
Tim Northovera2ee4332014-03-29 15:09:45 +0000388
Tim Northover573cbee2014-05-24 12:52:07 +0000389 case llvm::Triple::aarch64:
Tim Northovera2ee4332014-03-29 15:09:45 +0000390 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
391 "arm64-apple-darwin10", "", "", triple);
392 break;
Daniel Dunbareaff5fa2010-05-28 01:54:31 +0000393 }
Daniel Dunbar14ad22f2011-04-19 21:43:27 +0000394 return;
395 }
396
397 switch (os) {
Chandler Carrutha796f532011-11-05 20:17:13 +0000398 case llvm::Triple::Linux:
Chandler Carrutha796f532011-11-05 20:17:13 +0000399 llvm_unreachable("Include management is handled in the driver.");
Sylvestre Ledru75c29142014-08-18 15:13:44 +0000400 break;
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000401 case llvm::Triple::Win32:
402 switch (triple.getEnvironment()) {
403 default: llvm_unreachable("Include management is handled in the driver.");
404 case llvm::Triple::Cygnus:
405 // Cygwin-1.7
406 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.7.3");
407 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
408 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
409 // g++-4 / Cygwin-1.5
410 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
411 break;
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000412 }
Yaron Keren1c0070c2015-07-02 04:45:27 +0000413 break;
Chris Lattner002ba6b2010-01-09 05:41:14 +0000414 case llvm::Triple::DragonFly:
Dimitry Andricf59a2b32015-12-27 10:01:44 +0000415 AddPath("/usr/include/c++/5.0", CXXSystem, false);
Chris Lattner002ba6b2010-01-09 05:41:14 +0000416 break;
Daniel Dunbarea3813f2010-08-01 23:13:54 +0000417 case llvm::Triple::OpenBSD: {
418 std::string t = triple.getTriple();
419 if (t.substr(0, 6) == "x86_64")
420 t.replace(0, 6, "amd64");
421 AddGnuCPlusPlusIncludePaths("/usr/include/g++",
422 t, "", "", triple);
423 break;
424 }
Chris Lattner3e2ee142010-07-07 16:01:42 +0000425 case llvm::Triple::Minix:
426 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
427 "", "", "", triple);
428 break;
Rafael Espindola177f1d92009-10-27 14:47:31 +0000429 default:
430 break;
431 }
432}
433
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000434void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
435 const llvm::Triple &triple,
mike-mc6da2612010-05-16 19:03:52 +0000436 const HeaderSearchOptions &HSOpts) {
Chandler Carruthdf527832011-11-04 23:49:05 +0000437 // NB: This code path is going away. All of the logic is moving into the
438 // driver which has the information necessary to do target-specific
439 // selections of default include paths. Each target which moves there will be
440 // exempted from this logic here until we can delete the entire pile of code.
441 switch (triple.getOS()) {
442 default:
443 break; // Everything else continues to use this routine's logic.
444
Chandler Carrutha796f532011-11-05 20:17:13 +0000445 case llvm::Triple::Linux:
Chandler Carruthdf527832011-11-04 23:49:05 +0000446 return;
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000447
448 case llvm::Triple::Win32:
Yaron Keren1c0070c2015-07-02 04:45:27 +0000449 if (triple.getEnvironment() != llvm::Triple::Cygnus ||
Eric Christopher610952e2014-12-05 00:22:48 +0000450 triple.isOSBinFormatMachO())
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000451 return;
452 break;
Chandler Carruthdf527832011-11-04 23:49:05 +0000453 }
454
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000455 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
456 HSOpts.UseStandardSystemIncludes) {
Douglas Gregorf4016fd2011-07-29 20:21:18 +0000457 if (HSOpts.UseLibcxx) {
458 if (triple.isOSDarwin()) {
459 // On Darwin, libc++ may be installed alongside the compiler in
Justin Bogner13a641b2013-11-15 18:07:59 +0000460 // include/c++/v1.
Benjamin Kramer33d43302013-06-13 14:26:04 +0000461 if (!HSOpts.ResourceDir.empty()) {
462 // Remove version from foo/lib/clang/version
463 StringRef NoVer = llvm::sys::path::parent_path(HSOpts.ResourceDir);
464 // Remove clang from foo/lib/clang
Justin Bogner13a641b2013-11-15 18:07:59 +0000465 StringRef Lib = llvm::sys::path::parent_path(NoVer);
466 // Remove lib from foo/lib
467 SmallString<128> P = llvm::sys::path::parent_path(Lib);
468
469 // Get foo/include/c++/v1
470 llvm::sys::path::append(P, "include", "c++", "v1");
Yaron Keren92e1b622015-03-18 10:17:07 +0000471 AddUnmappedPath(P, CXXSystem, false);
Douglas Gregorf4016fd2011-07-29 20:21:18 +0000472 }
473 }
Daniel Dunbar9f237452013-01-30 00:19:24 +0000474 AddPath("/usr/include/c++/v1", CXXSystem, false);
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000475 } else {
Douglas Gregor7a200962011-06-27 15:47:15 +0000476 AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000477 }
Bob Wilsonb02ea3d2011-06-21 21:12:29 +0000478 }
Rafael Espindola962e5182009-11-23 16:31:19 +0000479
mike-mc6da2612010-05-16 19:03:52 +0000480 AddDefaultCIncludePaths(triple, HSOpts);
Daniel Dunbarec879912009-11-07 04:20:39 +0000481
482 // Add the default framework include paths on Darwin.
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000483 if (HSOpts.UseStandardSystemIncludes) {
484 if (triple.isOSDarwin()) {
Daniel Dunbar9f237452013-01-30 00:19:24 +0000485 AddPath("/System/Library/Frameworks", System, true);
486 AddPath("/Library/Frameworks", System, true);
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000487 }
Daniel Dunbarec879912009-11-07 04:20:39 +0000488 }
Rafael Espindola177f1d92009-10-27 14:47:31 +0000489}
490
Nico Webered9b4102008-08-22 09:25:22 +0000491/// RemoveDuplicates - If there are duplicate directory entries in the specified
Chad Rosierfd3c90c2011-10-10 18:44:24 +0000492/// search list, remove the later (dead) ones. Returns the number of non-system
493/// headers removed, which is used to update NumAngled.
494static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
495 unsigned First, bool Verbose) {
Nico Webered9b4102008-08-22 09:25:22 +0000496 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
497 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
498 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
Chad Rosierfd3c90c2011-10-10 18:44:24 +0000499 unsigned NonSystemRemoved = 0;
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000500 for (unsigned i = First; i != SearchList.size(); ++i) {
Chris Lattnere744d322008-09-26 17:46:45 +0000501 unsigned DirToRemove = i;
Mike Stump11289f42009-09-09 15:08:12 +0000502
Chris Lattner24c911e2009-02-08 01:00:10 +0000503 const DirectoryLookup &CurEntry = SearchList[i];
Mike Stump11289f42009-09-09 15:08:12 +0000504
Chris Lattner24c911e2009-02-08 01:00:10 +0000505 if (CurEntry.isNormalDir()) {
Nico Webered9b4102008-08-22 09:25:22 +0000506 // If this isn't the first time we've seen this dir, remove it.
David Blaikie82e95a32014-11-19 07:49:47 +0000507 if (SeenDirs.insert(CurEntry.getDir()).second)
Nico Webered9b4102008-08-22 09:25:22 +0000508 continue;
Chris Lattner24c911e2009-02-08 01:00:10 +0000509 } else if (CurEntry.isFramework()) {
Nico Webered9b4102008-08-22 09:25:22 +0000510 // If this isn't the first time we've seen this framework dir, remove it.
David Blaikie82e95a32014-11-19 07:49:47 +0000511 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()).second)
Nico Webered9b4102008-08-22 09:25:22 +0000512 continue;
Nico Webered9b4102008-08-22 09:25:22 +0000513 } else {
Chris Lattner24c911e2009-02-08 01:00:10 +0000514 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
Nico Webered9b4102008-08-22 09:25:22 +0000515 // If this isn't the first time we've seen this headermap, remove it.
David Blaikie82e95a32014-11-19 07:49:47 +0000516 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()).second)
Nico Webered9b4102008-08-22 09:25:22 +0000517 continue;
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000518 }
Mike Stump11289f42009-09-09 15:08:12 +0000519
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000520 // If we have a normal #include dir/framework/headermap that is shadowed
521 // later in the chain by a system include location, we actually want to
522 // ignore the user's request and drop the user dir... keeping the system
523 // dir. This is weird, but required to emulate GCC's search path correctly.
524 //
525 // Since dupes of system dirs are rare, just rescan to find the original
526 // that we're nuking instead of using a DenseMap.
Chris Lattner24c911e2009-02-08 01:00:10 +0000527 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000528 // Find the dir that this is the same of.
529 unsigned FirstDir;
530 for (FirstDir = 0; ; ++FirstDir) {
531 assert(FirstDir != i && "Didn't find dupe?");
Mike Stump11289f42009-09-09 15:08:12 +0000532
Chris Lattner24c911e2009-02-08 01:00:10 +0000533 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
534
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000535 // If these are different lookup types, then they can't be the dupe.
Chris Lattner24c911e2009-02-08 01:00:10 +0000536 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000537 continue;
Mike Stump11289f42009-09-09 15:08:12 +0000538
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000539 bool isSame;
Chris Lattner24c911e2009-02-08 01:00:10 +0000540 if (CurEntry.isNormalDir())
541 isSame = SearchEntry.getDir() == CurEntry.getDir();
542 else if (CurEntry.isFramework())
543 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000544 else {
Chris Lattner24c911e2009-02-08 01:00:10 +0000545 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
546 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000547 }
Mike Stump11289f42009-09-09 15:08:12 +0000548
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000549 if (isSame)
550 break;
551 }
Mike Stump11289f42009-09-09 15:08:12 +0000552
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000553 // If the first dir in the search path is a non-system dir, zap it
554 // instead of the system one.
555 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
556 DirToRemove = FirstDir;
557 }
558
559 if (Verbose) {
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000560 llvm::errs() << "ignoring duplicate directory \""
561 << CurEntry.getName() << "\"\n";
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000562 if (DirToRemove != i)
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000563 llvm::errs() << " as it is a non-system directory that duplicates "
564 << "a system directory\n";
Nico Webered9b4102008-08-22 09:25:22 +0000565 }
Chad Rosierfd3c90c2011-10-10 18:44:24 +0000566 if (DirToRemove != i)
567 ++NonSystemRemoved;
Mike Stump11289f42009-09-09 15:08:12 +0000568
Chris Lattnere744d322008-09-26 17:46:45 +0000569 // This is reached if the current entry is a duplicate. Remove the
570 // DirToRemove (usually the current dir).
571 SearchList.erase(SearchList.begin()+DirToRemove);
Nico Webered9b4102008-08-22 09:25:22 +0000572 --i;
573 }
Chad Rosierfd3c90c2011-10-10 18:44:24 +0000574 return NonSystemRemoved;
Nico Webered9b4102008-08-22 09:25:22 +0000575}
576
577
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000578void InitHeaderSearch::Realize(const LangOptions &Lang) {
Nico Webered9b4102008-08-22 09:25:22 +0000579 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
580 std::vector<DirectoryLookup> SearchList;
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000581 SearchList.reserve(IncludePath.size());
Mike Stump11289f42009-09-09 15:08:12 +0000582
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000583 // Quoted arguments go first.
Yaron Keren54bb2152015-10-01 11:19:28 +0000584 for (auto &Include : IncludePath)
585 if (Include.first == Quoted)
586 SearchList.push_back(Include.second);
587
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000588 // Deduplicate and remember index.
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000589 RemoveDuplicates(SearchList, 0, Verbose);
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000590 unsigned NumQuoted = SearchList.size();
Mike Stump11289f42009-09-09 15:08:12 +0000591
Yaron Keren54bb2152015-10-01 11:19:28 +0000592 for (auto &Include : IncludePath)
593 if (Include.first == Angled || Include.first == IndexHeaderMap)
594 SearchList.push_back(Include.second);
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000595
596 RemoveDuplicates(SearchList, NumQuoted, Verbose);
597 unsigned NumAngled = SearchList.size();
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000598
Yaron Keren54bb2152015-10-01 11:19:28 +0000599 for (auto &Include : IncludePath)
600 if (Include.first == System || Include.first == ExternCSystem ||
601 (!Lang.ObjC1 && !Lang.CPlusPlus && Include.first == CSystem) ||
602 (/*FIXME !Lang.ObjC1 && */ Lang.CPlusPlus &&
603 Include.first == CXXSystem) ||
604 (Lang.ObjC1 && !Lang.CPlusPlus && Include.first == ObjCSystem) ||
605 (Lang.ObjC1 && Lang.CPlusPlus && Include.first == ObjCXXSystem))
606 SearchList.push_back(Include.second);
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000607
Yaron Keren54bb2152015-10-01 11:19:28 +0000608 for (auto &Include : IncludePath)
609 if (Include.first == After)
610 SearchList.push_back(Include.second);
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000611
Chris Lattner705c5c82011-06-16 22:58:10 +0000612 // Remove duplicates across both the Angled and System directories. GCC does
613 // this and failing to remove duplicates across these two groups breaks
614 // #include_next.
Chad Rosierfd3c90c2011-10-10 18:44:24 +0000615 unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
616 NumAngled -= NonSystemRemoved;
Nico Webered9b4102008-08-22 09:25:22 +0000617
618 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000619 Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
Nico Webered9b4102008-08-22 09:25:22 +0000620
Richard Smith8acadcb2012-06-13 20:27:03 +0000621 Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes);
622
Nico Webered9b4102008-08-22 09:25:22 +0000623 // If verbose, print the list of directories that will be searched.
624 if (Verbose) {
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000625 llvm::errs() << "#include \"...\" search starts here:\n";
Nico Webered9b4102008-08-22 09:25:22 +0000626 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000627 if (i == NumQuoted)
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000628 llvm::errs() << "#include <...> search starts here:\n";
Nico Webered9b4102008-08-22 09:25:22 +0000629 const char *Name = SearchList[i].getName();
630 const char *Suffix;
631 if (SearchList[i].isNormalDir())
632 Suffix = "";
633 else if (SearchList[i].isFramework())
634 Suffix = " (framework directory)";
635 else {
636 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
637 Suffix = " (headermap)";
638 }
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000639 llvm::errs() << " " << Name << Suffix << "\n";
Nico Webered9b4102008-08-22 09:25:22 +0000640 }
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000641 llvm::errs() << "End of search list.\n";
Nico Webered9b4102008-08-22 09:25:22 +0000642 }
643}
Daniel Dunbar08d5669b2009-11-07 04:20:50 +0000644
Daniel Dunbar0c6c9302009-11-11 21:44:21 +0000645void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
646 const HeaderSearchOptions &HSOpts,
647 const LangOptions &Lang,
Daniel Dunbar08d5669b2009-11-07 04:20:50 +0000648 const llvm::Triple &Triple) {
649 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
650
651 // Add the user defined entries.
652 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
653 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
Daniel Dunbarc6c23752013-01-30 01:06:03 +0000654 if (E.IgnoreSysRoot) {
655 Init.AddUnmappedPath(E.Path, E.Group, E.IsFramework);
656 } else {
657 Init.AddPath(E.Path, E.Group, E.IsFramework);
658 }
Daniel Dunbar08d5669b2009-11-07 04:20:50 +0000659 }
660
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000661 Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
Daniel Dunbar08d5669b2009-11-07 04:20:50 +0000662
Richard Smith8acadcb2012-06-13 20:27:03 +0000663 for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i)
664 Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix,
665 HSOpts.SystemHeaderPrefixes[i].IsSystemHeader);
666
Douglas Gregor3ec66632012-02-02 18:42:48 +0000667 if (HSOpts.UseBuiltinIncludes) {
668 // Set up the builtin include directory in the module map.
Benjamin Kramer33d43302013-06-13 14:26:04 +0000669 SmallString<128> P = StringRef(HSOpts.ResourceDir);
670 llvm::sys::path::append(P, "include");
Yaron Keren92e1b622015-03-18 10:17:07 +0000671 if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P))
Douglas Gregor3ec66632012-02-02 18:42:48 +0000672 HS.getModuleMap().setBuiltinIncludeDir(Dir);
673 }
674
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000675 Init.Realize(Lang);
Daniel Dunbar08d5669b2009-11-07 04:20:50 +0000676}