[cmake-developers] [PATCH] Fix args handling in cmake -E time

Andrey Pokrovskiy wonder.mice at gmail.com
Tue Jan 19 21:20:48 EST 2016


>From 7b01d1aed22b16fd81c3ae47dd51311e9a15187a Mon Sep 17 00:00:00 2001
From: wonder-mice <wonder.mice at gmail.com>
Date: Tue, 19 Jan 2016 18:13:10 -0800
Subject: [PATCH] Fix args handling in cmake -E time

Previous implementation had two issues:
* Quotes in arguments where not escaped
* No special treatment for arguments with spaces

Because of that, following command line:
  cmake -E time cmake "-GUnix Makefile"
was interpreted as
  cmake -E time cmake "-GUnix" "Makefile"
Proposed patch fixes that by escaping all quotes in arguments and
wrapping all arguments in quotes before concatenating them.
---
 Source/cmAlgorithms.h | 2 +-
 Source/cmcmd.cxx      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index ef607d2..5b76429 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -230,7 +230,7 @@ template<typename Range>
 std::string cmJoin(Range const& r, std::string delimiter)
 {
   return cmJoin(r, delimiter.c_str());
-};
+}

 template<typename Range>
 typename Range::const_iterator cmRemoveN(Range& r, size_t n)
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index fb7b1f5..5643cb9 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -555,7 +555,7 @@ int
cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
     // Clock command
     else if (args[1] == "time" && args.size() > 2)
       {
-      std::string command = cmJoin(cmMakeRange(args).advance(2), " ");
+      std::string command = cmWrap('"', cmMakeRange(args).advance(2),
'"', " ");

       clock_t clock_start, clock_finish;
       time_t time_start, time_finish;
-- 
2.5.4 (Apple Git-61)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-args-handling-in-cmake-E-time.patch
Type: application/octet-stream
Size: 1660 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160119/f75bcc41/attachment.obj>


More information about the cmake-developers mailing list