Skip to content

Commit

Permalink
Add temporary flag to fix rules_swift remapping (#65)
Browse files Browse the repository at this point in the history
Signed-off-by: Brentley Jones <github@brentleyjones.com>
  • Loading branch information
brentleyjones authored Sep 7, 2022
1 parent 46450da commit ead3471
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion index-import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ static cl::opt<bool>
Incremental("incremental",
cl::desc("Only transfer units if they are newer"));

static cl::opt<bool> UndoRulesSwiftRenames(
"undo-rules_swift-renames",
cl::desc(
"Until Bazel 6.0, rules_swift replaces spaces in object files with "
"'__SPACE__'. Using this flag undoes that replacement, changing "
"'__SPACE__' into ' '. This flag will be removed in the future."));

struct Remapper {
public:
std::string remap(const llvm::StringRef input) const {
Expand Down Expand Up @@ -215,7 +222,18 @@ importUnit(StringRef outputUnitsPath, StringRef inputUnitPath,
ModuleNameScope &moduleNames) {
// The set of remapped paths.
auto workingDir = remapper.remap(reader->getWorkingDirectory());
auto outputFile = remapper.remap(reader->getOutputFile());

auto originalOutputFilePath = std::string(reader->getOutputFile());
if (UndoRulesSwiftRenames) {
// Replace all instances of "__SPACE__" iwith " "
std::string::size_type start = 0;
while ((start = originalOutputFilePath.find("__SPACE__", start)) !=
std::string::npos) {
originalOutputFilePath.replace(start, 9, " ");
start += 1;
}
}
auto outputFile = remapper.remap(originalOutputFilePath);

// Cloning records when we've got an output records path
const auto cloneDepRecords = !outputRecordsPath.empty();
Expand Down

0 comments on commit ead3471

Please sign in to comment.