Skip to content

Commit 846b9e6

Browse files
committed
[llvm][support] Move make_absolute from sys::fs to sys::path (llvm#161459)
The `llvm::sys::fs::make_absolute(const Twine &, SmallVectorImpl<char> &)` functions doesn't perform any FS access - it only modifies the second parameter via path/string operations. This function should live in the `llvm::sys::path` namespace for consistency and for making it easier to spot function calls that perform IO.
1 parent edea5c1 commit 846b9e6

File tree

19 files changed

+84
-84
lines changed

19 files changed

+84
-84
lines changed

clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
142142
// build directories, make them absolute immediately.
143143
SmallString<128> Path = R.getFilePath();
144144
if (BuildDir)
145-
llvm::sys::fs::make_absolute(*BuildDir, Path);
145+
llvm::sys::path::make_absolute(*BuildDir, Path);
146146
else
147147
SM.getFileManager().makeAbsolutePath(Path);
148148

clang-tools-extra/clang-move/Move.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ std::string MakeAbsolutePath(StringRef CurrentDir, StringRef Path) {
7575
return "";
7676
llvm::SmallString<128> InitialDirectory(CurrentDir);
7777
llvm::SmallString<128> AbsolutePath(Path);
78-
llvm::sys::fs::make_absolute(InitialDirectory, AbsolutePath);
78+
llvm::sys::path::make_absolute(InitialDirectory, AbsolutePath);
7979
return CleanPath(std::move(AbsolutePath));
8080
}
8181

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ struct FragmentCompiler {
131131
return std::nullopt;
132132
}
133133
llvm::SmallString<256> AbsPath = llvm::StringRef(*Path);
134-
llvm::sys::fs::make_absolute(FragmentDirectory, AbsPath);
134+
llvm::sys::path::make_absolute(FragmentDirectory, AbsPath);
135135
llvm::sys::path::native(AbsPath, Style);
136136
return AbsPath.str().str();
137137
}

clang-tools-extra/clangd/SystemIncludeExtractor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct DriverArgs {
106106
// relative or absolute).
107107
if (llvm::any_of(Driver,
108108
[](char C) { return llvm::sys::path::is_separator(C); })) {
109-
llvm::sys::fs::make_absolute(Cmd.Directory, Driver);
109+
llvm::sys::path::make_absolute(Cmd.Directory, Driver);
110110
}
111111
this->Driver = Driver.str().str();
112112
for (size_t I = 0, E = Cmd.CommandLine.size(); I < E; ++I) {

clang-tools-extra/clangd/index/SymbolCollector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class SymbolCollector::HeaderFileURICache {
325325
if (R.second) {
326326
llvm::SmallString<256> AbsPath = Path;
327327
if (!llvm::sys::path::is_absolute(AbsPath) && !FallbackDir.empty())
328-
llvm::sys::fs::make_absolute(FallbackDir, AbsPath);
328+
llvm::sys::path::make_absolute(FallbackDir, AbsPath);
329329
assert(llvm::sys::path::is_absolute(AbsPath) &&
330330
"If the VFS can't make paths absolute, a FallbackDir must be "
331331
"provided");

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ class TestScheme : public URIScheme {
577577
Body = Body.ltrim('/');
578578
llvm::SmallString<16> Path(Body);
579579
path::native(Path);
580-
fs::make_absolute(TestScheme::TestDir, Path);
580+
path::make_absolute(TestScheme::TestDir, Path);
581581
return std::string(Path);
582582
}
583583

clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ mapInputsToAbsPaths(clang::tooling::CompilationDatabase &CDB,
344344
}
345345
for (const auto &Cmd : Cmds) {
346346
llvm::SmallString<256> CDBPath(Cmd.Filename);
347-
llvm::sys::fs::make_absolute(Cmd.Directory, CDBPath);
347+
llvm::sys::path::make_absolute(Cmd.Directory, CDBPath);
348348
CDBToAbsPaths[std::string(CDBPath)] = std::string(AbsPath);
349349
}
350350
}

clang/lib/Frontend/CompileJobCache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static std::string fixupRelativePath(const std::string &Path, FileManager &FM,
271271
// Apply "normal" working directory.
272272
if (!WorkingDir.empty()) {
273273
SmallString<128> Tmp(Path);
274-
llvm::sys::fs::make_absolute(WorkingDir, Tmp);
274+
llvm::sys::path::make_absolute(WorkingDir, Tmp);
275275
return std::string(Tmp);
276276
}
277277
return Path;

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
19891989

19901990
llvm::SmallString<32> FilePath = File;
19911991
if (!WorkingDir.empty() && !path::is_absolute(FilePath))
1992-
fs::make_absolute(WorkingDir, FilePath);
1992+
path::make_absolute(WorkingDir, FilePath);
19931993
// remove_dots switches to backslashes on windows as a side-effect!
19941994
// We always want to suggest forward slashes for includes.
19951995
// (not remove_dots(..., posix) as that misparses windows paths).
@@ -2003,7 +2003,7 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
20032003
// `BestPrefixLength` accordingly.
20042004
auto CheckDir = [&](llvm::SmallString<32> Dir) -> bool {
20052005
if (!WorkingDir.empty() && !path::is_absolute(Dir))
2006-
fs::make_absolute(WorkingDir, Dir);
2006+
path::make_absolute(WorkingDir, Dir);
20072007
path::remove_dots(Dir, /*remove_dot_dot=*/true);
20082008
for (auto NI = path::begin(File), NE = path::end(File),
20092009
DI = path::begin(Dir), DE = path::end(Dir);

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DependencyConsumerForwarder : public DependencyFileGenerator {
6161
for (const auto &File : getDependencies()) {
6262
CanonPath = File;
6363
llvm::sys::path::remove_dots(CanonPath, /*remove_dot_dot=*/true);
64-
llvm::sys::fs::make_absolute(WorkingDirectory, CanonPath);
64+
llvm::sys::path::make_absolute(WorkingDirectory, CanonPath);
6565
C.handleFileDependency(CanonPath);
6666
}
6767
if (EmitDependencyFile)
@@ -1148,7 +1148,7 @@ void DependencyScanningWorker::computeDependenciesFromCompilerInvocation(
11481148
// FIXME: On Windows, WorkingDirectory is insufficient for making an
11491149
// absolute path if OutputFile has a root name.
11501150
llvm::SmallString<128> Path = StringRef(DepFile);
1151-
llvm::sys::fs::make_absolute(WorkingDirectory, Path);
1151+
llvm::sys::path::make_absolute(WorkingDirectory, Path);
11521152
DepFile = Path.str().str();
11531153
}
11541154

0 commit comments

Comments
 (0)