From d882ca7f1f1dee7d812d6b1ae060b5f671ab9ebc Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 23 Sep 2020 20:21:18 +0300 Subject: [PATCH] [Driver] Check whether Gentoo-specific configuration directory exists Check whether /etc/env.d/gcc exists before trying to read from any file from there. This saves a few OS calls on a non-Gentoo system. Differential Revision: https://reviews.llvm.org/D87143 --- clang/lib/Driver/ToolChains/Gnu.cpp | 7 +++++-- clang/lib/Driver/ToolChains/Gnu.h | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 68a75db..64ae5ac 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2535,6 +2535,9 @@ bool Generic_GCC::GCCInstallationDetector::ScanGentooConfigs( const llvm::Triple &TargetTriple, const ArgList &Args, const SmallVectorImpl &CandidateTriples, const SmallVectorImpl &CandidateBiarchTriples) { + if (!D.getVFS().exists(D.SysRoot + GentooConfigDir)) + return false; + for (StringRef CandidateTriple : CandidateTriples) { if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple)) return true; @@ -2551,7 +2554,7 @@ bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig( const llvm::Triple &TargetTriple, const ArgList &Args, StringRef CandidateTriple, bool NeedsBiarchSuffix) { llvm::ErrorOr> File = - D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" + + D.getVFS().getBufferForFile(D.SysRoot + GentooConfigDir + "/config-" + CandidateTriple.str()); if (File) { SmallVector Lines; @@ -2563,7 +2566,7 @@ bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig( continue; // Process the config file pointed to by CURRENT. llvm::ErrorOr> ConfigFile = - D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/" + + D.getVFS().getBufferForFile(D.SysRoot + GentooConfigDir + "/" + Line.str()); std::pair ActiveVersion = Line.rsplit('-'); // List of paths to scan for libraries. diff --git a/clang/lib/Driver/ToolChains/Gnu.h b/clang/lib/Driver/ToolChains/Gnu.h index 52690ab..5f3d1be 100644 --- a/clang/lib/Driver/ToolChains/Gnu.h +++ b/clang/lib/Driver/ToolChains/Gnu.h @@ -212,6 +212,9 @@ public: /// The set of multilibs that the detected installation supports. MultilibSet Multilibs; + // Gentoo-specific toolchain configurations are stored here. + const std::string GentooConfigDir = "/etc/env.d/gcc"; + public: explicit GCCInstallationDetector(const Driver &D) : IsValid(false), D(D) {} void init(const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args, -- 2.7.4