[PATCH] D46239: [llvm-rc] Default to writing the output next to the input, if no output is specified

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 29 12:52:25 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: zturner, mnbvmar.

This matches what rc.exe does if no output is specified.


Repository:
  rL LLVM

https://reviews.llvm.org/D46239

Files:
  test/tools/llvm-rc/tag-menu.test
  tools/llvm-rc/llvm-rc.cpp


Index: tools/llvm-rc/llvm-rc.cpp
===================================================================
--- tools/llvm-rc/llvm-rc.cpp
+++ tools/llvm-rc/llvm-rc.cpp
@@ -24,6 +24,7 @@
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
@@ -141,9 +142,15 @@
 
   if (!IsDryRun) {
     auto OutArgsInfo = InputArgs.getAllArgValues(OPT_FILEOUT);
+    if (OutArgsInfo.empty()) {
+      SmallString<128> OutputFile = InputFile;
+      llvm::sys::path::replace_extension(OutputFile, "res");
+      OutArgsInfo.push_back(OutputFile.str());
+    }
+
     if (OutArgsInfo.size() != 1)
       fatalError(
-          "Exactly one output file should be provided (using /FO flag).");
+          "No more than one output file should be provided (using /FO flag).");
 
     std::error_code EC;
     auto FOut =
Index: test/tools/llvm-rc/tag-menu.test
===================================================================
--- test/tools/llvm-rc/tag-menu.test
+++ test/tools/llvm-rc/tag-menu.test
@@ -1,6 +1,11 @@
 ; RUN: llvm-rc /FO %t %p/Inputs/tag-menu.rc
 ; RUN: llvm-readobj %t | FileCheck %s --check-prefix=MENU
 
+; Test running llvm-rc without an explicit output file.
+; RUN: cp %p/Inputs/tag-menu.rc %t.implicit.rc
+; RUN: llvm-rc %t.implicit.rc
+; RUN: llvm-readobj %t.implicit.res | FileCheck --check-prefix=MENU %s
+
 ; MENU: Resource type (int): 4
 ; MENU-NEXT: Resource name (string): CHECKRECURSION
 ; MENU-NEXT: Data version: 0


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46239.144492.patch
Type: text/x-patch
Size: 1632 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180429/8339fd4c/attachment.bin>


More information about the llvm-commits mailing list