Merge topic 'instrumentation-quote-command'

4e7b37cad3 instrumentation: Quote command arguments to preserve separation
99cd4d979b CTest: Fix startTime in test snippets when using instrumentation

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10386
This commit is contained in:
Brad King
2025-02-25 14:38:36 +00:00
committed by Kitware Robot
8 changed files with 11 additions and 10 deletions

View File

@@ -369,7 +369,7 @@ Example:
{
"version": 1,
"command" : "/usr/bin/c++ -MD -MT CMakeFiles/main.dir/main.cxx.o -MF CMakeFiles/main.dir/main.cxx.o.d -o CMakeFiles/main.dir/main.cxx.o -c <src>/main.cxx",
"command" : "\"/usr/bin/c++\" \"-MD\" \"-MT\" \"CMakeFiles/main.dir/main.cxx.o\" \"-MF\" \"CMakeFiles/main.dir/main.cxx.o.d\" \"-o\" \"CMakeFiles/main.dir/main.cxx.o\" \"-c\" \"<src>/main.cxx\"",
"role" : "compile",
"return" : 1,
"target": "main",

View File

@@ -57,6 +57,7 @@ bool cmProcess::StartProcess(uv_loop_t& loop, std::vector<size_t>* affinity)
return false;
}
this->StartTime = std::chrono::steady_clock::now();
this->SystemStartTime = std::chrono::system_clock::now();
this->ProcessArgs.clear();
// put the command as arg0
this->ProcessArgs.push_back(this->Command.c_str());

View File

@@ -538,7 +538,7 @@ std::string cmInstrumentation::GetCommandStr(
{
std::string command_str;
for (size_t i = 0; i < args.size(); ++i) {
command_str = cmStrCat(command_str, args[i]);
command_str = cmStrCat(command_str, '"', args[i], '"');
if (i < args.size() - 1) {
command_str = cmStrCat(command_str, ' ');
}

View File

@@ -111,7 +111,7 @@ foreach(snippet IN LISTS snippets)
# Verify command args were passed
if (filename MATCHES "^cmakeBuild|^ctest")
string(JSON command GET "${contents}" command)
if (NOT command MATCHES "-.* Debug")
if (NOT command MATCHES "Debug")
snippet_error(${snippet} "Command value missing passed arguments")
endif()
endif()

View File

@@ -3,5 +3,5 @@ cmake_instrumentation(
API_VERSION 1
DATA_VERSION 1
HOOKS preBuild postBuild
CALLBACK "\"${CMAKE_COMMAND}\" -P \"${hook_path}\" 0"
CALLBACK ${CMAKE_COMMAND} -P ${hook_path} 0
)

View File

@@ -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,6 +16,6 @@
DATA_VERSION 1
HOOKS postCMakeBuild
QUERIES staticSystemInformation dynamicSystemInformation
CALLBACK \"${CMAKE_COMMAND}\" -E echo callback2
CALLBACK \"${CMAKE_COMMAND}\" -E echo callback3
CALLBACK ${CMAKE_COMMAND} -E echo callback2
CALLBACK ${CMAKE_COMMAND} -E echo callback3
)

View File

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

View File

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