Skip to content

Commit 3010b7e

Browse files
tbaederrtstellar
authored andcommitted
[clang][driver] Remove dynamic gcc-toolset/devtoolset logic
This breaks when the newest available devtoolset directory is not a complete toolset: llvm/llvm-project#57843 Remove this again in favor or just adding the two new directories for devtoolset/gcc-toolset 12. This reverts commit 35aaf54. This reverts commit 9f97720. Fixes llvm/llvm-project#57843 Differential Revision: https://reviews.llvm.org/D136435
1 parent db68723 commit 3010b7e

File tree

2 files changed

+15
-117
lines changed

2 files changed

+15
-117
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,31 +2139,21 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
21392139
// and gcc-toolsets.
21402140
if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux &&
21412141
D.getVFS().exists("/opt/rh")) {
2142-
// Find the directory in /opt/rh/ starting with gcc-toolset-* or
2143-
// devtoolset-* with the highest version number and add that
2144-
// one to our prefixes.
2145-
std::string ChosenToolsetDir;
2146-
unsigned ChosenToolsetVersion = 0;
2147-
std::error_code EC;
2148-
for (llvm::vfs::directory_iterator LI = D.getVFS().dir_begin("/opt/rh", EC),
2149-
LE;
2150-
!EC && LI != LE; LI = LI.increment(EC)) {
2151-
StringRef ToolsetDir = llvm::sys::path::filename(LI->path());
2152-
unsigned ToolsetVersion;
2153-
if ((!ToolsetDir.startswith("gcc-toolset-") &&
2154-
!ToolsetDir.startswith("devtoolset-")) ||
2155-
ToolsetDir.substr(ToolsetDir.rfind('-') + 1)
2156-
.getAsInteger(10, ToolsetVersion))
2157-
continue;
2158-
2159-
if (ToolsetVersion > ChosenToolsetVersion) {
2160-
ChosenToolsetVersion = ToolsetVersion;
2161-
ChosenToolsetDir = "/opt/rh/" + ToolsetDir.str();
2162-
}
2163-
}
2164-
2165-
if (ChosenToolsetVersion > 0)
2166-
Prefixes.push_back(ChosenToolsetDir + "/root/usr");
2142+
// TODO: We may want to remove this, since the functionality
2143+
// can be achieved using config files.
2144+
Prefixes.push_back("/opt/rh/gcc-toolset-12/root/usr");
2145+
Prefixes.push_back("/opt/rh/gcc-toolset-11/root/usr");
2146+
Prefixes.push_back("/opt/rh/gcc-toolset-10/root/usr");
2147+
Prefixes.push_back("/opt/rh/devtoolset-12/root/usr");
2148+
Prefixes.push_back("/opt/rh/devtoolset-11/root/usr");
2149+
Prefixes.push_back("/opt/rh/devtoolset-10/root/usr");
2150+
Prefixes.push_back("/opt/rh/devtoolset-9/root/usr");
2151+
Prefixes.push_back("/opt/rh/devtoolset-8/root/usr");
2152+
Prefixes.push_back("/opt/rh/devtoolset-7/root/usr");
2153+
Prefixes.push_back("/opt/rh/devtoolset-6/root/usr");
2154+
Prefixes.push_back("/opt/rh/devtoolset-4/root/usr");
2155+
Prefixes.push_back("/opt/rh/devtoolset-3/root/usr");
2156+
Prefixes.push_back("/opt/rh/devtoolset-2/root/usr");
21672157
}
21682158

21692159
// Fall back to /usr which is used by most non-Solaris systems.

clang/unittests/Driver/ToolChainTest.cpp

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "clang/Driver/Driver.h"
1919
#include "llvm/ADT/ArrayRef.h"
2020
#include "llvm/MC/TargetRegistry.h"
21-
#include "llvm/Support/Host.h"
2221
#include "llvm/Support/TargetSelect.h"
2322
#include "llvm/Support/VirtualFileSystem.h"
2423
#include "llvm/Support/raw_ostream.h"
@@ -570,95 +569,4 @@ TEST(DxcModeTest, ValidatorVersionValidation) {
570569
Diags.Clear();
571570
DiagConsumer->clear();
572571
}
573-
574-
TEST(ToolChainTest, Toolsets) {
575-
// Ignore this test on Windows hosts.
576-
llvm::Triple Host(llvm::sys::getProcessTriple());
577-
if (Host.isOSWindows())
578-
GTEST_SKIP();
579-
580-
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
581-
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
582-
583-
// Check (newer) GCC toolset installation.
584-
{
585-
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
586-
new llvm::vfs::InMemoryFileSystem);
587-
588-
// These should be ignored.
589-
InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-2", 0,
590-
llvm::MemoryBuffer::getMemBuffer("\n"));
591-
InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-", 0,
592-
llvm::MemoryBuffer::getMemBuffer("\n"));
593-
InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--", 0,
594-
llvm::MemoryBuffer::getMemBuffer("\n"));
595-
InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--1", 0,
596-
llvm::MemoryBuffer::getMemBuffer("\n"));
597-
598-
// File needed for GCC installation detection.
599-
InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-12/root/usr/lib/gcc/"
600-
"x86_64-redhat-linux/11/crtbegin.o",
601-
0, llvm::MemoryBuffer::getMemBuffer("\n"));
602-
603-
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new SimpleDiagnosticConsumer);
604-
Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
605-
"clang LLVM compiler", InMemoryFileSystem);
606-
std::unique_ptr<Compilation> C(
607-
TheDriver.BuildCompilation({"clang", "--gcc-toolchain="}));
608-
ASSERT_TRUE(C);
609-
std::string S;
610-
{
611-
llvm::raw_string_ostream OS(S);
612-
C->getDefaultToolChain().printVerboseInfo(OS);
613-
}
614-
EXPECT_EQ("Found candidate GCC installation: "
615-
"/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
616-
"Selected GCC installation: "
617-
"/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
618-
"Candidate multilib: .;@m64\n"
619-
"Selected multilib: .;@m64\n",
620-
S);
621-
}
622-
623-
// And older devtoolset.
624-
{
625-
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
626-
new llvm::vfs::InMemoryFileSystem);
627-
628-
// These should be ignored.
629-
InMemoryFileSystem->addFile("/opt/rh/devtoolset-2", 0,
630-
llvm::MemoryBuffer::getMemBuffer("\n"));
631-
InMemoryFileSystem->addFile("/opt/rh/devtoolset-", 0,
632-
llvm::MemoryBuffer::getMemBuffer("\n"));
633-
InMemoryFileSystem->addFile("/opt/rh/devtoolset--", 0,
634-
llvm::MemoryBuffer::getMemBuffer("\n"));
635-
InMemoryFileSystem->addFile("/opt/rh/devtoolset--1", 0,
636-
llvm::MemoryBuffer::getMemBuffer("\n"));
637-
638-
// File needed for GCC installation detection.
639-
InMemoryFileSystem->addFile("/opt/rh/devtoolset-12/root/usr/lib/gcc/"
640-
"x86_64-redhat-linux/11/crtbegin.o",
641-
0, llvm::MemoryBuffer::getMemBuffer("\n"));
642-
643-
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new SimpleDiagnosticConsumer);
644-
Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
645-
"clang LLVM compiler", InMemoryFileSystem);
646-
std::unique_ptr<Compilation> C(
647-
TheDriver.BuildCompilation({"clang", "--gcc-toolchain="}));
648-
ASSERT_TRUE(C);
649-
std::string S;
650-
{
651-
llvm::raw_string_ostream OS(S);
652-
C->getDefaultToolChain().printVerboseInfo(OS);
653-
}
654-
EXPECT_EQ("Found candidate GCC installation: "
655-
"/opt/rh/devtoolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
656-
"Selected GCC installation: "
657-
"/opt/rh/devtoolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
658-
"Candidate multilib: .;@m64\n"
659-
"Selected multilib: .;@m64\n",
660-
S);
661-
}
662-
}
663-
664572
} // end anonymous namespace.

0 commit comments

Comments
 (0)