diff options
author | Chris Lattner <sabre@nondot.org> | 2011-02-17 02:14:49 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-02-17 02:14:49 +0000 |
commit | 9d50634cfc268ecc9a7250226dd5ca0e945240d4 (patch) | |
tree | 1ffd56a1c92f354ad4da2f2d0fd8222397285477 /lib/Frontend/DependencyFile.cpp | |
parent | 45d246f9f60b86ca583da461dcfb28af314a7332 (diff) |
fix clang -MM output to escape spaces in filenames. This seems to be
the only character that GCC escapes. PR9224.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125707 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/DependencyFile.cpp')
-rw-r--r-- | lib/Frontend/DependencyFile.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp index cdff8077ee..bc5a55df08 100644 --- a/lib/Frontend/DependencyFile.cpp +++ b/lib/Frontend/DependencyFile.cpp @@ -13,7 +13,6 @@ #include "clang/Frontend/Utils.h" #include "clang/Basic/FileManager.h" -#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/DependencyOutputOptions.h" #include "clang/Frontend/FrontendDiagnostic.h" @@ -22,7 +21,6 @@ #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/raw_ostream.h" -#include <string> using namespace clang; @@ -117,6 +115,16 @@ void DependencyFileCallback::FileChanged(SourceLocation Loc, Files.push_back(Filename); } +/// PrintFilename - GCC escapes spaces, but apparently not ' or " or other +/// scary characters. +static void PrintFilename(llvm::raw_ostream &OS, llvm::StringRef Filename) { + for (unsigned i = 0, e = Filename.size(); i != e; ++i) { + if (Filename[i] == ' ') + OS << '\\'; + OS << Filename[i]; + } +} + void DependencyFileCallback::OutputDependencyFile() { // Write out the dependency targets, trying to avoid overly long // lines when possible. We try our best to emit exactly the same @@ -130,14 +138,15 @@ void DependencyFileCallback::OutputDependencyFile() { unsigned N = I->length(); if (Columns == 0) { Columns += N; - *OS << *I; } else if (Columns + N + 2 > MaxColumns) { Columns = N + 2; - *OS << " \\\n " << *I; + *OS << " \\\n "; } else { Columns += N + 1; - *OS << ' ' << *I; + *OS << ' '; } + // Targets already quoted as needed. + *OS << *I; } *OS << ':'; @@ -155,7 +164,8 @@ void DependencyFileCallback::OutputDependencyFile() { *OS << " \\\n "; Columns = 2; } - *OS << ' ' << *I; + *OS << ' '; + PrintFilename(*OS, *I); Columns += N + 1; } *OS << '\n'; @@ -166,7 +176,8 @@ void DependencyFileCallback::OutputDependencyFile() { for (std::vector<std::string>::iterator I = Files.begin() + 1, E = Files.end(); I != E; ++I) { *OS << '\n'; - *OS << *I << ":\n"; + PrintFilename(*OS, *I); + *OS << ":\n"; } } } |