instrumentation: Gather compile trace files in compile rsp

Updates instrumentation logic for gathering compile trace files to parse
compiler options in a response file for the presence of `-ftime-trace=...`.
This commit is contained in:
Martin Duffy
2026-07-01 12:52:15 -04:00
parent 19d5579d67
commit 89b1e21a5e
3 changed files with 18 additions and 5 deletions
+3 -1
View File
@@ -1121,7 +1121,9 @@ std::string cmInstrumentation::GetCompileTraceFile(
{
cm::string_view const prefix = "-ftime-trace=";
std::string traceFile;
for (auto it = command.rbegin(); it != command.rend(); ++it) {
std::vector<std::string> fullCommand =
cmSystemTools::HandleResponseFile(command.cbegin(), command.cend());
for (auto it = fullCommand.rbegin(); it != fullCommand.rend(); ++it) {
std::string const& arg = *it;
if (cmHasPrefix(arg, prefix)) {
traceFile = arg.substr(prefix.size());
@@ -443,10 +443,6 @@ if("$ENV{CMAKE_OSX_ARCHITECTURES}" MATCHES "[;$]")
# `-ftime-trace` with multiple `-arch` puts the trace file in TMPDIR.
set(Skip_COMPILE_TRACE_QUERY_Case 1)
endif()
if(RunCMake_GENERATOR MATCHES "NMake")
# `-ftime-trace=` is hidden by `@<< ... <<` response file syntax.
set(Skip_COMPILE_TRACE_QUERY_ARG_Case 1)
endif()
if (NOT Skip_COMPILE_TRACE_QUERY_Case)
instrument(cmake-command-compile-trace
BUILD COMPILE_TRACE_QUERY
@@ -468,6 +464,16 @@ if (NOT Skip_COMPILE_TRACE_QUERY_Case)
CHECK_SCRIPT check-data-dir.cmake
)
endif()
if (RunCMake_GENERATOR MATCHES "Ninja" AND NOT CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
instrument(cmake-command-compile-trace-rsp
BUILD COMPILE_TRACE_QUERY
CONFIGURE_ARGS
"-DINSTRUMENT_COMPILE_TRACE=EXPLICIT"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_NINJA_FORCE_RESPONSE_FILE=ON"
CHECK_SCRIPT check-data-dir.cmake
)
endif()
endif()
# Test that interrupting `cmake --build` still writes the cmakeBuild snippet,
@@ -0,0 +1,5 @@
cmake_instrumentation(
API_VERSION 1
DATA_VERSION 1
OPTIONS compileTrace
)