2010-07-25 11:12:58 +08:00
|
|
|
//===--- InitHeaderSearch.cpp - Initialize header search paths ------------===//
|
2008-08-22 17:25:22 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2008-08-22 17:25:22 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the InitHeaderSearch class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2022-01-12 00:17:07 +08:00
|
|
|
#include "clang/Basic/DiagnosticFrontend.h"
|
2008-08-22 17:25:22 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/LangOptions.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Config/config.h" // C_INCLUDE_DIRS
|
2015-12-30 11:40:23 +08:00
|
|
|
#include "clang/Lex/HeaderMap.h"
|
2009-11-07 12:20:50 +08:00
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Lex/HeaderSearchOptions.h"
|
2008-08-22 17:25:22 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2009-11-13 13:13:58 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-11-12 13:48:41 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2009-11-10 07:02:47 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2009-12-08 20:38:20 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2011-11-05 07:49:05 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-11-30 02:12:39 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-02-01 22:25:28 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
using namespace clang;
|
2009-11-10 07:02:47 +08:00
|
|
|
using namespace clang::frontend;
|
|
|
|
|
|
|
|
namespace {
|
2021-05-28 20:05:22 +08:00
|
|
|
/// Holds information about a single DirectoryLookup object.
|
|
|
|
struct DirectoryLookupInfo {
|
|
|
|
IncludeDirGroup Group;
|
|
|
|
DirectoryLookup Lookup;
|
2021-10-12 15:34:43 +08:00
|
|
|
Optional<unsigned> UserEntryIdx;
|
2021-05-28 20:05:22 +08:00
|
|
|
|
2021-10-12 15:34:43 +08:00
|
|
|
DirectoryLookupInfo(IncludeDirGroup Group, DirectoryLookup Lookup,
|
|
|
|
Optional<unsigned> UserEntryIdx)
|
|
|
|
: Group(Group), Lookup(Lookup), UserEntryIdx(UserEntryIdx) {}
|
2021-05-28 20:05:22 +08:00
|
|
|
};
|
2009-11-10 07:02:47 +08:00
|
|
|
|
|
|
|
/// InitHeaderSearch - This class makes it easier to set the search paths of
|
|
|
|
/// a HeaderSearch object. InitHeaderSearch stores several search path lists
|
|
|
|
/// internally, which can be sent to a HeaderSearch object in one swoop.
|
|
|
|
class InitHeaderSearch {
|
2021-05-28 20:05:22 +08:00
|
|
|
std::vector<DirectoryLookupInfo> IncludePath;
|
2012-06-14 04:27:03 +08:00
|
|
|
std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
|
2011-06-17 06:56:45 +08:00
|
|
|
HeaderSearch &Headers;
|
2009-11-10 07:02:47 +08:00
|
|
|
bool Verbose;
|
2010-12-26 04:09:27 +08:00
|
|
|
std::string IncludeSysroot;
|
2013-01-30 07:59:43 +08:00
|
|
|
bool HasSysroot;
|
2009-11-10 07:02:47 +08:00
|
|
|
|
|
|
|
public:
|
2011-07-23 18:55:15 +08:00
|
|
|
InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
|
2020-01-29 03:23:46 +08:00
|
|
|
: Headers(HS), Verbose(verbose), IncludeSysroot(std::string(sysroot)),
|
|
|
|
HasSysroot(!(sysroot.empty() || sysroot == "/")) {}
|
2009-11-10 07:02:47 +08:00
|
|
|
|
2013-01-30 09:06:03 +08:00
|
|
|
/// AddPath - Add the specified path to the specified group list, prefixing
|
|
|
|
/// the sysroot if used.
|
2018-06-20 06:47:53 +08:00
|
|
|
/// Returns true if the path exists, false if it was ignored.
|
2021-10-12 15:34:43 +08:00
|
|
|
bool AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework,
|
|
|
|
Optional<unsigned> UserEntryIdx = None);
|
2013-01-30 09:06:03 +08:00
|
|
|
|
|
|
|
/// AddUnmappedPath - Add the specified path to the specified group list,
|
|
|
|
/// without performing any sysroot remapping.
|
2018-06-20 06:47:53 +08:00
|
|
|
/// Returns true if the path exists, false if it was ignored.
|
|
|
|
bool AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
|
2021-10-12 15:34:43 +08:00
|
|
|
bool isFramework,
|
|
|
|
Optional<unsigned> UserEntryIdx = None);
|
2009-11-10 07:02:47 +08:00
|
|
|
|
2012-06-14 04:27:03 +08:00
|
|
|
/// AddSystemHeaderPrefix - Add the specified prefix to the system header
|
|
|
|
/// prefix list.
|
|
|
|
void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
|
2020-01-29 09:57:59 +08:00
|
|
|
SystemHeaderPrefixes.emplace_back(std::string(Prefix), IsSystemHeader);
|
2012-06-14 04:27:03 +08:00
|
|
|
}
|
|
|
|
|
2010-05-06 01:00:31 +08:00
|
|
|
/// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
|
2009-11-10 07:02:47 +08:00
|
|
|
/// libstdc++.
|
2018-06-20 06:47:53 +08:00
|
|
|
/// Returns true if the \p Base path was found, false if it does not exist.
|
|
|
|
bool AddGnuCPlusPlusIncludePaths(StringRef Base, StringRef ArchDir,
|
|
|
|
StringRef Dir32, StringRef Dir64,
|
2009-11-10 07:02:47 +08:00
|
|
|
const llvm::Triple &triple);
|
|
|
|
|
2010-12-22 00:45:42 +08:00
|
|
|
/// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
|
2009-11-10 07:02:47 +08:00
|
|
|
/// libstdc++.
|
2012-03-26 06:46:17 +08:00
|
|
|
void AddMinGWCPlusPlusIncludePaths(StringRef Base,
|
|
|
|
StringRef Arch,
|
|
|
|
StringRef Version);
|
2009-11-10 07:02:47 +08:00
|
|
|
|
|
|
|
// AddDefaultCIncludePaths - Add paths that should always be searched.
|
2010-05-17 03:03:52 +08:00
|
|
|
void AddDefaultCIncludePaths(const llvm::Triple &triple,
|
|
|
|
const HeaderSearchOptions &HSOpts);
|
2009-11-10 07:02:47 +08:00
|
|
|
|
|
|
|
// AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
|
|
|
|
// compiling c++.
|
2018-06-20 06:47:53 +08:00
|
|
|
void AddDefaultCPlusPlusIncludePaths(const LangOptions &LangOpts,
|
|
|
|
const llvm::Triple &triple,
|
2011-06-27 23:47:15 +08:00
|
|
|
const HeaderSearchOptions &HSOpts);
|
2009-11-10 07:02:47 +08:00
|
|
|
|
|
|
|
/// AddDefaultSystemIncludePaths - Adds the default system include paths so
|
|
|
|
/// that e.g. stdio.h is found.
|
2011-10-12 02:20:10 +08:00
|
|
|
void AddDefaultIncludePaths(const LangOptions &Lang,
|
|
|
|
const llvm::Triple &triple,
|
|
|
|
const HeaderSearchOptions &HSOpts);
|
2009-11-10 07:02:47 +08:00
|
|
|
|
|
|
|
/// Realize - Merges all search path lists into one list and send it to
|
|
|
|
/// HeaderSearch.
|
2011-02-22 08:40:56 +08:00
|
|
|
void Realize(const LangOptions &Lang);
|
2009-11-10 07:02:47 +08:00
|
|
|
};
|
|
|
|
|
2011-06-17 06:56:45 +08:00
|
|
|
} // end anonymous namespace.
|
2008-08-22 17:25:22 +08:00
|
|
|
|
2013-01-30 07:59:37 +08:00
|
|
|
static bool CanPrefixSysroot(StringRef Path) {
|
2018-04-28 03:11:14 +08:00
|
|
|
#if defined(_WIN32)
|
2013-01-30 07:59:37 +08:00
|
|
|
return !Path.empty() && llvm::sys::path::is_separator(Path[0]);
|
|
|
|
#else
|
|
|
|
return llvm::sys::path::is_absolute(Path);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-06-20 06:47:53 +08:00
|
|
|
bool InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
|
2021-10-12 15:34:43 +08:00
|
|
|
bool isFramework,
|
|
|
|
Optional<unsigned> UserEntryIdx) {
|
2013-01-30 09:06:03 +08:00
|
|
|
// Add the path with sysroot prepended, if desired and this is a system header
|
|
|
|
// group.
|
|
|
|
if (HasSysroot) {
|
|
|
|
SmallString<256> MappedPathStorage;
|
|
|
|
StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
|
|
|
|
if (CanPrefixSysroot(MappedPathStr)) {
|
2021-10-12 15:34:43 +08:00
|
|
|
return AddUnmappedPath(IncludeSysroot + Path, Group, isFramework,
|
|
|
|
UserEntryIdx);
|
2013-01-30 09:06:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-12 15:34:43 +08:00
|
|
|
return AddUnmappedPath(Path, Group, isFramework, UserEntryIdx);
|
2013-01-30 09:06:03 +08:00
|
|
|
}
|
|
|
|
|
2018-06-20 06:47:53 +08:00
|
|
|
bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
|
2021-10-12 15:34:43 +08:00
|
|
|
bool isFramework,
|
|
|
|
Optional<unsigned> UserEntryIdx) {
|
2009-12-08 20:38:20 +08:00
|
|
|
assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-01-30 09:06:03 +08:00
|
|
|
FileManager &FM = Headers.getFileMgr();
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<256> MappedPathStorage;
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2019-09-14 02:00:51 +08:00
|
|
|
// If use system headers while cross-compiling, emit the warning.
|
|
|
|
if (HasSysroot && (MappedPathStr.startswith("/usr/include") ||
|
|
|
|
MappedPathStr.startswith("/usr/local/include"))) {
|
|
|
|
Headers.getDiags().Report(diag::warn_poison_system_directories)
|
|
|
|
<< MappedPathStr;
|
|
|
|
}
|
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// Compute the DirectoryLookup type.
|
2008-10-27 09:19:25 +08:00
|
|
|
SrcMgr::CharacteristicKind Type;
|
2013-01-30 08:19:24 +08:00
|
|
|
if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) {
|
2008-09-27 05:18:42 +08:00
|
|
|
Type = SrcMgr::C_User;
|
2013-01-30 08:19:24 +08:00
|
|
|
} else if (Group == ExternCSystem) {
|
2008-09-27 05:18:42 +08:00
|
|
|
Type = SrcMgr::C_ExternCSystem;
|
2013-01-30 08:19:24 +08:00
|
|
|
} else {
|
|
|
|
Type = SrcMgr::C_System;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// If the directory exists, add it.
|
2019-08-31 09:26:04 +08:00
|
|
|
if (auto DE = FM.getOptionalDirectoryRef(MappedPathStr)) {
|
2021-10-12 15:34:43 +08:00
|
|
|
IncludePath.emplace_back(Group, DirectoryLookup(*DE, Type, isFramework),
|
|
|
|
UserEntryIdx);
|
2018-06-20 06:47:53 +08:00
|
|
|
return true;
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// Check to see if this is an apple-style headermap (which are not allowed to
|
|
|
|
// be frameworks).
|
|
|
|
if (!isFramework) {
|
2019-08-02 05:31:56 +08:00
|
|
|
if (auto FE = FM.getFile(MappedPathStr)) {
|
|
|
|
if (const HeaderMap *HM = Headers.CreateHeaderMap(*FE)) {
|
2008-08-22 17:25:22 +08:00
|
|
|
// It is a headermap, add it to the search path.
|
2021-05-28 20:05:22 +08:00
|
|
|
IncludePath.emplace_back(
|
2021-10-12 15:34:43 +08:00
|
|
|
Group, DirectoryLookup(HM, Type, Group == IndexHeaderMap),
|
|
|
|
UserEntryIdx);
|
2018-06-20 06:47:53 +08:00
|
|
|
return true;
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
if (Verbose)
|
2010-11-15 08:48:13 +08:00
|
|
|
llvm::errs() << "ignoring nonexistent directory \""
|
|
|
|
<< MappedPathStr << "\"\n";
|
2018-06-20 06:47:53 +08:00
|
|
|
return false;
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
|
|
|
|
2018-06-20 06:47:53 +08:00
|
|
|
bool InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef ArchDir,
|
|
|
|
StringRef Dir32,
|
|
|
|
StringRef Dir64,
|
2009-10-15 01:09:44 +08:00
|
|
|
const llvm::Triple &triple) {
|
2009-11-24 00:31:19 +08:00
|
|
|
// Add the base dir
|
2018-06-20 06:47:53 +08:00
|
|
|
bool IsBaseFound = AddPath(Base, CXXSystem, false);
|
2009-11-17 03:49:37 +08:00
|
|
|
|
|
|
|
// Add the multilib dirs
|
2009-10-15 01:09:44 +08:00
|
|
|
llvm::Triple::ArchType arch = triple.getArch();
|
|
|
|
bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
|
|
|
|
if (is64bit)
|
2013-01-30 08:19:24 +08:00
|
|
|
AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, false);
|
2009-10-15 01:09:44 +08:00
|
|
|
else
|
2013-01-30 08:19:24 +08:00
|
|
|
AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, false);
|
2009-11-24 00:31:19 +08:00
|
|
|
|
|
|
|
// Add the backward dir
|
2013-01-30 08:19:24 +08:00
|
|
|
AddPath(Base + "/backward", CXXSystem, false);
|
2018-06-20 06:47:53 +08:00
|
|
|
return IsBaseFound;
|
2009-10-06 09:33:02 +08:00
|
|
|
}
|
2008-08-22 17:25:22 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
|
2012-03-26 06:46:17 +08:00
|
|
|
StringRef Arch,
|
|
|
|
StringRef Version) {
|
|
|
|
AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
|
2013-01-30 08:19:24 +08:00
|
|
|
CXXSystem, false);
|
2012-03-26 06:46:17 +08:00
|
|
|
AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
|
2013-01-30 08:19:24 +08:00
|
|
|
CXXSystem, false);
|
2012-03-26 06:46:17 +08:00
|
|
|
AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
|
2013-01-30 08:19:24 +08:00
|
|
|
CXXSystem, false);
|
2009-10-13 04:50:45 +08:00
|
|
|
}
|
2009-10-09 07:29:47 +08:00
|
|
|
|
2010-05-17 03:03:52 +08:00
|
|
|
void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
|
|
|
|
const HeaderSearchOptions &HSOpts) {
|
2011-02-03 02:59:27 +08:00
|
|
|
llvm::Triple::OSType os = triple.getOS();
|
|
|
|
|
[clang][Darwin] Refactor header search path logic into the driver
Summary:
This commit moves the logic for determining system, resource and C++
header search paths from CC1 to the driver. This refactor has already
been made for several platforms, but Darwin had been left behind.
This refactor tries to implement the previous search path logic with
perfect accuracy. In particular, the order of all include paths inside
CC1 and all paths that were skipped because nonexistent are conserved
after the refactor. This change was also tested against a code base
of significant size and revealed no problems.
Reviewers: jfb, arphaman
Subscribers: nemanjai, javed.absar, kbarton, christof, jkorous, dexonsmith, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61963
llvm-svn: 361278
2019-05-22 01:48:04 +08:00
|
|
|
if (triple.isOSDarwin()) {
|
|
|
|
llvm_unreachable("Include management is handled in the driver.");
|
|
|
|
}
|
|
|
|
|
2011-10-12 02:20:10 +08:00
|
|
|
if (HSOpts.UseStandardSystemIncludes) {
|
|
|
|
switch (os) {
|
2015-03-11 16:46:01 +08:00
|
|
|
case llvm::Triple::CloudABI:
|
2011-10-12 02:20:10 +08:00
|
|
|
case llvm::Triple::FreeBSD:
|
|
|
|
case llvm::Triple::NetBSD:
|
2012-08-02 20:27:08 +08:00
|
|
|
case llvm::Triple::OpenBSD:
|
2015-03-31 04:31:33 +08:00
|
|
|
case llvm::Triple::NaCl:
|
2015-10-14 20:25:43 +08:00
|
|
|
case llvm::Triple::PS4:
|
2015-12-16 21:27:38 +08:00
|
|
|
case llvm::Triple::ELFIAMCU:
|
2018-03-02 15:19:42 +08:00
|
|
|
case llvm::Triple::Fuchsia:
|
2011-10-12 02:20:10 +08:00
|
|
|
break;
|
2015-07-02 12:45:27 +08:00
|
|
|
case llvm::Triple::Win32:
|
|
|
|
if (triple.getEnvironment() != llvm::Triple::Cygnus)
|
|
|
|
break;
|
2017-06-03 14:27:16 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
2011-10-12 02:20:10 +08:00
|
|
|
default:
|
|
|
|
// FIXME: temporary hack: hard-coded paths.
|
2013-01-30 08:19:24 +08:00
|
|
|
AddPath("/usr/local/include", System, false);
|
2011-10-12 02:20:10 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-02-03 02:59:27 +08:00
|
|
|
}
|
2010-05-17 03:03:52 +08:00
|
|
|
|
|
|
|
// Builtin includes use #include_next directives and should be positioned
|
|
|
|
// just prior C include dirs.
|
|
|
|
if (HSOpts.UseBuiltinIncludes) {
|
|
|
|
// Ignore the sys root, we *always* look for clang headers relative to
|
|
|
|
// supplied path.
|
2013-06-13 22:26:04 +08:00
|
|
|
SmallString<128> P = StringRef(HSOpts.ResourceDir);
|
|
|
|
llvm::sys::path::append(P, "include");
|
2015-03-18 18:17:07 +08:00
|
|
|
AddUnmappedPath(P, ExternCSystem, false);
|
2010-05-17 03:03:52 +08:00
|
|
|
}
|
|
|
|
|
2011-10-12 02:20:10 +08:00
|
|
|
// All remaining additions are for system include directories, early exit if
|
|
|
|
// we aren't using them.
|
|
|
|
if (!HSOpts.UseStandardSystemIncludes)
|
|
|
|
return;
|
|
|
|
|
2010-05-17 03:03:52 +08:00
|
|
|
// Add dirs specified via 'configure --with-c-include-dirs'.
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef CIncludeDirs(C_INCLUDE_DIRS);
|
2009-11-12 15:28:29 +08:00
|
|
|
if (CIncludeDirs != "") {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<StringRef, 5> dirs;
|
2009-11-13 13:13:58 +08:00
|
|
|
CIncludeDirs.split(dirs, ":");
|
2015-10-01 19:19:28 +08:00
|
|
|
for (StringRef dir : dirs)
|
|
|
|
AddPath(dir, ExternCSystem, false);
|
2009-11-12 13:48:41 +08:00
|
|
|
return;
|
|
|
|
}
|
2011-02-03 02:59:27 +08:00
|
|
|
|
2009-10-09 07:29:47 +08:00
|
|
|
switch (os) {
|
2011-11-06 04:17:13 +08:00
|
|
|
case llvm::Triple::Linux:
|
2018-11-29 11:49:14 +08:00
|
|
|
case llvm::Triple::Hurd:
|
[Solaris] gcc toolchain handling revamp
Summary:
General idea is to utilize generic (mostly Generic_GCC) code
and get rid of Solaris-specific handling as much as possible.
In particular:
- scanLibDirForGCCTripleSolaris was removed, relying on generic
CollectLibDirsAndTriples
- findBiarchMultilibs is now properly utilized to switch between
m32 and m64 include & lib paths on Solaris
- C system include handling copied from Linux (bar multilib hacks)
Fixes PR24606.
Reviewers: dlj, rafael, jyknight, theraven, tstellar
Reviewed By: jyknight
Subscribers: aaron.ballman, mgorny, krytarowski, ro, joerg, cfe-commits
Differential Revision: https://reviews.llvm.org/D35755
llvm-svn: 323193
2018-01-23 20:23:52 +08:00
|
|
|
case llvm::Triple::Solaris:
|
2020-08-24 08:01:38 +08:00
|
|
|
case llvm::Triple::OpenBSD:
|
2011-11-06 04:17:13 +08:00
|
|
|
llvm_unreachable("Include management is handled in the driver.");
|
2011-11-05 07:49:05 +08:00
|
|
|
|
2015-03-11 16:46:01 +08:00
|
|
|
case llvm::Triple::CloudABI: {
|
|
|
|
// <sysroot>/<triple>/include
|
|
|
|
SmallString<128> P = StringRef(HSOpts.ResourceDir);
|
|
|
|
llvm::sys::path::append(P, "../../..", triple.str(), "include");
|
2015-03-18 18:17:07 +08:00
|
|
|
AddPath(P, System, false);
|
2015-03-11 16:46:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-12 03:29:39 +08:00
|
|
|
case llvm::Triple::Haiku:
|
2016-05-12 00:19:05 +08:00
|
|
|
AddPath("/boot/system/non-packaged/develop/headers", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/app", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/arch", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/device", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/drivers", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/game", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/interface", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/kernel", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/locale", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/mail", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/media", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/midi", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/midi2", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/net", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/opengl", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/storage", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/support", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/translation", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/add-ons/graphics", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/add-ons/input_server", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/add-ons/mail_daemon", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/add-ons/registrar", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/add-ons/screen_saver", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/add-ons/tracker", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/be_apps/Deskbar", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/be_apps/NetPositive", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/os/be_apps/Tracker", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/3rdparty", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/bsd", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/glibc", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers/posix", System, false);
|
|
|
|
AddPath("/boot/system/develop/headers", System, false);
|
2010-08-22 09:00:03 +08:00
|
|
|
break;
|
2011-07-02 06:41:14 +08:00
|
|
|
case llvm::Triple::RTEMS:
|
|
|
|
break;
|
2014-03-28 06:50:18 +08:00
|
|
|
case llvm::Triple::Win32:
|
|
|
|
switch (triple.getEnvironment()) {
|
|
|
|
default: llvm_unreachable("Include management is handled in the driver.");
|
|
|
|
case llvm::Triple::Cygnus:
|
|
|
|
AddPath("/usr/include/w32api", System, false);
|
|
|
|
break;
|
|
|
|
case llvm::Triple::GNU:
|
|
|
|
break;
|
2011-06-27 23:47:15 +08:00
|
|
|
}
|
2009-10-09 07:29:47 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
2009-10-14 02:51:32 +08:00
|
|
|
|
2015-03-11 16:46:01 +08:00
|
|
|
switch (os) {
|
|
|
|
case llvm::Triple::CloudABI:
|
|
|
|
case llvm::Triple::RTEMS:
|
2015-03-31 04:31:33 +08:00
|
|
|
case llvm::Triple::NaCl:
|
2015-12-16 21:27:38 +08:00
|
|
|
case llvm::Triple::ELFIAMCU:
|
2018-03-02 15:19:42 +08:00
|
|
|
case llvm::Triple::Fuchsia:
|
2015-03-11 16:46:01 +08:00
|
|
|
break;
|
2015-10-14 20:25:43 +08:00
|
|
|
case llvm::Triple::PS4: {
|
|
|
|
// <isysroot> gets prepended later in AddPath().
|
2021-12-27 01:39:26 +08:00
|
|
|
std::string BaseSDKPath;
|
2015-10-14 20:25:43 +08:00
|
|
|
if (!HasSysroot) {
|
2016-05-17 01:22:25 +08:00
|
|
|
const char *envValue = getenv("SCE_ORBIS_SDK_DIR");
|
2015-10-14 20:25:43 +08:00
|
|
|
if (envValue)
|
|
|
|
BaseSDKPath = envValue;
|
|
|
|
else {
|
|
|
|
// HSOpts.ResourceDir variable contains the location of Clang's
|
|
|
|
// resource files.
|
|
|
|
// Assuming that Clang is configured for PS4 without
|
|
|
|
// --with-clang-resource-dir option, the location of Clang's resource
|
|
|
|
// files is <SDK_DIR>/host_tools/lib/clang
|
|
|
|
SmallString<128> P = StringRef(HSOpts.ResourceDir);
|
|
|
|
llvm::sys::path::append(P, "../../..");
|
2020-01-29 03:23:46 +08:00
|
|
|
BaseSDKPath = std::string(P.str());
|
2015-10-14 20:25:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
AddPath(BaseSDKPath + "/target/include", System, false);
|
2022-03-02 23:56:32 +08:00
|
|
|
if (triple.isPS4())
|
2015-10-14 20:25:43 +08:00
|
|
|
AddPath(BaseSDKPath + "/target/include_common", System, false);
|
2017-06-03 14:27:16 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
2015-10-14 20:25:43 +08:00
|
|
|
}
|
2015-03-11 16:46:01 +08:00
|
|
|
default:
|
2013-01-30 08:19:24 +08:00
|
|
|
AddPath("/usr/include", ExternCSystem, false);
|
2015-03-11 16:46:01 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-10-27 22:47:31 +08:00
|
|
|
}
|
|
|
|
|
2018-06-20 06:47:53 +08:00
|
|
|
void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
|
|
|
|
const LangOptions &LangOpts, const llvm::Triple &triple,
|
|
|
|
const HeaderSearchOptions &HSOpts) {
|
2009-10-27 22:47:31 +08:00
|
|
|
llvm::Triple::OSType os = triple.getOS();
|
|
|
|
// FIXME: temporary hack: hard-coded paths.
|
2011-04-20 05:43:27 +08:00
|
|
|
|
|
|
|
if (triple.isOSDarwin()) {
|
[clang][Darwin] Refactor header search path logic into the driver
Summary:
This commit moves the logic for determining system, resource and C++
header search paths from CC1 to the driver. This refactor has already
been made for several platforms, but Darwin had been left behind.
This refactor tries to implement the previous search path logic with
perfect accuracy. In particular, the order of all include paths inside
CC1 and all paths that were skipped because nonexistent are conserved
after the refactor. This change was also tested against a code base
of significant size and revealed no problems.
Reviewers: jfb, arphaman
Subscribers: nemanjai, javed.absar, kbarton, christof, jkorous, dexonsmith, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61963
llvm-svn: 361278
2019-05-22 01:48:04 +08:00
|
|
|
llvm_unreachable("Include management is handled in the driver.");
|
2011-04-20 05:43:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (os) {
|
2011-11-06 04:17:13 +08:00
|
|
|
case llvm::Triple::Linux:
|
2018-11-29 11:49:14 +08:00
|
|
|
case llvm::Triple::Hurd:
|
[Solaris] gcc toolchain handling revamp
Summary:
General idea is to utilize generic (mostly Generic_GCC) code
and get rid of Solaris-specific handling as much as possible.
In particular:
- scanLibDirForGCCTripleSolaris was removed, relying on generic
CollectLibDirsAndTriples
- findBiarchMultilibs is now properly utilized to switch between
m32 and m64 include & lib paths on Solaris
- C system include handling copied from Linux (bar multilib hacks)
Fixes PR24606.
Reviewers: dlj, rafael, jyknight, theraven, tstellar
Reviewed By: jyknight
Subscribers: aaron.ballman, mgorny, krytarowski, ro, joerg, cfe-commits
Differential Revision: https://reviews.llvm.org/D35755
llvm-svn: 323193
2018-01-23 20:23:52 +08:00
|
|
|
case llvm::Triple::Solaris:
|
2020-07-07 23:10:15 +08:00
|
|
|
case llvm::Triple::AIX:
|
2011-11-06 04:17:13 +08:00
|
|
|
llvm_unreachable("Include management is handled in the driver.");
|
2014-08-18 23:13:44 +08:00
|
|
|
break;
|
2014-03-28 06:50:18 +08:00
|
|
|
case llvm::Triple::Win32:
|
|
|
|
switch (triple.getEnvironment()) {
|
|
|
|
default: llvm_unreachable("Include management is handled in the driver.");
|
|
|
|
case llvm::Triple::Cygnus:
|
|
|
|
// Cygwin-1.7
|
|
|
|
AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.7.3");
|
|
|
|
AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
|
|
|
|
AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
|
|
|
|
// g++-4 / Cygwin-1.5
|
|
|
|
AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
|
|
|
|
break;
|
|
|
|
}
|
2015-07-02 12:45:27 +08:00
|
|
|
break;
|
2010-01-09 13:41:14 +08:00
|
|
|
case llvm::Triple::DragonFly:
|
2015-12-27 18:01:44 +08:00
|
|
|
AddPath("/usr/include/c++/5.0", CXXSystem, false);
|
2009-10-27 22:47:31 +08:00
|
|
|
break;
|
2010-07-08 00:01:42 +08:00
|
|
|
case llvm::Triple::Minix:
|
|
|
|
AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
|
|
|
|
"", "", "", triple);
|
|
|
|
break;
|
2009-10-27 22:47:31 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-12 02:20:10 +08:00
|
|
|
void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
|
|
|
|
const llvm::Triple &triple,
|
2010-05-17 03:03:52 +08:00
|
|
|
const HeaderSearchOptions &HSOpts) {
|
2011-11-05 07:49:05 +08:00
|
|
|
// NB: This code path is going away. All of the logic is moving into the
|
|
|
|
// driver which has the information necessary to do target-specific
|
|
|
|
// selections of default include paths. Each target which moves there will be
|
|
|
|
// exempted from this logic here until we can delete the entire pile of code.
|
|
|
|
switch (triple.getOS()) {
|
|
|
|
default:
|
|
|
|
break; // Everything else continues to use this routine's logic.
|
|
|
|
|
2019-06-13 17:42:43 +08:00
|
|
|
case llvm::Triple::Emscripten:
|
2011-11-06 04:17:13 +08:00
|
|
|
case llvm::Triple::Linux:
|
2018-11-29 11:49:14 +08:00
|
|
|
case llvm::Triple::Hurd:
|
2020-08-24 08:01:38 +08:00
|
|
|
case llvm::Triple::OpenBSD:
|
[Solaris] gcc toolchain handling revamp
Summary:
General idea is to utilize generic (mostly Generic_GCC) code
and get rid of Solaris-specific handling as much as possible.
In particular:
- scanLibDirForGCCTripleSolaris was removed, relying on generic
CollectLibDirsAndTriples
- findBiarchMultilibs is now properly utilized to switch between
m32 and m64 include & lib paths on Solaris
- C system include handling copied from Linux (bar multilib hacks)
Fixes PR24606.
Reviewers: dlj, rafael, jyknight, theraven, tstellar
Reviewed By: jyknight
Subscribers: aaron.ballman, mgorny, krytarowski, ro, joerg, cfe-commits
Differential Revision: https://reviews.llvm.org/D35755
llvm-svn: 323193
2018-01-23 20:23:52 +08:00
|
|
|
case llvm::Triple::Solaris:
|
2019-06-13 17:42:43 +08:00
|
|
|
case llvm::Triple::WASI:
|
2020-07-07 23:10:15 +08:00
|
|
|
case llvm::Triple::AIX:
|
2011-11-05 07:49:05 +08:00
|
|
|
return;
|
2014-03-28 06:50:18 +08:00
|
|
|
|
|
|
|
case llvm::Triple::Win32:
|
2015-07-02 12:45:27 +08:00
|
|
|
if (triple.getEnvironment() != llvm::Triple::Cygnus ||
|
2014-12-05 08:22:48 +08:00
|
|
|
triple.isOSBinFormatMachO())
|
2014-03-28 06:50:18 +08:00
|
|
|
return;
|
|
|
|
break;
|
2019-06-13 17:42:43 +08:00
|
|
|
|
|
|
|
case llvm::Triple::UnknownOS:
|
2019-11-26 01:50:58 +08:00
|
|
|
if (triple.isWasm())
|
2019-06-13 17:42:43 +08:00
|
|
|
return;
|
|
|
|
break;
|
2011-11-05 07:49:05 +08:00
|
|
|
}
|
|
|
|
|
[clang][Darwin] Refactor header search path logic into the driver
Summary:
This commit moves the logic for determining system, resource and C++
header search paths from CC1 to the driver. This refactor has already
been made for several platforms, but Darwin had been left behind.
This refactor tries to implement the previous search path logic with
perfect accuracy. In particular, the order of all include paths inside
CC1 and all paths that were skipped because nonexistent are conserved
after the refactor. This change was also tested against a code base
of significant size and revealed no problems.
Reviewers: jfb, arphaman
Subscribers: nemanjai, javed.absar, kbarton, christof, jkorous, dexonsmith, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61963
llvm-svn: 361278
2019-05-22 01:48:04 +08:00
|
|
|
// All header search logic is handled in the Driver for Darwin.
|
|
|
|
if (triple.isOSDarwin()) {
|
|
|
|
if (HSOpts.UseStandardSystemIncludes) {
|
|
|
|
// Add the default framework include paths on Darwin.
|
|
|
|
AddPath("/System/Library/Frameworks", System, true);
|
|
|
|
AddPath("/Library/Frameworks", System, true);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-29 07:23:45 +08:00
|
|
|
if (Lang.CPlusPlus && !Lang.AsmPreprocessor &&
|
|
|
|
HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) {
|
2011-07-30 04:21:18 +08:00
|
|
|
if (HSOpts.UseLibcxx) {
|
2013-01-30 08:19:24 +08:00
|
|
|
AddPath("/usr/include/c++/v1", CXXSystem, false);
|
2011-10-12 02:20:10 +08:00
|
|
|
} else {
|
2018-06-20 06:47:53 +08:00
|
|
|
AddDefaultCPlusPlusIncludePaths(Lang, triple, HSOpts);
|
2011-10-12 02:20:10 +08:00
|
|
|
}
|
2011-06-22 05:12:29 +08:00
|
|
|
}
|
2009-11-24 00:31:19 +08:00
|
|
|
|
2010-05-17 03:03:52 +08:00
|
|
|
AddDefaultCIncludePaths(triple, HSOpts);
|
2009-10-27 22:47:31 +08:00
|
|
|
}
|
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
/// RemoveDuplicates - If there are duplicate directory entries in the specified
|
2011-10-11 02:44:24 +08:00
|
|
|
/// search list, remove the later (dead) ones. Returns the number of non-system
|
|
|
|
/// headers removed, which is used to update NumAngled.
|
2021-10-12 15:34:43 +08:00
|
|
|
static unsigned RemoveDuplicates(std::vector<DirectoryLookupInfo> &SearchList,
|
2011-10-11 02:44:24 +08:00
|
|
|
unsigned First, bool Verbose) {
|
2008-08-22 17:25:22 +08:00
|
|
|
llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
|
|
|
|
llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
|
|
|
|
llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
|
2011-10-11 02:44:24 +08:00
|
|
|
unsigned NonSystemRemoved = 0;
|
2011-02-22 08:40:56 +08:00
|
|
|
for (unsigned i = First; i != SearchList.size(); ++i) {
|
2008-09-27 01:46:45 +08:00
|
|
|
unsigned DirToRemove = i;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2021-10-12 15:34:43 +08:00
|
|
|
const DirectoryLookup &CurEntry = SearchList[i].Lookup;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 09:00:10 +08:00
|
|
|
if (CurEntry.isNormalDir()) {
|
2008-08-22 17:25:22 +08:00
|
|
|
// If this isn't the first time we've seen this dir, remove it.
|
2014-11-19 15:49:47 +08:00
|
|
|
if (SeenDirs.insert(CurEntry.getDir()).second)
|
2008-08-22 17:25:22 +08:00
|
|
|
continue;
|
2009-02-08 09:00:10 +08:00
|
|
|
} else if (CurEntry.isFramework()) {
|
2008-08-22 17:25:22 +08:00
|
|
|
// If this isn't the first time we've seen this framework dir, remove it.
|
2014-11-19 15:49:47 +08:00
|
|
|
if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()).second)
|
2008-08-22 17:25:22 +08:00
|
|
|
continue;
|
|
|
|
} else {
|
2009-02-08 09:00:10 +08:00
|
|
|
assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
|
2008-08-22 17:25:22 +08:00
|
|
|
// If this isn't the first time we've seen this headermap, remove it.
|
2014-11-19 15:49:47 +08:00
|
|
|
if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()).second)
|
2008-08-22 17:25:22 +08:00
|
|
|
continue;
|
2009-02-08 08:55:22 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 08:55:22 +08:00
|
|
|
// If we have a normal #include dir/framework/headermap that is shadowed
|
|
|
|
// later in the chain by a system include location, we actually want to
|
|
|
|
// ignore the user's request and drop the user dir... keeping the system
|
|
|
|
// dir. This is weird, but required to emulate GCC's search path correctly.
|
|
|
|
//
|
|
|
|
// Since dupes of system dirs are rare, just rescan to find the original
|
|
|
|
// that we're nuking instead of using a DenseMap.
|
2009-02-08 09:00:10 +08:00
|
|
|
if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
|
2009-02-08 08:55:22 +08:00
|
|
|
// Find the dir that this is the same of.
|
|
|
|
unsigned FirstDir;
|
2016-12-02 17:51:51 +08:00
|
|
|
for (FirstDir = First;; ++FirstDir) {
|
2009-02-08 08:55:22 +08:00
|
|
|
assert(FirstDir != i && "Didn't find dupe?");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2021-10-12 15:34:43 +08:00
|
|
|
const DirectoryLookup &SearchEntry = SearchList[FirstDir].Lookup;
|
2009-02-08 09:00:10 +08:00
|
|
|
|
2009-02-08 08:55:22 +08:00
|
|
|
// If these are different lookup types, then they can't be the dupe.
|
2009-02-08 09:00:10 +08:00
|
|
|
if (SearchEntry.getLookupType() != CurEntry.getLookupType())
|
2009-02-08 08:55:22 +08:00
|
|
|
continue;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 08:55:22 +08:00
|
|
|
bool isSame;
|
2009-02-08 09:00:10 +08:00
|
|
|
if (CurEntry.isNormalDir())
|
|
|
|
isSame = SearchEntry.getDir() == CurEntry.getDir();
|
|
|
|
else if (CurEntry.isFramework())
|
|
|
|
isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
|
2009-02-08 08:55:22 +08:00
|
|
|
else {
|
2009-02-08 09:00:10 +08:00
|
|
|
assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
|
|
|
|
isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
|
2009-02-08 08:55:22 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 08:55:22 +08:00
|
|
|
if (isSame)
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-08 08:55:22 +08:00
|
|
|
// If the first dir in the search path is a non-system dir, zap it
|
|
|
|
// instead of the system one.
|
2021-10-12 15:34:43 +08:00
|
|
|
if (SearchList[FirstDir].Lookup.getDirCharacteristic() == SrcMgr::C_User)
|
2009-02-08 08:55:22 +08:00
|
|
|
DirToRemove = FirstDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Verbose) {
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << "ignoring duplicate directory \""
|
|
|
|
<< CurEntry.getName() << "\"\n";
|
2009-02-08 08:55:22 +08:00
|
|
|
if (DirToRemove != i)
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << " as it is a non-system directory that duplicates "
|
|
|
|
<< "a system directory\n";
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
2011-10-11 02:44:24 +08:00
|
|
|
if (DirToRemove != i)
|
|
|
|
++NonSystemRemoved;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-09-27 01:46:45 +08:00
|
|
|
// This is reached if the current entry is a duplicate. Remove the
|
|
|
|
// DirToRemove (usually the current dir).
|
|
|
|
SearchList.erase(SearchList.begin()+DirToRemove);
|
2008-08-22 17:25:22 +08:00
|
|
|
--i;
|
|
|
|
}
|
2011-10-11 02:44:24 +08:00
|
|
|
return NonSystemRemoved;
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
|
|
|
|
2021-10-12 15:34:43 +08:00
|
|
|
/// Extract DirectoryLookups from DirectoryLookupInfos.
|
|
|
|
static std::vector<DirectoryLookup>
|
|
|
|
extractLookups(const std::vector<DirectoryLookupInfo> &Infos) {
|
|
|
|
std::vector<DirectoryLookup> Lookups;
|
|
|
|
Lookups.reserve(Infos.size());
|
|
|
|
llvm::transform(Infos, std::back_inserter(Lookups),
|
|
|
|
[](const DirectoryLookupInfo &Info) { return Info.Lookup; });
|
|
|
|
return Lookups;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Collect the mapping between indices of DirectoryLookups and UserEntries.
|
|
|
|
static llvm::DenseMap<unsigned, unsigned>
|
|
|
|
mapToUserEntries(const std::vector<DirectoryLookupInfo> &Infos) {
|
|
|
|
llvm::DenseMap<unsigned, unsigned> LookupsToUserEntries;
|
|
|
|
for (unsigned I = 0, E = Infos.size(); I < E; ++I) {
|
|
|
|
// Check whether this DirectoryLookup maps to a HeaderSearch::UserEntry.
|
|
|
|
if (Infos[I].UserEntryIdx)
|
|
|
|
LookupsToUserEntries.insert({I, *Infos[I].UserEntryIdx});
|
|
|
|
}
|
|
|
|
return LookupsToUserEntries;
|
|
|
|
}
|
2008-08-22 17:25:22 +08:00
|
|
|
|
2011-02-22 08:40:56 +08:00
|
|
|
void InitHeaderSearch::Realize(const LangOptions &Lang) {
|
2008-08-22 17:25:22 +08:00
|
|
|
// Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
|
2021-10-12 15:34:43 +08:00
|
|
|
std::vector<DirectoryLookupInfo> SearchList;
|
2011-02-22 08:40:56 +08:00
|
|
|
SearchList.reserve(IncludePath.size());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-06-17 06:56:45 +08:00
|
|
|
// Quoted arguments go first.
|
2015-10-01 19:19:28 +08:00
|
|
|
for (auto &Include : IncludePath)
|
2021-05-28 20:05:22 +08:00
|
|
|
if (Include.Group == Quoted)
|
2021-10-12 15:34:43 +08:00
|
|
|
SearchList.push_back(Include);
|
2015-10-01 19:19:28 +08:00
|
|
|
|
2011-06-17 06:56:45 +08:00
|
|
|
// Deduplicate and remember index.
|
2011-02-22 08:40:56 +08:00
|
|
|
RemoveDuplicates(SearchList, 0, Verbose);
|
2011-06-17 06:56:45 +08:00
|
|
|
unsigned NumQuoted = SearchList.size();
|
2011-02-22 08:40:56 +08:00
|
|
|
|
2015-10-01 19:19:28 +08:00
|
|
|
for (auto &Include : IncludePath)
|
2021-05-28 20:05:22 +08:00
|
|
|
if (Include.Group == Angled || Include.Group == IndexHeaderMap)
|
2021-10-12 15:34:43 +08:00
|
|
|
SearchList.push_back(Include);
|
2011-06-17 06:56:45 +08:00
|
|
|
|
|
|
|
RemoveDuplicates(SearchList, NumQuoted, Verbose);
|
|
|
|
unsigned NumAngled = SearchList.size();
|
2011-02-22 08:40:56 +08:00
|
|
|
|
2015-10-01 19:19:28 +08:00
|
|
|
for (auto &Include : IncludePath)
|
2021-05-28 20:05:22 +08:00
|
|
|
if (Include.Group == System || Include.Group == ExternCSystem ||
|
|
|
|
(!Lang.ObjC && !Lang.CPlusPlus && Include.Group == CSystem) ||
|
2018-10-31 04:31:30 +08:00
|
|
|
(/*FIXME !Lang.ObjC && */ Lang.CPlusPlus &&
|
2021-05-28 20:05:22 +08:00
|
|
|
Include.Group == CXXSystem) ||
|
|
|
|
(Lang.ObjC && !Lang.CPlusPlus && Include.Group == ObjCSystem) ||
|
|
|
|
(Lang.ObjC && Lang.CPlusPlus && Include.Group == ObjCXXSystem))
|
2021-10-12 15:34:43 +08:00
|
|
|
SearchList.push_back(Include);
|
2015-10-01 19:19:28 +08:00
|
|
|
|
|
|
|
for (auto &Include : IncludePath)
|
2021-05-28 20:05:22 +08:00
|
|
|
if (Include.Group == After)
|
2021-10-12 15:34:43 +08:00
|
|
|
SearchList.push_back(Include);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-06-17 06:58:10 +08:00
|
|
|
// Remove duplicates across both the Angled and System directories. GCC does
|
|
|
|
// this and failing to remove duplicates across these two groups breaks
|
|
|
|
// #include_next.
|
2011-10-11 02:44:24 +08:00
|
|
|
unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
|
|
|
|
NumAngled -= NonSystemRemoved;
|
2008-08-22 17:25:22 +08:00
|
|
|
|
|
|
|
bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
|
2021-10-12 15:34:43 +08:00
|
|
|
Headers.SetSearchPaths(extractLookups(SearchList), NumQuoted, NumAngled,
|
|
|
|
DontSearchCurDir, mapToUserEntries(SearchList));
|
2008-08-22 17:25:22 +08:00
|
|
|
|
2012-06-14 04:27:03 +08:00
|
|
|
Headers.SetSystemHeaderPrefixes(SystemHeaderPrefixes);
|
|
|
|
|
2008-08-22 17:25:22 +08:00
|
|
|
// If verbose, print the list of directories that will be searched.
|
|
|
|
if (Verbose) {
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << "#include \"...\" search starts here:\n";
|
2008-08-22 17:25:22 +08:00
|
|
|
for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
|
2011-06-17 06:56:45 +08:00
|
|
|
if (i == NumQuoted)
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << "#include <...> search starts here:\n";
|
2021-10-12 15:34:43 +08:00
|
|
|
StringRef Name = SearchList[i].Lookup.getName();
|
2008-08-22 17:25:22 +08:00
|
|
|
const char *Suffix;
|
2021-10-12 15:34:43 +08:00
|
|
|
if (SearchList[i].Lookup.isNormalDir())
|
2008-08-22 17:25:22 +08:00
|
|
|
Suffix = "";
|
2021-10-12 15:34:43 +08:00
|
|
|
else if (SearchList[i].Lookup.isFramework())
|
2008-08-22 17:25:22 +08:00
|
|
|
Suffix = " (framework directory)";
|
|
|
|
else {
|
2021-10-12 15:34:43 +08:00
|
|
|
assert(SearchList[i].Lookup.isHeaderMap() && "Unknown DirectoryLookup");
|
2008-08-22 17:25:22 +08:00
|
|
|
Suffix = " (headermap)";
|
|
|
|
}
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << " " << Name << Suffix << "\n";
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
2009-12-03 17:14:02 +08:00
|
|
|
llvm::errs() << "End of search list.\n";
|
2008-08-22 17:25:22 +08:00
|
|
|
}
|
|
|
|
}
|
2009-11-07 12:20:50 +08:00
|
|
|
|
2009-11-12 05:44:21 +08:00
|
|
|
void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
|
|
|
|
const HeaderSearchOptions &HSOpts,
|
|
|
|
const LangOptions &Lang,
|
2009-11-07 12:20:50 +08:00
|
|
|
const llvm::Triple &Triple) {
|
|
|
|
InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
|
|
|
|
|
|
|
|
// Add the user defined entries.
|
|
|
|
for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
|
|
|
|
const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
|
2013-01-30 09:06:03 +08:00
|
|
|
if (E.IgnoreSysRoot) {
|
2021-10-12 15:34:43 +08:00
|
|
|
Init.AddUnmappedPath(E.Path, E.Group, E.IsFramework, i);
|
2013-01-30 09:06:03 +08:00
|
|
|
} else {
|
2021-10-12 15:34:43 +08:00
|
|
|
Init.AddPath(E.Path, E.Group, E.IsFramework, i);
|
2013-01-30 09:06:03 +08:00
|
|
|
}
|
2009-11-07 12:20:50 +08:00
|
|
|
}
|
|
|
|
|
2011-10-12 02:20:10 +08:00
|
|
|
Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
|
2009-11-07 12:20:50 +08:00
|
|
|
|
2012-06-14 04:27:03 +08:00
|
|
|
for (unsigned i = 0, e = HSOpts.SystemHeaderPrefixes.size(); i != e; ++i)
|
|
|
|
Init.AddSystemHeaderPrefix(HSOpts.SystemHeaderPrefixes[i].Prefix,
|
|
|
|
HSOpts.SystemHeaderPrefixes[i].IsSystemHeader);
|
|
|
|
|
2012-02-03 02:42:48 +08:00
|
|
|
if (HSOpts.UseBuiltinIncludes) {
|
|
|
|
// Set up the builtin include directory in the module map.
|
2013-06-13 22:26:04 +08:00
|
|
|
SmallString<128> P = StringRef(HSOpts.ResourceDir);
|
|
|
|
llvm::sys::path::append(P, "include");
|
2019-08-02 05:31:56 +08:00
|
|
|
if (auto Dir = HS.getFileMgr().getDirectory(P))
|
|
|
|
HS.getModuleMap().setBuiltinIncludeDir(*Dir);
|
2012-02-03 02:42:48 +08:00
|
|
|
}
|
|
|
|
|
2011-02-22 08:40:56 +08:00
|
|
|
Init.Realize(Lang);
|
2009-11-07 12:20:50 +08:00
|
|
|
}
|