diff options
author | Michal Gorny <mgorny@gentoo.org> | 2016-10-25 15:07:41 +0000 |
---|---|---|
committer | Michal Gorny <mgorny@gentoo.org> | 2016-10-25 15:07:41 +0000 |
commit | bd449c27d5097e4f79e7aa694739fe829f4a1cb8 (patch) | |
tree | e03a37855e9904e7219a2f5b2afe1a6412450d28 /clang/lib/Driver/ToolChains.cpp | |
parent | 9ccc7ad62d319127670e70e8082a6018987ed25a (diff) | |
download | bcm5719-llvm-bd449c27d5097e4f79e7aa694739fe829f4a1cb8.tar.gz bcm5719-llvm-bd449c27d5097e4f79e7aa694739fe829f4a1cb8.zip |
[Driver] Support obtaining active toolchain from gcc-config on Gentoo
Support using gcc-config to determine the correct GCC toolchain location
on Gentoo. In order to do that, attempt to read gcc-config configuration
form [[sysroot]]/etc/env.d/gcc, if no custom toolchain location is
provided.
Differential Revision: https://reviews.llvm.org/D25661
llvm-svn: 285074
Diffstat (limited to 'clang/lib/Driver/ToolChains.cpp')
-rw-r--r-- | clang/lib/Driver/ToolChains.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 131cdae56d2..f04c443a886 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -1438,6 +1438,43 @@ void Generic_GCC::GCCInstallationDetector::init( } } + // Try to respect gcc-config on Gentoo. However, do that only + // if --gcc-toolchain is not provided or equal to the Gentoo install + // in /usr. This avoids accidentally enforcing the system GCC version + // when using a custom toolchain. + if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") { + for (StringRef CandidateTriple : CandidateTripleAliases) { + llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = + D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" + + CandidateTriple.str()); + if (File) { + SmallVector<StringRef, 2> Lines; + File.get()->getBuffer().split(Lines, "\n"); + for (StringRef Line : Lines) { + // CURRENT=triple-version + if (Line.consume_front("CURRENT=")) { + const std::pair<StringRef, StringRef> ActiveVersion = + Line.rsplit('-'); + // Note: Strictly speaking, we should be reading + // /etc/env.d/gcc/${CURRENT} now. However, the file doesn't + // contain anything new or especially useful to us. + const std::string GentooPath = D.SysRoot + "/usr/lib/gcc/" + + ActiveVersion.first.str() + "/" + + ActiveVersion.second.str(); + if (D.getVFS().exists(GentooPath + "/crtbegin.o")) { + Version = GCCVersion::Parse(ActiveVersion.second); + GCCInstallPath = GentooPath; + GCCParentLibPath = GentooPath + "/../../.."; + GCCTriple.setTriple(ActiveVersion.first); + IsValid = true; + return; + } + } + } + } + } + } + // Loop over the various components which exist and select the best GCC // installation available. GCC installs are ranked by version number. Version = GCCVersion::Parse("0.0.0"); |