Skip to content

Commit 2251aef

Browse files
committed
Revert "[clang-doc][NFC] refactor out file helpers (llvm#134298)"
This reverts commit e10f67a.
1 parent 7f4b0ab commit 2251aef

File tree

6 files changed

+61
-109
lines changed

6 files changed

+61
-109
lines changed

clang-tools-extra/clang-doc/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ set(LLVM_LINK_COMPONENTS
33
BitstreamReader
44
FrontendOpenMP
55
)
6-
add_subdirectory(support)
76

87
add_clang_library(clangDoc STATIC
98
BitcodeReader.cpp
@@ -24,7 +23,6 @@ add_clang_library(clangDoc STATIC
2423

2524
clang_target_link_libraries(clangDoc
2625
PRIVATE
27-
clangDocSupport
2826
clangAnalysis
2927
clangAST
3028
clangASTMatchers

clang-tools-extra/clang-doc/HTMLGenerator.cpp

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "Generators.h"
1010
#include "Representation.h"
11-
#include "support/File.h"
1211
#include "clang/Basic/Version.h"
1312
#include "llvm/ADT/StringExtras.h"
1413
#include "llvm/ADT/StringRef.h"
@@ -252,6 +251,47 @@ static void appendVector(std::vector<Derived> &&New,
252251
std::move(New.begin(), New.end(), std::back_inserter(Original));
253252
}
254253

254+
// Compute the relative path from an Origin directory to a Destination directory
255+
static SmallString<128> computeRelativePath(StringRef Destination,
256+
StringRef Origin) {
257+
// If Origin is empty, the relative path to the Destination is its complete
258+
// path.
259+
if (Origin.empty())
260+
return Destination;
261+
262+
// The relative path is an empty path if both directories are the same.
263+
if (Destination == Origin)
264+
return {};
265+
266+
// These iterators iterate through each of their parent directories
267+
llvm::sys::path::const_iterator FileI = llvm::sys::path::begin(Destination);
268+
llvm::sys::path::const_iterator FileE = llvm::sys::path::end(Destination);
269+
llvm::sys::path::const_iterator DirI = llvm::sys::path::begin(Origin);
270+
llvm::sys::path::const_iterator DirE = llvm::sys::path::end(Origin);
271+
// Advance both iterators until the paths differ. Example:
272+
// Destination = A/B/C/D
273+
// Origin = A/B/E/F
274+
// FileI will point to C and DirI to E. The directories behind them is the
275+
// directory they share (A/B).
276+
while (FileI != FileE && DirI != DirE && *FileI == *DirI) {
277+
++FileI;
278+
++DirI;
279+
}
280+
SmallString<128> Result; // This will hold the resulting path.
281+
// Result has to go up one directory for each of the remaining directories in
282+
// Origin
283+
while (DirI != DirE) {
284+
llvm::sys::path::append(Result, "..");
285+
++DirI;
286+
}
287+
// Result has to append each of the remaining directories in Destination
288+
while (FileI != FileE) {
289+
llvm::sys::path::append(Result, *FileI);
290+
++FileI;
291+
}
292+
return Result;
293+
}
294+
255295
// HTML generation
256296

257297
static std::vector<std::unique_ptr<TagNode>>
@@ -1098,6 +1138,23 @@ static llvm::Error genIndex(const ClangDocContext &CDCtx) {
10981138
return llvm::Error::success();
10991139
}
11001140

1141+
static llvm::Error copyFile(StringRef FilePath, StringRef OutDirectory) {
1142+
llvm::SmallString<128> PathWrite;
1143+
llvm::sys::path::native(OutDirectory, PathWrite);
1144+
llvm::sys::path::append(PathWrite, llvm::sys::path::filename(FilePath));
1145+
llvm::SmallString<128> PathRead;
1146+
llvm::sys::path::native(FilePath, PathRead);
1147+
std::error_code OK;
1148+
std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite);
1149+
if (FileErr != OK) {
1150+
return llvm::createStringError(llvm::inconvertibleErrorCode(),
1151+
"error creating file " +
1152+
llvm::sys::path::filename(FilePath) +
1153+
": " + FileErr.message() + "\n");
1154+
}
1155+
return llvm::Error::success();
1156+
}
1157+
11011158
llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
11021159
auto Err = serializeIndex(CDCtx);
11031160
if (Err)

clang-tools-extra/clang-doc/support/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

clang-tools-extra/clang-doc/support/File.cpp

Lines changed: 0 additions & 72 deletions
This file was deleted.

clang-tools-extra/clang-doc/support/File.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

revert_patches.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ breaks aompSmoke:
1616
[Clang][AMDGPU] Remove special handling for COV4 libraries
1717
huber,saiyed
1818
---
19+
Revert "[clang-doc][NFC] refactor out file helpers (#134298)"
20+
This reverts commit e10f67a8270c7745b8a9306a9910b06cfc8d2c55.
21+
---

0 commit comments

Comments
 (0)