forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 344
Support hermetic index store data via path remappings #4207
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
836e3f0
Support remapping index store paths
DavidGoldman c50d6c2
Swap to indexstore_store_create_with_options
DavidGoldman 3b53e89
Add documentation comments to indexstore.h
DavidGoldman c394fb8
indexstore_creation_options_create() --> indexstore_creation_options_…
DavidGoldman a0248b7
Don't make stdout absolute
DavidGoldman dd5dc70
Add PathRemapper utility class
DavidGoldman 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//===--- PathRemapper.h - Remap filepath prefixes ---------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines a data structure that stores a string-to-string | ||
// mapping used to transform file paths based on a prefix mapping. It | ||
// is optimized for the common case of having 0, 1, or 2 mappings. | ||
// | ||
// Remappings are stored such that they are applied in the order they | ||
// are passed on the command line, with the first one winning - a path will | ||
// only be remapped by a single mapping, if any, not multiple. The ordering | ||
// would only matter if one source mapping was a prefix of another. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_BASIC_PATHREMAPPER_H | ||
#define LLVM_CLANG_BASIC_PATHREMAPPER_H | ||
|
||
#include "clang/Basic/LLVM.h" | ||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/ADT/Twine.h" | ||
|
||
#include <string> | ||
#include <utility> | ||
|
||
namespace clang { | ||
|
||
class PathRemapper { | ||
SmallVector<std::pair<std::string, std::string>, 2> PathMappings; | ||
public: | ||
/// Adds a mapping such that any paths starting with `FromPrefix` have that | ||
/// portion replaced with `ToPrefix`. | ||
void addMapping(StringRef FromPrefix, StringRef ToPrefix) { | ||
PathMappings.emplace_back(FromPrefix.str(), ToPrefix.str()); | ||
} | ||
|
||
/// Returns a remapped `Path` if it starts with a prefix in the map; otherwise | ||
/// the original path is returned. | ||
std::string remapPath(StringRef Path) const { | ||
for (const auto &Mapping : PathMappings) | ||
if (Path.startswith(Mapping.first)) | ||
return (Twine(Mapping.second) + | ||
Path.substr(Mapping.first.size())).str(); | ||
return Path.str(); | ||
} | ||
|
||
/// Return true if there are no path remappings (meaning remapPath will always | ||
/// return the path given). | ||
bool empty() const { | ||
return PathMappings.empty(); | ||
} | ||
|
||
const SmallVector<std::pair<std::string, std::string>, 2> & getMappings() { | ||
return PathMappings; | ||
} | ||
}; | ||
|
||
} // end namespace clang | ||
|
||
#endif |
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
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
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.