[PATCH] Files in a compilation database using relative paths are not being transformed
Ariel Bernal
ariel.j.bernal at intel.com
Fri Oct 4 09:29:06 PDT 2013
Hi revane, tareqsiraj,
This patch fixes the path for the YAML files, and complements D1800 which makes replacements independent of the location.
http://llvm-reviews.chandlerc.com/D1837
Files:
clang-modernize/Core/Transform.cpp
test/clang-modernize/Compilations/Inputs/compile_commands_rel.json
test/clang-modernize/Compilations/compilation_rel.cpp
test/clang-modernize/Compilations/no_compilation_rel.cpp
Index: clang-modernize/Core/Transform.cpp
===================================================================
--- clang-modernize/Core/Transform.cpp
+++ clang-modernize/Core/Transform.cpp
@@ -98,7 +98,13 @@
assert(Overrides != 0 && "Subclass transform didn't provide InputState");
Overrides->applyOverrides(CI.getSourceManager());
- CurrentSource = Filename;
+
+ 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_rel.json
===================================================================
--- /dev/null
+++ test/clang-modernize/Compilations/Inputs/compile_commands_rel.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_rel.cpp
===================================================================
--- /dev/null
+++ test/clang-modernize/Compilations/compilation_rel.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/CompilationRel
+// RUN: mkdir -p %T/CompilationRel
+// RUN: mkdir -p %T/CompilationRel/a1
+// RUN: mkdir -p %T/CompilationRel/a2
+// RUN: mkdir -p %T/CompilationRel/a3
+
+// This test uses a compilation database
+// RUN: sed -e 's#$(path)#%/T/CompilationRel#g' %S/Inputs/compile_commands_rel.json > %T/CompilationRel/compile_commands.json
+
+// Check that files are tranformed when -p and -include are specified.
+// RUN: cp %S/Inputs/compilations.cpp %T/CompilationRel/a1
+// RUN: cp %S/Inputs/compilations.cpp %T/CompilationRel/a2
+// RUN: cp %S/Inputs/compilations.cpp %T/CompilationRel/a3
+
+// RUN: clang-modernize -use-nullptr -p=%T/CompilationRel -include=%T/CompilationRel/a1,%T/CompilationRel/a3
+// RUN: diff -b %S/Inputs/compilations_expected.cpp %T/CompilationRel/a1/compilations.cpp
+// RUN: not diff -b %S/Inputs/compilations_expected.cpp %T/CompilationRel/a2/compilations.cpp
+// RUN: diff -b %S/Inputs/compilations_expected.cpp %T/CompilationRel/a3/compilations.cpp
Index: test/clang-modernize/Compilations/no_compilation_rel.cpp
===================================================================
--- /dev/null
+++ test/clang-modernize/Compilations/no_compilation_rel.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/NoCompilationRel
+// RUN: mkdir -p %T/NoCompilationRel
+// RUN: mkdir -p %T/NoCompilationRel/a1
+// RUN: mkdir -p %T/NoCompilationRel/a2
+// RUN: mkdir -p %T/NoCompilationRel/a3
+
+// RUN: cp %S/Inputs/compilations.cpp %T/NoCompilationRel/a1
+// RUN: cp %S/Inputs/compilations.cpp %T/NoCompilationRel/a2
+// RUN: cp %S/Inputs/compilations.cpp %T/NoCompilationRel/a3
+// RUN: cd %T
+// RUN: clang-modernize -use-nullptr ./NoCompilationRel/a1/compilations.cpp ./NoCompilationRel/a3/compilations.cpp
+// RUN: diff -b %S/Inputs/compilations_expected.cpp %T/NoCompilationRel/a1/compilations.cpp
+// RUN: not diff -b %S/Inputs/compilations_expected.cpp %T/NoCompilationRel/a2/compilations.cpp
+// RUN: diff -b %S/Inputs/compilations_expected.cpp %T/NoCompilationRel/a3/compilations.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1837.1.patch
Type: text/x-patch
Size: 4137 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131004/9c0275a8/attachment.bin>
More information about the cfe-commits
mailing list