Fix invocation issues with clang runner (#4353)

`ToolContext` should be explicitly initialized.

`-c` can still require a valid, writable `-o` path.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
Jon Ross-Perkins
2024-09-27 20:33:11 +00:00
committed by GitHub
co-authored by Chandler Carruth
parent 42bda1e38f
commit 4332d8239d
2 changed files with 11 additions and 6 deletions
+4 -1
View File
@@ -135,7 +135,10 @@ auto ClangRunner::Run(llvm::ArrayRef<llvm::StringRef> args) -> bool {
// busybox of LLD as well, and having even the subprocesses consistently run
// the Carbon install toolchain and not a system toolchain whenever possible.
driver.CC1Main = [](llvm::SmallVectorImpl<const char*>& argv) -> int {
llvm::ToolContext tool_context;
// TODO: Try to use a better path for argv[0] (maybe in the LLVM install
// paths). This works for now.
llvm::ToolContext tool_context = {
.Path = argv[0], .PrependArg = "clang", .NeedsPrependArg = true};
return clang_main(argv.size(), const_cast<char**>(argv.data()),
tool_context);
};
+7 -5
View File
@@ -155,6 +155,7 @@ TEST(ClangRunnerTest, LinkCommandEcho) {
TEST(ClangRunnerTest, DashC) {
std::filesystem::path test_file =
WriteTestFile("test.cpp", "int test() { return 0; }");
std::filesystem::path test_output = WriteTestFile("test.o", "");
const auto install_paths =
InstallPaths::MakeForBazelRunfiles(Testing::GetExePath());
@@ -164,11 +165,12 @@ TEST(ClangRunnerTest, DashC) {
ClangRunner runner(&install_paths, target, &verbose_os);
std::string out;
std::string err;
EXPECT_TRUE(
RunWithCapturedOutput(out, err,
[&] {
return runner.Run({"-c", test_file.string()});
}))
EXPECT_TRUE(RunWithCapturedOutput(out, err,
[&] {
return runner.Run(
{"-c", test_file.string(), "-o",
test_output.string()});
}))
<< "Verbose output from runner:\n"
<< verbose_out << "\n";