mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
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:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user