[PATCH] D25929: Add llvm-echo command.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 25 18:22:30 PDT 2016


ruiu updated this revision to Diff 75824.
ruiu added a comment.

- Use llvm-echo instead of echo for all lit tests.


https://reviews.llvm.org/D25929

Files:
  CMakeLists.txt
  utils/lit/lit/TestRunner.py
  utils/llvm-echo/CMakeLists.txt
  utils/llvm-echo/llvm-echo.cpp


Index: utils/llvm-echo/llvm-echo.cpp
===================================================================
--- /dev/null
+++ utils/llvm-echo/llvm-echo.cpp
@@ -0,0 +1,45 @@
+//===- llvm-echo.cpp - The 'echo' command --------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is an implementation of a portable "echo" command.
+// It tokenizes command line arguments in the Unix style even on Windows.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/StringSaver.h"
+#include <iostream>
+
+#if LLVM_ON_WIN32
+#include <windows.h>
+#endif
+
+using namespace llvm;
+
+int main(int Argc, const char **Argv) {
+  SmallVector<const char *, 4> Args;
+
+#if LLVM_ON_WIN32
+  const char *Cmdline = GetCommandLineA();
+  BumpPtrAllocator Alloc;
+  StringSaver Saver(Alloc);
+  llvm::cl::TokenizeGNUCommandLine(Cmdline, Saver, Args);
+#else
+  Args.insert(Args.begin(), Argv, Argv + Argc);
+#endif
+
+  for (int I = 1, E = Args.size(); I < E; ++I) {
+    if (I != 1)
+      std::cout << " ";
+    std::cout << Args[I];
+  }
+  std::cout << "\n";
+  return 0;
+}
Index: utils/llvm-echo/CMakeLists.txt
===================================================================
--- /dev/null
+++ utils/llvm-echo/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_llvm_utility(llvm-echo llvm-echo.cpp)
+
+target_link_libraries(llvm-echo LLVMSupport)
Index: utils/lit/lit/TestRunner.py
===================================================================
--- utils/lit/lit/TestRunner.py
+++ utils/lit/lit/TestRunner.py
@@ -653,6 +653,14 @@
                 ('%:t', tmpBase + '.tmp'),
                 ('%:T', tmpDir),
                 ])
+
+    # Use llvm-echo instead of echo because some echo commands on Windows
+    # interpret command line arguments differently and thus echoes
+    # different strings. (On Windows, command line tokenization is not
+    # done by shell but by each command's CRT, so ARGV may vary for the
+    # same arguments.)
+    substitutions.extend([('^\s*echo\s', 'llvm-echo ')])
+
     return substitutions
 
 def applySubstitutions(script, substitutions):
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -782,6 +782,7 @@
   add_subdirectory(utils/PerfectShuffle)
   add_subdirectory(utils/count)
   add_subdirectory(utils/not)
+  add_subdirectory(utils/llvm-echo)
   add_subdirectory(utils/llvm-lit)
   add_subdirectory(utils/yaml-bench)
   add_subdirectory(utils/unittest)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25929.75824.patch
Type: text/x-patch
Size: 2843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161026/ef8855aa/attachment.bin>


More information about the llvm-commits mailing list