blob: 3072751ad9c64de63ae09a509049361f122357c3 [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
Daniel Dunbar08d5669b2009-11-07 04:20:50 +000018#include "clang/Lex/HeaderSearch.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000019#include "clang/Lex/HeaderSearchOptions.h"
Nico Webered9b4102008-08-22 09:25:22 +000020#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000021#include "llvm/ADT/SmallString.h"
Rafael Espindola46129b02009-11-13 05:13:58 +000022#include "llvm/ADT/SmallVector.h"
Rafael Espindolaf401fa02009-11-12 05:48:41 +000023#include "llvm/ADT/StringExtras.h"
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000024#include "llvm/ADT/Triple.h"
Benjamin Kramerc6ad84c2009-12-08 12:38:20 +000025#include "llvm/ADT/Twine.h"
Chandler Carruthdf527832011-11-04 23:49:05 +000026#include "llvm/Support/ErrorHandling.h"
John McCall65b8da02013-04-11 22:55:55 +000027#include "llvm/Support/FileSystem.h"
Michael J. Spencer8aaf4992010-11-29 18:12:39 +000028#include "llvm/Support/Path.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "llvm/Support/raw_ostream.h"
Dylan Noblesmith86780e92012-02-01 14:25:28 +000030
Nico Webered9b4102008-08-22 09:25:22 +000031using namespace clang;
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000032using namespace clang::frontend;
33
34namespace {
35
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.
39class InitHeaderSearch {
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +000040 std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
41 typedef std::vector<std::pair<IncludeDirGroup,
42 DirectoryLookup> >::const_iterator path_iterator;
Richard Smith8acadcb2012-06-13 20:27:03 +000043 std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
Chris Lattner0c64f4b2011-06-16 22:56:45 +000044 HeaderSearch &Headers;
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000045 bool Verbose;
Michael J. Spencerbc7fcc22010-12-25 20:09:27 +000046 std::string IncludeSysroot;
Daniel Dunbar335a37b2013-01-29 23:59:43 +000047 bool HasSysroot;
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000048
49public:
50
Chris Lattner0e62c1c2011-07-23 10:55:15 +000051 InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
Michael J. Spencerbc7fcc22010-12-25 20:09:27 +000052 : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
Daniel Dunbar335a37b2013-01-29 23:59:43 +000053 HasSysroot(!(sysroot.empty() || sysroot == "/")) {
Chandler Carrutheb842002010-11-15 07:15:26 +000054 }
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000055
Daniel Dunbarc6c23752013-01-30 01:06:03 +000056 /// 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);
59
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,
63 bool isFramework);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000064
Richard Smith8acadcb2012-06-13 20:27:03 +000065 /// AddSystemHeaderPrefix - Add the specified prefix to the system header
66 /// prefix list.
67 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
Benjamin Kramer3204b152015-05-29 19:42:19 +000068 SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
Richard Smith8acadcb2012-06-13 20:27:03 +000069 }
70
mike-m6fa3cd22010-05-05 17:00:31 +000071 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000072 /// libstdc++.
Chris Lattner0e62c1c2011-07-23 10:55:15 +000073 void AddGnuCPlusPlusIncludePaths(StringRef Base,
74 StringRef ArchDir,
75 StringRef Dir32,
76 StringRef Dir64,
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000077 const llvm::Triple &triple);
78
Michael J. Spencerbc721822010-12-21 16:45:42 +000079 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000080 /// libstdc++.
Aaron Ballmaneceaddc2012-03-25 22:46:17 +000081 void AddMinGWCPlusPlusIncludePaths(StringRef Base,
82 StringRef Arch,
83 StringRef Version);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000084
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000085 // AddDefaultCIncludePaths - Add paths that should always be searched.
mike-mc6da2612010-05-16 19:03:52 +000086 void AddDefaultCIncludePaths(const llvm::Triple &triple,
87 const HeaderSearchOptions &HSOpts);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000088
89 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
90 // compiling c++.
Douglas Gregor7a200962011-06-27 15:47:15 +000091 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
92 const HeaderSearchOptions &HSOpts);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000093
94 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
95 /// that e.g. stdio.h is found.
Daniel Dunbarb25bfde2011-10-11 18:20:10 +000096 void AddDefaultIncludePaths(const LangOptions &Lang,
97 const llvm::Triple &triple,
98 const HeaderSearchOptions &HSOpts);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +000099
100 /// Realize - Merges all search path lists into one list and send it to
101 /// HeaderSearch.
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000102 void Realize(const LangOptions &Lang);
Daniel Dunbar4df9aa22009-11-09 23:02:47 +0000103};
104
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000105} // end anonymous namespace.
Nico Webered9b4102008-08-22 09:25:22 +0000106
Daniel Dunbar2e8eb012013-01-29 23:59:37 +0000107static bool CanPrefixSysroot(StringRef Path) {
Hans Wennborg501eadb2014-03-12 16:07:46 +0000108#if defined(LLVM_ON_WIN32)
Daniel Dunbar2e8eb012013-01-29 23:59:37 +0000109 return !Path.empty() && llvm::sys::path::is_separator(Path[0]);
110#else
111 return llvm::sys::path::is_absolute(Path);
112#endif
113}
114
Daniel Dunbar9f237452013-01-30 00:19:24 +0000115void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
Daniel Dunbarc6c23752013-01-30 01:06:03 +0000116 bool isFramework) {
117 // Add the path with sysroot prepended, if desired and this is a system header
118 // group.
119 if (HasSysroot) {
120 SmallString<256> MappedPathStorage;
121 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
122 if (CanPrefixSysroot(MappedPathStr)) {
123 AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
124 return;
125 }
126 }
Mike Stump11289f42009-09-09 15:08:12 +0000127
Daniel Dunbarc6c23752013-01-30 01:06:03 +0000128 AddUnmappedPath(Path, Group, isFramework);
129}
130
131void InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
132 bool isFramework) {
133 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
134
135 FileManager &FM = Headers.getFileMgr();
Dylan Noblesmith2c1dd272012-02-05 02:13:05 +0000136 SmallString<256> MappedPathStorage;
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000137 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
Mike Stump11289f42009-09-09 15:08:12 +0000138
Nico Webered9b4102008-08-22 09:25:22 +0000139 // Compute the DirectoryLookup type.
Chris Lattner66a740e2008-10-27 01:19:25 +0000140 SrcMgr::CharacteristicKind Type;
Daniel Dunbar9f237452013-01-30 00:19:24 +0000141 if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) {
Chris Lattnerb03dc762008-09-26 21:18:42 +0000142 Type = SrcMgr::C_User;
Daniel Dunbar9f237452013-01-30 00:19:24 +0000143 } else if (Group == ExternCSystem) {
Chris Lattnerb03dc762008-09-26 21:18:42 +0000144 Type = SrcMgr::C_ExternCSystem;
Daniel Dunbar9f237452013-01-30 00:19:24 +0000145 } else {
146 Type = SrcMgr::C_System;
147 }
Mike Stump11289f42009-09-09 15:08:12 +0000148
Nico Webered9b4102008-08-22 09:25:22 +0000149 // If the directory exists, add it.
Chris Lattner5159f612010-11-23 08:35:12 +0000150 if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
Daniel Dunbarae4feb62013-01-25 01:50:28 +0000151 IncludePath.push_back(
152 std::make_pair(Group, DirectoryLookup(DE, Type, isFramework)));
Nico Webered9b4102008-08-22 09:25:22 +0000153 return;
154 }
Mike Stump11289f42009-09-09 15:08:12 +0000155
Nico Webered9b4102008-08-22 09:25:22 +0000156 // Check to see if this is an apple-style headermap (which are not allowed to
157 // be frameworks).
158 if (!isFramework) {
Chris Lattner5159f612010-11-23 08:35:12 +0000159 if (const FileEntry *FE = FM.getFile(MappedPathStr)) {
Nico Webered9b4102008-08-22 09:25:22 +0000160 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
161 // It is a headermap, add it to the search path.
Daniel Dunbarae4feb62013-01-25 01:50:28 +0000162 IncludePath.push_back(
163 std::make_pair(Group,
164 DirectoryLookup(HM, Type, Group == IndexHeaderMap)));
Nico Webered9b4102008-08-22 09:25:22 +0000165 return;
166 }
167 }
168 }
Mike Stump11289f42009-09-09 15:08:12 +0000169
Nico Webered9b4102008-08-22 09:25:22 +0000170 if (Verbose)
Chandler Carruth03ac1b02010-11-15 00:48:13 +0000171 llvm::errs() << "ignoring nonexistent directory \""
172 << MappedPathStr << "\"\n";
Nico Webered9b4102008-08-22 09:25:22 +0000173}
174
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000175void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
176 StringRef ArchDir,
177 StringRef Dir32,
178 StringRef Dir64,
Rafael Espindola0a1ac332009-10-14 17:09:44 +0000179 const llvm::Triple &triple) {
Rafael Espindola962e5182009-11-23 16:31:19 +0000180 // Add the base dir
Daniel Dunbar9f237452013-01-30 00:19:24 +0000181 AddPath(Base, CXXSystem, false);
Rafael Espindolaabab8792009-11-16 19:49:37 +0000182
183 // Add the multilib dirs
Rafael Espindola0a1ac332009-10-14 17:09:44 +0000184 llvm::Triple::ArchType arch = triple.getArch();
185 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
Rafael Espindola0a1ac332009-10-14 17:09:44 +0000186 if (is64bit)
Daniel Dunbar9f237452013-01-30 00:19:24 +0000187 AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, false);
Rafael Espindola0a1ac332009-10-14 17:09:44 +0000188 else
Daniel Dunbar9f237452013-01-30 00:19:24 +0000189 AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, false);
Rafael Espindola962e5182009-11-23 16:31:19 +0000190
191 // Add the backward dir
Daniel Dunbar9f237452013-01-30 00:19:24 +0000192 AddPath(Base + "/backward", CXXSystem, false);
Rafael Espindolac3031a92009-10-06 01:33:02 +0000193}
Nico Webered9b4102008-08-22 09:25:22 +0000194
Aaron Ballman9345d682012-03-25 15:47:41 +0000195void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
Aaron Ballmaneceaddc2012-03-25 22:46:17 +0000196 StringRef Arch,
197 StringRef Version) {
198 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
Daniel Dunbar9f237452013-01-30 00:19:24 +0000199 CXXSystem, false);
Aaron Ballmaneceaddc2012-03-25 22:46:17 +0000200 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
Daniel Dunbar9f237452013-01-30 00:19:24 +0000201 CXXSystem, false);
Aaron Ballmaneceaddc2012-03-25 22:46:17 +0000202 AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
Daniel Dunbar9f237452013-01-30 00:19:24 +0000203 CXXSystem, false);
Aaron Ballman9345d682012-03-25 15:47:41 +0000204}
205
mike-mc6da2612010-05-16 19:03:52 +0000206void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
207 const HeaderSearchOptions &HSOpts) {
Benjamin Kramer24f1d3e2011-02-02 18:59:27 +0000208 llvm::Triple::OSType os = triple.getOS();
209
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000210 if (HSOpts.UseStandardSystemIncludes) {
211 switch (os) {
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000212 case llvm::Triple::CloudABI:
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000213 case llvm::Triple::FreeBSD:
214 case llvm::Triple::NetBSD:
Hans Wennborgae298f22012-08-02 12:27:08 +0000215 case llvm::Triple::OpenBSD:
Eli Friedman9fa28852012-08-08 23:57:20 +0000216 case llvm::Triple::Bitrig:
Derek Schuff6ab52fa2015-03-30 20:31:33 +0000217 case llvm::Triple::NaCl:
Filipe Cabecinhasc888e192015-10-14 12:25:43 +0000218 case llvm::Triple::PS4:
Andrey Bokhanko0b135e02015-12-16 13:27:38 +0000219 case llvm::Triple::ELFIAMCU:
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000220 break;
Yaron Keren1c0070c2015-07-02 04:45:27 +0000221 case llvm::Triple::Win32:
222 if (triple.getEnvironment() != llvm::Triple::Cygnus)
223 break;
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000224 default:
225 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbar9f237452013-01-30 00:19:24 +0000226 AddPath("/usr/local/include", System, false);
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000227 break;
228 }
Benjamin Kramer24f1d3e2011-02-02 18:59:27 +0000229 }
mike-mc6da2612010-05-16 19:03:52 +0000230
231 // Builtin includes use #include_next directives and should be positioned
232 // just prior C include dirs.
233 if (HSOpts.UseBuiltinIncludes) {
234 // Ignore the sys root, we *always* look for clang headers relative to
235 // supplied path.
Benjamin Kramer33d43302013-06-13 14:26:04 +0000236 SmallString<128> P = StringRef(HSOpts.ResourceDir);
237 llvm::sys::path::append(P, "include");
Yaron Keren92e1b622015-03-18 10:17:07 +0000238 AddUnmappedPath(P, ExternCSystem, false);
mike-mc6da2612010-05-16 19:03:52 +0000239 }
240
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000241 // All remaining additions are for system include directories, early exit if
242 // we aren't using them.
243 if (!HSOpts.UseStandardSystemIncludes)
244 return;
245
mike-mc6da2612010-05-16 19:03:52 +0000246 // Add dirs specified via 'configure --with-c-include-dirs'.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000247 StringRef CIncludeDirs(C_INCLUDE_DIRS);
Daniel Dunbar71ed08b2009-11-12 07:28:29 +0000248 if (CIncludeDirs != "") {
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000249 SmallVector<StringRef, 5> dirs;
Rafael Espindola46129b02009-11-13 05:13:58 +0000250 CIncludeDirs.split(dirs, ":");
Yaron Keren54bb2152015-10-01 11:19:28 +0000251 for (StringRef dir : dirs)
252 AddPath(dir, ExternCSystem, false);
Rafael Espindolaf401fa02009-11-12 05:48:41 +0000253 return;
254 }
Benjamin Kramer24f1d3e2011-02-02 18:59:27 +0000255
Mike Stump904ad902009-10-08 23:29:47 +0000256 switch (os) {
Chandler Carrutha796f532011-11-05 20:17:13 +0000257 case llvm::Triple::Linux:
Chandler Carrutha796f532011-11-05 20:17:13 +0000258 llvm_unreachable("Include management is handled in the driver.");
Chandler Carruthdf527832011-11-04 23:49:05 +0000259
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000260 case llvm::Triple::CloudABI: {
261 // <sysroot>/<triple>/include
262 SmallString<128> P = StringRef(HSOpts.ResourceDir);
263 llvm::sys::path::append(P, "../../..", triple.str(), "include");
Yaron Keren92e1b622015-03-18 10:17:07 +0000264 AddPath(P, System, false);
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000265 break;
266 }
267
Chris Lattnerb986aba2010-04-11 19:29:39 +0000268 case llvm::Triple::Haiku:
Daniel Dunbar9f237452013-01-30 00:19:24 +0000269 AddPath("/boot/common/include", System, false);
270 AddPath("/boot/develop/headers/os", System, false);
271 AddPath("/boot/develop/headers/os/app", System, false);
272 AddPath("/boot/develop/headers/os/arch", System, false);
273 AddPath("/boot/develop/headers/os/device", System, false);
274 AddPath("/boot/develop/headers/os/drivers", System, false);
275 AddPath("/boot/develop/headers/os/game", System, false);
276 AddPath("/boot/develop/headers/os/interface", System, false);
277 AddPath("/boot/develop/headers/os/kernel", System, false);
278 AddPath("/boot/develop/headers/os/locale", System, false);
279 AddPath("/boot/develop/headers/os/mail", System, false);
280 AddPath("/boot/develop/headers/os/media", System, false);
281 AddPath("/boot/develop/headers/os/midi", System, false);
282 AddPath("/boot/develop/headers/os/midi2", System, false);
283 AddPath("/boot/develop/headers/os/net", System, false);
284 AddPath("/boot/develop/headers/os/storage", System, false);
285 AddPath("/boot/develop/headers/os/support", System, false);
286 AddPath("/boot/develop/headers/os/translation", System, false);
287 AddPath("/boot/develop/headers/os/add-ons/graphics", System, false);
288 AddPath("/boot/develop/headers/os/add-ons/input_server", System, false);
289 AddPath("/boot/develop/headers/os/add-ons/screen_saver", System, false);
290 AddPath("/boot/develop/headers/os/add-ons/tracker", System, false);
291 AddPath("/boot/develop/headers/os/be_apps/Deskbar", System, false);
292 AddPath("/boot/develop/headers/os/be_apps/NetPositive", System, false);
293 AddPath("/boot/develop/headers/os/be_apps/Tracker", System, false);
294 AddPath("/boot/develop/headers/cpp", System, false);
295 AddPath("/boot/develop/headers/cpp/i586-pc-haiku", System, false);
296 AddPath("/boot/develop/headers/3rdparty", System, false);
297 AddPath("/boot/develop/headers/bsd", System, false);
298 AddPath("/boot/develop/headers/glibc", System, false);
299 AddPath("/boot/develop/headers/posix", System, false);
300 AddPath("/boot/develop/headers", System, false);
Eli Friedman04831922010-08-22 01:00:03 +0000301 break;
Douglas Gregor9fabd852011-07-01 22:41:14 +0000302 case llvm::Triple::RTEMS:
303 break;
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000304 case llvm::Triple::Win32:
305 switch (triple.getEnvironment()) {
306 default: llvm_unreachable("Include management is handled in the driver.");
307 case llvm::Triple::Cygnus:
308 AddPath("/usr/include/w32api", System, false);
309 break;
310 case llvm::Triple::GNU:
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000311 break;
Douglas Gregor7a200962011-06-27 15:47:15 +0000312 }
Mike Stump904ad902009-10-08 23:29:47 +0000313 break;
314 default:
Mike Stump904ad902009-10-08 23:29:47 +0000315 break;
316 }
John Thompson4334ce62009-10-13 18:51:32 +0000317
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000318 switch (os) {
319 case llvm::Triple::CloudABI:
320 case llvm::Triple::RTEMS:
Derek Schuff6ab52fa2015-03-30 20:31:33 +0000321 case llvm::Triple::NaCl:
Andrey Bokhanko0b135e02015-12-16 13:27:38 +0000322 case llvm::Triple::ELFIAMCU:
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000323 break;
Filipe Cabecinhasc888e192015-10-14 12:25:43 +0000324 case llvm::Triple::PS4: {
325 // <isysroot> gets prepended later in AddPath().
326 std::string BaseSDKPath = "";
327 if (!HasSysroot) {
328 const char *envValue = getenv("SCE_PS4_SDK_DIR");
329 if (envValue)
330 BaseSDKPath = envValue;
331 else {
332 // HSOpts.ResourceDir variable contains the location of Clang's
333 // resource files.
334 // Assuming that Clang is configured for PS4 without
335 // --with-clang-resource-dir option, the location of Clang's resource
336 // files is <SDK_DIR>/host_tools/lib/clang
337 SmallString<128> P = StringRef(HSOpts.ResourceDir);
338 llvm::sys::path::append(P, "../../..");
339 BaseSDKPath = P.str();
340 }
341 }
342 AddPath(BaseSDKPath + "/target/include", System, false);
343 if (triple.isPS4CPU())
344 AddPath(BaseSDKPath + "/target/include_common", System, false);
345 }
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000346 default:
Daniel Dunbar9f237452013-01-30 00:19:24 +0000347 AddPath("/usr/include", ExternCSystem, false);
Ed Schouten2b60d1e2015-03-11 08:46:01 +0000348 break;
349 }
Rafael Espindola177f1d92009-10-27 14:47:31 +0000350}
351
Chris Lattner5561bf32010-05-05 05:28:39 +0000352void InitHeaderSearch::
Douglas Gregor7a200962011-06-27 15:47:15 +0000353AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
Rafael Espindola177f1d92009-10-27 14:47:31 +0000354 llvm::Triple::OSType os = triple.getOS();
355 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbar14ad22f2011-04-19 21:43:27 +0000356
357 if (triple.isOSDarwin()) {
Daniel Dunbareaff5fa2010-05-28 01:54:31 +0000358 switch (triple.getArch()) {
359 default: break;
360
NAKAMURA Takumi029d74b2011-02-17 08:50:50 +0000361 case llvm::Triple::ppc:
Douglas Gregoreb0bdf02010-05-29 01:15:12 +0000362 case llvm::Triple::ppc64:
Douglas Gregor117ef272010-05-29 01:21:11 +0000363 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
NAKAMURA Takumi029d74b2011-02-17 08:50:50 +0000364 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregor117ef272010-05-29 01:21:11 +0000365 triple);
Douglas Gregoreb0bdf02010-05-29 01:15:12 +0000366 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
NAKAMURA Takumi029d74b2011-02-17 08:50:50 +0000367 "powerpc-apple-darwin10", "", "ppc64",
Douglas Gregoreb0bdf02010-05-29 01:15:12 +0000368 triple);
369 break;
370
Daniel Dunbareaff5fa2010-05-28 01:54:31 +0000371 case llvm::Triple::x86:
372 case llvm::Triple::x86_64:
373 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
374 "i686-apple-darwin10", "", "x86_64", triple);
375 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
376 "i686-apple-darwin8", "", "", triple);
377 break;
378
379 case llvm::Triple::arm:
380 case llvm::Triple::thumb:
381 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
382 "arm-apple-darwin10", "v7", "", triple);
383 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
384 "arm-apple-darwin10", "v6", "", triple);
385 break;
Tim Northovera2ee4332014-03-29 15:09:45 +0000386
Tim Northover573cbee2014-05-24 12:52:07 +0000387 case llvm::Triple::aarch64:
Tim Northovera2ee4332014-03-29 15:09:45 +0000388 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
389 "arm64-apple-darwin10", "", "", triple);
390 break;
Daniel Dunbareaff5fa2010-05-28 01:54:31 +0000391 }
Daniel Dunbar14ad22f2011-04-19 21:43:27 +0000392 return;
393 }
394
395 switch (os) {
Chandler Carrutha796f532011-11-05 20:17:13 +0000396 case llvm::Triple::Linux:
Chandler Carrutha796f532011-11-05 20:17:13 +0000397 llvm_unreachable("Include management is handled in the driver.");
Sylvestre Ledru75c29142014-08-18 15:13:44 +0000398 break;
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000399 case llvm::Triple::Win32:
400 switch (triple.getEnvironment()) {
401 default: llvm_unreachable("Include management is handled in the driver.");
402 case llvm::Triple::Cygnus:
403 // Cygwin-1.7
404 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.7.3");
405 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
406 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
407 // g++-4 / Cygwin-1.5
408 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
409 break;
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000410 }
Yaron Keren1c0070c2015-07-02 04:45:27 +0000411 break;
Chris Lattner002ba6b2010-01-09 05:41:14 +0000412 case llvm::Triple::DragonFly:
Dimitry Andricf59a2b32015-12-27 10:01:44 +0000413 AddPath("/usr/include/c++/5.0", CXXSystem, false);
Chris Lattner002ba6b2010-01-09 05:41:14 +0000414 break;
Daniel Dunbarea3813f2010-08-01 23:13:54 +0000415 case llvm::Triple::OpenBSD: {
416 std::string t = triple.getTriple();
417 if (t.substr(0, 6) == "x86_64")
418 t.replace(0, 6, "amd64");
419 AddGnuCPlusPlusIncludePaths("/usr/include/g++",
420 t, "", "", triple);
421 break;
422 }
Chris Lattner3e2ee142010-07-07 16:01:42 +0000423 case llvm::Triple::Minix:
424 AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
425 "", "", "", triple);
426 break;
Rafael Espindola177f1d92009-10-27 14:47:31 +0000427 default:
428 break;
429 }
430}
431
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000432void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
433 const llvm::Triple &triple,
mike-mc6da2612010-05-16 19:03:52 +0000434 const HeaderSearchOptions &HSOpts) {
Chandler Carruthdf527832011-11-04 23:49:05 +0000435 // NB: This code path is going away. All of the logic is moving into the
436 // driver which has the information necessary to do target-specific
437 // selections of default include paths. Each target which moves there will be
438 // exempted from this logic here until we can delete the entire pile of code.
439 switch (triple.getOS()) {
440 default:
441 break; // Everything else continues to use this routine's logic.
442
Chandler Carrutha796f532011-11-05 20:17:13 +0000443 case llvm::Triple::Linux:
Chandler Carruthdf527832011-11-04 23:49:05 +0000444 return;
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000445
446 case llvm::Triple::Win32:
Yaron Keren1c0070c2015-07-02 04:45:27 +0000447 if (triple.getEnvironment() != llvm::Triple::Cygnus ||
Eric Christopher610952e2014-12-05 00:22:48 +0000448 triple.isOSBinFormatMachO())
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000449 return;
450 break;
Chandler Carruthdf527832011-11-04 23:49:05 +0000451 }
452
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000453 if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
454 HSOpts.UseStandardSystemIncludes) {
Douglas Gregorf4016fd2011-07-29 20:21:18 +0000455 if (HSOpts.UseLibcxx) {
456 if (triple.isOSDarwin()) {
457 // On Darwin, libc++ may be installed alongside the compiler in
Justin Bogner13a641b2013-11-15 18:07:59 +0000458 // include/c++/v1.
Benjamin Kramer33d43302013-06-13 14:26:04 +0000459 if (!HSOpts.ResourceDir.empty()) {
460 // Remove version from foo/lib/clang/version
461 StringRef NoVer = llvm::sys::path::parent_path(HSOpts.ResourceDir);
462 // Remove clang from foo/lib/clang
Justin Bogner13a641b2013-11-15 18:07:59 +0000463 StringRef Lib = llvm::sys::path::parent_path(NoVer);
464 // Remove lib from foo/lib
465 SmallString<128> P = llvm::sys::path::parent_path(Lib);
466
467 // Get foo/include/c++/v1
468 llvm::sys::path::append(P, "include", "c++", "v1");
Yaron Keren92e1b622015-03-18 10:17:07 +0000469 AddUnmappedPath(P, CXXSystem, false);
Douglas Gregorf4016fd2011-07-29 20:21:18 +0000470 }
471 }
Daniel Dunbar9f237452013-01-30 00:19:24 +0000472 AddPath("/usr/include/c++/v1", CXXSystem, false);
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000473 } else {
Douglas Gregor7a200962011-06-27 15:47:15 +0000474 AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000475 }
Bob Wilsonb02ea3d2011-06-21 21:12:29 +0000476 }
Rafael Espindola962e5182009-11-23 16:31:19 +0000477
mike-mc6da2612010-05-16 19:03:52 +0000478 AddDefaultCIncludePaths(triple, HSOpts);
Daniel Dunbarec879912009-11-07 04:20:39 +0000479
480 // Add the default framework include paths on Darwin.
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000481 if (HSOpts.UseStandardSystemIncludes) {
482 if (triple.isOSDarwin()) {
Daniel Dunbar9f237452013-01-30 00:19:24 +0000483 AddPath("/System/Library/Frameworks", System, true);
484 AddPath("/Library/Frameworks", System, true);
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000485 }
Daniel Dunbarec879912009-11-07 04:20:39 +0000486 }
Rafael Espindola177f1d92009-10-27 14:47:31 +0000487}
488
Nico Webered9b4102008-08-22 09:25:22 +0000489/// RemoveDuplicates - If there are duplicate directory entries in the specified
Chad Rosierfd3c90c2011-10-10 18:44:24 +0000490/// search list, remove the later (dead) ones. Returns the number of non-system
491/// headers removed, which is used to update NumAngled.
492static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
493 unsigned First, bool Verbose) {
Nico Webered9b4102008-08-22 09:25:22 +0000494 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
495 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
496 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
Chad Rosierfd3c90c2011-10-10 18:44:24 +0000497 unsigned NonSystemRemoved = 0;
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000498 for (unsigned i = First; i != SearchList.size(); ++i) {
Chris Lattnere744d322008-09-26 17:46:45 +0000499 unsigned DirToRemove = i;
Mike Stump11289f42009-09-09 15:08:12 +0000500
Chris Lattner24c911e2009-02-08 01:00:10 +0000501 const DirectoryLookup &CurEntry = SearchList[i];
Mike Stump11289f42009-09-09 15:08:12 +0000502
Chris Lattner24c911e2009-02-08 01:00:10 +0000503 if (CurEntry.isNormalDir()) {
Nico Webered9b4102008-08-22 09:25:22 +0000504 // If this isn't the first time we've seen this dir, remove it.
David Blaikie82e95a32014-11-19 07:49:47 +0000505 if (SeenDirs.insert(CurEntry.getDir()).second)
Nico Webered9b4102008-08-22 09:25:22 +0000506 continue;
Chris Lattner24c911e2009-02-08 01:00:10 +0000507 } else if (CurEntry.isFramework()) {
Nico Webered9b4102008-08-22 09:25:22 +0000508 // If this isn't the first time we've seen this framework dir, remove it.
David Blaikie82e95a32014-11-19 07:49:47 +0000509 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()).second)
Nico Webered9b4102008-08-22 09:25:22 +0000510 continue;
Nico Webered9b4102008-08-22 09:25:22 +0000511 } else {
Chris Lattner24c911e2009-02-08 01:00:10 +0000512 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
Nico Webered9b4102008-08-22 09:25:22 +0000513 // If this isn't the first time we've seen this headermap, remove it.
David Blaikie82e95a32014-11-19 07:49:47 +0000514 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()).second)
Nico Webered9b4102008-08-22 09:25:22 +0000515 continue;
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000516 }
Mike Stump11289f42009-09-09 15:08:12 +0000517
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000518 // If we have a normal #include dir/framework/headermap that is shadowed
519 // later in the chain by a system include location, we actually want to
520 // ignore the user's request and drop the user dir... keeping the system
521 // dir. This is weird, but required to emulate GCC's search path correctly.
522 //
523 // Since dupes of system dirs are rare, just rescan to find the original
524 // that we're nuking instead of using a DenseMap.
Chris Lattner24c911e2009-02-08 01:00:10 +0000525 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000526 // Find the dir that this is the same of.
527 unsigned FirstDir;
528 for (FirstDir = 0; ; ++FirstDir) {
529 assert(FirstDir != i && "Didn't find dupe?");
Mike Stump11289f42009-09-09 15:08:12 +0000530
Chris Lattner24c911e2009-02-08 01:00:10 +0000531 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
532
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000533 // If these are different lookup types, then they can't be the dupe.
Chris Lattner24c911e2009-02-08 01:00:10 +0000534 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000535 continue;
Mike Stump11289f42009-09-09 15:08:12 +0000536
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000537 bool isSame;
Chris Lattner24c911e2009-02-08 01:00:10 +0000538 if (CurEntry.isNormalDir())
539 isSame = SearchEntry.getDir() == CurEntry.getDir();
540 else if (CurEntry.isFramework())
541 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000542 else {
Chris Lattner24c911e2009-02-08 01:00:10 +0000543 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
544 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000545 }
Mike Stump11289f42009-09-09 15:08:12 +0000546
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000547 if (isSame)
548 break;
549 }
Mike Stump11289f42009-09-09 15:08:12 +0000550
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000551 // If the first dir in the search path is a non-system dir, zap it
552 // instead of the system one.
553 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
554 DirToRemove = FirstDir;
555 }
556
557 if (Verbose) {
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000558 llvm::errs() << "ignoring duplicate directory \""
559 << CurEntry.getName() << "\"\n";
Chris Lattnerbf20a9a2009-02-08 00:55:22 +0000560 if (DirToRemove != i)
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000561 llvm::errs() << " as it is a non-system directory that duplicates "
562 << "a system directory\n";
Nico Webered9b4102008-08-22 09:25:22 +0000563 }
Chad Rosierfd3c90c2011-10-10 18:44:24 +0000564 if (DirToRemove != i)
565 ++NonSystemRemoved;
Mike Stump11289f42009-09-09 15:08:12 +0000566
Chris Lattnere744d322008-09-26 17:46:45 +0000567 // This is reached if the current entry is a duplicate. Remove the
568 // DirToRemove (usually the current dir).
569 SearchList.erase(SearchList.begin()+DirToRemove);
Nico Webered9b4102008-08-22 09:25:22 +0000570 --i;
571 }
Chad Rosierfd3c90c2011-10-10 18:44:24 +0000572 return NonSystemRemoved;
Nico Webered9b4102008-08-22 09:25:22 +0000573}
574
575
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000576void InitHeaderSearch::Realize(const LangOptions &Lang) {
Nico Webered9b4102008-08-22 09:25:22 +0000577 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
578 std::vector<DirectoryLookup> SearchList;
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000579 SearchList.reserve(IncludePath.size());
Mike Stump11289f42009-09-09 15:08:12 +0000580
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000581 // Quoted arguments go first.
Yaron Keren54bb2152015-10-01 11:19:28 +0000582 for (auto &Include : IncludePath)
583 if (Include.first == Quoted)
584 SearchList.push_back(Include.second);
585
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000586 // Deduplicate and remember index.
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000587 RemoveDuplicates(SearchList, 0, Verbose);
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000588 unsigned NumQuoted = SearchList.size();
Mike Stump11289f42009-09-09 15:08:12 +0000589
Yaron Keren54bb2152015-10-01 11:19:28 +0000590 for (auto &Include : IncludePath)
591 if (Include.first == Angled || Include.first == IndexHeaderMap)
592 SearchList.push_back(Include.second);
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000593
594 RemoveDuplicates(SearchList, NumQuoted, Verbose);
595 unsigned NumAngled = SearchList.size();
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000596
Yaron Keren54bb2152015-10-01 11:19:28 +0000597 for (auto &Include : IncludePath)
598 if (Include.first == System || Include.first == ExternCSystem ||
599 (!Lang.ObjC1 && !Lang.CPlusPlus && Include.first == CSystem) ||
600 (/*FIXME !Lang.ObjC1 && */ Lang.CPlusPlus &&
601 Include.first == CXXSystem) ||
602 (Lang.ObjC1 && !Lang.CPlusPlus && Include.first == ObjCSystem) ||
603 (Lang.ObjC1 && Lang.CPlusPlus && Include.first == ObjCXXSystem))
604 SearchList.push_back(Include.second);
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000605
Yaron Keren54bb2152015-10-01 11:19:28 +0000606 for (auto &Include : IncludePath)
607 if (Include.first == After)
608 SearchList.push_back(Include.second);
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000609
Chris Lattner705c5c82011-06-16 22:58:10 +0000610 // Remove duplicates across both the Angled and System directories. GCC does
611 // this and failing to remove duplicates across these two groups breaks
612 // #include_next.
Chad Rosierfd3c90c2011-10-10 18:44:24 +0000613 unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
614 NumAngled -= NonSystemRemoved;
Nico Webered9b4102008-08-22 09:25:22 +0000615
616 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000617 Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
Nico Webered9b4102008-08-22 09:25:22 +0000618
Richard Smith8acadcb2012-06-13 20:27:03 +0000619 Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes);
620
Nico Webered9b4102008-08-22 09:25:22 +0000621 // If verbose, print the list of directories that will be searched.
622 if (Verbose) {
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000623 llvm::errs() << "#include \"...\" search starts here:\n";
Nico Webered9b4102008-08-22 09:25:22 +0000624 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
Chris Lattner0c64f4b2011-06-16 22:56:45 +0000625 if (i == NumQuoted)
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000626 llvm::errs() << "#include <...> search starts here:\n";
Nico Webered9b4102008-08-22 09:25:22 +0000627 const char *Name = SearchList[i].getName();
628 const char *Suffix;
629 if (SearchList[i].isNormalDir())
630 Suffix = "";
631 else if (SearchList[i].isFramework())
632 Suffix = " (framework directory)";
633 else {
634 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
635 Suffix = " (headermap)";
636 }
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000637 llvm::errs() << " " << Name << Suffix << "\n";
Nico Webered9b4102008-08-22 09:25:22 +0000638 }
Daniel Dunbarf680e7d2009-12-03 09:14:02 +0000639 llvm::errs() << "End of search list.\n";
Nico Webered9b4102008-08-22 09:25:22 +0000640 }
641}
Daniel Dunbar08d5669b2009-11-07 04:20:50 +0000642
Daniel Dunbar0c6c9302009-11-11 21:44:21 +0000643void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
644 const HeaderSearchOptions &HSOpts,
645 const LangOptions &Lang,
Daniel Dunbar08d5669b2009-11-07 04:20:50 +0000646 const llvm::Triple &Triple) {
647 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
648
649 // Add the user defined entries.
650 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
651 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
Daniel Dunbarc6c23752013-01-30 01:06:03 +0000652 if (E.IgnoreSysRoot) {
653 Init.AddUnmappedPath(E.Path, E.Group, E.IsFramework);
654 } else {
655 Init.AddPath(E.Path, E.Group, E.IsFramework);
656 }
Daniel Dunbar08d5669b2009-11-07 04:20:50 +0000657 }
658
Daniel Dunbarb25bfde2011-10-11 18:20:10 +0000659 Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
Daniel Dunbar08d5669b2009-11-07 04:20:50 +0000660
Richard Smith8acadcb2012-06-13 20:27:03 +0000661 for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i)
662 Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix,
663 HSOpts.SystemHeaderPrefixes[i].IsSystemHeader);
664
Douglas Gregor3ec66632012-02-02 18:42:48 +0000665 if (HSOpts.UseBuiltinIncludes) {
666 // Set up the builtin include directory in the module map.
Benjamin Kramer33d43302013-06-13 14:26:04 +0000667 SmallString<128> P = StringRef(HSOpts.ResourceDir);
668 llvm::sys::path::append(P, "include");
Yaron Keren92e1b622015-03-18 10:17:07 +0000669 if (const DirectoryEntry *Dir = HS.getFileMgr().getDirectory(P))
Douglas Gregor3ec66632012-02-02 18:42:48 +0000670 HS.getModuleMap().setBuiltinIncludeDir(Dir);
671 }
672
Joerg Sonnenbergercc9c8eb2011-02-22 00:40:56 +0000673 Init.Realize(Lang);
Daniel Dunbar08d5669b2009-11-07 04:20:50 +0000674}