From 48292c8624b901a842b6d4f8a88ca00f898e5639 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 13 Jan 2023 11:55:56 -0500 Subject: try_compile: Record stack of in-progess checks in configure log Many `try_compile` and `try_run` calls occur inside check modules between `message(CHECK_START)` and `message(CHECK_{PASS,FAIL})` pairs. Add a field to configure log entries to report this context. Issue: #23200 --- Help/manual/cmake-configure-log.7.rst | 13 +++++++++++++ Source/cmConfigureLog.cxx | 16 ++++++++++++++++ Source/cmConfigureLog.h | 1 + Source/cmTryCompileCommand.cxx | 1 + Source/cmTryRunCommand.cxx | 1 + Source/cmake.h | 4 ++++ Tests/RunCMake/try_compile/ConfigureLog-config.txt | 5 +++++ Tests/RunCMake/try_compile/ConfigureLog-stdout.txt | 4 ++++ Tests/RunCMake/try_compile/ConfigureLog.cmake | 9 +++++++++ Tests/RunCMake/try_compile/Inspect-config.txt | 4 ++++ Tests/RunCMake/try_run/ConfigureLog-config.txt | 7 +++++++ Tests/RunCMake/try_run/ConfigureLog-stdout.txt | 4 ++++ Tests/RunCMake/try_run/ConfigureLog.cmake | 9 +++++++++ 13 files changed, 78 insertions(+) create mode 100644 Tests/RunCMake/try_compile/ConfigureLog-stdout.txt create mode 100644 Tests/RunCMake/try_run/ConfigureLog-stdout.txt diff --git a/Help/manual/cmake-configure-log.7.rst b/Help/manual/cmake-configure-log.7.rst index 98f20ff..2620124 100644 --- a/Help/manual/cmake-configure-log.7.rst +++ b/Help/manual/cmake-configure-log.7.rst @@ -106,6 +106,8 @@ Every event kind is represented by a YAML mapping of the form: kind: "-v" backtrace: - ": ()" + checks: + - "Checking for something" #...event-specific keys... The keys common to all events are: @@ -119,6 +121,13 @@ The keys common to all events are: least-recent. Each node is a string specifying one location formatted as ``: ()``. +``checks`` + An optional key that is present when the event occurred with + at least one pending :command:`message(CHECK_START)`. Its value + is a YAML block sequence reporting the stack of pending checks, + from most-recent to least-recent. Each node is a string containing + a pending check message. + Additional mapping keys are specific to each (versioned) event kind, described below. @@ -141,6 +150,8 @@ A ``try_compile-v1`` event is a YAML mapping: kind: "try_compile-v1" backtrace: - "CMakeLists.txt:123 (try_compile)" + checks: + - "Checking for something" description: "Explicit LOG_DESCRIPTION" directories: source: "/path/to/.../TryCompile-01234" @@ -212,6 +223,8 @@ A ``try_run-v1`` event is a YAML mapping: kind: "try_run-v1" backtrace: - "CMakeLists.txt:456 (try_run)" + checks: + - "Checking for something" description: "Explicit LOG_DESCRIPTION" directories: source: "/path/to/.../TryCompile-56789" diff --git a/Source/cmConfigureLog.cxx b/Source/cmConfigureLog.cxx index c2a5b5e..1b00b4f 100644 --- a/Source/cmConfigureLog.cxx +++ b/Source/cmConfigureLog.cxx @@ -17,6 +17,7 @@ #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmRange.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmake.h" @@ -78,6 +79,21 @@ void cmConfigureLog::WriteBacktrace(cmMakefile const& mf) this->WriteValue("backtrace"_s, backtrace); } +void cmConfigureLog::WriteChecks(cmMakefile const& mf) +{ + if (!mf.GetCMakeInstance()->HasCheckInProgress()) { + return; + } + this->BeginObject("checks"_s); + for (auto const& value : + cmReverseRange(mf.GetCMakeInstance()->GetCheckInProgressMessages())) { + this->BeginLine() << "- "; + this->Encoder->write(value, &this->Stream); + this->EndLine(); + } + this->EndObject(); +} + void cmConfigureLog::EnsureInit() { if (this->Opened) { diff --git a/Source/cmConfigureLog.h b/Source/cmConfigureLog.h index 9caac66..d672445 100644 --- a/Source/cmConfigureLog.h +++ b/Source/cmConfigureLog.h @@ -29,6 +29,7 @@ public: bool IsAnyLogVersionEnabled(std::vector const& v) const; void WriteBacktrace(cmMakefile const& mf); + void WriteChecks(cmMakefile const& mf); void EnsureInit(); diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx index ebbb4f2..789ffe9 100644 --- a/Source/cmTryCompileCommand.cxx +++ b/Source/cmTryCompileCommand.cxx @@ -27,6 +27,7 @@ void WriteTryCompileEvent(cmConfigureLog& log, cmMakefile const& mf, if (log.IsAnyLogVersionEnabled(LogVersionsWithTryCompileV1)) { log.BeginEvent("try_compile-v1"); log.WriteBacktrace(mf); + log.WriteChecks(mf); cmCoreTryCompile::WriteTryCompileEventFields(log, compileResult); log.EndEvent(); } diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index a8e8b48..21bd95a 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -46,6 +46,7 @@ void WriteTryRunEvent(cmConfigureLog& log, cmMakefile const& mf, if (log.IsAnyLogVersionEnabled(LogVersionsWithTryRunV1)) { log.BeginEvent("try_run-v1"); log.WriteBacktrace(mf); + log.WriteChecks(mf); cmCoreTryCompile::WriteTryCompileEventFields(log, compileResult); log.BeginObject("runResult"_s); diff --git a/Source/cmake.h b/Source/cmake.h index 12160ad..d1f388a 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -479,6 +479,10 @@ public: { this->CheckInProgressMessages.emplace_back(std::move(message)); } + std::vector const& GetCheckInProgressMessages() const + { + return this->CheckInProgressMessages; + } //! Should `message` command display context. bool GetShowLogContext() const { return this->LogContext; } diff --git a/Tests/RunCMake/try_compile/ConfigureLog-config.txt b/Tests/RunCMake/try_compile/ConfigureLog-config.txt index caf8a71..262ed3c 100644 --- a/Tests/RunCMake/try_compile/ConfigureLog-config.txt +++ b/Tests/RunCMake/try_compile/ConfigureLog-config.txt @@ -8,6 +8,8 @@ events: - "[^"]*/Modules/CMakeTestCCompiler.cmake:[0-9]+ \(CMAKE_DETERMINE_COMPILER_ABI\)" - "ConfigureLog.cmake:[0-9]+ \(enable_language\)" - "CMakeLists.txt:[0-9]+ \(include\)" + checks: + - "Detecting C compiler ABI info" directories: source: "[^"]*/Tests/RunCMake/try_compile/ConfigureLog-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" binary: "[^"]*/Tests/RunCMake/try_compile/ConfigureLog-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" @@ -35,6 +37,9 @@ events: backtrace: - "ConfigureLog.cmake:[0-9]+ \(try_compile\)" - "CMakeLists.txt:[0-9]+ \(include\)" + checks: + - "Check 2" + - "Check 1" description: "Source that should compile\." directories: source: "[^"]*/Tests/RunCMake/try_compile/ConfigureLog-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" diff --git a/Tests/RunCMake/try_compile/ConfigureLog-stdout.txt b/Tests/RunCMake/try_compile/ConfigureLog-stdout.txt new file mode 100644 index 0000000..ba32642 --- /dev/null +++ b/Tests/RunCMake/try_compile/ConfigureLog-stdout.txt @@ -0,0 +1,4 @@ +-- Check 1 +-- Check 2 +-- Check 2 - passed +-- Check 1 - passed diff --git a/Tests/RunCMake/try_compile/ConfigureLog.cmake b/Tests/RunCMake/try_compile/ConfigureLog.cmake index 511ade9..294e0f9 100644 --- a/Tests/RunCMake/try_compile/ConfigureLog.cmake +++ b/Tests/RunCMake/try_compile/ConfigureLog.cmake @@ -10,7 +10,16 @@ try_compile(COMPILE_RESULT NO_LOG ) +message(CHECK_START "Check 1") +message(CHECK_START "Check 2") try_compile(COMPILE_RESULT SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureLog-test.c LOG_DESCRIPTION "Source that should compile." ) +if (COMPILE_RESULT) + message(CHECK_PASS "passed") + message(CHECK_PASS "passed") +else() + message(CHECK_FAIL "failed") + message(CHECK_FAIL "failed") +endif() diff --git a/Tests/RunCMake/try_compile/Inspect-config.txt b/Tests/RunCMake/try_compile/Inspect-config.txt index 47169cf..e09fe55 100644 --- a/Tests/RunCMake/try_compile/Inspect-config.txt +++ b/Tests/RunCMake/try_compile/Inspect-config.txt @@ -8,6 +8,8 @@ events: - "[^"]*/Modules/CMakeTestCCompiler.cmake:[0-9]+ \(CMAKE_DETERMINE_COMPILER_ABI\)" - "Inspect.cmake:[0-9]+ \(enable_language\)" - "CMakeLists.txt:[0-9]+ \(include\)" + checks: + - "Detecting C compiler ABI info" directories: source: "[^"]*/Tests/RunCMake/try_compile/Inspect-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" binary: "[^"]*/Tests/RunCMake/try_compile/Inspect-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" @@ -23,6 +25,8 @@ events: - "[^"]*/Modules/CMakeTestCXXCompiler.cmake:[0-9]+ \(CMAKE_DETERMINE_COMPILER_ABI\)" - "Inspect.cmake:[0-9]+ \(enable_language\)" - "CMakeLists.txt:[0-9]+ \(include\)" + checks: + - "Detecting CXX compiler ABI info" directories: source: "[^"]*/Tests/RunCMake/try_compile/Inspect-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" binary: "[^"]*/Tests/RunCMake/try_compile/Inspect-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" diff --git a/Tests/RunCMake/try_run/ConfigureLog-config.txt b/Tests/RunCMake/try_run/ConfigureLog-config.txt index 18903d8..ba396e0 100644 --- a/Tests/RunCMake/try_run/ConfigureLog-config.txt +++ b/Tests/RunCMake/try_run/ConfigureLog-config.txt @@ -7,6 +7,8 @@ events: - "[^"]*/Modules/CMakeDetermineCompilerABI.cmake:[0-9]+ \(try_compile\)" - "[^"]*/Modules/CMakeTestCCompiler.cmake:[0-9]+ \(CMAKE_DETERMINE_COMPILER_ABI\)" - "CMakeLists.txt:[0-9]+ \(project\)" + checks: + - "Detecting C compiler ABI info" directories: source: "[^"]*/Tests/RunCMake/try_run/ConfigureLog-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" binary: "[^"]*/Tests/RunCMake/try_run/ConfigureLog-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" @@ -37,6 +39,8 @@ events: backtrace: - "ConfigureLog.cmake:[0-9]+ \(try_run\)" - "CMakeLists.txt:[0-9]+ \(include\)" + checks: + - "Check 1" description: "Source that should compile\." directories: source: "[^"]*/Tests/RunCMake/try_run/ConfigureLog-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" @@ -59,6 +63,9 @@ events: backtrace: - "ConfigureLog.cmake:[0-9]+ \(try_run\)" - "CMakeLists.txt:[0-9]+ \(include\)" + checks: + - "Check 2" + - "Check 1" directories: source: "[^"]*/Tests/RunCMake/try_run/ConfigureLog-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" binary: "[^"]*/Tests/RunCMake/try_run/ConfigureLog-build/CMakeFiles/CMakeScratch/TryCompile-[^/]+" diff --git a/Tests/RunCMake/try_run/ConfigureLog-stdout.txt b/Tests/RunCMake/try_run/ConfigureLog-stdout.txt new file mode 100644 index 0000000..ba32642 --- /dev/null +++ b/Tests/RunCMake/try_run/ConfigureLog-stdout.txt @@ -0,0 +1,4 @@ +-- Check 1 +-- Check 2 +-- Check 2 - passed +-- Check 1 - passed diff --git a/Tests/RunCMake/try_run/ConfigureLog.cmake b/Tests/RunCMake/try_run/ConfigureLog.cmake index e39310c..6635d73 100644 --- a/Tests/RunCMake/try_run/ConfigureLog.cmake +++ b/Tests/RunCMake/try_run/ConfigureLog.cmake @@ -8,15 +8,24 @@ try_run(RUN_RESULT COMPILE_RESULT NO_LOG ) +message(CHECK_START "Check 1") try_run(RUN_RESULT COMPILE_RESULT SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureLog-test.c LOG_DESCRIPTION "Source that should compile." ) +message(CHECK_START "Check 2") try_run(RUN_RESULT COMPILE_RESULT SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureLog-test.c RUN_OUTPUT_VARIABLE RUN_OUTPUT ) +if (RUN_RESULT) + message(CHECK_PASS "passed") + message(CHECK_PASS "passed") +else() + message(CHECK_FAIL "failed") + message(CHECK_FAIL "failed") +endif() try_run(RUN_RESULT COMPILE_RESULT SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ConfigureLog-test.c -- cgit v0.12