-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang-doc] Adds a mustache backend #133161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3d7441a
59df7dd
ad61ab4
8e2d7fa
1e62f7d
233b3c1
af48431
85cb28e
c685493
8c85923
3c19f18
0d459f8
75925a4
c753075
19bed2c
2a3c40e
1b07553
1cf5eb0
8ba6a5d
79ea4bc
6010fb2
85c4c21
356217c
450a6b1
9dbd1b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//===-- FileHelpersClangDoc.cpp - File Helpers -------------------*- C++-*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include "FileHelpersClangDoc.h" | ||
#include "llvm/Support/FileSystem.h" | ||
#include "llvm/Support/Path.h" | ||
|
||
namespace clang { | ||
namespace doc { | ||
|
||
llvm::Error | ||
copyFile(llvm::StringRef FilePath, llvm::StringRef OutDirectory) { | ||
llvm::SmallString<128> PathWrite; | ||
llvm::sys::path::native(OutDirectory, PathWrite); | ||
llvm::sys::path::append(PathWrite, llvm::sys::path::filename(FilePath)); | ||
llvm::SmallString<128> PathRead; | ||
llvm::sys::path::native(FilePath, PathRead); | ||
std::error_code OK; | ||
std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite); | ||
if (FileErr != OK) { | ||
return llvm::createStringError(llvm::inconvertibleErrorCode(), | ||
"error creating file " + | ||
llvm::sys::path::filename(FilePath) + | ||
": " + FileErr.message() + "\n"); | ||
} | ||
return llvm::Error::success(); | ||
} | ||
|
||
|
||
llvm::SmallString<128> computeRelativePath(llvm::StringRef Destination, | ||
llvm::StringRef Origin) { | ||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should drop this in favor of |
||
// If Origin is empty, the relative path to the Destination is its complete | ||
// path. | ||
if (Origin.empty()) | ||
return Destination; | ||
|
||
// The relative path is an empty path if both directories are the same. | ||
if (Destination == Origin) | ||
return {}; | ||
|
||
// These iterators iterate through each of their parent directories | ||
llvm::sys::path::const_iterator FileI = llvm::sys::path::begin(Destination); | ||
llvm::sys::path::const_iterator FileE = llvm::sys::path::end(Destination); | ||
llvm::sys::path::const_iterator DirI = llvm::sys::path::begin(Origin); | ||
llvm::sys::path::const_iterator DirE = llvm::sys::path::end(Origin); | ||
// Advance both iterators until the paths differ. Example: | ||
// Destination = A/B/C/D | ||
// Origin = A/B/E/F | ||
// FileI will point to C and DirI to E. The directories behind them is the | ||
// directory they share (A/B). | ||
while (FileI != FileE && DirI != DirE && *FileI == *DirI) { | ||
++FileI; | ||
++DirI; | ||
} | ||
llvm::SmallString<128> Result; // This will hold the resulting path. | ||
// Result has to go up one directory for each of the remaining directories in | ||
// Origin | ||
while (DirI != DirE) { | ||
llvm::sys::path::append(Result, ".."); | ||
++DirI; | ||
} | ||
// Result has to append each of the remaining directories in Destination | ||
while (FileI != FileE) { | ||
llvm::sys::path::append(Result, *FileI); | ||
++FileI; | ||
} | ||
return Result; | ||
} | ||
|
||
} // namespace doc | ||
} // namespace clang |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//===-- FileHelpersClangDoc.h --- File Helpers -------------------*- C++-*-===// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably putting this in |
||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_FILEHELPER_H | ||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_FILEHELPER_H | ||
|
||
#include "llvm/ADT/StringExtras.h" | ||
#include "llvm/Support/Error.h" | ||
|
||
namespace clang { | ||
namespace doc { | ||
|
||
llvm::Error | ||
copyFile(llvm::StringRef FilePath, llvm::StringRef OutDirectory); | ||
|
||
llvm::SmallString<128> | ||
computeRelativePath(llvm::StringRef Destination,llvm::StringRef Origin); | ||
|
||
} // namespace doc | ||
} // namespace clang | ||
|
||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_FILEHELPER_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.