summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Bolvansky <david.bolvansky@gmail.com>2018-09-13 14:27:32 +0000
committerDavid Bolvansky <david.bolvansky@gmail.com>2018-09-13 14:27:32 +0000
commita79c7739c3ccabf30e2b1c056181c4eee5914be4 (patch)
treec467340858995dac50656000d96b094a24355ad5
parent1a7f6a9239dcbf44b462d425f48ae11ed5e9ce0e (diff)
Print correctly dependency paths on Windows
Summary: Before: main.o: main.c ../include/lib\test.h After: main.o: main.c ../include/lib/test.h Fixes PR38877 Reviewers: zturner Subscribers: xbolva00, cfe-commits Differential Revision: https://reviews.llvm.org/D51847 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342139 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Frontend/DependencyFile.cpp22
-rw-r--r--test/Frontend/dependency-gen-escaping.c2
-rw-r--r--test/Frontend/dependency-gen.c10
-rw-r--r--test/Modules/relative-dep-gen.cpp6
4 files changed, 22 insertions, 18 deletions
diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp
index e6e07190e1..a3f3479209 100644
--- a/lib/Frontend/DependencyFile.cpp
+++ b/lib/Frontend/DependencyFile.cpp
@@ -386,28 +386,32 @@ bool DFGImpl::AddFilename(StringRef Filename) {
/// for Windows file-naming info.
static void PrintFilename(raw_ostream &OS, StringRef Filename,
DependencyOutputFormat OutputFormat) {
+ // Convert filename to platform native path
+ llvm::SmallString<256> NativePath;
+ llvm::sys::path::native(Filename.str(), NativePath);
+
if (OutputFormat == DependencyOutputFormat::NMake) {
// Add quotes if needed. These are the characters listed as "special" to
// NMake, that are legal in a Windows filespec, and that could cause
// misinterpretation of the dependency string.
- if (Filename.find_first_of(" #${}^!") != StringRef::npos)
- OS << '\"' << Filename << '\"';
+ if (NativePath.find_first_of(" #${}^!") != StringRef::npos)
+ OS << '\"' << NativePath << '\"';
else
- OS << Filename;
+ OS << NativePath;
return;
}
assert(OutputFormat == DependencyOutputFormat::Make);
- for (unsigned i = 0, e = Filename.size(); i != e; ++i) {
- if (Filename[i] == '#') // Handle '#' the broken gcc way.
+ for (unsigned i = 0, e = NativePath.size(); i != e; ++i) {
+ if (NativePath[i] == '#') // Handle '#' the broken gcc way.
OS << '\\';
- else if (Filename[i] == ' ') { // Handle space correctly.
+ else if (NativePath[i] == ' ') { // Handle space correctly.
OS << '\\';
unsigned j = i;
- while (j > 0 && Filename[--j] == '\\')
+ while (j > 0 && NativePath[--j] == '\\')
OS << '\\';
- } else if (Filename[i] == '$') // $ is escaped by $$.
+ } else if (NativePath[i] == '$') // $ is escaped by $$.
OS << '$';
- OS << Filename[i];
+ OS << NativePath[i];
}
}
diff --git a/test/Frontend/dependency-gen-escaping.c b/test/Frontend/dependency-gen-escaping.c
index c8d1191674..deca57e417 100644
--- a/test/Frontend/dependency-gen-escaping.c
+++ b/test/Frontend/dependency-gen-escaping.c
@@ -21,7 +21,7 @@
// Backslash followed by # or space should escape both characters, because
// that's what GNU Make wants. GCC does the right thing with space, but not
// #, so Clang does too. (There should be 3 backslashes before the #.)
-// SEP2F: a\b\\#c\\\ d.h
+// SEP2F: a{{[/\\]}}b{{[/\\]}}\#c{{/|\\\\}}\ d.h
// With -fms-compatibility, Backslashes in #include are treated as path separators.
// Backslashes are given in the emission for special characters, like 0x20 or 0x23.
// SEP5C: a{{[/\\]}}b{{[/\\]}}\#c{{/|\\\\}}\ d.h
diff --git a/test/Frontend/dependency-gen.c b/test/Frontend/dependency-gen.c
index cd222c5dfd..963419cb11 100644
--- a/test/Frontend/dependency-gen.c
+++ b/test/Frontend/dependency-gen.c
@@ -4,19 +4,19 @@
// RUN: echo > %t.dir/a/b/x.h
// RUN: cd %t.dir
// RUN: %clang -MD -MF - %s -fsyntax-only -I a/b | FileCheck -check-prefix=CHECK-ONE %s
-// CHECK-ONE: {{ }}a/b{{[/\\]}}x.h
+// CHECK-ONE: {{ }}a{{[/\\]}}b{{[/\\]}}x.h
// PR8974 (-include flag)
// RUN: %clang -MD -MF - %s -fsyntax-only -include a/b/x.h -DINCLUDE_FLAG_TEST | FileCheck -check-prefix=CHECK-TWO %s
-// CHECK-TWO: {{ }}a/b/x.h
+// CHECK-TWO: {{ }}a{{[/\\]}}b{{[/\\]}}x.h
// rdar://problem/9734352 (paths involving ".")
// RUN: %clang -MD -MF - %s -fsyntax-only -I ./a/b | FileCheck -check-prefix=CHECK-THREE %s
-// CHECK-THREE: {{ }}a/b{{[/\\]}}x.h
+// CHECK-THREE: {{ }}a{{[/\\]}}b{{[/\\]}}x.h
// RUN: %clang -MD -MF - %s -fsyntax-only -I .//./a/b/ | FileCheck -check-prefix=CHECK-FOUR %s
-// CHECK-FOUR: {{ }}a/b{{[/\\]}}x.h
+// CHECK-FOUR: {{ }}a{{[/\\]}}b{{[/\\]}}x.h
// RUN: %clang -MD -MF - %s -fsyntax-only -I a/b/. | FileCheck -check-prefix=CHECK-FIVE %s
-// CHECK-FIVE: {{ }}a/b/.{{[/\\]}}x.h
+// CHECK-FIVE: {{ }}a{{[/\\]}}b{{[/\\]}}.{{[/\\]}}x.h
// RUN: cd a/b
// RUN: %clang -MD -MF - %s -fsyntax-only -I ./ | FileCheck -check-prefix=CHECK-SIX %s
// CHECK-SIX: {{ }}x.h
diff --git a/test/Modules/relative-dep-gen.cpp b/test/Modules/relative-dep-gen.cpp
index bfa9471859..e1db618c36 100644
--- a/test/Modules/relative-dep-gen.cpp
+++ b/test/Modules/relative-dep-gen.cpp
@@ -30,9 +30,9 @@
#include "Inputs/relative-dep-gen-1.h"
// CHECK-BUILD: mod.pcm:
-// CHECK-BUILD: {{[ \t]}}Inputs/relative-dep-gen{{(-cwd)?}}.modulemap
-// CHECK-BUILD: {{[ \t]}}Inputs/relative-dep-gen-1.h
-// CHECK-BUILD: {{[ \t]}}Inputs/relative-dep-gen-2.h
+// CHECK-BUILD: {{[ \t]}}Inputs{{[/\\]}}relative-dep-gen{{(-cwd)?}}.modulemap
+// CHECK-BUILD: {{[ \t]}}Inputs{{[/\\]}}relative-dep-gen-1.h
+// CHECK-BUILD: {{[ \t]}}Inputs{{[/\\]}}relative-dep-gen-2.h
// CHECK-USE: use.o:
// CHECK-USE-DAG: {{[ \t]}}relative-dep-gen.cpp
// CHECK-EXPLICIT-DAG: mod.pcm