[PATCH] D26656: [COFF] Fix manifest resource file creation on Windows

Rudy Pons via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 15 11:06:50 PST 2016


Ilod updated the summary for this revision.
Ilod updated this revision to Diff 78035.
Ilod added a comment.

Not much simpler in fact, because we need to handle a vector of files, but more local, so probably easier to understand.


https://reviews.llvm.org/D26656

Files:
  COFF/DriverUtils.cpp


Index: COFF/DriverUtils.cpp
===================================================================
--- COFF/DriverUtils.cpp
+++ COFF/DriverUtils.cpp
@@ -587,8 +587,25 @@
   E.add("/readonly");
   E.add("/nologo");
   E.add("/out:" + Twine(File.Path));
-  for (MemoryBufferRef MB : MBs)
-    E.add(MB.getBufferIdentifier());
+
+  std::vector<TemporaryFile> ResFiles;
+  ResFiles.reserve(MBs.size());
+  for (MemoryBufferRef MB : MBs) {
+    // We store the temporary file in a vector to avoid deletion
+    // before running cvtres
+    ResFiles.emplace_back("resource-file", "res");
+    TemporaryFile& ResFile = ResFiles.back();
+    // Write the content of the resource in a temporary file
+    std::error_code EC;
+    llvm::raw_fd_ostream OS(ResFile.Path, EC, sys::fs::F_None);
+    if (EC)
+      fatal(EC, "failed to open " + ResFile.Path);
+    OS << MB.getBuffer();
+    OS.close();
+
+    E.add(ResFile.Path);
+  }
+
   E.run();
   return File.getMemoryBuffer();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26656.78035.patch
Type: text/x-patch
Size: 972 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161115/7ce42592/attachment.bin>


More information about the llvm-commits mailing list