summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-06-20 03:28:46 +0000
committerJustin Bogner <mail@justinbogner.com>2014-06-20 03:28:46 +0000
commit3f05ce1565771ec6daa895dcd7121bb48478536e (patch)
tree77420900b3f58dd6dab7e1a47bb620fa6306c6d5
parentff6e3ae78538bf28671496dca103e93d9b32ac80 (diff)
downloadclang-3f05ce1565771ec6daa895dcd7121bb48478536e.tar.gz
clang-3f05ce1565771ec6daa895dcd7121bb48478536e.tar.bz2
clang-3f05ce1565771ec6daa895dcd7121bb48478536e.tar.xz
Frontend: Disentangle removePathTraversal from concatenating paths
This reimplements part of r211303 in a bit of a cleaner way. Doing so allows us to use a proper absolute path when calling addFileMapping rather than relying on a substring being one, which should fix the tests on Windows. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211338 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Frontend/ModuleDependencyCollector.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/Frontend/ModuleDependencyCollector.cpp b/lib/Frontend/ModuleDependencyCollector.cpp
index e6e67739a8..d30f9214f8 100644
--- a/lib/Frontend/ModuleDependencyCollector.cpp
+++ b/lib/Frontend/ModuleDependencyCollector.cpp
@@ -57,13 +57,14 @@ void ModuleDependencyCollector::writeFileMap() {
VFSWriter.write(OS);
}
-/// Append the absolute path in Nested to the path given by Root. This will
-/// remove directory traversal from the resulting nested path.
-static void appendNestedPath(SmallVectorImpl<char> &Root, StringRef Nested) {
+/// Remove traversal (ie, . or ..) from the given absolute path.
+static void removePathTraversal(SmallVectorImpl<char> &Path) {
using namespace llvm::sys;
SmallVector<StringRef, 16> ComponentStack;
+ StringRef P(Path.data(), Path.size());
- StringRef Rel = path::relative_path(Nested);
+ // Skip the root path, then look for traversal in the components.
+ StringRef Rel = path::relative_path(P);
for (StringRef C : llvm::make_range(path::begin(Rel), path::end(Rel))) {
if (C == ".")
continue;
@@ -73,9 +74,14 @@ static void appendNestedPath(SmallVectorImpl<char> &Root, StringRef Nested) {
} else
ComponentStack.push_back(C);
}
+
// The stack is now the path without any directory traversal.
+ SmallString<256> Buffer = path::root_path(P);
for (StringRef C : ComponentStack)
- path::append(Root, C);
+ path::append(Buffer, C);
+
+ // Put the result in Path.
+ Path.swap(Buffer);
}
std::error_code ModuleDependencyListener::copyToRoot(StringRef Src) {
@@ -84,10 +90,11 @@ std::error_code ModuleDependencyListener::copyToRoot(StringRef Src) {
// We need an absolute path to append to the root.
SmallString<256> AbsoluteSrc = Src;
fs::make_absolute(AbsoluteSrc);
+ removePathTraversal(AbsoluteSrc);
+
// Build the destination path.
SmallString<256> Dest = Collector.getDest();
- size_t RootLen = Dest.size();
- appendNestedPath(Dest, AbsoluteSrc);
+ path::append(Dest, path::relative_path(AbsoluteSrc));
// Copy the file into place.
if (std::error_code EC = fs::create_directories(path::parent_path(Dest),
@@ -96,7 +103,7 @@ std::error_code ModuleDependencyListener::copyToRoot(StringRef Src) {
if (std::error_code EC = fs::copy_file(AbsoluteSrc.str(), Dest.str()))
return EC;
// Use the absolute path under the root for the file mapping.
- Collector.addFileMapping(Dest.substr(RootLen), Dest.str());
+ Collector.addFileMapping(AbsoluteSrc.str(), Dest.str());
return std::error_code();
}