mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-28 03:25:23 +00:00
Support/PathV2: Move make_absolute from path to fs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121108 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -104,6 +104,19 @@ public:
|
|||||||
/// @name Physical Operators
|
/// @name Physical Operators
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
/// @brief Make \a path an absolute path.
|
||||||
|
///
|
||||||
|
/// Makes \a path absolute using the current directory if it is not already. An
|
||||||
|
/// empty \a path will result in the current directory.
|
||||||
|
///
|
||||||
|
/// /absolute/path => /absolute/path
|
||||||
|
/// relative/../path => <current-directory>/relative/../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
|
||||||
|
/// platform specific error_code.
|
||||||
|
error_code make_absolute(SmallVectorImpl<char> &path);
|
||||||
|
|
||||||
/// @brief Copy the file at \a from to the path \a to.
|
/// @brief Copy the file at \a from to the path \a to.
|
||||||
///
|
///
|
||||||
/// @param from The path to copy the file from.
|
/// @param from The path to copy the file from.
|
||||||
|
@@ -117,19 +117,6 @@ inline reverse_iterator rend(const StringRef &path) {
|
|||||||
/// @name Lexical Modifiers
|
/// @name Lexical Modifiers
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
/// @brief Make \a path an absolute path.
|
|
||||||
///
|
|
||||||
/// Makes \a path absolute using the current directory if it is not already. An
|
|
||||||
/// empty \a path will result in the current directory.
|
|
||||||
///
|
|
||||||
/// /absolute/path => /absolute/path
|
|
||||||
/// relative/../path => <current-directory>/relative/../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
|
|
||||||
/// platform specific error_code.
|
|
||||||
error_code make_absolute(SmallVectorImpl<char> &path);
|
|
||||||
|
|
||||||
/// @brief Remove the last component from \a path unless it is the root dir.
|
/// @brief Remove the last component from \a path unless it is the root dir.
|
||||||
///
|
///
|
||||||
/// directory/filename.cpp => directory/
|
/// directory/filename.cpp => directory/
|
||||||
|
@@ -424,61 +424,6 @@ error_code append(SmallVectorImpl<char> &path, const Twine &a,
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code make_absolute(SmallVectorImpl<char> &path) {
|
|
||||||
StringRef p(path.data(), path.size());
|
|
||||||
|
|
||||||
bool rootName = false, rootDirectory = false;
|
|
||||||
if (error_code ec = has_root_name(p, rootName)) return ec;
|
|
||||||
if (error_code ec = has_root_directory(p, rootDirectory)) return ec;
|
|
||||||
|
|
||||||
// Already absolute.
|
|
||||||
if (rootName && rootDirectory)
|
|
||||||
return success;
|
|
||||||
|
|
||||||
// All of the following conditions will need the current directory.
|
|
||||||
SmallString<128> current_dir;
|
|
||||||
if (error_code ec = fs::current_path(current_dir)) return ec;
|
|
||||||
|
|
||||||
// Relative path. Prepend the current directory.
|
|
||||||
if (!rootName && !rootDirectory) {
|
|
||||||
// Append path to the current directory.
|
|
||||||
if (error_code ec = append(current_dir, p)) return ec;
|
|
||||||
// Set path to the result.
|
|
||||||
path.swap(current_dir);
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rootName && rootDirectory) {
|
|
||||||
StringRef cdrn;
|
|
||||||
if (error_code ec = root_name(current_dir, cdrn)) return ec;
|
|
||||||
SmallString<128> curDirRootName(cdrn.begin(), cdrn.end());
|
|
||||||
if (error_code ec = append(curDirRootName, p)) return ec;
|
|
||||||
// Set path to the result.
|
|
||||||
path.swap(curDirRootName);
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rootName && !rootDirectory) {
|
|
||||||
StringRef pRootName;
|
|
||||||
StringRef bRootDirectory;
|
|
||||||
StringRef bRelativePath;
|
|
||||||
StringRef pRelativePath;
|
|
||||||
if (error_code ec = root_name(p, pRootName)) return ec;
|
|
||||||
if (error_code ec = root_directory(current_dir, bRootDirectory)) return ec;
|
|
||||||
if (error_code ec = relative_path(current_dir, bRelativePath)) return ec;
|
|
||||||
if (error_code ec = relative_path(p, pRelativePath)) return ec;
|
|
||||||
|
|
||||||
SmallString<128> res;
|
|
||||||
if (error_code ec = append(res, pRootName, bRootDirectory,
|
|
||||||
bRelativePath, pRelativePath)) return ec;
|
|
||||||
path.swap(res);
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm_unreachable("All rootName and rootDirectory combinations should have "
|
|
||||||
"occurred above!");
|
|
||||||
}
|
|
||||||
|
|
||||||
error_code parent_path(const StringRef &path, StringRef &result) {
|
error_code parent_path(const StringRef &path, StringRef &result) {
|
||||||
size_t end_pos = parent_path_end(path);
|
size_t end_pos = parent_path_end(path);
|
||||||
if (end_pos == StringRef::npos)
|
if (end_pos == StringRef::npos)
|
||||||
@@ -673,6 +618,63 @@ error_code is_relative(const Twine &path, bool &result) {
|
|||||||
|
|
||||||
namespace fs {
|
namespace fs {
|
||||||
|
|
||||||
|
error_code make_absolute(SmallVectorImpl<char> &path) {
|
||||||
|
StringRef p(path.data(), path.size());
|
||||||
|
|
||||||
|
bool rootName = false, rootDirectory = false;
|
||||||
|
if (error_code ec = path::has_root_name(p, rootName)) return ec;
|
||||||
|
if (error_code ec = path::has_root_directory(p, rootDirectory)) return ec;
|
||||||
|
|
||||||
|
// Already absolute.
|
||||||
|
if (rootName && rootDirectory)
|
||||||
|
return success;
|
||||||
|
|
||||||
|
// All of the following conditions will need the current directory.
|
||||||
|
SmallString<128> current_dir;
|
||||||
|
if (error_code ec = current_path(current_dir)) return ec;
|
||||||
|
|
||||||
|
// Relative path. Prepend the current directory.
|
||||||
|
if (!rootName && !rootDirectory) {
|
||||||
|
// Append path to the current directory.
|
||||||
|
if (error_code ec = path::append(current_dir, p)) return ec;
|
||||||
|
// Set path to the result.
|
||||||
|
path.swap(current_dir);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rootName && rootDirectory) {
|
||||||
|
StringRef cdrn;
|
||||||
|
if (error_code ec = path::root_name(current_dir, cdrn)) return ec;
|
||||||
|
SmallString<128> curDirRootName(cdrn.begin(), cdrn.end());
|
||||||
|
if (error_code ec = path::append(curDirRootName, p)) return ec;
|
||||||
|
// Set path to the result.
|
||||||
|
path.swap(curDirRootName);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootName && !rootDirectory) {
|
||||||
|
StringRef pRootName;
|
||||||
|
StringRef bRootDirectory;
|
||||||
|
StringRef bRelativePath;
|
||||||
|
StringRef pRelativePath;
|
||||||
|
if (error_code ec = path::root_name(p, pRootName)) return ec;
|
||||||
|
if (error_code ec = path::root_directory(current_dir, bRootDirectory))
|
||||||
|
return ec;
|
||||||
|
if (error_code ec = path::relative_path(current_dir, bRelativePath))
|
||||||
|
return ec;
|
||||||
|
if (error_code ec = path::relative_path(p, pRelativePath)) return ec;
|
||||||
|
|
||||||
|
SmallString<128> res;
|
||||||
|
if (error_code ec = path::append(res, pRootName, bRootDirectory,
|
||||||
|
bRelativePath, pRelativePath)) return ec;
|
||||||
|
path.swap(res);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
llvm_unreachable("All rootName and rootDirectory combinations should have "
|
||||||
|
"occurred above!");
|
||||||
|
}
|
||||||
|
|
||||||
error_code create_directories(const Twine &path, bool &existed) {
|
error_code create_directories(const Twine &path, bool &existed) {
|
||||||
SmallString<128> path_storage;
|
SmallString<128> path_storage;
|
||||||
StringRef p = path.toStringRef(path_storage);
|
StringRef p = path.toStringRef(path_storage);
|
||||||
|
@@ -104,7 +104,7 @@ TEST(Support, Path) {
|
|||||||
|
|
||||||
SmallString<16> temp_store;
|
SmallString<16> temp_store;
|
||||||
temp_store = *i;
|
temp_store = *i;
|
||||||
ASSERT_FALSE(path::make_absolute(temp_store));
|
ASSERT_FALSE(fs::make_absolute(temp_store));
|
||||||
temp_store = *i;
|
temp_store = *i;
|
||||||
ASSERT_FALSE(path::remove_filename(temp_store));
|
ASSERT_FALSE(path::remove_filename(temp_store));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user