mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[Support] Remove error return value from one overload of fs::make_absolute
Summary: The version of make_absolute which accepted a specific directory to use as the "base" for the computation could never fail, even though it returned a std::error_code. The reason for that seems to be historical -- the CWD flavour (which can fail due to failure to retrieve CWD) was there first, and the new version was implemented by extending that. This removes the error return value from the non-CWD overload and reimplements the CWD version on top of that. This enables us to remove some dead code where people were pessimistically trying to handle the errors returned from this function. Reviewers: zturner, sammccall Subscribers: hiraditya, kristina, llvm-commits Differential Revision: https://reviews.llvm.org/D56599 llvm-svn: 351317
This commit is contained in:
parent
102ecb8ab9
commit
a203e4cb0a
@ -302,10 +302,7 @@ public:
|
|||||||
/// relative/../path => <current-directory>/relative/../path
|
/// relative/../path => <current-directory>/relative/../path
|
||||||
///
|
///
|
||||||
/// @param path A path that is modified to be an absolute path.
|
/// @param path A path that is modified to be an absolute path.
|
||||||
/// @returns errc::success if \a path has been made absolute, otherwise a
|
void make_absolute(const Twine ¤t_directory, SmallVectorImpl<char> &path);
|
||||||
/// platform-specific error_code.
|
|
||||||
std::error_code make_absolute(const Twine ¤t_directory,
|
|
||||||
SmallVectorImpl<char> &path);
|
|
||||||
|
|
||||||
/// Make \a path an absolute path.
|
/// Make \a path an absolute path.
|
||||||
///
|
///
|
||||||
|
@ -849,9 +849,8 @@ getPotentiallyUniqueTempFileName(const Twine &Prefix, StringRef Suffix,
|
|||||||
return createTemporaryFile(Prefix, Suffix, Dummy, ResultPath, FS_Name);
|
return createTemporaryFile(Prefix, Suffix, Dummy, ResultPath, FS_Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::error_code make_absolute(const Twine ¤t_directory,
|
void make_absolute(const Twine ¤t_directory,
|
||||||
SmallVectorImpl<char> &path,
|
SmallVectorImpl<char> &path) {
|
||||||
bool use_current_directory) {
|
|
||||||
StringRef p(path.data(), path.size());
|
StringRef p(path.data(), path.size());
|
||||||
|
|
||||||
bool rootDirectory = path::has_root_directory(p);
|
bool rootDirectory = path::has_root_directory(p);
|
||||||
@ -860,14 +859,11 @@ static std::error_code make_absolute(const Twine ¤t_directory,
|
|||||||
|
|
||||||
// Already absolute.
|
// Already absolute.
|
||||||
if (rootName && rootDirectory)
|
if (rootName && rootDirectory)
|
||||||
return std::error_code();
|
return;
|
||||||
|
|
||||||
// All of the following conditions will need the current directory.
|
// All of the following conditions will need the current directory.
|
||||||
SmallString<128> current_dir;
|
SmallString<128> current_dir;
|
||||||
if (use_current_directory)
|
current_directory.toVector(current_dir);
|
||||||
current_directory.toVector(current_dir);
|
|
||||||
else if (std::error_code ec = current_path(current_dir))
|
|
||||||
return ec;
|
|
||||||
|
|
||||||
// Relative path. Prepend the current directory.
|
// Relative path. Prepend the current directory.
|
||||||
if (!rootName && !rootDirectory) {
|
if (!rootName && !rootDirectory) {
|
||||||
@ -875,7 +871,7 @@ static std::error_code make_absolute(const Twine ¤t_directory,
|
|||||||
path::append(current_dir, p);
|
path::append(current_dir, p);
|
||||||
// Set path to the result.
|
// Set path to the result.
|
||||||
path.swap(current_dir);
|
path.swap(current_dir);
|
||||||
return std::error_code();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rootName && rootDirectory) {
|
if (!rootName && rootDirectory) {
|
||||||
@ -884,7 +880,7 @@ static std::error_code make_absolute(const Twine ¤t_directory,
|
|||||||
path::append(curDirRootName, p);
|
path::append(curDirRootName, p);
|
||||||
// Set path to the result.
|
// Set path to the result.
|
||||||
path.swap(curDirRootName);
|
path.swap(curDirRootName);
|
||||||
return std::error_code();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rootName && !rootDirectory) {
|
if (rootName && !rootDirectory) {
|
||||||
@ -896,20 +892,23 @@ static std::error_code make_absolute(const Twine ¤t_directory,
|
|||||||
SmallString<128> res;
|
SmallString<128> res;
|
||||||
path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
|
path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
|
||||||
path.swap(res);
|
path.swap(res);
|
||||||
return std::error_code();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm_unreachable("All rootName and rootDirectory combinations should have "
|
llvm_unreachable("All rootName and rootDirectory combinations should have "
|
||||||
"occurred above!");
|
"occurred above!");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_code make_absolute(const Twine ¤t_directory,
|
|
||||||
SmallVectorImpl<char> &path) {
|
|
||||||
return make_absolute(current_directory, path, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::error_code make_absolute(SmallVectorImpl<char> &path) {
|
std::error_code make_absolute(SmallVectorImpl<char> &path) {
|
||||||
return make_absolute(Twine(), path, false);
|
if (path::is_absolute(path))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
SmallString<128> current_dir;
|
||||||
|
if (std::error_code ec = current_path(current_dir))
|
||||||
|
return ec;
|
||||||
|
|
||||||
|
make_absolute(current_dir, path);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_code create_directories(const Twine &Path, bool IgnoreExisting,
|
std::error_code create_directories(const Twine &Path, bool IgnoreExisting,
|
||||||
|
@ -128,7 +128,8 @@ std::error_code FileSystem::makeAbsolute(SmallVectorImpl<char> &Path) const {
|
|||||||
if (!WorkingDir)
|
if (!WorkingDir)
|
||||||
return WorkingDir.getError();
|
return WorkingDir.getError();
|
||||||
|
|
||||||
return llvm::sys::fs::make_absolute(WorkingDir.get(), Path);
|
llvm::sys::fs::make_absolute(WorkingDir.get(), Path);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::error_code FileSystem::getRealPath(const Twine &Path,
|
std::error_code FileSystem::getRealPath(const Twine &Path,
|
||||||
|
@ -231,13 +231,8 @@ static bool writeReport(LocationInfoTy &LocationInfo) {
|
|||||||
bool FirstFile = true;
|
bool FirstFile = true;
|
||||||
for (auto &FI : LocationInfo) {
|
for (auto &FI : LocationInfo) {
|
||||||
SmallString<128> FileName(FI.first);
|
SmallString<128> FileName(FI.first);
|
||||||
if (!InputRelDir.empty()) {
|
if (!InputRelDir.empty())
|
||||||
if (std::error_code EC = sys::fs::make_absolute(InputRelDir, FileName)) {
|
sys::fs::make_absolute(InputRelDir, FileName);
|
||||||
WithColor::error() << "Can't resolve file path to " << FileName << ": "
|
|
||||||
<< EC.message() << "\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto &FileInfo = FI.second;
|
const auto &FileInfo = FI.second;
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ TEST(Support, Path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SmallString<32> Relative("foo.cpp");
|
SmallString<32> Relative("foo.cpp");
|
||||||
ASSERT_NO_ERROR(sys::fs::make_absolute("/root", Relative));
|
sys::fs::make_absolute("/root", Relative);
|
||||||
Relative[5] = '/'; // Fix up windows paths.
|
Relative[5] = '/'; // Fix up windows paths.
|
||||||
ASSERT_EQ("/root/foo.cpp", Relative);
|
ASSERT_EQ("/root/foo.cpp", Relative);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user