<div dir="ltr"><div>Hi,</div>I think this change breaks cmake build. Please consider the attached fix (I can't push atm).<div><br></div><div>thank you,</div><div>Jan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 30, 2015 at 8:59 AM, Daniel Jasper via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: djasper<br>
Date: Wed Sep 30 08:59:29 2015<br>
New Revision: 248904<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=248904&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=248904&view=rev</a><br>
Log:<br>
clang-format: Use Rewriter again to write the output files.<br>
<br>
This has two advantages:<br>
1. Atomic writes.<br>
2. Proper handling of line endings (hopefully solving <a href="http://llvm.org/PR24999" rel="noreferrer" target="_blank">llvm.org/PR24999</a><br>
<br>
Modified:<br>
    cfe/trunk/tools/clang-format/ClangFormat.cpp<br>
<br>
Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=248904&r1=248903&r2=248904&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=248904&r1=248903&r2=248904&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)<br>
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Wed Sep 30 08:59:29 2015<br>
@@ -19,6 +19,7 @@<br>
 #include "clang/Basic/SourceManager.h"<br>
 #include "clang/Basic/Version.h"<br>
 #include "clang/Format/Format.h"<br>
+#include "clang/Rewrite/Core/Rewriter.h"<br>
 #include "llvm/ADT/StringMap.h"<br>
 #include "llvm/Support/CommandLine.h"<br>
 #include "llvm/Support/Debug.h"<br>
@@ -77,7 +78,7 @@ AssumeFileName("assume-filename",<br>
                cl::desc("When reading from stdin, clang-format assumes this\n"<br>
                         "filename to look for a style config file (with\n"<br>
                         "-style=file) and to determine the language."),<br>
-               cl::cat(ClangFormatCategory));<br>
+               cl::init("<stdin>"), cl::cat(ClangFormatCategory));<br>
<br>
 static cl::opt<bool> Inplace("i",<br>
                              cl::desc("Inplace edit <file>s, if specified."),<br>
@@ -109,8 +110,7 @@ namespace format {<br>
<br>
 static FileID createInMemoryFile(StringRef FileName, MemoryBuffer *Source,<br>
                                  SourceManager &Sources, FileManager &Files) {<br>
-  const FileEntry *Entry = Files.getVirtualFile(FileName == "-" ? "<stdin>" :<br>
-                                                    FileName,<br>
+  const FileEntry *Entry = Files.getVirtualFile(FileName,<br>
                                                 Source->getBufferSize(), 0);<br>
   Sources.overrideFileContents(Entry, Source, true);<br>
   return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User);<br>
@@ -132,7 +132,7 @@ static bool fillRanges(MemoryBuffer *Cod<br>
       IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),<br>
       new DiagnosticOptions);<br>
   SourceManager Sources(Diagnostics, Files);<br>
-  FileID ID = createInMemoryFile("-", Code, Sources, Files);<br>
+  FileID ID = createInMemoryFile("<irrelevant>", Code, Sources, Files);<br>
   if (!LineRanges.empty()) {<br>
     if (!Offsets.empty() || !Lengths.empty()) {<br>
       llvm::errs() << "error: cannot use -lines with -offset/-length\n";<br>
@@ -255,8 +255,8 @@ static bool format(StringRef FileName) {<br>
<br>
   bool IncompleteFormat = false;<br>
   Replaces = tooling::mergeReplacements(<br>
-      Replaces,<br>
-      reformat(FormatStyle, ChangedCode, Ranges, FileName, &IncompleteFormat));<br>
+      Replaces, reformat(FormatStyle, ChangedCode, Ranges, AssumedFileName,<br>
+                         &IncompleteFormat));<br>
   if (OutputXML) {<br>
     llvm::outs() << "<?xml version='1.0'?>\n<replacements "<br>
                     "xml:space='preserve' incomplete_format='"<br>
@@ -269,27 +269,26 @@ static bool format(StringRef FileName) {<br>
     outputReplacementsXML(Replaces);<br>
     llvm::outs() << "</replacements>\n";<br>
   } else {<br>
-    std::string FormattedCode =<br>
-        applyAllReplacements(Code->getBuffer(), Replaces);<br>
+    FileManager Files((FileSystemOptions()));<br>
+    DiagnosticsEngine Diagnostics(<br>
+        IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),<br>
+        new DiagnosticOptions);<br>
+    SourceManager Sources(Diagnostics, Files);<br>
+    FileID ID = createInMemoryFile(AssumedFileName, Code.get(), Sources, Files);<br>
+    Rewriter Rewrite(Sources, LangOptions());<br>
+    tooling::applyAllReplacements(Replaces, Rewrite);<br>
     if (Inplace) {<br>
       if (FileName == "-")<br>
         llvm::errs() << "error: cannot use -i when reading from stdin.\n";<br>
-      else {<br>
-        std::error_code EC;<br>
-        raw_fd_ostream FileOut(FileName, EC, llvm::sys::fs::F_Text);<br>
-        if (EC) {<br>
-          llvm::errs() << EC.message() << "\n";<br>
-          return true;<br>
-        }<br>
-        FileOut << FormattedCode;<br>
-      }<br>
+      else if (Rewrite.overwriteChangedFiles())<br>
+        return true;<br>
     } else {<br>
       if (Cursor.getNumOccurrences() != 0)<br>
         outs() << "{ \"Cursor\": "<br>
                << tooling::shiftedCodePosition(Replaces, Cursor)<br>
                << ", \"IncompleteFormat\": "<br>
                << (IncompleteFormat ? "true" : "false") << " }\n";<br>
-      outs() << FormattedCode;<br>
+      Rewrite.getEditBuffer(ID).write(outs());<br>
     }<br>
   }<br>
   return false;<br>
@@ -350,3 +349,4 @@ int main(int argc, const char **argv) {<br>
   }<br>
   return Error ? 1 : 0;<br>
 }<br>
+<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>