Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ void BinaryContext::preprocessDWODebugInfo() {
"files.\n";
}
// Prevent failures when DWOName is already an absolute path.
sys::fs::make_absolute(DWOCompDir, AbsolutePath);
sys::path::make_absolute(DWOCompDir, AbsolutePath);
DWARFUnit *DWOCU =
DwarfUnit->getNonSkeletonUnitDIE(false, AbsolutePath).getDwarfUnit();
if (!DWOCU->isDWOUnit()) {
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Rewrite/DWARFRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ void DWARFRewriter::writeDWOFiles(
else if (!sys::fs::exists(CompDir))
CompDir = ".";
// Prevent failures when DWOName is already an absolute path.
sys::fs::make_absolute(CompDir, AbsolutePath);
sys::path::make_absolute(CompDir, AbsolutePath);

std::error_code EC;
std::unique_ptr<ToolOutputFile> TempOut =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
// build directories, make them absolute immediately.
SmallString<128> Path = R.getFilePath();
if (BuildDir)
llvm::sys::fs::make_absolute(*BuildDir, Path);
llvm::sys::path::make_absolute(*BuildDir, Path);
else
SM.getFileManager().makeAbsolutePath(Path);

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-move/Move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ std::string MakeAbsolutePath(StringRef CurrentDir, StringRef Path) {
return "";
llvm::SmallString<128> InitialDirectory(CurrentDir);
llvm::SmallString<128> AbsolutePath(Path);
llvm::sys::fs::make_absolute(InitialDirectory, AbsolutePath);
llvm::sys::path::make_absolute(InitialDirectory, AbsolutePath);
return CleanPath(std::move(AbsolutePath));
}

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/ConfigCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct FragmentCompiler {
return std::nullopt;
}
llvm::SmallString<256> AbsPath = llvm::StringRef(*Path);
llvm::sys::fs::make_absolute(FragmentDirectory, AbsPath);
llvm::sys::path::make_absolute(FragmentDirectory, AbsPath);
llvm::sys::path::native(AbsPath, Style);
return AbsPath.str().str();
}
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/SystemIncludeExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct DriverArgs {
// relative or absolute).
if (llvm::any_of(Driver,
[](char C) { return llvm::sys::path::is_separator(C); })) {
llvm::sys::fs::make_absolute(Cmd.Directory, Driver);
llvm::sys::path::make_absolute(Cmd.Directory, Driver);
}
this->Driver = Driver.str().str();
for (size_t I = 0, E = Cmd.CommandLine.size(); I < E; ++I) {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/index/SymbolCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class SymbolCollector::HeaderFileURICache {
if (R.second) {
llvm::SmallString<256> AbsPath = Path;
if (!llvm::sys::path::is_absolute(AbsPath) && !FallbackDir.empty())
llvm::sys::fs::make_absolute(FallbackDir, AbsPath);
llvm::sys::path::make_absolute(FallbackDir, AbsPath);
assert(llvm::sys::path::is_absolute(AbsPath) &&
"If the VFS can't make paths absolute, a FallbackDir must be "
"provided");
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/tool/ClangdMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class TestScheme : public URIScheme {
Body = Body.ltrim('/');
llvm::SmallString<16> Path(Body);
path::native(Path);
fs::make_absolute(TestScheme::TestDir, Path);
path::make_absolute(TestScheme::TestDir, Path);
return std::string(Path);
}

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ mapInputsToAbsPaths(clang::tooling::CompilationDatabase &CDB,
}
for (const auto &Cmd : Cmds) {
llvm::SmallString<256> CDBPath(Cmd.Filename);
llvm::sys::fs::make_absolute(Cmd.Directory, CDBPath);
llvm::sys::path::make_absolute(Cmd.Directory, CDBPath);
CDBToAbsPaths[std::string(CDBPath)] = std::string(AbsPath);
}
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Lex/HeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,7 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(

llvm::SmallString<32> FilePath = File;
if (!WorkingDir.empty() && !path::is_absolute(FilePath))
fs::make_absolute(WorkingDir, FilePath);
path::make_absolute(WorkingDir, FilePath);
// remove_dots switches to backslashes on windows as a side-effect!
// We always want to suggest forward slashes for includes.
// (not remove_dots(..., posix) as that misparses windows paths).
Expand All @@ -2091,7 +2091,7 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
// `BestPrefixLength` accordingly.
auto CheckDir = [&](llvm::SmallString<32> Dir) -> bool {
if (!WorkingDir.empty() && !path::is_absolute(Dir))
fs::make_absolute(WorkingDir, Dir);
path::make_absolute(WorkingDir, Dir);
path::remove_dots(Dir, /*remove_dot_dot=*/true);
for (auto NI = path::begin(File), NE = path::end(File),
DI = path::begin(Dir), DE = path::end(Dir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DependencyConsumerForwarder : public DependencyFileGenerator {
for (const auto &File : getDependencies()) {
CanonPath = File;
llvm::sys::path::remove_dots(CanonPath, /*remove_dot_dot=*/true);
llvm::sys::fs::make_absolute(WorkingDirectory, CanonPath);
llvm::sys::path::make_absolute(WorkingDirectory, CanonPath);
C.handleFileDependency(CanonPath);
}
}
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Frontend/CompilerInstanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST(CompilerInstance, DefaultVFSOverlayFromInvocation) {

SmallString<256> CurrentPath;
sys::fs::current_path(CurrentPath);
sys::fs::make_absolute(CurrentPath, FileName);
sys::path::make_absolute(CurrentPath, FileName);

// Mount the VFS file itself on the path 'virtual.file'. Makes this test
// a bit shorter than creating a new dummy file just for this purpose.
Expand Down
12 changes: 0 additions & 12 deletions llvm/include/llvm/Support/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,6 @@ class file_status : public basic_file_status {
/// @name Physical Operators
/// @{

/// Make \a path an absolute path.
///
/// Makes \a path absolute using the \a current_directory if it is not already.
/// An empty \a path will result in the \a current_directory.
///
/// /absolute/path => /absolute/path
/// relative/../path => <current-directory>/relative/../path
///
/// @param path A path that is modified to be an absolute path.
LLVM_ABI void make_absolute(const Twine &current_directory,
SmallVectorImpl<char> &path);

/// Make \a path an absolute path.
///
/// Makes \a path absolute using the current directory if it is not already. An
Expand Down
12 changes: 12 additions & 0 deletions llvm/include/llvm/Support/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,18 @@ LLVM_ABI bool is_absolute_gnu(const Twine &path, Style style = Style::native);
/// @result True if the path is relative, false if it is not.
LLVM_ABI bool is_relative(const Twine &path, Style style = Style::native);

/// Make \a path an absolute path.
///
/// Makes \a path absolute using the \a current_directory if it is not already.
/// An empty \a path will result in the \a current_directory.
///
/// /absolute/path => /absolute/path
/// relative/../path => <current-directory>/relative/../path
///
/// @param path A path that is modified to be an absolute path.
LLVM_ABI void make_absolute(const Twine &current_directory,
SmallVectorImpl<char> &path);

} // end namespace path
} // end namespace sys
} // end namespace llvm
Expand Down
100 changes: 50 additions & 50 deletions llvm/lib/Support/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,55 @@ bool is_relative(const Twine &path, Style style) {
return !is_absolute(path, style);
}

void make_absolute(const Twine &current_directory,
SmallVectorImpl<char> &path) {
StringRef p(path.data(), path.size());

bool rootDirectory = has_root_directory(p);
bool rootName = has_root_name(p);

// Already absolute.
if ((rootName || is_style_posix(Style::native)) && rootDirectory)
return;

// All the following conditions will need the current directory.
SmallString<128> current_dir;
current_directory.toVector(current_dir);

// Relative path. Prepend the current directory.
if (!rootName && !rootDirectory) {
// Append path to the current directory.
append(current_dir, p);
// Set path to the result.
path.swap(current_dir);
return;
}

if (!rootName && rootDirectory) {
StringRef cdrn = root_name(current_dir);
SmallString<128> curDirRootName(cdrn.begin(), cdrn.end());
append(curDirRootName, p);
// Set path to the result.
path.swap(curDirRootName);
return;
}

if (rootName && !rootDirectory) {
StringRef pRootName = root_name(p);
StringRef bRootDirectory = root_directory(current_dir);
StringRef bRelativePath = relative_path(current_dir);
StringRef pRelativePath = relative_path(p);

SmallString<128> res;
append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
path.swap(res);
return;
}

llvm_unreachable("All rootName and rootDirectory combinations should have "
"occurred above!");
}

StringRef remove_leading_dotslash(StringRef Path, Style style) {
// Remove leading "./" (or ".//" or "././" etc.)
while (Path.size() > 2 && Path[0] == '.' && is_separator(Path[1], style)) {
Expand Down Expand Up @@ -903,55 +952,6 @@ getPotentiallyUniqueTempFileName(const Twine &Prefix, StringRef Suffix,
return createTemporaryFile(Prefix, Suffix, Dummy, ResultPath, FS_Name);
}

void make_absolute(const Twine &current_directory,
SmallVectorImpl<char> &path) {
StringRef p(path.data(), path.size());

bool rootDirectory = path::has_root_directory(p);
bool rootName = path::has_root_name(p);

// Already absolute.
if ((rootName || is_style_posix(Style::native)) && rootDirectory)
return;

// All of the following conditions will need the current directory.
SmallString<128> current_dir;
current_directory.toVector(current_dir);

// Relative path. Prepend the current directory.
if (!rootName && !rootDirectory) {
// Append path to the current directory.
path::append(current_dir, p);
// Set path to the result.
path.swap(current_dir);
return;
}

if (!rootName && rootDirectory) {
StringRef cdrn = path::root_name(current_dir);
SmallString<128> curDirRootName(cdrn.begin(), cdrn.end());
path::append(curDirRootName, p);
// Set path to the result.
path.swap(curDirRootName);
return;
}

if (rootName && !rootDirectory) {
StringRef pRootName = path::root_name(p);
StringRef bRootDirectory = path::root_directory(current_dir);
StringRef bRelativePath = path::relative_path(current_dir);
StringRef pRelativePath = path::relative_path(p);

SmallString<128> res;
path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
path.swap(res);
return;
}

llvm_unreachable("All rootName and rootDirectory combinations should have "
"occurred above!");
}

std::error_code make_absolute(SmallVectorImpl<char> &path) {
if (path::is_absolute(path))
return {};
Expand All @@ -960,7 +960,7 @@ std::error_code make_absolute(SmallVectorImpl<char> &path) {
if (std::error_code ec = current_path(current_dir))
return ec;

make_absolute(current_dir, path);
path::make_absolute(current_dir, path);
return {};
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Support/VirtualFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ std::error_code FileSystem::makeAbsolute(SmallVectorImpl<char> &Path) const {
if (!WorkingDir)
return WorkingDir.getError();

llvm::sys::fs::make_absolute(WorkingDir.get(), Path);
sys::path::make_absolute(WorkingDir.get(), Path);
return {};
}

Expand Down Expand Up @@ -300,7 +300,7 @@ class RealFileSystem : public FileSystem {
if (!WD || !*WD)
return Path;
Path.toVector(Storage);
sys::fs::make_absolute(WD->get().Resolved, Storage);
sys::path::make_absolute(WD->get().Resolved, Storage);
return Storage;
}

Expand Down
6 changes: 3 additions & 3 deletions llvm/tools/llvm-config/llvm-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,18 @@ int main(int argc, char **argv) {
ActivePrefix = CurrentExecPrefix;
{
SmallString<256> Path(LLVM_INSTALL_INCLUDEDIR);
sys::fs::make_absolute(ActivePrefix, Path);
sys::path::make_absolute(ActivePrefix, Path);
ActiveIncludeDir = std::string(Path);
}
{
SmallString<256> Path(LLVM_TOOLS_INSTALL_DIR);
sys::fs::make_absolute(ActivePrefix, Path);
sys::path::make_absolute(ActivePrefix, Path);
ActiveBinDir = std::string(Path);
}
ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
{
SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR);
sys::fs::make_absolute(ActivePrefix, Path);
sys::path::make_absolute(ActivePrefix, Path);
ActiveCMakeDir = std::string(Path);
}
ActiveIncludeOption = "-I" + ActiveIncludeDir;
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-dwp/llvm-dwp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ getDWOFilenames(StringRef ExecFilename) {
dwarf::toString(Die.find(dwarf::DW_AT_comp_dir), "");
if (!DWOCompDir.empty()) {
SmallString<16> DWOPath(DWOName);
sys::fs::make_absolute(DWOCompDir, DWOPath);
sys::path::make_absolute(DWOCompDir, DWOPath);
if (!sys::fs::exists(DWOPath) && sys::fs::exists(DWOName))
DWOPaths.push_back(std::move(DWOName));
else
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-opt-report/OptReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static bool writeReport(LocationInfoTy &LocationInfo) {
for (auto &FI : LocationInfo) {
SmallString<128> FileName(FI.first);
if (!InputRelDir.empty())
sys::fs::make_absolute(InputRelDir, FileName);
sys::path::make_absolute(InputRelDir, FileName);

const auto &FileInfo = FI.second;

Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/Support/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ TEST(Support, Path) {

{
SmallString<32> Relative("foo.cpp");
sys::fs::make_absolute("/root", Relative);
path::make_absolute("/root", Relative);
Relative[5] = '/'; // Fix up windows paths.
ASSERT_EQ("/root/foo.cpp", Relative);
}

{
SmallString<32> Relative("foo.cpp");
sys::fs::make_absolute("//root", Relative);
path::make_absolute("//root", Relative);
Relative[6] = '/'; // Fix up windows paths.
ASSERT_EQ("//root/foo.cpp", Relative);
}
Expand Down