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