diff --git a/Source/cmInstrumentation.cxx b/Source/cmInstrumentation.cxx index 5d2755fd5d..f8dfc27e9a 100644 --- a/Source/cmInstrumentation.cxx +++ b/Source/cmInstrumentation.cxx @@ -1098,8 +1098,16 @@ std::string cmInstrumentation::GetCompileTraceFile( outputPath.substr(0, outputPath.size() - ext.size()), ".json"); } } - if (!cmSystemTools::FileIsFullPath(traceFile)) { - traceFile = cmStrCat(workingDir, '/', traceFile); + + if (cmSystemTools::FileIsFullPath(traceFile)) { + return traceFile; + } + if (cmSystemTools::FileExists(cmStrCat(workingDir, '/', traceFile), true)) { + return cmStrCat(workingDir, '/', traceFile); + } + if (cmSystemTools::FileExists(cmStrCat(this->binaryDir, '/', traceFile), + true)) { + return cmStrCat(this->binaryDir, '/', traceFile); } return traceFile; diff --git a/Source/cmInstrumentation.h b/Source/cmInstrumentation.h index a4d9132ac0..fc468b094d 100644 --- a/Source/cmInstrumentation.h +++ b/Source/cmInstrumentation.h @@ -119,9 +119,9 @@ private: static bool IsInstrumentableTargetType(cmStateEnums::TargetType type); void PrepareDataForCDash(std::string const& data_dir, std::string const& index_path); - static std::string GetCompileTraceFile( - std::vector const& command, Json::Value const& outputs, - std::string const& workingDir); + std::string GetCompileTraceFile(std::vector const& command, + Json::Value const& outputs, + std::string const& workingDir); void CollectCompileTraceFile(Json::Value& root, std::string traceFile, long int oldTimestamp, std::string const& commandHash, diff --git a/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake b/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake index 8c06d7923f..ee0a82fd93 100644 --- a/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake +++ b/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake @@ -8,6 +8,7 @@ function(instrument test) set(OPTIONS "BUILD" "BUILD_MAKE_PROGRAM" + "BUILD_MAKE_PROGRAM_CHANGE_DIR" "INSTALL" "INSTALL_PARALLEL" "TEST" @@ -181,7 +182,13 @@ function(instrument test) set(RunCMake_QUIET_ERROR 1) # Force reconfigure to test for double preBuild & postBuild hooks file(TOUCH ${RunCMake_TEST_BINARY_DIR}/CMakeCache.txt) - run_cmake_command(${test}-make-program ${RunCMake_MAKE_PROGRAM}) + if (ARGS_BUILD_MAKE_PROGRAM_CHANGE_DIR) + set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY ${RunCMake_BINARY_DIR}) + run_cmake_command(${test}-make-program ${RunCMake_MAKE_PROGRAM} -C ${RunCMake_TEST_BINARY_DIR}) + unset(RunCMake_TEST_COMMAND_WORKING_DIRECTORY) + else() + run_cmake_command(${test}-make-program ${RunCMake_MAKE_PROGRAM}) + endif() unset(RunCMake_TEST_OUTPUT_MERGE) unset(RunCMake_QUIET_ERROR) endif() @@ -434,4 +441,13 @@ if(NOT Skip_BUILD_MAKE_PROGRAM_Case) instrument(cmake-command-build-snippet BUILD_MAKE_PROGRAM CHECK_SCRIPT check-data-dir.cmake) + if (NOT Skip_COMPILE_TRACE_QUERY_Case AND NOT RunCMake_GENERATOR STREQUAL "NMake Makefiles") + instrument(cmake-command-compile-trace-make-program + BUILD_MAKE_PROGRAM BUILD_MAKE_PROGRAM_CHANGE_DIR COMPILE_TRACE_QUERY + CONFIGURE_ARGS + "-DINSTRUMENT_COMPILE_TRACE=DEFAULT" + "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" + CHECK_SCRIPT check-data-dir.cmake + ) + endif() endif() diff --git a/Tests/RunCMake/Instrumentation/query/cmake-command-compile-trace-make-program.cmake b/Tests/RunCMake/Instrumentation/query/cmake-command-compile-trace-make-program.cmake new file mode 100644 index 0000000000..110de96273 --- /dev/null +++ b/Tests/RunCMake/Instrumentation/query/cmake-command-compile-trace-make-program.cmake @@ -0,0 +1,5 @@ +cmake_instrumentation( + API_VERSION 1 + DATA_VERSION 1 + OPTIONS compileTrace +)