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
2024-09-23 22:26:53 +00:00
committed by GitHub
parent edc6ed3d10
commit c7057eff89
8 changed files with 78 additions and 10 deletions
+14
View File
@@ -44,6 +44,11 @@ auto InstallPaths::MakeExeRelative(llvm::StringRef exe_path) -> InstallPaths {
llvm::sys::path::remove_filename(paths.prefix_);
llvm::sys::path::append(paths.prefix_, llvm::sys::path::Style::posix, "../");
if (auto error = llvm::sys::fs::make_absolute(paths.prefix_)) {
paths.SetError(error.message());
return paths;
}
paths.CheckMarkerFile();
return paths;
}
@@ -67,6 +72,11 @@ auto InstallPaths::MakeForBazelRunfiles(llvm::StringRef exe_path)
llvm::sys::path::append(paths.prefix_, llvm::sys::path::Style::posix,
"../../");
if (auto error = llvm::sys::fs::make_absolute(paths.prefix_)) {
paths.SetError(error.message());
return paths;
}
paths.CheckMarkerFile();
CARBON_CHECK(!paths.error(), "{0}", *paths.error());
return paths;
@@ -125,6 +135,10 @@ auto InstallPaths::SetError(llvm::Twine message) -> void {
}
auto InstallPaths::CheckMarkerFile() -> void {
if (!llvm::sys::path::is_absolute(prefix_)) {
SetError(llvm::Twine("Not an absolute path: ") + prefix_);
}
llvm::SmallString<256> path(prefix_);
llvm::sys::path::append(path, llvm::sys::path::Style::posix, MarkerPath);
if (!llvm::sys::fs::exists(path)) {