This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, master has been updated
       via  74569996e8fe798386cca2d4241acea0644f6275 (commit)
       via  d4611b05a87e125406588921a7cedc4efae8c8cd (commit)
       via  f7612a66680f0a6ab4bb16ff3f545463bf900ad6 (commit)
       via  02ed66c04bf24d4c13fb6f82d040b835c966bf0c (commit)
       via  e1df51b19f1f9707a946068f5bf563c582e08d4f (commit)
       via  15feb5d3f899b1d7f8fb9b92f41cb0f307fa5640 (commit)
       via  0746a3398f4e22f80c19b6253c4df652f9c41214 (commit)
       via  5531e0447257f7a7c2df8a8434f0ba2e207a9938 (commit)
       via  c2b3d0872e41b172ebded93b2c98e0ffb3b54e6b (commit)
       via  03e4fe65b0c4666ed46d0f2a7e2cfe00e30f7406 (commit)
       via  7ddf46230431cd3375f911d4b406af663595861d (commit)
       via  9a7b4f47aa3cf4ce03aad117d2e1de893c34acb0 (commit)
       via  f0c00bec1d7ce8f1209c4024e6000f907f11f1e9 (commit)
       via  53227a4ff27c6eda7cb5b3b283f96d1f2d2d56ca (commit)
      from  e5b0b8560dc40d8d7556a34b7b69409c7c2502fe (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=74569996e8fe798386cca2d4241acea0644f6275
commit 74569996e8fe798386cca2d4241acea0644f6275
Merge: d4611b05a8 53227a4ff2
Author:     Brad King <brad.k...@kitware.com>
AuthorDate: Thu Nov 7 15:26:39 2019 +0000
Commit:     Kitware Robot <kwro...@kitware.com>
CommitDate: Thu Nov 7 10:27:59 2019 -0500

    Merge topic 'refactor-foreach'
    
    53227a4ff2 Refactor: Modernize `foreach` code and fix some bugs
    
    Acked-by: Kitware Robot <kwro...@kitware.com>
    Merge-request: !3986


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=d4611b05a87e125406588921a7cedc4efae8c8cd
commit d4611b05a87e125406588921a7cedc4efae8c8cd
Merge: f7612a6668 02ed66c04b
Author:     Brad King <brad.k...@kitware.com>
AuthorDate: Thu Nov 7 15:26:25 2019 +0000
Commit:     Kitware Robot <kwro...@kitware.com>
CommitDate: Thu Nov 7 10:26:50 2019 -0500

    Merge branch 'release-3.16'


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f7612a66680f0a6ab4bb16ff3f545463bf900ad6
commit f7612a66680f0a6ab4bb16ff3f545463bf900ad6
Merge: e1df51b19f 7ddf462304
Author:     Brad King <brad.k...@kitware.com>
AuthorDate: Thu Nov 7 15:26:25 2019 +0000
Commit:     Kitware Robot <kwro...@kitware.com>
CommitDate: Thu Nov 7 10:26:50 2019 -0500

    Merge topic 'unity-include-generated'
    
    7ddf462304 Unity build: Include GENERATED files into unity build
    
    Acked-by: Kitware Robot <kwro...@kitware.com>
    Acked-by: Julien Schueller <schuel...@phimeca.com>
    Merge-request: !4001


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e1df51b19f1f9707a946068f5bf563c582e08d4f
commit e1df51b19f1f9707a946068f5bf563c582e08d4f
Merge: 15feb5d3f8 0746a3398f
Author:     Brad King <brad.k...@kitware.com>
AuthorDate: Thu Nov 7 15:24:35 2019 +0000
Commit:     Kitware Robot <kwro...@kitware.com>
CommitDate: Thu Nov 7 10:25:45 2019 -0500

    Merge branch 'release-3.16'


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=15feb5d3f899b1d7f8fb9b92f41cb0f307fa5640
commit 15feb5d3f899b1d7f8fb9b92f41cb0f307fa5640
Merge: 5531e04472 f0c00bec1d
Author:     Brad King <brad.k...@kitware.com>
AuthorDate: Thu Nov 7 15:24:35 2019 +0000
Commit:     Kitware Robot <kwro...@kitware.com>
CommitDate: Thu Nov 7 10:25:45 2019 -0500

    Merge topic 'llvm-rc-fix'
    
    f0c00bec1d CMakeVersion.rc: Fix build with llvm-rc
    
    Acked-by: Kitware Robot <kwro...@kitware.com>
    Merge-request: !4003


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5531e0447257f7a7c2df8a8434f0ba2e207a9938
commit 5531e0447257f7a7c2df8a8434f0ba2e207a9938
Merge: c2b3d0872e 03e4fe65b0
Author:     Brad King <brad.k...@kitware.com>
AuthorDate: Thu Nov 7 15:24:23 2019 +0000
Commit:     Kitware Robot <kwro...@kitware.com>
CommitDate: Thu Nov 7 10:24:34 2019 -0500

    Merge branch 'release-3.16'


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c2b3d0872e41b172ebded93b2c98e0ffb3b54e6b
commit c2b3d0872e41b172ebded93b2c98e0ffb3b54e6b
Merge: e5b0b8560d 9a7b4f47aa
Author:     Brad King <brad.k...@kitware.com>
AuthorDate: Thu Nov 7 15:24:23 2019 +0000
Commit:     Kitware Robot <kwro...@kitware.com>
CommitDate: Thu Nov 7 10:24:34 2019 -0500

    Merge topic 'objc-x-objc'
    
    9a7b4f47aa ObjC: Mark explicitly the language for compilation
    
    Acked-by: Kitware Robot <kwro...@kitware.com>
    Merge-request: !4002


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=53227a4ff27c6eda7cb5b3b283f96d1f2d2d56ca
commit 53227a4ff27c6eda7cb5b3b283f96d1f2d2d56ca
Author:     Alex Turbov <i.za...@gmail.com>
AuthorDate: Mon Nov 4 17:11:07 2019 +0200
Commit:     Alex Turbov <i.za...@gmail.com>
CommitDate: Wed Nov 6 16:14:47 2019 +0200

    Refactor: Modernize `foreach` code and fix some bugs
    
    - fix the typo in `foreach` documentation
    - fix broken `foreach(... IN ITEMS ... LISTS ...)`
    - add tests of `foreach` for existed functionality and fixes

diff --git a/Help/command/foreach.rst b/Help/command/foreach.rst
index ae2afb2905..ecbfed3d9d 100644
--- a/Help/command/foreach.rst
+++ b/Help/command/foreach.rst
@@ -47,7 +47,7 @@ of undocumented behavior that may change in future releases.
 
 .. code-block:: cmake
 
-  foreach(loop_var IN [LISTS [<lists>]] [ITEMS [<items>]])
+  foreach(<loop_var> IN [LISTS [<lists>]] [ITEMS [<items>]])
 
 In this variant, ``<lists>`` is a whitespace or semicolon
 separated list of list-valued variables. The ``foreach``
diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx
index 44392baa75..91cd4efd47 100644
--- a/Source/cmForEachCommand.cxx
+++ b/Source/cmForEachCommand.cxx
@@ -2,7 +2,12 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmForEachCommand.h"
 
-#include <cstdio>
+#include <algorithm>
+#include <cstddef>
+// NOTE The declaration of `std::abs` has moved to `cmath` since C++17
+// See https://en.cppreference.com/w/cpp/numeric/math/abs
+// ALERT But IWYU used to lint `#include`s do not "understand"
+// conditional compilation (i.e. `#if __cplusplus >= 201703L`)
 #include <cstdlib>
 #include <utility>
 
@@ -21,8 +26,6 @@
 #include "cmSystemTools.h"
 
 namespace {
-bool HandleInMode(std::vector<std::string> const& args, cmMakefile& makefile);
-
 class cmForEachFunctionBlocker : public cmFunctionBlocker
 {
 public:
@@ -60,7 +63,8 @@ bool 
cmForEachFunctionBlocker::ArgumentsMatch(cmListFileFunction const& lff,
 {
   std::vector<std::string> expandedArguments;
   mf.ExpandArguments(lff.Arguments, expandedArguments);
-  return expandedArguments.empty() || expandedArguments[0] == this->Args[0];
+  return expandedArguments.empty() ||
+    expandedArguments.front() == this->Args.front();
 }
 
 bool cmForEachFunctionBlocker::Replay(
@@ -70,13 +74,13 @@ bool cmForEachFunctionBlocker::Replay(
   // at end of for each execute recorded commands
   // store the old value
   std::string oldDef;
-  if (mf.GetDefinition(this->Args[0])) {
-    oldDef = mf.GetDefinition(this->Args[0]);
+  if (mf.GetDefinition(this->Args.front())) {
+    oldDef = mf.GetDefinition(this->Args.front());
   }
 
   for (std::string const& arg : cmMakeRange(this->Args).advance(1)) {
     // set the variable to the loop value
-    mf.AddDefinition(this->Args[0], arg);
+    mf.AddDefinition(this->Args.front(), arg);
     // Invoke all the functions that were collected in the block.
     for (cmListFileFunction const& func : functions) {
       cmExecutionStatus status(mf);
@@ -84,12 +88,12 @@ bool cmForEachFunctionBlocker::Replay(
       if (status.GetReturnInvoked()) {
         inStatus.SetReturnInvoked();
         // restore the variable to its prior value
-        mf.AddDefinition(this->Args[0], oldDef);
+        mf.AddDefinition(this->Args.front(), oldDef);
         return true;
       }
       if (status.GetBreakInvoked()) {
         // restore the variable to its prior value
-        mf.AddDefinition(this->Args[0], oldDef);
+        mf.AddDefinition(this->Args.front(), oldDef);
         return true;
       }
       if (status.GetContinueInvoked()) {
@@ -102,11 +106,48 @@ bool cmForEachFunctionBlocker::Replay(
   }
 
   // restore the variable to its prior value
-  mf.AddDefinition(this->Args[0], oldDef);
+  mf.AddDefinition(this->Args.front(), oldDef);
   return true;
 }
+
+bool HandleInMode(std::vector<std::string> const& args, cmMakefile& makefile)
+{
+  auto fb = cm::make_unique<cmForEachFunctionBlocker>(&makefile);
+  fb->Args.push_back(args.front());
+
+  enum Doing
+  {
+    DoingNone,
+    DoingLists,
+    DoingItems
+  };
+  Doing doing = DoingNone;
+  for (std::string const& arg : cmMakeRange(args).advance(2)) {
+    if (arg == "LISTS") {
+      doing = DoingLists;
+    } else if (arg == "ITEMS") {
+      doing = DoingItems;
+    } else if (doing == DoingLists) {
+      auto const& value = makefile.GetSafeDefinition(arg);
+      if (!value.empty()) {
+        cmExpandList(value, fb->Args, true);
+      }
+    } else if (doing == DoingItems) {
+      fb->Args.push_back(arg);
+    } else {
+      makefile.IssueMessage(MessageType::FATAL_ERROR,
+                            cmStrCat("Unknown argument:\n", "  ", arg, "\n"));
+      return true;
+    }
+  }
+
+  makefile.AddFunctionBlocker(std::move(fb));
+
+  return true;
 }
 
+} // anonymous namespace
+
 bool cmForEachCommand(std::vector<std::string> const& args,
                       cmExecutionStatus& status)
 {
@@ -126,16 +167,16 @@ bool cmForEachCommand(std::vector<std::string> const& 
args,
       int stop = 0;
       int step = 0;
       if (args.size() == 3) {
-        stop = atoi(args[2].c_str());
+        stop = std::stoi(args[2]);
       }
       if (args.size() == 4) {
-        start = atoi(args[2].c_str());
-        stop = atoi(args[3].c_str());
+        start = std::stoi(args[2]);
+        stop = std::stoi(args[3]);
       }
       if (args.size() == 5) {
-        start = atoi(args[2].c_str());
-        stop = atoi(args[3].c_str());
-        step = atoi(args[4].c_str());
+        start = std::stoi(args[2]);
+        stop = std::stoi(args[3]);
+        step = std::stoi(args[4]);
       }
       if (step == 0) {
         if (start > stop) {
@@ -151,21 +192,24 @@ bool cmForEachCommand(std::vector<std::string> const& 
args,
                    ", stop ", stop, ", step ", step));
         return false;
       }
-      std::vector<std::string> range;
-      char buffer[100];
-      range.push_back(args[0]);
-      int cc;
-      for (cc = start;; cc += step) {
-        if ((step > 0 && cc > stop) || (step < 0 && cc < stop)) {
-          break;
-        }
-        sprintf(buffer, "%d", cc);
-        range.emplace_back(buffer);
-        if (cc == stop) {
-          break;
-        }
-      }
-      fb->Args = range;
+
+      // Calculate expected iterations count and reserve enough space
+      // in the `fb->Args` vector. The first item is the iteration variable
+      // name...
+      const std::size_t iter_cnt = 2u +
+        int(start < stop) * (stop - start) / std::abs(step) +
+        int(start > stop) * (start - stop) / std::abs(step);
+      fb->Args.resize(iter_cnt);
+      fb->Args.front() = args.front();
+      auto cc = start;
+      auto generator = [&cc, step]() -> std::string {
+        auto result = std::to_string(cc);
+        cc += step;
+        return result;
+      };
+      // Fill the `range` vector w/ generated string values
+      // (starting from 2nd position)
+      std::generate(++fb->Args.begin(), fb->Args.end(), generator);
     } else {
       fb->Args = args;
     }
@@ -176,42 +220,3 @@ bool cmForEachCommand(std::vector<std::string> const& args,
 
   return true;
 }
-
-namespace {
-bool HandleInMode(std::vector<std::string> const& args, cmMakefile& makefile)
-{
-  auto fb = cm::make_unique<cmForEachFunctionBlocker>(&makefile);
-  fb->Args.push_back(args[0]);
-
-  enum Doing
-  {
-    DoingNone,
-    DoingLists,
-    DoingItems
-  };
-  Doing doing = DoingNone;
-  for (unsigned int i = 2; i < args.size(); ++i) {
-    if (doing == DoingItems) {
-      fb->Args.push_back(args[i]);
-    } else if (args[i] == "LISTS") {
-      doing = DoingLists;
-    } else if (args[i] == "ITEMS") {
-      doing = DoingItems;
-    } else if (doing == DoingLists) {
-      const char* value = makefile.GetDefinition(args[i]);
-      if (value && *value) {
-        cmExpandList(value, fb->Args, true);
-      }
-    } else {
-      makefile.IssueMessage(
-        MessageType::FATAL_ERROR,
-        cmStrCat("Unknown argument:\n", "  ", args[i], "\n"));
-      return true;
-    }
-  }
-
-  makefile.AddFunctionBlocker(std::move(fb));
-
-  return true;
-}
-}
diff --git a/Tests/RunCMake/foreach/RunCMakeTest.cmake 
b/Tests/RunCMake/foreach/RunCMakeTest.cmake
index 4b74cfe493..0f1fdd47d8 100644
--- a/Tests/RunCMake/foreach/RunCMakeTest.cmake
+++ b/Tests/RunCMake/foreach/RunCMakeTest.cmake
@@ -1,3 +1,4 @@
 include(RunCMake)
 
 run_cmake(BadRangeInFunction)
+run_cmake(foreach-all-test)
diff --git a/Tests/RunCMake/foreach/foreach-all-test-stdout.txt 
b/Tests/RunCMake/foreach/foreach-all-test-stdout.txt
new file mode 100644
index 0000000000..e8f622d6ee
--- /dev/null
+++ b/Tests/RunCMake/foreach/foreach-all-test-stdout.txt
@@ -0,0 +1,44 @@
+-- foreach\(RANGE\):
+--   \[0\.\.1\]/1
+--     < 0
+--     < 1
+--   \[1\.\.1\]/1
+--     < 1
+--   \[0\.\.10\]/2
+--     < 0
+--     < 2
+--     < 4
+--     < 6
+--     < 8
+--     < 10
+--   \[-10\.\.0\]/3
+--     < -10
+--     < -7
+--     < -4
+--     < -1
+--   \[0\.\.-10\]/-5
+--     < 0
+--     < -5
+--     < -10
+-- foreach\(IN ITEMS\):
+--   < one
+--   < two
+--   < three
+-- foreach\(IN LISTS\):
+--   < satu
+--   < dua
+--   < tiga
+-- foreach\(IN LISTS and ITEMS\):
+--   < satu
+--   < dua
+--   < tiga
+--   < one
+--   < two
+--   < three
+-- foreach\(IN ITEMS and LISTS\):
+--   < one
+--   < two
+--   < three
+--   < satu
+--   < dua
+--   < tiga
diff --git a/Tests/RunCMake/foreach/foreach-all-test.cmake 
b/Tests/RunCMake/foreach/foreach-all-test.cmake
new file mode 100644
index 0000000000..2e377c8028
--- /dev/null
+++ b/Tests/RunCMake/foreach/foreach-all-test.cmake
@@ -0,0 +1,67 @@
+message(STATUS "foreach(RANGE):")
+list(APPEND CMAKE_MESSAGE_INDENT "  ")
+
+message(STATUS "[0..1]/1")
+list(APPEND CMAKE_MESSAGE_INDENT "  < ")
+foreach(i RANGE 1)
+    message(STATUS ${i})
+endforeach()
+list(POP_BACK CMAKE_MESSAGE_INDENT)
+
+message(STATUS "[1..1]/1")
+list(APPEND CMAKE_MESSAGE_INDENT "  < ")
+foreach(i RANGE 1 1)
+    message(STATUS ${i})
+endforeach()
+list(POP_BACK CMAKE_MESSAGE_INDENT)
+
+message(STATUS "[0..10]/2")
+list(APPEND CMAKE_MESSAGE_INDENT "  < ")
+foreach(i RANGE 0 10 2)
+    message(STATUS ${i})
+endforeach()
+list(POP_BACK CMAKE_MESSAGE_INDENT)
+
+message(STATUS "[-10..0]/3")
+list(APPEND CMAKE_MESSAGE_INDENT "  < ")
+foreach(i RANGE -10 0 3)
+    message(STATUS ${i})
+endforeach()
+list(POP_BACK CMAKE_MESSAGE_INDENT)
+
+message(STATUS "[0..-10]/-5")
+list(APPEND CMAKE_MESSAGE_INDENT "  < ")
+foreach(i RANGE 0 -10 -5)
+    message(STATUS ${i})
+endforeach()
+list(POP_BACK CMAKE_MESSAGE_INDENT)
+list(POP_BACK CMAKE_MESSAGE_INDENT)
+
+message(STATUS "foreach(IN ITEMS):")
+list(APPEND CMAKE_MESSAGE_INDENT "  < ")
+foreach(i IN ITEMS one two three)
+    message(STATUS ${i})
+endforeach()
+list(POP_BACK CMAKE_MESSAGE_INDENT)
+
+message(STATUS "foreach(IN LISTS):")
+list(APPEND CMAKE_MESSAGE_INDENT "  < ")
+list(APPEND count satu dua tiga)
+foreach(i IN LISTS count)
+    message(STATUS ${i})
+endforeach()
+list(POP_BACK CMAKE_MESSAGE_INDENT)
+
+message(STATUS "foreach(IN LISTS and ITEMS):")
+list(APPEND CMAKE_MESSAGE_INDENT "  < ")
+foreach(i IN LISTS count ITEMS one two three)
+    message(STATUS ${i})
+endforeach()
+list(POP_BACK CMAKE_MESSAGE_INDENT)
+
+message(STATUS "foreach(IN ITEMS and LISTS):")
+list(APPEND CMAKE_MESSAGE_INDENT "  < ")
+foreach(i IN ITEMS one two three LISTS count)
+    message(STATUS ${i})
+endforeach()
+list(POP_BACK CMAKE_MESSAGE_INDENT)
diff --git a/Utilities/IWYU/mapping.imp b/Utilities/IWYU/mapping.imp
index ef31e8befe..5e4c7ba586 100644
--- a/Utilities/IWYU/mapping.imp
+++ b/Utilities/IWYU/mapping.imp
@@ -24,6 +24,7 @@
   { include: [ "<bits/shared_ptr.h>", private, "<memory>", public ] },
   { include: [ "<bits/std_function.h>", private, "<functional>", public ] },
   { include: [ "<bits/refwrap.h>", private, "<functional>", public ] },
+  { include: [ "<bits/std_abs.h>", private, "<stdlib.h>", public ] },
   { include: [ "<bits/stdint-intn.h>", private, "<stdint.h>", public ] },
   { include: [ "<bits/stdint-uintn.h>", private, "<stdint.h>", public ] },
   { include: [ "<bits/time.h>", private, "<time.h>", public ] },

-----------------------------------------------------------------------

Summary of changes:
 Help/command/foreach.rst                           |   2 +-
 Help/prop_tgt/UNITY_BUILD.rst                      |   5 +-
 Modules/CMakeOBJCInformation.cmake                 |   2 +-
 Modules/CMakeOBJCXXInformation.cmake               |   2 +-
 Source/CMakeLists.txt                              |   2 +-
 Source/cmForEachCommand.cxx                        | 145 +++++++++++----------
 Source/cmLocalGenerator.cxx                        |   1 -
 .../UnityBuild/unitybuild_skip-check.cmake         |   6 +-
 Tests/RunCMake/UnityBuild/unitybuild_skip.cmake    |   5 +-
 Tests/RunCMake/foreach/RunCMakeTest.cmake          |   1 +
 Tests/RunCMake/foreach/foreach-all-test-stdout.txt |  44 +++++++
 Tests/RunCMake/foreach/foreach-all-test.cmake      |  67 ++++++++++
 Utilities/IWYU/mapping.imp                         |   1 +
 13 files changed, 198 insertions(+), 85 deletions(-)
 create mode 100644 Tests/RunCMake/foreach/foreach-all-test-stdout.txt
 create mode 100644 Tests/RunCMake/foreach/foreach-all-test.cmake


hooks/post-receive
-- 
CMake
_______________________________________________
Cmake-commits mailing list
Cmake-commits@cmake.org
https://cmake.org/mailman/listinfo/cmake-commits

Reply via email to