mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-18 08:51:52 +08:00
instrumentation: Allow multiple CALLBACK arguments
Don't require quotes around CALLBACK argument and allow it to be passed multiple times.
This commit is contained in:
@@ -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
|
||||
``<build>/.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"
|
||||
]
|
||||
}
|
||||
|
@@ -80,8 +80,9 @@ void cmInstrumentation::ReadJSONQuery(std::string const& file)
|
||||
}
|
||||
|
||||
void cmInstrumentation::WriteJSONQuery(
|
||||
std::set<cmInstrumentationQuery::Query>& queries_,
|
||||
std::set<cmInstrumentationQuery::Hook>& hooks_, std::string& callback)
|
||||
std::set<cmInstrumentationQuery::Query> const& queries_,
|
||||
std::set<cmInstrumentationQuery::Hook> const& hooks_,
|
||||
std::vector<std::vector<std::string>> 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;
|
||||
|
@@ -41,9 +41,9 @@ public:
|
||||
bool HasPreOrPostBuildHook() const;
|
||||
bool ReadJSONQueries(std::string const& directory);
|
||||
void ReadJSONQuery(std::string const& file);
|
||||
void WriteJSONQuery(std::set<cmInstrumentationQuery::Query>& queries,
|
||||
std::set<cmInstrumentationQuery::Hook>& hooks,
|
||||
std::string& callback);
|
||||
void WriteJSONQuery(std::set<cmInstrumentationQuery::Query> const& queries,
|
||||
std::set<cmInstrumentationQuery::Hook> const& hooks,
|
||||
std::vector<std::vector<std::string>> const& callback);
|
||||
void ClearGeneratedQueries();
|
||||
int CollectTimingData(cmInstrumentationQuery::Hook hook);
|
||||
int SpawnBuildDaemon();
|
||||
|
@@ -81,7 +81,7 @@ bool cmInstrumentationCommand(std::vector<std::string> const& args,
|
||||
ArgumentParser::NonEmpty<std::string> DataVersion;
|
||||
ArgumentParser::NonEmpty<std::vector<std::string>> Queries;
|
||||
ArgumentParser::NonEmpty<std::vector<std::string>> Hooks;
|
||||
ArgumentParser::NonEmpty<std::vector<std::string>> Callback;
|
||||
ArgumentParser::NonEmpty<std::vector<std::vector<std::string>>> Callbacks;
|
||||
};
|
||||
|
||||
static auto const parser = cmArgumentParser<Arguments>{}
|
||||
@@ -89,7 +89,7 @@ bool cmInstrumentationCommand(std::vector<std::string> 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<std::string> unparsedArguments;
|
||||
Arguments const arguments = parser.Parse(args, &unparsedArguments);
|
||||
@@ -137,14 +137,10 @@ bool cmInstrumentationCommand(std::vector<std::string> 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;
|
||||
}
|
||||
|
@@ -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
|
||||
)
|
||||
|
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"callbacks" :
|
||||
[
|
||||
"\"@CMAKE_COMMAND@\" -E echo callback2"
|
||||
"\"@CMAKE_COMMAND@\" -E echo callback2",
|
||||
"\"@CMAKE_COMMAND@\" -E echo callback3"
|
||||
],
|
||||
"hooks" :
|
||||
[
|
||||
|
Reference in New Issue
Block a user