-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang-doc][NFC] refactor out file helpers #134298
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # clang-doc/support contains support libraries that do not depend | ||
| # on clang either programmatically or conceptually. | ||
| set(LLVM_LINK_COMPONENTS | ||
| Support | ||
| ) | ||
|
|
||
| add_clang_library(clangDocSupport STATIC | ||
| File.cpp | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| //===-- 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 "File.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 FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite); | ||
| if (FileErr) { | ||
| 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) { | ||
| // 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //===-- File.h --- 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_FILEHELPER_H | ||
PeterChou1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #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 | ||
PeterChou1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.