[Driver] Move information about toolchain specific include directories

from the common driver code to the corresponding `MultilibSet` declarations.

Now the `MultilibSet` can hold an optional callback function which is
responsible to return a set of include directories specific for the toolchain.
That allows to remove MIPS toolchain specific directories from
`Linux::AddClangSystemIncludeArgs` method and simplify adding new directories
in the future.

llvm-svn: 214949
This commit is contained in:
Simon Atanasyan 2014-08-06 05:44:47 +00:00
parent ce49b5ba98
commit 9e49e145b1
2 changed files with 46 additions and 17 deletions

View File

@ -97,6 +97,10 @@ public:
typedef multilib_list::iterator iterator; typedef multilib_list::iterator iterator;
typedef multilib_list::const_iterator const_iterator; typedef multilib_list::const_iterator const_iterator;
typedef std::function<std::vector<std::string>(
StringRef InstallDir, StringRef Triple, const Multilib &M)>
IncludeDirsFunc;
struct FilterCallback { struct FilterCallback {
virtual ~FilterCallback() {}; virtual ~FilterCallback() {};
/// \return true iff the filter should remove the Multilib from the set /// \return true iff the filter should remove the Multilib from the set
@ -105,6 +109,7 @@ public:
private: private:
multilib_list Multilibs; multilib_list Multilibs;
IncludeDirsFunc IncludeCallback;
public: public:
MultilibSet() {} MultilibSet() {}
@ -150,6 +155,12 @@ public:
void print(raw_ostream &OS) const; void print(raw_ostream &OS) const;
MultilibSet &setIncludeDirsCallback(IncludeDirsFunc F) {
IncludeCallback = F;
return *this;
}
IncludeDirsFunc includeDirsCallback() const { return IncludeCallback; }
private: private:
/// Apply the filter to Multilibs and return the subset that remains /// Apply the filter to Multilibs and return the subset that remains
static multilib_list filterCopy(const FilterCallback &F, static multilib_list filterCopy(const FilterCallback &F,

View File

@ -1726,7 +1726,14 @@ static bool findMIPSMultilibs(const llvm::Triple &TargetTriple, StringRef Path,
.Maybe(SoftFloat) .Maybe(SoftFloat)
.Maybe(Nan2008) .Maybe(Nan2008)
.FilterOut(".*sof/nan2008") .FilterOut(".*sof/nan2008")
.FilterOut(NonExistent); .FilterOut(NonExistent)
.setIncludeDirsCallback([](
StringRef InstallDir, StringRef TripleStr, const Multilib &M) {
std::vector<std::string> Dirs;
Dirs.push_back((InstallDir + "/include").str());
Dirs.push_back((InstallDir + "/../../../../sysroot/usr/include").str());
return Dirs;
});
} }
// Check for Code Sourcery toolchain multilibs // Check for Code Sourcery toolchain multilibs
@ -1771,7 +1778,15 @@ static bool findMIPSMultilibs(const llvm::Triple &TargetTriple, StringRef Path,
.Maybe(MAbi64) .Maybe(MAbi64)
.FilterOut("/mips16.*/64") .FilterOut("/mips16.*/64")
.FilterOut("/micromips.*/64") .FilterOut("/micromips.*/64")
.FilterOut(NonExistent); .FilterOut(NonExistent)
.setIncludeDirsCallback([](
StringRef InstallDir, StringRef TripleStr, const Multilib &M) {
std::vector<std::string> Dirs;
Dirs.push_back((InstallDir + "/include").str());
Dirs.push_back((InstallDir + "/../../../../" + TripleStr +
"/libc/usr/include").str());
return Dirs;
});
} }
MultilibSet AndroidMipsMultilibs = MultilibSet() MultilibSet AndroidMipsMultilibs = MultilibSet()
@ -1813,7 +1828,14 @@ static bool findMIPSMultilibs(const llvm::Triple &TargetTriple, StringRef Path,
.Maybe(Mips64r6) .Maybe(Mips64r6)
.Maybe(MAbi64) .Maybe(MAbi64)
.Maybe(LittleEndian) .Maybe(LittleEndian)
.FilterOut(NonExistent); .FilterOut(NonExistent)
.setIncludeDirsCallback([](
StringRef InstallDir, StringRef TripleStr, const Multilib &M) {
std::vector<std::string> Dirs;
Dirs.push_back((InstallDir + "/include").str());
Dirs.push_back((InstallDir + "/../../../../sysroot/usr/include").str());
return Dirs;
});
} }
StringRef CPUName; StringRef CPUName;
@ -3215,20 +3237,16 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
// Lacking those, try to detect the correct set of system includes for the // Lacking those, try to detect the correct set of system includes for the
// target triple. // target triple.
// Sourcery CodeBench and modern FSF Mips toolchains put extern C // Add include directories specific to the selected multilib set and multilib.
// system includes under three additional directories. if (GCCInstallation.isValid()) {
if (GCCInstallation.isValid() && isMipsArch(getTriple().getArch())) { auto Callback = Multilibs.includeDirsCallback();
addExternCSystemIncludeIfExists( if (Callback) {
DriverArgs, CC1Args, GCCInstallation.getInstallPath() + "/include"); const auto IncludePaths = Callback(GCCInstallation.getInstallPath(),
GCCInstallation.getTriple().str(),
addExternCSystemIncludeIfExists( GCCInstallation.getMultilib());
DriverArgs, CC1Args, for (const auto &Path : IncludePaths)
GCCInstallation.getInstallPath() + "/../../../../" + addExternCSystemIncludeIfExists(DriverArgs, CC1Args, Path);
GCCInstallation.getTriple().str() + "/libc/usr/include"); }
addExternCSystemIncludeIfExists(
DriverArgs, CC1Args,
GCCInstallation.getInstallPath() + "/../../../../sysroot/usr/include");
} }
// Implement generic Debian multiarch support. // Implement generic Debian multiarch support.