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()`.
This commit is contained in:
Paolo Tranquilli
2022-10-28 11:16:49 +02:00
parent 8628ff5e52
commit a87495226a
2 changed files with 5 additions and 9 deletions

View File

@@ -36,11 +36,7 @@ void ensureParentDir(const fs::path& path) {
fs::path initPath(const std::filesystem::path& target, const std::filesystem::path& dir) {
fs::path ret{dir};
assert(!target.empty() && "target must be a non-empty path");
if (target.is_absolute()) {
ret += target;
} else {
ret /= target;
}
ret /= target.relative_path();
ensureParentDir(ret);
return ret;
}

View File

@@ -21,7 +21,7 @@ static std::optional<fs::path> rewriteOutputFileMap(const fs::path& scratchDir,
const fs::path& outputFileMapPath,
const std::vector<fs::path>& inputs,
PathRemapping& remapping) {
auto newMapPath = scratchDir / outputFileMapPath;
auto newMapPath = scratchDir / outputFileMapPath.relative_path();
// TODO: do not assume absolute path for the second parameter
auto outputMapOrError = swift::OutputFileMap::loadFromPath(outputFileMapPath.c_str(), "");
@@ -41,8 +41,8 @@ static std::optional<fs::path> rewriteOutputFileMap(const fs::path& scratchDir,
auto& newMap = newOutputMap.getOrCreateOutputMapForInput(key.c_str());
newMap.copyFrom(*oldMap);
for (auto& entry : newMap) {
auto oldPath = entry.getSecond();
auto newPath = scratchDir / oldPath;
fs::path oldPath = entry.getSecond();
auto newPath = scratchDir / oldPath.relative_path();
entry.getSecond() = newPath;
remapping[oldPath] = newPath;
}
@@ -91,7 +91,7 @@ PathRemapping rewriteOutputsInPlace(const fs::path& scratchDir, std::vector<std:
for (size_t i = 0; i < CLIArgs.size(); i++) {
if (pathRewriteOptions.count(CLIArgs[i])) {
fs::path oldPath = CLIArgs[i + 1];
auto newPath = scratchDir / oldPath;
auto newPath = scratchDir / oldPath.relative_path();
CLIArgs[++i] = newPath.string();
newLocations.push_back(newPath);