[PATCH] D69665: [llvm-ar] Fix llvm-ar response file reading on Windows

Owen Reynolds via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 31 09:05:22 PDT 2019


gbreynoo created this revision.
gbreynoo added reviewers: rupprecht, MaskRay, ruiu.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
gbreynoo set the repository for this revision to rL LLVM.

Response files where not being correctly read on Windows, this change fixes the issue and adds some tests.


Repository:
  rL LLVM

https://reviews.llvm.org/D69665

Files:
  llvm/test/tools/llvm-ar/response-utf8.test
  llvm/test/tools/llvm-ar/response.test
  llvm/tools/llvm-ar/llvm-ar.cpp


Index: llvm/tools/llvm-ar/llvm-ar.cpp
===================================================================
--- llvm/tools/llvm-ar/llvm-ar.cpp
+++ llvm/tools/llvm-ar/llvm-ar.cpp
@@ -1089,7 +1089,11 @@
 static int ar_main(int argc, char **argv) {
   SmallVector<const char *, 0> Argv(argv, argv + argc);
   StringSaver Saver(Alloc);
-  cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv);
+  cl::ExpandResponseFiles(Saver,
+                          Triple(sys::getProcessTriple()).isOSWindows()
+                              ? cl::TokenizeWindowsCommandLine
+                              : cl::TokenizeGNUCommandLine,
+                          Argv);
   for (size_t i = 1; i < Argv.size(); ++i) {
     StringRef Arg = Argv[i];
     const char *match;
Index: llvm/test/tools/llvm-ar/response.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-ar/response.test
@@ -0,0 +1,20 @@
+## llvm-ar should be able to consume response files.
+
+# RUN: echo contents > %t.txt
+# RUN: echo rc %t1.a %t.txt > %t.response1.txt
+# RUN: llvm-ar @%t.response1.txt
+# RUN: llvm-ar p %t1.a | FileCheck %s
+
+## Quotes and Spaces.
+# RUN: echo contents > "%t space.txt"
+## Python is used here to ensure the quotes are written to the response file
+# RUN: %python -c "import os; open(r'%t.response2.txt', 'wb').write(r'%t2.a \"%t space.txt\"'+ '\n')"
+# RUN: llvm-ar rc @%t.response2.txt
+# RUN: llvm-ar p %t2.a | FileCheck %s
+
+## Arguments after the response file.
+# RUN: echo rc %t3.a > %t.response3.txt
+# RUN: llvm-ar @%t.response3.txt %t.txt
+# RUN: llvm-ar p %t3.a | FileCheck %s
+
+CHECK: contents
Index: llvm/test/tools/llvm-ar/response-utf8.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-ar/response-utf8.test
@@ -0,0 +1,8 @@
+## Check that response files can cope with non-ascii characters.
+
+# RUN: llvm-ar r %t.a %s
+
+# RUN: echo "r %t-£.a %s" > %t-non-ascii.txt
+# RUN: llvm-ar @%t-non-ascii.txt
+## Work-around diff not working with non-ascii filenames on windows.
+RUN: env LANG=en_US.UTF-8 %python -c "assert open(ur'%t-\U000000A3.a', 'rb').read() == open(r'%t.a', 'rb').read()"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69665.227289.patch
Type: text/x-patch
Size: 2239 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191031/1ad0ed6a/attachment.bin>


More information about the llvm-commits mailing list