|
8 | 8 |
|
9 | 9 | #include "Generators.h"
|
10 | 10 | #include "Representation.h"
|
11 |
| -#include "support/File.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,47 @@ 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 | +} |
| 294 | + |
255 | 295 | // HTML generation
|
256 | 296 |
|
257 | 297 | static std::vector<std::unique_ptr<TagNode>>
|
@@ -1098,6 +1138,23 @@ static llvm::Error genIndex(const ClangDocContext &CDCtx) {
|
1098 | 1138 | return llvm::Error::success();
|
1099 | 1139 | }
|
1100 | 1140 |
|
| 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 | + |
1101 | 1158 | llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
|
1102 | 1159 | auto Err = serializeIndex(CDCtx);
|
1103 | 1160 | if (Err)
|
|
0 commit comments