InitHeaderSearch.cpp revision 33cc2437ae3a609cdc44179931a2909eb48a8200
10fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber//===--- InitHeaderSearch.cpp - Initialize header search paths ----------*-===// 20fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 30fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// The LLVM Compiler Infrastructure 40fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 50fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// This file is distributed under the University of Illinois Open Source 60fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// License. See LICENSE.TXT for details. 70fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 80fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber//===----------------------------------------------------------------------===// 90fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 100fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// This file implements the InitHeaderSearch class. 110fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 120fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber//===----------------------------------------------------------------------===// 130fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 142cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar#include "clang/Frontend/Utils.h" 150fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "clang/Basic/FileManager.h" 160fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "clang/Basic/LangOptions.h" 1763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#include "clang/Frontend/HeaderSearchOptions.h" 1863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#include "clang/Lex/HeaderSearch.h" 190fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "llvm/ADT/SmallString.h" 200fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "llvm/ADT/SmallPtrSet.h" 21aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola#include "llvm/ADT/SmallVector.h" 22f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola#include "llvm/ADT/StringExtras.h" 232cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar#include "llvm/ADT/Triple.h" 24d57a7ef9252964bc6c8471451d7bd395b0520cb8Chris Lattner#include "llvm/Support/raw_ostream.h" 250fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "llvm/System/Path.h" 26121e3c207415fb4c105d690de384d8f3d49b0f2dArgyrios Kyrtzidis#include "llvm/Config/config.h" 27620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump#ifdef _MSC_VER 28620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #define WIN32_LEAN_AND_MEAN 1 29620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #include <windows.h> 30620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump#endif 310fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weberusing namespace clang; 322cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarusing namespace clang::frontend; 332cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 342cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarnamespace { 352cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 362cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar/// InitHeaderSearch - This class makes it easier to set the search paths of 372cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar/// a HeaderSearch object. InitHeaderSearch stores several search path lists 382cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar/// internally, which can be sent to a HeaderSearch object in one swoop. 392cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarclass InitHeaderSearch { 402cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar std::vector<DirectoryLookup> IncludeGroup[4]; 412cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar HeaderSearch& Headers; 422cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar bool Verbose; 432cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar std::string isysroot; 442cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 452cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarpublic: 462cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 472cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar InitHeaderSearch(HeaderSearch &HS, 482cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar bool verbose = false, const std::string &iSysroot = "") 492cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar : Headers(HS), Verbose(verbose), isysroot(iSysroot) {} 502cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 512cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddPath - Add the specified path to the specified group list. 522cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar void AddPath(const llvm::StringRef &Path, IncludeDirGroup Group, 532cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar bool isCXXAware, bool isUserSupplied, 542cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar bool isFramework, bool IgnoreSysRoot = false); 552cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 562cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to suport a gnu 572cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// libstdc++. 58ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola void AddGnuCPlusPlusIncludePaths(const std::string &Base, 59ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola const char *ArchDir, 60ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola const char *Dir32, 612cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar const char *Dir64, 622cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar const llvm::Triple &triple); 632cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 642cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to suport a MinGW 652cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// libstdc++. 662cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar void AddMinGWCPlusPlusIncludePaths(const std::string &Base, 672cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar const char *Arch, 682cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar const char *Version); 692cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 702cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddDelimitedPaths - Add a list of paths delimited by the system PATH 712cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// separator. The processing follows that of the CPATH variable for gcc. 722cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar void AddDelimitedPaths(const char *String); 732cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 742cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar // AddDefaultCIncludePaths - Add paths that should always be searched. 752cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar void AddDefaultCIncludePaths(const llvm::Triple &triple); 762cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 772cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when 782cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar // compiling c++. 792cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple); 802cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 812cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddDefaultSystemIncludePaths - Adds the default system include paths so 822cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// that e.g. stdio.h is found. 832cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar void AddDefaultSystemIncludePaths(const LangOptions &Lang, 842cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar const llvm::Triple &triple); 852cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 862cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// Realize - Merges all search path lists into one list and send it to 872cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// HeaderSearch. 882cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar void Realize(); 892cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar}; 902cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 912cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar} 920fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 93458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramervoid InitHeaderSearch::AddPath(const llvm::StringRef &Path, 94458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer IncludeDirGroup Group, bool isCXXAware, 95458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer bool isUserSupplied, bool isFramework, 96458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer bool IgnoreSysRoot) { 970fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber assert(!Path.empty() && "can't handle empty path here"); 980fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber FileManager &FM = Headers.getFileMgr(); 991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1000fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Compute the actual path, taking into consideration -isysroot. 1010fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber llvm::SmallString<256> MappedPath; 1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1030fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Handle isysroot. 1046858dd3fcc2d3ac6a706a0294be1d3ac51849022Chris Lattner if (Group == System && !IgnoreSysRoot) { 1050fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // FIXME: Portability. This should be a sys::Path interface, this doesn't 1060fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // handle things like C:\ right, nor win32 \\network\device\blah. 1070fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present. 1080fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber MappedPath.append(isysroot.begin(), isysroot.end()); 1090fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1110fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber MappedPath.append(Path.begin(), Path.end()); 1120fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 1130fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Compute the DirectoryLookup type. 1149d72851fec9e9c62570a027d42701562bbf29751Chris Lattner SrcMgr::CharacteristicKind Type; 1150fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (Group == Quoted || Group == Angled) 1160b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner Type = SrcMgr::C_User; 1170fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else if (isCXXAware) 1180b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner Type = SrcMgr::C_System; 1190fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else 1200b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner Type = SrcMgr::C_ExternCSystem; 1211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1230fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If the directory exists, add it. 124458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer if (const DirectoryEntry *DE = FM.getDirectory(MappedPath.str())) { 1250fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied, 1260fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber isFramework)); 1270fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber return; 1280fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1300fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Check to see if this is an apple-style headermap (which are not allowed to 1310fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // be frameworks). 1320fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (!isFramework) { 133458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer if (const FileEntry *FE = FM.getFile(MappedPath.str())) { 1340fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { 1350fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // It is a headermap, add it to the search path. 1360fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied)); 1370fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber return; 1380fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1390fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1400fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1420fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (Verbose) 1437765934ad7e157b5fcf925792a38e01b1edbcf8aDaniel Dunbar llvm::errs() << "ignoring nonexistent directory \"" 1447765934ad7e157b5fcf925792a38e01b1edbcf8aDaniel Dunbar << MappedPath.str() << "\"\n"; 1450fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber} 1460fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 1470fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 148e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbarvoid InitHeaderSearch::AddDelimitedPaths(const char *at) { 149e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar if (*at == 0) // Empty string should not add '.' path. 1500fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber return; 1510fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 1520fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber const char* delim = strchr(at, llvm::sys::PathSeparator); 1530fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber while (delim != 0) { 1540fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (delim-at == 0) 1550fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber AddPath(".", Angled, false, true, false); 1560fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else 157458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer AddPath(llvm::StringRef(at, delim-at), Angled, false, true, false); 1580fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber at = delim + 1; 1590fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber delim = strchr(at, llvm::sys::PathSeparator); 1600fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1610fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (*at == 0) 1620fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber AddPath(".", Angled, false, true, false); 1630fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else 1640fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber AddPath(at, Angled, false, true, false); 1650fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber} 1660fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 167ec05766fe525a8f81c7dc96ddbdc874814a14b2cMike Stumpvoid InitHeaderSearch::AddGnuCPlusPlusIncludePaths(const std::string &Base, 168ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola const char *ArchDir, 16931b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola const char *Dir32, 17031b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola const char *Dir64, 17131b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola const llvm::Triple &triple) { 1726ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola // Add the base dir 173ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddPath(Base, System, true, false, false); 174ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola 175ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola // Add the multilib dirs 17631b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola llvm::Triple::ArchType arch = triple.getArch(); 17731b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; 17831b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola if (is64bit) 179ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddPath(Base + "/" + ArchDir + "/" + Dir64, System, true, false, false); 18031b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola else 181ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddPath(Base + "/" + ArchDir + "/" + Dir32, System, true, false, false); 1826ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola 1836ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola // Add the backward dir 1846ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola AddPath(Base + "/backward", System, true, false, false); 1852e9f652d53346bf7e64c8a12a9ff06b004a3e489Rafael Espindola} 1860fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 187620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stumpvoid InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(const std::string &Base, 188620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump const char *Arch, 189620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump const char *Version) { 1905c5758bb0a4ec0f572cd20249277736da5715003Daniel Dunbar std::string localBase = Base + "/" + Arch + "/" + Version + "/include"; 1915c5758bb0a4ec0f572cd20249277736da5715003Daniel Dunbar AddPath(localBase, System, true, false, false); 1925c5758bb0a4ec0f572cd20249277736da5715003Daniel Dunbar AddPath(localBase + "/c++", System, true, false, false); 1935c5758bb0a4ec0f572cd20249277736da5715003Daniel Dunbar AddPath(localBase + "/c++/backward", System, true, false, false); 194620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump} 19543d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump 196620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // FIXME: This probably should goto to some platform utils place. 197620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump#ifdef _MSC_VER 19875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson 199620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // Read registry string. 20075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // This also supports a means to look for high-versioned keys by use 20175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // of a $VERSION placeholder in the key path. 20275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // $VERSION in the key path is a placeholder for the version number, 20375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // causing the highest value path to be searched for and used. 20475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION". 20575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // There can be additional characters in the component. Only the numberic 20675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // characters are compared. 207620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stumpbool getSystemRegistryString(const char *keyPath, const char *valueName, 20843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump char *value, size_t maxLength) { 20943d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump HKEY hRootKey = NULL; 21043d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump HKEY hKey = NULL; 21143d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump const char* subKey = NULL; 21243d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump DWORD valueType; 21343d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump DWORD valueSize = maxLength - 1; 21475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson long lResult; 21543d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump bool returnValue = false; 21643d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) { 21743d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump hRootKey = HKEY_CLASSES_ROOT; 21843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump subKey = keyPath + 18; 21943d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 22043d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) { 22143d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump hRootKey = HKEY_USERS; 22243d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump subKey = keyPath + 11; 22343d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 22443d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) { 22543d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump hRootKey = HKEY_LOCAL_MACHINE; 22643d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump subKey = keyPath + 19; 227121e3c207415fb4c105d690de384d8f3d49b0f2dArgyrios Kyrtzidis } 22843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) { 22943d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump hRootKey = HKEY_CURRENT_USER; 23043d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump subKey = keyPath + 18; 23143d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 23243d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump else 23343d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump return(false); 23475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson const char *placeHolder = strstr(subKey, "$VERSION"); 23575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson char bestName[256]; 23675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson bestName[0] = '\0'; 23775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // If we have a $VERSION placeholder, do the highest-version search. 23875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (placeHolder) { 23975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson const char *keyEnd = placeHolder - 1; 24075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson const char *nextKey = placeHolder; 24175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Find end of previous key. 24275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson while ((keyEnd > subKey) && (*keyEnd != '\\')) 24375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson keyEnd--; 24475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Find end of key containing $VERSION. 24575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson while (*nextKey && (*nextKey != '\\')) 24675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson nextKey++; 24775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson size_t partialKeyLength = keyEnd - subKey; 24875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson char partialKey[256]; 24975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (partialKeyLength > sizeof(partialKey)) 25075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson partialKeyLength = sizeof(partialKey); 25175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson strncpy(partialKey, subKey, partialKeyLength); 25275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson partialKey[partialKeyLength] = '\0'; 25375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson HKEY hTopKey = NULL; 25475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ, &hTopKey); 25575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (lResult == ERROR_SUCCESS) { 25675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson char keyName[256]; 25775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson int bestIndex = -1; 25875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson double bestValue = 0.0; 25975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson DWORD index, size = sizeof(keyName) - 1; 26033cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL, 26133cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes NULL, NULL, NULL) == ERROR_SUCCESS; index++) { 26233cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes const char *sp = keyName; 26333cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes while (*sp && !isdigit(*sp)) 26433cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes sp++; 26533cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes if (!*sp) 26633cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes continue; 26733cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes const char *ep = sp + 1; 26833cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes while (*ep && (isdigit(*ep) || (*ep == '.'))) 26933cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes ep++; 27033cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes char numBuf[32]; 27133cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes strncpy(numBuf, sp, sizeof(numBuf) - 1); 27233cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes numBuf[sizeof(numBuf) - 1] = '\0'; 27333cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes double value = strtod(numBuf, NULL); 27433cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes if (value > bestValue) { 27533cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes bestIndex = (int)index; 27633cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes bestValue = value; 27733cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes strcpy(bestName, keyName); 27833cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes } 27975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson size = sizeof(keyName) - 1; 28075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 28175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // If we found the highest versioned key, open the key and get the value. 28275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (bestIndex != -1) { 28375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Append rest of key. 28475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson strncat(bestName, nextKey, sizeof(bestName) - 1); 28575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson bestName[sizeof(bestName) - 1] = '\0'; 28675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Open the chosen key path remainder. 28775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ, &hKey); 28875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (lResult == ERROR_SUCCESS) { 28975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, 29075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson (LPBYTE)value, &valueSize); 29175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (lResult == ERROR_SUCCESS) 29275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson returnValue = true; 29375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson RegCloseKey(hKey); 29475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 29575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 29675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson RegCloseKey(hTopKey); 29775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 29875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 29975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson else { 30075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey); 30175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (lResult == ERROR_SUCCESS) { 30275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, 30375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson (LPBYTE)value, &valueSize); 30475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (lResult == ERROR_SUCCESS) 30575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson returnValue = true; 30675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson RegCloseKey(hKey); 30775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 30843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 30943d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump return(returnValue); 31043d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump} 311620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump#else // _MSC_VER 312620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // Read registry string. 313620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stumpbool getSystemRegistryString(const char *, const char *, char *, size_t) { 314620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump return(false); 315620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump} 316620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump#endif // _MSC_VER 317121e3c207415fb4c105d690de384d8f3d49b0f2dArgyrios Kyrtzidis 31843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump // Get Visual Studio installation directory. 31943d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stumpbool getVisualStudioDir(std::string &path) { 32075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson char vsIDEInstallDir[256]; 321620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // Try the Windows registry first. 32275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson bool hasVCDir = getSystemRegistryString( 32375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION", 32475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1); 32543d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump // If we have both vc80 and vc90, pick version we were compiled with. 32675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (hasVCDir && vsIDEInstallDir[0]) { 327620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE"); 328620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump if (p) 329620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump *p = '\0'; 330620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump path = vsIDEInstallDir; 331620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump return(true); 33243d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 333620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump else { 334620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // Try the environment. 335620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump const char* vs90comntools = getenv("VS90COMNTOOLS"); 336620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump const char* vs80comntools = getenv("VS80COMNTOOLS"); 337620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump const char* vscomntools = NULL; 338620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // If we have both vc80 and vc90, pick version we were compiled with. 339620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump if (vs90comntools && vs80comntools) { 340620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #if (_MSC_VER >= 1500) // VC90 341620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump vscomntools = vs90comntools; 342620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #elif (_MSC_VER == 1400) // VC80 343620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump vscomntools = vs80comntools; 344620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #else 345620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump vscomntools = vs90comntools; 346620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #endif 347620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump } 348620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump else if (vs90comntools) 349620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump vscomntools = vs90comntools; 350620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump else if (vs80comntools) 351620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump vscomntools = vs80comntools; 352620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump if (vscomntools && *vscomntools) { 353620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump char *p = (char*)strstr(vscomntools, "\\Common7\\Tools"); 354620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump if (p) 355620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump *p = '\0'; 356620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump path = vscomntools; 357620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump return(true); 358620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump } 359620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump else 360620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump return(false); 361620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump } 362620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump return(false); 36343d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump} 3644d374d4a4832a01d5d3b75c59cb1567e60df41e7Sebastian Redl 36575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Get Windows SDK installation directory. 36675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompsonbool getWindowsSDKDir(std::string &path) { 36775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson char windowsSDKInstallDir[256]; 36875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Try the Windows registry. 36975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson bool hasSDKDir = getSystemRegistryString( 37075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION", 37175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson "InstallationFolder", windowsSDKInstallDir, sizeof(windowsSDKInstallDir) - 1); 37275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // If we have both vc80 and vc90, pick version we were compiled with. 37375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (hasSDKDir && windowsSDKInstallDir[0]) { 37475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson path = windowsSDKInstallDir; 37575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson return(true); 37675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 37775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson return(false); 37875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson} 37975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson 380e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindolavoid InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple) { 38143d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump // FIXME: temporary hack: hard-coded paths. 382c706468b1e00bab49ca92eb500a39657f530f828Daniel Dunbar llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS); 383c706468b1e00bab49ca92eb500a39657f530f828Daniel Dunbar if (CIncludeDirs != "") { 384aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola llvm::SmallVector<llvm::StringRef, 5> dirs; 385aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola CIncludeDirs.split(dirs, ":"); 386aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin(); 387aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola i != dirs.end(); 388aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola ++i) 389f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola AddPath(*i, System, false, false, false); 390f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola return; 391f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola } 39243d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump llvm::Triple::OSType os = triple.getOS(); 39343d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump switch (os) { 39443d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump case llvm::Triple::Win32: 39543d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump { 396620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump std::string VSDir; 39775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson std::string WindowsSDKDir; 398620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump if (getVisualStudioDir(VSDir)) { 399620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump AddPath(VSDir + "\\VC\\include", System, false, false, false); 40075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (getWindowsSDKDir(WindowsSDKDir)) 40175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson AddPath(WindowsSDKDir, System, false, false, false); 40275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson else 40375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson AddPath(VSDir + "\\VC\\PlatformSDK\\Include", 40475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson System, false, false, false); 405620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump } 4069319f02dea2449caf5c7a0d07c596ca324e43574John Thompson else { 4079319f02dea2449caf5c7a0d07c596ca324e43574John Thompson // Default install paths. 4089319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include", 4099319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4109319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath( 4119319f02dea2449caf5c7a0d07c596ca324e43574John Thompson "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", 4129319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4139319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include", 4149319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4159319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath( 4169319f02dea2449caf5c7a0d07c596ca324e43574John Thompson "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include", 4179319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4189319f02dea2449caf5c7a0d07c596ca324e43574John Thompson // For some clang developers. 4199319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath("G:/Program Files/Microsoft Visual Studio 9.0/VC/include", 4209319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4219319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath( 4229319f02dea2449caf5c7a0d07c596ca324e43574John Thompson "G:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", 4239319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4249319f02dea2449caf5c7a0d07c596ca324e43574John Thompson } 42543d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 42643d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump break; 42743d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump case llvm::Triple::MinGW64: 428620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump case llvm::Triple::MinGW32: 42943d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump AddPath("c:/mingw/include", System, true, false, false); 43043d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump break; 43143d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump default: 43243d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump break; 4330fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 434d3f88343af2dec3459493fafa22532317321eaf0John Thompson 435d3f88343af2dec3459493fafa22532317321eaf0John Thompson AddPath("/usr/local/include", System, false, false, false); 436d3f88343af2dec3459493fafa22532317321eaf0John Thompson AddPath("/usr/include", System, false, false, false); 437e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola} 438e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola 439e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindolavoid InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) { 440e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola llvm::Triple::OSType os = triple.getOS(); 441ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT); 442ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola if (CxxIncludeRoot != "") { 443ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola llvm::StringRef CxxIncludeArch(CXX_INCLUDE_ARCH); 444ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola if (CxxIncludeArch == "") 445ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(), 446ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, triple); 447ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola else 448ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH, 449ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, triple); 450ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola return; 451ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola } 452e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // FIXME: temporary hack: hard-coded paths. 453e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola switch (os) { 454e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::Cygwin: 455e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include", 456e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola System, true, false, false); 457e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++", 458e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola System, true, false, false); 459e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 460e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::MinGW64: 461e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Try gcc 4.4.0 462e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.4.0"); 463e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Try gcc 4.3.0 464e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.3.0"); 465e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Fall through. 466e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::MinGW32: 467e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Try gcc 4.4.0 468e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); 469e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Try gcc 4.3.0 470e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); 471e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 472e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::Darwin: 473e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 474ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-apple-darwin10", "", "x86_64", triple); 475e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", 476ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-apple-darwin8", "", "", triple); 477e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 478e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::Linux: 479e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Ubuntu 7.10 - Gutsy Gibbon 480e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.3", 481ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i486-linux-gnu", "", "", triple); 482e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Ubuntu 9.04 483e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.3", 484ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "x86_64-linux-gnu","32", "", triple); 4855114ecab149ab91d13d3f7fd165dbe0839c1f2e8Sebastian Redl // Ubuntu 9.10 4865114ecab149ab91d13d3f7fd165dbe0839c1f2e8Sebastian Redl AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", 487ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "x86_64-linux-gnu", "32", "", triple); 488e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Fedora 8 489e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", 490ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i386-redhat-linux", "", "", triple); 491e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Fedora 9 492e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", 493ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i386-redhat-linux", "", "", triple); 494e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Fedora 10 495e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", 496ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i386-redhat-linux","", "", triple); 497189a14869a36ecf8bd5edc94255a34061044efe2Nuno Lopes 498189a14869a36ecf8bd5edc94255a34061044efe2Nuno Lopes // Fedora 11 499189a14869a36ecf8bd5edc94255a34061044efe2Nuno Lopes AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", 500189a14869a36ecf8bd5edc94255a34061044efe2Nuno Lopes "i586-redhat-linux","", "", triple); 501189a14869a36ecf8bd5edc94255a34061044efe2Nuno Lopes 50233cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes // Fedora 12 50333cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", 50433cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes "i686-redhat-linux","", "", triple); 50533cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes 506e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // openSUSE 11.1 32 bit 507e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 508ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i586-suse-linux", "", "", triple); 509e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // openSUSE 11.1 64 bit 510e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 511ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "x86_64-suse-linux", "32", "", triple); 512e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // openSUSE 11.2 513e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 514ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i586-suse-linux", "", "", triple); 515e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 516ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "x86_64-suse-linux", "", "", triple); 517e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Arch Linux 2008-06-24 518e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", 519ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-pc-linux-gnu", "", "", triple); 520e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", 521ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "x86_64-unknown-linux-gnu", "", "", triple); 522e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Gentoo x86 2009.1 stable 523e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths( 52440d1bb6383c14d5f8249d0640e8088a91b694c66John Thompson "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4", 525ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-pc-linux-gnu", "", "", triple); 526e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Gentoo x86 2009.0 stable 527e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths( 52840d1bb6383c14d5f8249d0640e8088a91b694c66John Thompson "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4", 529ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-pc-linux-gnu", "", "", triple); 530e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Gentoo x86 2008.0 stable 531e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths( 53240d1bb6383c14d5f8249d0640e8088a91b694c66John Thompson "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", 533ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-pc-linux-gnu", "", "", triple); 534e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Ubuntu 8.10 535e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 536ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i486-pc-linux-gnu", "", "", triple); 537e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Ubuntu 9.04 538e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 539ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i486-linux-gnu","", "", triple); 540e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Gentoo amd64 stable 541e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths( 542e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", 543ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-pc-linux-gnu", "", "", triple); 5445d7a188cbc66d0af5aa3c135942a9e4aa7cb69f9Benjamin Kramer // Exherbo (2009-10-26) 545ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", 546ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "x86_64-pc-linux-gnu", "32", "", triple); 547ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", 548ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-pc-linux-gnu", "", "", triple); 549e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 550e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::FreeBSD: 551e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // DragonFly 552e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddPath("/usr/include/c++/4.1", System, true, false, false); 553e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // FreeBSD 554e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddPath("/usr/include/c++/4.2", System, true, false, false); 555e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 556e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::Solaris: 557e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Solaris - Fall though.. 558e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::AuroraUX: 559e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // AuroraUX 560e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", 561ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i386-pc-solaris2.11", "", "", triple); 562e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 563e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola default: 564e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 565e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola } 566e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola} 567e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola 568e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindolavoid InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang, 569e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola const llvm::Triple &triple) { 5706ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola if (Lang.CPlusPlus) 5716ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola AddDefaultCPlusPlusIncludePaths(triple); 5726ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola 573e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddDefaultCIncludePaths(triple); 574e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar 575e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar // Add the default framework include paths on Darwin. 576e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar if (triple.getOS() == llvm::Triple::Darwin) { 577e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar AddPath("/System/Library/Frameworks", System, true, false, true); 578e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar AddPath("/Library/Frameworks", System, true, false, true); 579e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar } 580e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola} 581e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola 5820fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber/// RemoveDuplicates - If there are duplicate directory entries in the specified 5830fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber/// search list, remove the later (dead) ones. 5840fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weberstatic void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, 5850fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber bool Verbose) { 5860fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; 5870fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; 5880fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; 5890fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber for (unsigned i = 0; i != SearchList.size(); ++i) { 5907a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner unsigned DirToRemove = i; 5911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59243eee07270bf1966ea7289310066aa670c4b647fChris Lattner const DirectoryLookup &CurEntry = SearchList[i]; 5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59443eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (CurEntry.isNormalDir()) { 5950fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If this isn't the first time we've seen this dir, remove it. 59643eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SeenDirs.insert(CurEntry.getDir())) 5970fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber continue; 59843eee07270bf1966ea7289310066aa670c4b647fChris Lattner } else if (CurEntry.isFramework()) { 5990fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If this isn't the first time we've seen this framework dir, remove it. 60043eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) 6010fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber continue; 6020fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } else { 60343eee07270bf1966ea7289310066aa670c4b647fChris Lattner assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); 6040fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If this isn't the first time we've seen this headermap, remove it. 60543eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) 6060fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber continue; 60730f05b553db067c994966daca37e75324ee7b424Chris Lattner } 6081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60930f05b553db067c994966daca37e75324ee7b424Chris Lattner // If we have a normal #include dir/framework/headermap that is shadowed 61030f05b553db067c994966daca37e75324ee7b424Chris Lattner // later in the chain by a system include location, we actually want to 61130f05b553db067c994966daca37e75324ee7b424Chris Lattner // ignore the user's request and drop the user dir... keeping the system 61230f05b553db067c994966daca37e75324ee7b424Chris Lattner // dir. This is weird, but required to emulate GCC's search path correctly. 61330f05b553db067c994966daca37e75324ee7b424Chris Lattner // 61430f05b553db067c994966daca37e75324ee7b424Chris Lattner // Since dupes of system dirs are rare, just rescan to find the original 61530f05b553db067c994966daca37e75324ee7b424Chris Lattner // that we're nuking instead of using a DenseMap. 61643eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { 61730f05b553db067c994966daca37e75324ee7b424Chris Lattner // Find the dir that this is the same of. 61830f05b553db067c994966daca37e75324ee7b424Chris Lattner unsigned FirstDir; 61930f05b553db067c994966daca37e75324ee7b424Chris Lattner for (FirstDir = 0; ; ++FirstDir) { 62030f05b553db067c994966daca37e75324ee7b424Chris Lattner assert(FirstDir != i && "Didn't find dupe?"); 6211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62243eee07270bf1966ea7289310066aa670c4b647fChris Lattner const DirectoryLookup &SearchEntry = SearchList[FirstDir]; 62343eee07270bf1966ea7289310066aa670c4b647fChris Lattner 62430f05b553db067c994966daca37e75324ee7b424Chris Lattner // If these are different lookup types, then they can't be the dupe. 62543eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SearchEntry.getLookupType() != CurEntry.getLookupType()) 62630f05b553db067c994966daca37e75324ee7b424Chris Lattner continue; 6271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62830f05b553db067c994966daca37e75324ee7b424Chris Lattner bool isSame; 62943eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (CurEntry.isNormalDir()) 63043eee07270bf1966ea7289310066aa670c4b647fChris Lattner isSame = SearchEntry.getDir() == CurEntry.getDir(); 63143eee07270bf1966ea7289310066aa670c4b647fChris Lattner else if (CurEntry.isFramework()) 63243eee07270bf1966ea7289310066aa670c4b647fChris Lattner isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); 63330f05b553db067c994966daca37e75324ee7b424Chris Lattner else { 63443eee07270bf1966ea7289310066aa670c4b647fChris Lattner assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); 63543eee07270bf1966ea7289310066aa670c4b647fChris Lattner isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); 63630f05b553db067c994966daca37e75324ee7b424Chris Lattner } 6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63830f05b553db067c994966daca37e75324ee7b424Chris Lattner if (isSame) 63930f05b553db067c994966daca37e75324ee7b424Chris Lattner break; 64030f05b553db067c994966daca37e75324ee7b424Chris Lattner } 6411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64230f05b553db067c994966daca37e75324ee7b424Chris Lattner // If the first dir in the search path is a non-system dir, zap it 64330f05b553db067c994966daca37e75324ee7b424Chris Lattner // instead of the system one. 64430f05b553db067c994966daca37e75324ee7b424Chris Lattner if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) 64530f05b553db067c994966daca37e75324ee7b424Chris Lattner DirToRemove = FirstDir; 64630f05b553db067c994966daca37e75324ee7b424Chris Lattner } 64730f05b553db067c994966daca37e75324ee7b424Chris Lattner 64830f05b553db067c994966daca37e75324ee7b424Chris Lattner if (Verbose) { 649e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "ignoring duplicate directory \"" 650e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar << CurEntry.getName() << "\"\n"; 65130f05b553db067c994966daca37e75324ee7b424Chris Lattner if (DirToRemove != i) 652e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << " as it is a non-system directory that duplicates " 653e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar << "a system directory\n"; 6540fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6567a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner // This is reached if the current entry is a duplicate. Remove the 6577a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner // DirToRemove (usually the current dir). 6587a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner SearchList.erase(SearchList.begin()+DirToRemove); 6590fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber --i; 6600fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 6610fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber} 6620fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 6630fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 6640fca022d77b89100e746f4d659b84ed5b1ee0158Nico Webervoid InitHeaderSearch::Realize() { 6650fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. 6660fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber std::vector<DirectoryLookup> SearchList; 6670fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber SearchList = IncludeGroup[Angled]; 6680fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber SearchList.insert(SearchList.end(), IncludeGroup[System].begin(), 6690fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber IncludeGroup[System].end()); 6700fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber SearchList.insert(SearchList.end(), IncludeGroup[After].begin(), 6710fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber IncludeGroup[After].end()); 6720fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber RemoveDuplicates(SearchList, Verbose); 6730fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber RemoveDuplicates(IncludeGroup[Quoted], Verbose); 6741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6750fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Prepend QUOTED list on the search list. 6761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(), 6770fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber IncludeGroup[Quoted].end()); 6781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6790fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 6800fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber bool DontSearchCurDir = false; // TODO: set to true if -I- is set? 6810fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(), 6820fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber DontSearchCurDir); 6830fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 6840fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If verbose, print the list of directories that will be searched. 6850fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (Verbose) { 686e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "#include \"...\" search starts here:\n"; 6870fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber unsigned QuotedIdx = IncludeGroup[Quoted].size(); 6880fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { 6890fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (i == QuotedIdx) 690e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "#include <...> search starts here:\n"; 6910fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber const char *Name = SearchList[i].getName(); 6920fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber const char *Suffix; 6930fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (SearchList[i].isNormalDir()) 6940fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber Suffix = ""; 6950fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else if (SearchList[i].isFramework()) 6960fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber Suffix = " (framework directory)"; 6970fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else { 6980fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); 6990fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber Suffix = " (headermap)"; 7000fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 701e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << " " << Name << Suffix << "\n"; 7020fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 703e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "End of search list.\n"; 7040fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 7050fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber} 70663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 7075814e657c9ad9ef6049a2a4af0d2aad248a8a15cDaniel Dunbarvoid clang::ApplyHeaderSearchOptions(HeaderSearch &HS, 7085814e657c9ad9ef6049a2a4af0d2aad248a8a15cDaniel Dunbar const HeaderSearchOptions &HSOpts, 7095814e657c9ad9ef6049a2a4af0d2aad248a8a15cDaniel Dunbar const LangOptions &Lang, 71063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar const llvm::Triple &Triple) { 71163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); 71263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 71363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar // Add the user defined entries. 71463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { 71563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; 7161b483e70ad3f670f6dd0bc62dbe0921a28195f24Daniel Dunbar Init.AddPath(E.Path, E.Group, false, E.IsUserSupplied, E.IsFramework, 7171b483e70ad3f670f6dd0bc62dbe0921a28195f24Daniel Dunbar false); 71863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar } 71963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 72063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar // Add entries from CPATH and friends. 72163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar Init.AddDelimitedPaths(HSOpts.EnvIncPath.c_str()); 722c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar if (Lang.CPlusPlus && Lang.ObjC1) 723c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath.c_str()); 724c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar else if (Lang.CPlusPlus) 725c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath.c_str()); 726c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar else if (Lang.ObjC1) 727c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath.c_str()); 728c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar else 729c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar Init.AddDelimitedPaths(HSOpts.CEnvIncPath.c_str()); 73063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 73163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar if (!HSOpts.BuiltinIncludePath.empty()) { 73263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar // Ignore the sys root, we *always* look for clang headers relative to 73363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar // supplied path. 7342cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar Init.AddPath(HSOpts.BuiltinIncludePath, System, 73563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar false, false, false, /*IgnoreSysRoot=*/ true); 73663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar } 73763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 738dd35ce9a783dea7e6660f9cb1d973742f3b3c73fDaniel Dunbar if (HSOpts.UseStandardIncludes) 73963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar Init.AddDefaultSystemIncludePaths(Lang, Triple); 74063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 74163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar Init.Realize(); 74263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar} 743