[PATCH] D25508: [clang-move] Don't comparing absolute file path to relative path.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 12 07:33:47 PDT 2016
hokein updated this revision to Diff 74375.
hokein added a comment.
Update the patch based on offline discussion.
https://reviews.llvm.org/D25508
Files:
clang-move/ClangMove.cpp
test/clang-move/Inputs/database_template.json
test/clang-move/move-class.cpp
Index: test/clang-move/move-class.cpp
===================================================================
--- test/clang-move/move-class.cpp
+++ test/clang-move/move-class.cpp
@@ -1,21 +1,24 @@
// RUN: mkdir -p %T/clang-move/build
+// RUN: mkdir -p %T/clang-move/include
// RUN: sed 's|$test_dir|%/T/clang-move|g' %S/Inputs/database_template.json > %T/clang-move/compile_commands.json
-// RUN: cp %S/Inputs/test* %T/clang-move/
-// RUN: touch %T/clang-move/test2.h
-// RUN: cd %T/clang-move
-// RUN: clang-move -name="a::Foo" -new_cc=%T/clang-move/new_test.cpp -new_header=%T/clang-move/new_test.h -old_cc=../clang-move/test.cpp -old_header=../clang-move/test.h %T/clang-move/test.cpp
+// RUN: cp %S/Inputs/test.h %T/clang-move/include
+// RUN: cp %S/Inputs/test.cpp %T/clang-move
+// RUN: touch %T/clang-move/include/test2.h
+// RUN: cd %T/clang-move/build
+// RUN: clang-move -name="a::Foo" -new_cc=%T/clang-move/new_test.cpp -new_header=%T/clang-move/new_test.h -old_cc=../test.cpp -old_header=../include/test.h %T/clang-move/test.cpp
// RUN: FileCheck -input-file=%T/clang-move/new_test.cpp -check-prefix=CHECK-NEW-TEST-CPP %s
// RUN: FileCheck -input-file=%T/clang-move/new_test.h -check-prefix=CHECK-NEW-TEST-H %s
// RUN: FileCheck -input-file=%T/clang-move/test.cpp -check-prefix=CHECK-OLD-TEST-CPP %s
-// RUN: FileCheck -input-file=%T/clang-move/test.h %s -implicit-check-not='{{namespace.*}}'
+// RUN: FileCheck -input-file=%T/clang-move/include/test.h %s -implicit-check-not='{{namespace.*}}'
//
-// RUN: cp %S/Inputs/test* %T/clang-move/
-// RUN: cd %T/clang-move
-// RUN: clang-move -name="a::Foo" -new_cc=%T/clang-move/new_test.cpp -new_header=%T/clang-move/new_test.h -old_cc=%T/clang-move/test.cpp -old_header=%T/clang-move/test.h %T/clang-move/test.cpp
+// RUN: cp %S/Inputs/test.h %T/clang-move/include
+// RUN: cp %S/Inputs/test.cpp %T/clang-move
+// RUN: cd %T/clang-move/build
+// RUN: clang-move -name="a::Foo" -new_cc=%T/clang-move/new_test.cpp -new_header=%T/clang-move/new_test.h -old_cc=%T/clang-move/test.cpp -old_header=%T/clang-move/include/test.h %T/clang-move/test.cpp
// RUN: FileCheck -input-file=%T/clang-move/new_test.cpp -check-prefix=CHECK-NEW-TEST-CPP %s
// RUN: FileCheck -input-file=%T/clang-move/new_test.h -check-prefix=CHECK-NEW-TEST-H %s
// RUN: FileCheck -input-file=%T/clang-move/test.cpp -check-prefix=CHECK-OLD-TEST-CPP %s
-// RUN: FileCheck -input-file=%T/clang-move/test.h %s -implicit-check-not='{{namespace.*}}'
+// RUN: FileCheck -input-file=%T/clang-move/include/test.h %s -implicit-check-not='{{namespace.*}}'
//
// CHECK-NEW-TEST-H: namespace a {
// CHECK-NEW-TEST-H: class Foo {
Index: test/clang-move/Inputs/database_template.json
===================================================================
--- test/clang-move/Inputs/database_template.json
+++ test/clang-move/Inputs/database_template.json
@@ -1,7 +1,7 @@
[
{
"directory": "$test_dir/build",
- "command": "clang++ -o test.o $test_dir/test.cpp",
+ "command": "clang++ -o test.o -I../include $test_dir/test.cpp",
"file": "$test_dir/test.cpp"
}
]
Index: clang-move/ClangMove.cpp
===================================================================
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -51,8 +51,18 @@
SM.getFileManager().getVirtualFileSystem()->makeAbsolute(AbsolutePath))
llvm::errs() << "Warning: could not make absolute file: '" << EC.message()
<< '\n';
- llvm::sys::path::remove_dots(AbsolutePath, /*remove_dot_dot=*/true);
- llvm::sys::path::native(AbsolutePath);
+ // Handle symbolic link path cases.
+ // We are trying to get the real file path of the symlink.
+ const DirectoryEntry *Dir = SM.getFileManager().getDirectory(
+ llvm::sys::path::parent_path(AbsolutePath.str()));
+ if (Dir) {
+ StringRef DirName = SM.getFileManager().getCanonicalName(Dir);
+ SmallVector<char, 128> AbsoluteFilename;
+ llvm::sys::path::append(AbsoluteFilename, DirName,
+ llvm::sys::path::filename(AbsolutePath.str()));
+ return llvm::StringRef(AbsoluteFilename.data(), AbsoluteFilename.size())
+ .str();
+ }
return AbsolutePath.str();
}
@@ -382,12 +392,14 @@
llvm::StringRef SearchPath,
llvm::StringRef FileName,
const SourceManager& SM) {
- auto AbsoluteSearchPath = MakeAbsolutePath(SM, SearchPath);
+ SmallVector<char, 128> HeaderWithSearchPath;
+ llvm::sys::path::append(HeaderWithSearchPath, SearchPath, IncludeHeader);
// FIXME: Add old.h to the new.cc/h when the new target has dependencies on
// old.h/c. For instance, when moved class uses another class defined in
// old.h, the old.h should be added in new.h.
if (MakeAbsolutePath(OriginalRunningDirectory, Spec.OldHeader) ==
- MakeAbsolutePath(AbsoluteSearchPath, IncludeHeader))
+ MakeAbsolutePath(SM, llvm::StringRef(HeaderWithSearchPath.data(),
+ HeaderWithSearchPath.size())))
return;
std::string IncludeLine =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25508.74375.patch
Type: text/x-patch
Size: 5103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161012/1f4cfc87/attachment.bin>
More information about the cfe-commits
mailing list