diff options
author | Timm Bäder <tbaeder@redhat.com> | 2022-05-18 10:31:41 +0200 |
---|---|---|
committer | Timm Bäder <tbaeder@redhat.com> | 2022-05-23 11:34:38 +0200 |
commit | 8717b492dfcd12d6387543a2f8322e0cf9059982 (patch) | |
tree | 790524578791d82ffdce31b9e1180070ae98bb2b /clang/unittests/Driver/ToolChainTest.cpp | |
parent | 8e9528cb544a3d70cea96f1f99318643095a1410 (diff) | |
download | llvm-8717b492dfcd12d6387543a2f8322e0cf9059982.zip llvm-8717b492dfcd12d6387543a2f8322e0cf9059982.tar.gz llvm-8717b492dfcd12d6387543a2f8322e0cf9059982.tar.bz2 |
[clang][driver] Dynamically select gcc-toolset/devtoolset version
And pick the highest one, instead of adding all possibilities to the
prefixes.
Differential Revision: https://reviews.llvm.org/D125862
Diffstat (limited to 'clang/unittests/Driver/ToolChainTest.cpp')
-rw-r--r-- | clang/unittests/Driver/ToolChainTest.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp index c652b09..4d2d938 100644 --- a/clang/unittests/Driver/ToolChainTest.cpp +++ b/clang/unittests/Driver/ToolChainTest.cpp @@ -610,4 +610,92 @@ TEST(DxcModeTest, ValidatorVersionValidation) { DiagConsumer->clear(); } +TEST(ToolChainTest, Toolsets) { + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); + IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); + struct TestDiagnosticConsumer : public DiagnosticConsumer {}; + + // Check (newer) GCC toolset installation. + { + IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( + new llvm::vfs::InMemoryFileSystem); + + // These should be ignored + InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-2", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--1", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + + // File needed for GCC installation detection. + InMemoryFileSystem->addFile( + "/opt/rh/gcc-toolset-12/lib/gcc/x86_64-redhat-linux/11/crtbegin.o", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + + DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); + Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags, + "clang LLVM compiler", InMemoryFileSystem); + std::unique_ptr<Compilation> C(TheDriver.BuildCompilation({"-v"})); + ASSERT_TRUE(C); + std::string S; + { + llvm::raw_string_ostream OS(S); + C->getDefaultToolChain().printVerboseInfo(OS); + } + if (is_style_windows(llvm::sys::path::Style::native)) + std::replace(S.begin(), S.end(), '\\', '/'); + EXPECT_EQ("Found candidate GCC installation: " + "/opt/rh/gcc-toolset-12/lib/gcc/x86_64-redhat-linux/11\n" + "Selected GCC installation: " + "/opt/rh/gcc-toolset-12/lib/gcc/x86_64-redhat-linux/11\n" + "Candidate multilib: .;@m64\n" + "Selected multilib: .;@m64\n", + S); + } + + // And older devtoolset. + { + IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( + new llvm::vfs::InMemoryFileSystem); + + // These should be ignored + InMemoryFileSystem->addFile("/opt/rh/devtoolset-2", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + InMemoryFileSystem->addFile("/opt/rh/devtoolset-", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + InMemoryFileSystem->addFile("/opt/rh/devtoolset--", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + InMemoryFileSystem->addFile("/opt/rh/devtoolset--1", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + + // File needed for GCC installation detection. + InMemoryFileSystem->addFile( + "/opt/rh/devtoolset-12/lib/gcc/x86_64-redhat-linux/11/crtbegin.o", 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + + DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); + Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags, + "clang LLVM compiler", InMemoryFileSystem); + std::unique_ptr<Compilation> C(TheDriver.BuildCompilation({"-v"})); + ASSERT_TRUE(C); + std::string S; + { + llvm::raw_string_ostream OS(S); + C->getDefaultToolChain().printVerboseInfo(OS); + } + if (is_style_windows(llvm::sys::path::Style::native)) + std::replace(S.begin(), S.end(), '\\', '/'); + EXPECT_EQ("Found candidate GCC installation: " + "/opt/rh/devtoolset-12/lib/gcc/x86_64-redhat-linux/11\n" + "Selected GCC installation: " + "/opt/rh/devtoolset-12/lib/gcc/x86_64-redhat-linux/11\n" + "Candidate multilib: .;@m64\n" + "Selected multilib: .;@m64\n", + S); + } +} + } // end anonymous namespace. |