|
8 | 8 |
|
9 | 9 | #include "Generators.h"
|
10 | 10 | #include "Representation.h"
|
11 |
| -#include "FileHelpersClangDoc.h" |
12 | 11 | #include "clang/Basic/Version.h"
|
13 | 12 | #include "llvm/ADT/StringExtras.h"
|
14 | 13 | #include "llvm/ADT/StringRef.h"
|
@@ -252,6 +251,46 @@ static void appendVector(std::vector<Derived> &&New,
|
252 | 251 | std::move(New.begin(), New.end(), std::back_inserter(Original));
|
253 | 252 | }
|
254 | 253 |
|
| 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 | +} |
255 | 294 |
|
256 | 295 | // HTML generation
|
257 | 296 |
|
@@ -1094,6 +1133,24 @@ static llvm::Error genIndex(const ClangDocContext &CDCtx) {
|
1094 | 1133 | return llvm::Error::success();
|
1095 | 1134 | }
|
1096 | 1135 |
|
| 1136 | +static llvm::Error |
| 1137 | +copyFile(StringRef FilePath, StringRef OutDirectory) { |
| 1138 | + llvm::SmallString<128> PathWrite; |
| 1139 | + llvm::sys::path::native(OutDirectory, PathWrite); |
| 1140 | + llvm::sys::path::append(PathWrite, llvm::sys::path::filename(FilePath)); |
| 1141 | + llvm::SmallString<128> PathRead; |
| 1142 | + llvm::sys::path::native(FilePath, PathRead); |
| 1143 | + std::error_code OK; |
| 1144 | + std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite); |
| 1145 | + if (FileErr != OK) { |
| 1146 | + return llvm::createStringError(llvm::inconvertibleErrorCode(), |
| 1147 | + "error creating file " + |
| 1148 | + llvm::sys::path::filename(FilePath) + |
| 1149 | + ": " + FileErr.message() + "\n"); |
| 1150 | + } |
| 1151 | + return llvm::Error::success(); |
| 1152 | +} |
| 1153 | + |
1097 | 1154 | llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
|
1098 | 1155 | auto Err = serializeIndex(CDCtx);
|
1099 | 1156 | if (Err)
|
|
0 commit comments