[PATCH] Files in a compilation database using relative paths are not being transformed
Ariel Bernal
ariel.j.bernal at intel.com
Mon Oct 7 09:18:51 PDT 2013
Addressed comments
Hi revane, tareqsiraj,
http://llvm-reviews.chandlerc.com/D1837
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1837?vs=4675&id=4708#toc
Files:
clang-modernize/Core/Transform.cpp
test/clang-modernize/Compilations/Inputs/compile_commands_relative.json
test/clang-modernize/Compilations/compilation_relative.cpp
test/clang-modernize/Compilations/no_compilation_relative.cpp
Index: clang-modernize/Core/Transform.cpp
===================================================================
--- clang-modernize/Core/Transform.cpp
+++ clang-modernize/Core/Transform.cpp
@@ -94,7 +94,16 @@
}
bool Transform::handleBeginSource(CompilerInstance &CI, StringRef Filename) {
- CurrentSource = Filename;
+ assert(Overrides != 0 && "Subclass transform didn't provide InputState");
+
+ Overrides->applyOverrides(CI.getSourceManager());
+
+ llvm::SmallString<256> FilePath(Filename);
+ llvm::error_code EC = llvm::sys::fs::make_absolute(FilePath);
+ assert(!EC && "File path can't be made absolute");
+ (void) EC;
+
+ CurrentSource = FilePath.c_str();
if (Options().EnableTiming) {
Timings.push_back(std::make_pair(Filename.str(), llvm::TimeRecord()));
Index: test/clang-modernize/Compilations/Inputs/compile_commands_relative.json
===================================================================
--- /dev/null
+++ test/clang-modernize/Compilations/Inputs/compile_commands_relative.json
@@ -0,0 +1,17 @@
+[
+{
+ "directory": "$(path)/a1/",
+ "command": "clang++ -o compilations.o -c compilations.cpp -std=c++11",
+ "file": "compilations.cpp"
+},
+{
+ "directory": "$(path)/a2/",
+ "command": "clang++ -o compilations.o -c compilations.cpp -std=c++11",
+ "file": "compilations.cpp"
+},
+{
+ "directory": "$(path)/a3/",
+ "command": "clang++ -o compilations.o -c compilations.cpp -std=c++11",
+ "file": "compilations.cpp"
+}
+]
Index: test/clang-modernize/Compilations/compilation_relative.cpp
===================================================================
--- /dev/null
+++ test/clang-modernize/Compilations/compilation_relative.cpp
@@ -0,0 +1,25 @@
+// The following block tests:
+// - Relative paths are use in the compilation database.
+// - A compilation database is detected from build path specified by -p and
+// -include was provided.
+
+// Create directory structure
+// a1, a2 and a3 are specified paths for files in the compilation database.
+// RUN: rm -rf %T/CompilationRelative
+// RUN: mkdir -p %T/CompilationRelative
+// RUN: mkdir -p %T/CompilationRelative/a1
+// RUN: mkdir -p %T/CompilationRelative/a2
+// RUN: mkdir -p %T/CompilationRelative/a3
+
+// This test uses a compilation database
+// RUN: sed -e 's#$(path)#%/T/CompilationRelative#g' %S/Inputs/compile_commands_relative.json > %T/CompilationRelative/compile_commands.json
+
+// Check that files are tranformed when -p and -include are specified.
+// RUN: cp %S/Inputs/compilations.cpp %T/CompilationRelative/a1
+// RUN: cp %S/Inputs/compilations.cpp %T/CompilationRelative/a2
+// RUN: cp %S/Inputs/compilations.cpp %T/CompilationRelative/a3
+
+// RUN: clang-modernize -use-nullptr -p=%T/CompilationRelative -include=%T/CompilationRelative/a1,%T/CompilationRelative/a3
+// RUN: diff -b %S/Inputs/compilations_expected.cpp %T/CompilationRelative/a1/compilations.cpp
+// RUN: not diff -b %S/Inputs/compilations_expected.cpp %T/CompilationRelative/a2/compilations.cpp
+// RUN: diff -b %S/Inputs/compilations_expected.cpp %T/CompilationRelative/a3/compilations.cpp
Index: test/clang-modernize/Compilations/no_compilation_relative.cpp
===================================================================
--- /dev/null
+++ test/clang-modernize/Compilations/no_compilation_relative.cpp
@@ -0,0 +1,19 @@
+// The following block tests that files are transformed when specified using
+// relative paths.
+
+// Create directory structure
+// a1, a2 and a3 are specified paths for files in the compilation database.
+// RUN: rm -rf %T/NoCompilationRelative
+// RUN: mkdir -p %T/NoCompilationRelative
+// RUN: mkdir -p %T/NoCompilationRelative/a1
+// RUN: mkdir -p %T/NoCompilationRelative/a2
+// RUN: mkdir -p %T/NoCompilationRelative/a3
+
+// RUN: cp %S/Inputs/compilations.cpp %T/NoCompilationRelative/a1
+// RUN: cp %S/Inputs/compilations.cpp %T/NoCompilationRelative/a2
+// RUN: cp %S/Inputs/compilations.cpp %T/NoCompilationRelative/a3
+// RUN: cd %T
+// RUN: clang-modernize -use-nullptr ./NoCompilationRelative/a1/compilations.cpp ./NoCompilationRelative/a3/compilations.cpp
+// RUN: diff -b %S/Inputs/compilations_expected.cpp %T/NoCompilationRelative/a1/compilations.cpp
+// RUN: not diff -b %S/Inputs/compilations_expected.cpp %T/NoCompilationRelative/a2/compilations.cpp
+// RUN: diff -b %S/Inputs/compilations_expected.cpp %T/NoCompilationRelative/a3/compilations.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1837.2.patch
Type: text/x-patch
Size: 4401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131007/8e725df5/attachment.bin>
More information about the cfe-commits
mailing list