Ver Fonte

instrumentation: Additional data in custom, install and link snippets

- Include `config` in all `install` and `custom` snippets
- Include `target` for `custom` snippets where applicable
- Document and test inclusion of `language` in `link` snippets

Issue: #27244
Martin Duffy há 3 semanas atrás
pai
commit
2fdd1e787f

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

@@ -359,8 +359,9 @@ and contain the following data:
     * ``test``: a single test executed by CTest
 
   ``target``
-    The CMake target associated with the command. Only included when ``role`` is
-    ``compile`` or ``link``.
+    The CMake target associated with the command. Included when ``role`` is
+    ``compile``, or ``link``, and when ``role`` is ``custom`` and the custom
+    command is attached to a target with :ref:`add_custom_command(TARGET)`.
 
   ``targetType``
     The :prop_tgt:`TYPE` of the target. Only included when ``role`` is
@@ -391,14 +392,15 @@ and contain the following data:
 
   ``language``
     The language of the source file being compiled. Only included when ``role`` is
-    ``compile``.
+    ``compile`` or ``link``.
 
   ``testName``
     The name of the test being executed. Only included when ``role`` is ``test``.
 
   ``config``
     The type of build, such as ``Release`` or ``Debug``. Only included when
-    ``role`` is ``compile``, ``link`` or ``test``.
+    ``role`` is one of: ``compile``, ``link``, ``custom``, ``install``,
+    ``test``.
 
   ``dynamicSystemInformation``
     Specifies the dynamic information collected about the host machine

+ 2 - 0
Source/cmFastbuildTargetGenerator.cxx

@@ -715,6 +715,8 @@ std::string cmFastbuildTargetGenerator::MakeCustomLauncher(
   }
   vars.Output = output.c_str();
   vars.Role = ccg.GetCC().GetRole().c_str();
+  vars.CMTargetName = ccg.GetCC().GetTarget().c_str();
+  vars.Config = ccg.GetOutputConfig().c_str();
 
   auto rulePlaceholderExpander =
     this->LocalGenerator->CreateRulePlaceholderExpander();

+ 5 - 0
Source/cmInstallScriptHandler.cxx

@@ -119,10 +119,15 @@ int cmInstallScriptHandler::Install(unsigned int j,
                        "install",
                        "--build-dir",
                        this->binaryDir,
+                       "--config",
+                       "",
                        "--" };
   }
 
   for (auto& script : this->scripts) {
+    if (!instrument_arg.empty()) {
+      instrument_arg[7] = script.config; // --config <script.config>
+    }
     script.command.insert(script.command.begin(), instrument_arg.begin(),
                           instrument_arg.end());
     runners.emplace_back(script);

+ 2 - 1
Source/cmInstrumentation.cxx

@@ -637,7 +637,8 @@ int cmInstrumentation::InstrumentCommand(
 
   // Create empty config entry if config not found
   if (!root.isMember("config") &&
-      (command_type == "compile" || command_type == "link")) {
+      (command_type == "compile" || command_type == "link" ||
+       command_type == "custom" || command_type == "install")) {
     root["config"] = "";
   }
 

+ 2 - 0
Source/cmLocalNinjaGenerator.cxx

@@ -912,6 +912,8 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
   }
   vars.Output = output.c_str();
   vars.Role = ccg.GetCC().GetRole().c_str();
+  vars.CMTargetName = ccg.GetCC().GetTarget().c_str();
+  vars.Config = ccg.GetOutputConfig().c_str();
 
   auto rulePlaceholderExpander = this->CreateRulePlaceholderExpander();
 

+ 2 - 0
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -1073,6 +1073,8 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
         }
         vars.Output = output.c_str();
         vars.Role = ccg.GetCC().GetRole().c_str();
+        vars.CMTargetName = ccg.GetCC().GetTarget().c_str();
+        vars.Config = ccg.GetOutputConfig().c_str();
 
         launcher = val;
         rulePlaceholderExpander->ExpandRuleVariables(this, launcher, vars);

+ 2 - 3
Source/cmake.cxx

@@ -2750,19 +2750,18 @@ int cmake::ActualConfigure()
         cmStrCat('"', cmSystemTools::GetCTestCommand(), "\" --instrument ");
     }
     std::string common_args =
-      cmStrCat(" --target-name <TARGET_NAME> --build-dir \"",
+      cmStrCat(" --target-name <TARGET_NAME> --config <CONFIG> --build-dir \"",
                this->State->GetBinaryDirectory(), "\" ");
     this->State->SetGlobalProperty(
       "RULE_LAUNCH_COMPILE",
       cmStrCat(
         launcher, "--command-type compile", common_args,
-        "--config <CONFIG> "
         "--output <OBJECT> --source <SOURCE> --language <LANGUAGE> -- "));
     this->State->SetGlobalProperty(
       "RULE_LAUNCH_LINK",
       cmStrCat(
         launcher, "--command-type link", common_args,
-        "--output <TARGET> --target-type <TARGET_TYPE> --config <CONFIG> "
+        "--output <TARGET> --target-type <TARGET_TYPE> "
         "--language <LANGUAGE> --target-labels \"<TARGET_LABELS>\" -- "));
     this->State->SetGlobalProperty(
       "RULE_LAUNCH_CUSTOM",

+ 16 - 3
Tests/RunCMake/Instrumentation/check-data-dir.cmake

@@ -87,8 +87,21 @@ foreach(snippet IN LISTS snippets)
   # Verify contents of custom-* Snippets
   if (filename MATCHES "^custom-")
     string(JSON outputs GET "${contents}" outputs)
-    if (NOT output1 MATCHES "output1" OR NOT output2 MATCHES "output2")
-      json_error("${snippet}" "Custom command missing outputs")
+    # if "outputs" is CMakeFiles/customTarget, should not have a "target"
+    if (outputs MATCHES "customTarget")
+      json_missing_key("${snippet}" "${contents}" target)
+    # if "outputs" is empty list, should have "target" main
+    elseif (outputs MATCHES "\\[\\]")
+      json_assert_key("${snippet}" "${contents}" target main)
+    # if "outputs" is includes output1, should also include output2, and no target
+    elseif (outputs MATCHES "output1")
+      if (NOT outputs MATCHES "output2")
+        json_error("${snippet}" "Custom command missing outputs")
+      endif()
+      json_missing_key("${snippet}" "${contents}" target)
+    # unrecognized outputs
+    else()
+      json_error("${snippet}" "Custom command has unexpected outputs\n${outputs}")
     endif()
   endif()
 
@@ -101,7 +114,7 @@ foreach(snippet IN LISTS snippets)
   endif()
 
   # Verify that Config is Debug
-  if (filename MATCHES "^test|^compile|^link")
+  if (filename MATCHES "^test|^compile|^link|^custom|^install")
     string(JSON config GET "${contents}" config)
     if (NOT config STREQUAL "Debug")
       json_error(${snippet} "Unexpected config: ${config}")

+ 4 - 0
Tests/RunCMake/Instrumentation/project/CMakeLists.txt

@@ -9,12 +9,16 @@ endif()
 add_executable(main main.cxx)
 add_library(lib lib.cxx)
 target_link_libraries(main lib)
+add_custom_command(TARGET main POST_BUILD
+  COMMAND ${CMAKE_COMMAND} -E true
+)
 add_custom_command(
   COMMAND ${CMAKE_COMMAND} -E true
   OUTPUT output1 output2
 )
 set_property(SOURCE output1 output2 PROPERTY SYMBOLIC 1)
 add_custom_target(customTarget ALL
+  COMMAND ${CMAKE_COMMAND} -E true
   DEPENDS output1
 )
 add_test(NAME test COMMAND $<TARGET_FILE:main>)

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

@@ -17,6 +17,7 @@ function(snippet_has_fields snippet contents)
     json_has_key("${snippet}" "${contents}" targetType)
     json_has_key("${snippet}" "${contents}" targetLabels)
     json_has_key("${snippet}" "${contents}" config)
+    json_has_key("${snippet}" "${contents}" language)
   elseif (filename MATCHES "^compile-*")
     json_has_key("${snippet}" "${contents}" target)
     json_has_key("${snippet}" "${contents}" outputs)
@@ -27,9 +28,12 @@ function(snippet_has_fields snippet contents)
   elseif (filename MATCHES "^custom-*")
     json_has_key("${snippet}" "${contents}" outputs)
     json_has_key("${snippet}" "${contents}" outputSizes)
+    json_has_key("${snippet}" "${contents}" config)
   elseif (filename MATCHES "^test-*")
     json_has_key("${snippet}" "${contents}" testName)
     json_has_key("${snippet}" "${contents}" config)
+  elseif (filename MATCHES "^install-*")
+    json_has_key("${snippet}" "${contents}" config)
   endif()
   if(ARGS_DYNAMIC_QUERY)
     json_has_key("${snippet}" "${contents}" dynamicSystemInformation)