diff --git a/Help/command/cmake_instrumentation.rst b/Help/command/cmake_instrumentation.rst index 4eb0c22ed4..75427d4963 100644 --- a/Help/command/cmake_instrumentation.rst +++ b/Help/command/cmake_instrumentation.rst @@ -23,8 +23,8 @@ only supported value for both fields is 1. See :ref:`cmake-instrumentation v1` for details of the data output content and location. Each of the optional keywords ``HOOKS``, ``QUERIES``, and ``CALLBACK`` -correspond to one of the parameters to the :ref:`cmake-instrumentation v1 Query Files`. Note that the -``CALLBACK`` keyword only accepts a single callback. +correspond to one of the parameters to the :ref:`cmake-instrumentation v1 Query Files`. +The ``CALLBACK`` keyword can be provided multiple times to create multiple callbacks. Whenever ``cmake_instrumentation`` is invoked, a query file is generated in ``/.cmake/timing/v1/query/generated`` to enable instrumentation @@ -43,7 +43,8 @@ equivalent JSON query file. DATA_VERSION 1 HOOKS postGenerate preCMakeBuild postCMakeBuild QUERIES staticSystemInformation dynamicSystemInformation - CALLBACK "${CMAKE_COMMAND} -P /path/to/handle_data.cmake" + CALLBACK ${CMAKE_COMMAND} -P /path/to/handle_data.cmake + CALLBACK ${CMAKE_COMMAND} -P /path/to/handle_data_2.cmake ) .. code-block:: json @@ -58,5 +59,6 @@ equivalent JSON query file. ], "callbacks": [ "/path/to/cmake -P /path/to/handle_data.cmake" + "/path/to/cmake -P /path/to/handle_data_2.cmake" ] } diff --git a/Source/cmInstrumentation.cxx b/Source/cmInstrumentation.cxx index 245195f8a1..5877323287 100644 --- a/Source/cmInstrumentation.cxx +++ b/Source/cmInstrumentation.cxx @@ -80,8 +80,9 @@ void cmInstrumentation::ReadJSONQuery(std::string const& file) } void cmInstrumentation::WriteJSONQuery( - std::set& queries_, - std::set& hooks_, std::string& callback) + std::set const& queries_, + std::set const& hooks_, + std::vector> const& callbacks_) { Json::Value root; root["version"] = 1; @@ -94,8 +95,8 @@ void cmInstrumentation::WriteJSONQuery( root["hooks"].append(cmInstrumentationQuery::HookString[hook]); } root["callbacks"] = Json::arrayValue; - if (!callback.empty()) { - root["callbacks"].append(callback); + for (auto const& callback : callbacks_) { + root["callbacks"].append(cmInstrumentation::GetCommandStr(callback)); } cmsys::Directory d; int n = 0; @@ -455,7 +456,7 @@ std::string cmInstrumentation::GetCommandStr( for (size_t i = 0; i < args.size(); ++i) { command_str = cmStrCat(command_str, args[i]); if (i < args.size() - 1) { - command_str = cmStrCat(command_str, " "); + command_str = cmStrCat(command_str, ' '); } } return command_str; diff --git a/Source/cmInstrumentation.h b/Source/cmInstrumentation.h index e9eceacad0..d17e99c30d 100644 --- a/Source/cmInstrumentation.h +++ b/Source/cmInstrumentation.h @@ -41,9 +41,9 @@ public: bool HasPreOrPostBuildHook() const; bool ReadJSONQueries(std::string const& directory); void ReadJSONQuery(std::string const& file); - void WriteJSONQuery(std::set& queries, - std::set& hooks, - std::string& callback); + void WriteJSONQuery(std::set const& queries, + std::set const& hooks, + std::vector> const& callback); void ClearGeneratedQueries(); int CollectTimingData(cmInstrumentationQuery::Hook hook); int SpawnBuildDaemon(); diff --git a/Source/cmInstrumentationCommand.cxx b/Source/cmInstrumentationCommand.cxx index 406ced8ce7..3b530ee73b 100644 --- a/Source/cmInstrumentationCommand.cxx +++ b/Source/cmInstrumentationCommand.cxx @@ -81,7 +81,7 @@ bool cmInstrumentationCommand(std::vector const& args, ArgumentParser::NonEmpty DataVersion; ArgumentParser::NonEmpty> Queries; ArgumentParser::NonEmpty> Hooks; - ArgumentParser::NonEmpty> Callback; + ArgumentParser::NonEmpty>> Callbacks; }; static auto const parser = cmArgumentParser{} @@ -89,7 +89,7 @@ bool cmInstrumentationCommand(std::vector const& args, .Bind("DATA_VERSION"_s, &Arguments::DataVersion) .Bind("QUERIES"_s, &Arguments::Queries) .Bind("HOOKS"_s, &Arguments::Hooks) - .Bind("CALLBACK"_s, &Arguments::Callback); + .Bind("CALLBACK"_s, &Arguments::Callbacks); std::vector unparsedArguments; Arguments const arguments = parser.Parse(args, &unparsedArguments); @@ -137,14 +137,10 @@ bool cmInstrumentationCommand(std::vector const& args, hooks.insert(hook); } - std::string callback; - for (auto const& arg : arguments.Callback) { - callback = cmStrCat(callback, arg); - } - status.GetMakefile() .GetCMakeInstance() ->GetInstrumentation() - ->WriteJSONQuery(queries, hooks, callback); + ->WriteJSONQuery(queries, hooks, arguments.Callbacks); + return true; } diff --git a/Tests/RunCMake/Instrumentation/query/cmake-command.cmake b/Tests/RunCMake/Instrumentation/query/cmake-command.cmake index dbbebb1215..3f66de5f3d 100644 --- a/Tests/RunCMake/Instrumentation/query/cmake-command.cmake +++ b/Tests/RunCMake/Instrumentation/query/cmake-command.cmake @@ -8,7 +8,7 @@ API_VERSION 1 DATA_VERSION 1 HOOKS postGenerate - CALLBACK "\"${CMAKE_COMMAND}\" -E echo callback1" + CALLBACK \"${CMAKE_COMMAND}\" -E echo callback1 ) # Query 2 cmake_instrumentation( @@ -16,5 +16,6 @@ DATA_VERSION 1 HOOKS postCMakeBuild QUERIES staticSystemInformation dynamicSystemInformation - CALLBACK "\"${CMAKE_COMMAND}\" -E echo callback2" + CALLBACK \"${CMAKE_COMMAND}\" -E echo callback2 + CALLBACK \"${CMAKE_COMMAND}\" -E echo callback3 ) diff --git a/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in b/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in index 0e2bd317e5..3591633222 100644 --- a/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in +++ b/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in @@ -1,7 +1,8 @@ { "callbacks" : [ - "\"@CMAKE_COMMAND@\" -E echo callback2" + "\"@CMAKE_COMMAND@\" -E echo callback2", + "\"@CMAKE_COMMAND@\" -E echo callback3" ], "hooks" : [