Skip to content

Commit a874952

Browse files
committed
Swift: fix remapping
With the change to `std::filesystem` some path concatenations were translated to appending, which is not the same. In case rhs is absolute `lhs / rhs == rhs`, while concatenating treats `rhs` as if it was relative. The same behaviour can be obtained in `std::filesystem` by using `lhs / rhs.relative_path()`.
1 parent 8628ff5 commit a874952

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

swift/extractor/infra/file/TargetFile.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ void ensureParentDir(const fs::path& path) {
3636
fs::path initPath(const std::filesystem::path& target, const std::filesystem::path& dir) {
3737
fs::path ret{dir};
3838
assert(!target.empty() && "target must be a non-empty path");
39-
if (target.is_absolute()) {
40-
ret += target;
41-
} else {
42-
ret /= target;
43-
}
39+
ret /= target.relative_path();
4440
ensureParentDir(ret);
4541
return ret;
4642
}

swift/extractor/remapping/SwiftOutputRewrite.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static std::optional<fs::path> rewriteOutputFileMap(const fs::path& scratchDir,
2121
const fs::path& outputFileMapPath,
2222
const std::vector<fs::path>& inputs,
2323
PathRemapping& remapping) {
24-
auto newMapPath = scratchDir / outputFileMapPath;
24+
auto newMapPath = scratchDir / outputFileMapPath.relative_path();
2525

2626
// TODO: do not assume absolute path for the second parameter
2727
auto outputMapOrError = swift::OutputFileMap::loadFromPath(outputFileMapPath.c_str(), "");
@@ -41,8 +41,8 @@ static std::optional<fs::path> rewriteOutputFileMap(const fs::path& scratchDir,
4141
auto& newMap = newOutputMap.getOrCreateOutputMapForInput(key.c_str());
4242
newMap.copyFrom(*oldMap);
4343
for (auto& entry : newMap) {
44-
auto oldPath = entry.getSecond();
45-
auto newPath = scratchDir / oldPath;
44+
fs::path oldPath = entry.getSecond();
45+
auto newPath = scratchDir / oldPath.relative_path();
4646
entry.getSecond() = newPath;
4747
remapping[oldPath] = newPath;
4848
}
@@ -91,7 +91,7 @@ PathRemapping rewriteOutputsInPlace(const fs::path& scratchDir, std::vector<std:
9191
for (size_t i = 0; i < CLIArgs.size(); i++) {
9292
if (pathRewriteOptions.count(CLIArgs[i])) {
9393
fs::path oldPath = CLIArgs[i + 1];
94-
auto newPath = scratchDir / oldPath;
94+
auto newPath = scratchDir / oldPath.relative_path();
9595
CLIArgs[++i] = newPath.string();
9696
newLocations.push_back(newPath);
9797

0 commit comments

Comments
 (0)