Browse Source

Merge topic 'instrumentation-show-only'

de3cb099a3 instrumentation: Add showOnly to ctest snippets
2976742520 instrumentation: Only quote arguments that contain a space

Acked-by: Kitware Robot <[email protected]>
Reviewed-by: Craig Scott <[email protected]>
Merge-request: !11337
Brad King 1 week ago
parent
commit
41a5e3b395

+ 4 - 0
Help/manual/cmake-instrumentation.7.rst

@@ -423,6 +423,10 @@ and contain the following data:
     contains information about the CMake configure and generate steps
     responsible for generating the ``command`` in this snippet.
 
+  ``showOnly``
+    A boolean representing whether the ``--show-only`` option was passed to
+    ``ctest``. Only included when ``role`` is ``ctest``.
+
 Example:
 
 .. code-block:: json

+ 4 - 1
Source/cmCTest.cxx

@@ -2672,7 +2672,10 @@ int cmCTest::ExecuteTests(std::vector<std::string> const& args)
   auto processHandler = [&handler]() -> int {
     return handler.ProcessHandler();
   };
-  int ret = instrumentation.InstrumentCommand("ctest", args, processHandler);
+  std::map<std::string, std::string> data;
+  data["showOnly"] = this->GetShowOnly() ? "1" : "0";
+  int ret =
+    instrumentation.InstrumentCommand("ctest", args, processHandler, data);
   instrumentation.CollectTimingData(cmInstrumentationQuery::Hook::PostCTest);
   if (ret < 0) {
     cmCTestLog(this, ERROR_MESSAGE, "Errors while running CTest\n");

+ 7 - 1
Source/cmInstrumentation.cxx

@@ -663,6 +663,8 @@ int cmInstrumentation::InstrumentCommand(
     for (auto const& item : data.value()) {
       if (item.first == "role" && !item.second.empty()) {
         command_type = item.second;
+      } else if (item.first == "showOnly") {
+        root[item.first] = item.second == "1" ? true : false;
       } else if (!item.second.empty()) {
         root[item.first] = item.second;
       }
@@ -743,7 +745,11 @@ std::string cmInstrumentation::GetCommandStr(
 {
   std::string command_str;
   for (size_t i = 0; i < args.size(); ++i) {
-    command_str = cmStrCat(command_str, '"', args[i], '"');
+    if (args[i].find(' ') != std::string::npos) {
+      command_str = cmStrCat(command_str, '"', args[i], '"');
+    } else {
+      command_str = cmStrCat(command_str, args[i]);
+    }
     if (i < args.size() - 1) {
       command_str = cmStrCat(command_str, ' ');
     }

+ 4 - 0
Tests/RunCMake/Instrumentation/RunCMakeTest.cmake

@@ -63,6 +63,10 @@ function(instrument test)
     set(copy_loc ${v1}/query/generated) # Copied files here should be cleared on configure
   endif()
   if (ARGS_COPY_QUERIES)
+    set(CMAKE_COMMAND_QUOTE ${CMAKE_COMMAND})
+    if (CMAKE_COMMAND MATCHES " ")
+      set(CMAKE_COMMAND_QUOTE "\\\"${CMAKE_COMMAND}\\\"")
+    endif()
     file(MAKE_DIRECTORY ${copy_loc})
     set(generated_queries "0;1;2")
     foreach(n IN LISTS generated_queries)

+ 1 - 1
Tests/RunCMake/Instrumentation/query/generated/query-1.json.in

@@ -1,7 +1,7 @@
 {
   "callbacks" :
   [
-    "\"@CMAKE_COMMAND@\" \"-E\" \"echo\" \"callback1\""
+    "@CMAKE_COMMAND_QUOTE@ -E echo callback1"
   ],
   "hooks" :
   [

+ 2 - 2
Tests/RunCMake/Instrumentation/query/generated/query-2.json.in

@@ -1,8 +1,8 @@
 {
   "callbacks" :
   [
-    "\"@CMAKE_COMMAND@\" \"-E\" \"echo\" \"callback2\"",
-    "\"@CMAKE_COMMAND@\" \"-E\" \"echo\" \"callback3\""
+    "@CMAKE_COMMAND_QUOTE@ -E echo callback2",
+    "@CMAKE_COMMAND_QUOTE@ -E echo callback3"
   ],
   "hooks" :
   [

+ 2 - 0
Tests/RunCMake/Instrumentation/verify-snippet.cmake

@@ -27,6 +27,8 @@ function(snippet_has_fields snippet contents)
     json_has_key("${snippet}" "${contents}" outputs)
     json_has_key("${snippet}" "${contents}" outputSizes)
     json_has_key("${snippet}" "${contents}" config)
+  elseif (filename MATCHES "^ctest-*")
+    json_has_key("${snippet}" "${contents}" showOnly)
   elseif (filename MATCHES "^test-*")
     json_has_key("${snippet}" "${contents}" testName)
     json_has_key("${snippet}" "${contents}" config)