diff --git a/Help/manual/cmake-instrumentation.7.rst b/Help/manual/cmake-instrumentation.7.rst index a551212375..6e32ad38c1 100644 --- a/Help/manual/cmake-instrumentation.7.rst +++ b/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 diff --git a/Source/cmFastbuildTargetGenerator.cxx b/Source/cmFastbuildTargetGenerator.cxx index 54c05accd5..f52ac99700 100644 --- a/Source/cmFastbuildTargetGenerator.cxx +++ b/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(); diff --git a/Source/cmInstallScriptHandler.cxx b/Source/cmInstallScriptHandler.cxx index 5bcca67adc..5fc2b35a94 100644 --- a/Source/cmInstallScriptHandler.cxx +++ b/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.command.insert(script.command.begin(), instrument_arg.begin(), instrument_arg.end()); runners.emplace_back(script); diff --git a/Source/cmInstrumentation.cxx b/Source/cmInstrumentation.cxx index edc1c30eb3..92cf4979a8 100644 --- a/Source/cmInstrumentation.cxx +++ b/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"] = ""; } diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index a1b9c34895..56a6aa1922 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/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(); diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index c3d6ac71b3..fd491219b6 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/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); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index c367563503..234aa805a9 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2750,19 +2750,18 @@ int cmake::ActualConfigure() cmStrCat('"', cmSystemTools::GetCTestCommand(), "\" --instrument "); } std::string common_args = - cmStrCat(" --target-name --build-dir \"", + cmStrCat(" --target-name --config --build-dir \"", this->State->GetBinaryDirectory(), "\" "); this->State->SetGlobalProperty( "RULE_LAUNCH_COMPILE", cmStrCat( launcher, "--command-type compile", common_args, - "--config " "--output --source --language -- ")); this->State->SetGlobalProperty( "RULE_LAUNCH_LINK", cmStrCat( launcher, "--command-type link", common_args, - "--output --target-type --config " + "--output --target-type " "--language --target-labels \"\" -- ")); this->State->SetGlobalProperty( "RULE_LAUNCH_CUSTOM", diff --git a/Tests/RunCMake/Instrumentation/check-data-dir.cmake b/Tests/RunCMake/Instrumentation/check-data-dir.cmake index bbbc8f397f..f90bde22a9 100644 --- a/Tests/RunCMake/Instrumentation/check-data-dir.cmake +++ b/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}") diff --git a/Tests/RunCMake/Instrumentation/project/CMakeLists.txt b/Tests/RunCMake/Instrumentation/project/CMakeLists.txt index 7d8982c83e..80fd14bbad 100644 --- a/Tests/RunCMake/Instrumentation/project/CMakeLists.txt +++ b/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 $) diff --git a/Tests/RunCMake/Instrumentation/verify-snippet.cmake b/Tests/RunCMake/Instrumentation/verify-snippet.cmake index 0139b68ade..37913f56e4 100644 --- a/Tests/RunCMake/Instrumentation/verify-snippet.cmake +++ b/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)