Improve install_paths handling for relative paths. (#4331)

Because install_paths is not presently validated, and it's resolved
after the `SetWorkingDirForBazel` call, if a relative path is used with
bazel then it would fail silently. This starts making the driver share
install path errors, and starts changing how `//toolchain` launches
`carbon`.

Note the implementation is still brittle and will break with symlinks.
That's something I plan to address as part of busyboxing.
This commit is contained in:
Jon Ross-Perkins authored and GitHub committed 2024-09-23 22:26:53 +00:00
1 parent edc6ed3d10
commit c7057eff89
8 files changed
+78 -10

No files matched your search

+6 -2
View File
@@ -19,15 +19,19 @@ auto main(int argc, char** argv) -> int {
return EXIT_FAILURE;
}
// Resolve paths before calling SetWorkingDirForBazel.
std::string exe_path = Carbon::FindExecutablePath(argv[0]);
const auto install_paths = Carbon::InstallPaths::MakeExeRelative(exe_path);
if (install_paths.error()) {
llvm::errs() << "error: " << *install_paths.error();
return EXIT_FAILURE;
}
Carbon::SetWorkingDirForBazel();
llvm::SmallVector<llvm::StringRef> args(argv + 1, argv + argc);
auto fs = llvm::vfs::getRealFileSystem();
const auto install_paths = Carbon::InstallPaths::MakeExeRelative(exe_path);
Carbon::Driver driver(*fs, &install_paths, llvm::outs(), llvm::errs());
bool success = driver.RunCommand(args).success;
return success ? EXIT_SUCCESS : EXIT_FAILURE;