cpack: Record CMake listfile coverage

The CPack generator modules, the CPack configuration file and the install
scripts that cpack runs to make a package are CMake language code, but
only cpack runs them.  Start recording when cpack starts its work, as
ctest does, and write the tracefile on every return.  The help and
version options record nothing.

Issue: #28192
This commit is contained in:
Mickaël Germain committed 2026-11-02 08:19:40 -08:00
1 parent d602bd63b0
commit 54dc4d7bcc
5 files changed
+37 -2

No files matched your search

+5 -2
View File
@@ -40,6 +40,8 @@ These modes record coverage:
as ``CTestTestfile.cmake`` files and :ref:`Dashboard Client` scripts.
To record coverage for each test instead, use the ``CMAKE`` value of the
CTest :ref:`CoverageTool <ctest-CoverageTool>` setting.
* :manual:`cpack(1)`, for the CPack configuration file, the CPack generator
modules and the install scripts that it runs to make a package.
These modes do not record coverage and do not check the directory:
@@ -47,8 +49,9 @@ These modes do not record coverage and do not check the directory:
* :option:`cmake --build` and the :option:`cmake -E` commands. This
includes ``cmake -E cmake_depends``, which reads files that CMake
generates.
* :option:`cmake --help`, :option:`cmake --version`, :option:`ctest --help`
and :option:`ctest --version`.
* :option:`cmake --help`, :option:`cmake --version`, :option:`ctest --help`,
:option:`ctest --version`, :option:`cpack --help` and
:option:`cpack --version`.
* ``cmake --system-information``.
* ``cmake --check-build-system``, which the build system runs to check
whether it must re-run configure. If the check decides to re-run
+15
View File
@@ -29,6 +29,7 @@
#include "cmGlobalGenerator.h"
#include "cmJSONState.h"
#include "cmList.h"
#include "cmListFileCoverage.h"
#include "cmMakefile.h"
#include "cmState.h"
#include "cmStateSnapshot.h"
@@ -86,6 +87,11 @@ std::vector<cmDocumentationEntry> makeGeneratorDocs(
return docs;
}
// Write the CMake listfile coverage of this process on every return.
struct ListFileCoverageFinisher
{
~ListFileCoverageFinisher() { cmListFileCoverage::Finish(); }
};
} // namespace
// this is CPack.
@@ -444,7 +450,16 @@ int main(int argc, char const* const* argv)
// This part is used for cpack documentation lookup as well.
cminst.AddCMakePaths();
ListFileCoverageFinisher const coverageFinisher{};
if (parsed && !help) {
// Record coverage of the CMake code that cpack runs, such as the CPack
// generator modules and the install scripts of the project.
std::string error;
if (!cmListFileCoverage::Start(error)) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, error << '\n');
return 1;
}
// find out which system cpack is running on, so it can setup the search
// paths, so FIND_XXX() commands can be used in scripts
std::string systemFile =
@@ -0,0 +1,6 @@
# cpack records its configuration file and the install scripts it runs.
set(expect_sf_regex
"/CPackConfig\\.cmake$"
"/cmake_install\\.cmake$"
)
include(${RunCMake_SOURCE_DIR}/check-lcov.cmake)
@@ -0,0 +1,2 @@
install(CODE "set(installed 1)")
include(CPack)
@@ -75,6 +75,15 @@ block()
${CMAKE_COMMAND} --install . --prefix ${RunCMake_TEST_BINARY_DIR}/prefix)
endblock()
# Package a project. Only cpack records.
block()
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CPack-build)
run_cmake(CPack)
set(RunCMake_TEST_NO_CLEAN 1)
run_coverage(CPack-package COMMAND run_cmake_command CPack-package
${CMAKE_CPACK_COMMAND} -G TGZ -C Debug)
endblock()
# Modes that do not record. The variable is set only in the child, so no
# driver process creates the directory.
function(run_no_record case dir)