CPack: Introduce pre- and post- build actions
CPack learned the `CPACK_PRE_BUILD_SCRIPTS`, `CPACK_POST_BUILD_SCRIPTS`, and `CPACK_PACKAGE_FILES` variables. The first two are lists of scripts to perform - after pre-install files into a staging directory and before producing the resulting packages - after produsing the packages The post-build script(s) also get the list of actually produced packages in the `CPACK_PACKAGE_FILES`. Issue: #19077
This commit is contained in:
parent
43b10e2411
commit
915409af49
5
Help/release/dev/cpack-pre-and-post-build-scripts.rst
Normal file
5
Help/release/dev/cpack-pre-and-post-build-scripts.rst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
cpack-pre-and-post-build-scripts
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
* CPack learned the :variable:`CPACK_PRE_BUILD_SCRIPTS`, :variable:`CPACK_POST_BUILD_SCRIPTS`,
|
||||||
|
and :variable:`CPACK_PACKAGE_FILES` variables.
|
@ -386,6 +386,21 @@ The following variables are for advanced uses of CPack:
|
|||||||
select the CPack generator(s) to be used when building the ``package``
|
select the CPack generator(s) to be used when building the ``package``
|
||||||
target or when running :manual:`cpack <cpack(1)>` without the ``-G`` option.
|
target or when running :manual:`cpack <cpack(1)>` without the ``-G`` option.
|
||||||
|
|
||||||
|
.. variable:: CPACK_PRE_BUILD_SCRIPTS
|
||||||
|
|
||||||
|
List of CMake scripts to execute after CPack has installed the files to
|
||||||
|
be packed into a staging directory and before producing the result
|
||||||
|
packages.
|
||||||
|
|
||||||
|
.. variable:: CPACK_POST_BUILD_SCRIPTS
|
||||||
|
|
||||||
|
List of CMake scripts to execute after CPack has produced the result
|
||||||
|
packages and before copying them back to a build directory.
|
||||||
|
|
||||||
|
.. variable:: CPACK_PACKAGE_FILES
|
||||||
|
|
||||||
|
List of resulting package files passed to the ``CPACK_POST_BUILD_SCRIPTS``.
|
||||||
|
|
||||||
#]=======================================================================]
|
#]=======================================================================]
|
||||||
|
|
||||||
# Define this var in order to avoid (or warn) concerning multiple inclusion
|
# Define this var in order to avoid (or warn) concerning multiple inclusion
|
||||||
|
@ -264,6 +264,23 @@ int cmCPackGenerator::InstallProject()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run pre-build actions
|
||||||
|
const char* preBuildScripts = this->GetOption("CPACK_PRE_BUILD_SCRIPTS");
|
||||||
|
if (preBuildScripts) {
|
||||||
|
const auto scripts = cmExpandedList(preBuildScripts, false);
|
||||||
|
for (const auto& script : scripts) {
|
||||||
|
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
|
||||||
|
"Executing pre-build script: " << script << std::endl);
|
||||||
|
|
||||||
|
if (!this->MakefileMap->ReadListFile(script)) {
|
||||||
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||||
|
"The pre-build script not found: " << script
|
||||||
|
<< std::endl);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (setDestDir) {
|
if (setDestDir) {
|
||||||
cmSystemTools::PutEnv("DESTDIR=");
|
cmSystemTools::PutEnv("DESTDIR=");
|
||||||
}
|
}
|
||||||
@ -333,7 +350,8 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
|
|||||||
if (installDirectoriesVector.size() % 2 != 0) {
|
if (installDirectoriesVector.size() % 2 != 0) {
|
||||||
cmCPackLogger(
|
cmCPackLogger(
|
||||||
cmCPackLog::LOG_ERROR,
|
cmCPackLog::LOG_ERROR,
|
||||||
"CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> and "
|
"CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> "
|
||||||
|
"and "
|
||||||
"<subdirectory>. The <subdirectory> can be '.' to be installed in "
|
"<subdirectory>. The <subdirectory> can be '.' to be installed in "
|
||||||
"the toplevel directory of installation."
|
"the toplevel directory of installation."
|
||||||
<< std::endl);
|
<< std::endl);
|
||||||
@ -475,10 +493,10 @@ int cmCPackGenerator::InstallProjectViaInstallScript(
|
|||||||
"- Install script: " << installScript << std::endl);
|
"- Install script: " << installScript << std::endl);
|
||||||
|
|
||||||
if (setDestDir) {
|
if (setDestDir) {
|
||||||
// For DESTDIR based packaging, use the *project* CMAKE_INSTALL_PREFIX
|
// For DESTDIR based packaging, use the *project*
|
||||||
// underneath the tempInstallDirectory. The value of the project's
|
// CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
|
||||||
// CMAKE_INSTALL_PREFIX is sent in here as the value of the
|
// value of the project's CMAKE_INSTALL_PREFIX is sent in here as the
|
||||||
// CPACK_INSTALL_PREFIX variable.
|
// value of the CPACK_INSTALL_PREFIX variable.
|
||||||
|
|
||||||
std::string dir;
|
std::string dir;
|
||||||
if (this->GetOption("CPACK_INSTALL_PREFIX")) {
|
if (this->GetOption("CPACK_INSTALL_PREFIX")) {
|
||||||
@ -1076,6 +1094,25 @@ int cmCPackGenerator::DoPackage()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Run post-build actions
|
||||||
|
const char* postBuildScripts = this->GetOption("CPACK_POST_BUILD_SCRIPTS");
|
||||||
|
if (postBuildScripts) {
|
||||||
|
this->MakefileMap->AddDefinition("CPACK_PACKAGE_FILES",
|
||||||
|
cmJoin(this->packageFileNames, ";"));
|
||||||
|
|
||||||
|
const auto scripts = cmExpandedList(postBuildScripts, false);
|
||||||
|
for (const auto& script : scripts) {
|
||||||
|
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
|
||||||
|
"Executing post-build script: " << script << std::endl);
|
||||||
|
|
||||||
|
if (!this->MakefileMap->ReadListFile(script)) {
|
||||||
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||||
|
"The post-build script not found: " << script
|
||||||
|
<< std::endl);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Prepare checksum algorithm*/
|
/* Prepare checksum algorithm*/
|
||||||
const char* algo = this->GetOption("CPACK_PACKAGE_CHECKSUM");
|
const char* algo = this->GetOption("CPACK_PACKAGE_CHECKSUM");
|
||||||
@ -1378,7 +1415,8 @@ int cmCPackGenerator::PrepareGroupingKind()
|
|||||||
<< std::endl);
|
<< std::endl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if user specified packaging method, override the default packaging method
|
// if user specified packaging method, override the default packaging
|
||||||
|
// method
|
||||||
if (method != UNKNOWN_COMPONENT_PACKAGE_METHOD) {
|
if (method != UNKNOWN_COMPONENT_PACKAGE_METHOD) {
|
||||||
componentPackageMethod = method;
|
componentPackageMethod = method;
|
||||||
}
|
}
|
||||||
|
@ -46,3 +46,4 @@ run_cpack_test_subtests(
|
|||||||
"MONOLITHIC;COMPONENT"
|
"MONOLITHIC;COMPONENT"
|
||||||
)
|
)
|
||||||
run_cpack_test(PROJECT_META "RPM.PROJECT_META;DEB.PROJECT_META" false "MONOLITHIC;COMPONENT")
|
run_cpack_test(PROJECT_META "RPM.PROJECT_META;DEB.PROJECT_META" false "MONOLITHIC;COMPONENT")
|
||||||
|
run_cpack_test_package_target(PRE_POST_SCRIPTS "ZIP" false "MONOLITHIC;COMPONENT")
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
set(SATU "/satu;/satu/CMakeLists.txt")
|
||||||
|
set(DUA "/dua;/dua/CMakeLists.txt")
|
||||||
|
|
||||||
|
if(GENERATOR_TYPE STREQUAL ZIP)
|
||||||
|
set(_ext "zip")
|
||||||
|
elseif(GENERATOR_TYPE STREQUAL TGZ)
|
||||||
|
set(_ext "tar.gz")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(PACKAGING_TYPE STREQUAL "COMPONENT")
|
||||||
|
set(EXPECTED_FILES_COUNT "2")
|
||||||
|
set(EXPECTED_FILE_1 "*-satu.${_ext}")
|
||||||
|
set(EXPECTED_FILE_CONTENT_1_LIST ${SATU})
|
||||||
|
set(EXPECTED_FILE_2 "*-dua.${_ext}")
|
||||||
|
set(EXPECTED_FILE_CONTENT_2_LIST ${DUA})
|
||||||
|
else()
|
||||||
|
set(EXPECTED_FILES_COUNT "1")
|
||||||
|
set(EXPECTED_FILE_CONTENT_1_LIST ${SATU} ${DUA})
|
||||||
|
endif()
|
@ -0,0 +1,4 @@
|
|||||||
|
-- The message from .*/Tests/RunCMake/CPack/tests/PRE_POST_SCRIPTS/pre\.cmake and generator ZIP
|
||||||
|
.*
|
||||||
|
-- The message from .*/Tests/RunCMake/CPack/tests/PRE_POST_SCRIPTS/post\.cmake and generator ZIP
|
||||||
|
-- Built packages: .*/_CPack_Packages/.*/pre_post_scripts-.*-dua.zip;.*/_CPack_Packages/.*/pre_post_scripts-.*-satu.zip
|
@ -0,0 +1,4 @@
|
|||||||
|
-- The message from .*/Tests/RunCMake/CPack/tests/PRE_POST_SCRIPTS/pre\.cmake and generator ZIP
|
||||||
|
.*
|
||||||
|
-- The message from .*/Tests/RunCMake/CPack/tests/PRE_POST_SCRIPTS/post\.cmake and generator ZIP
|
||||||
|
-- Built packages: .*/_CPack_Packages/.*/pre_post_scripts-0\.1\.1-.*\.zip
|
2
Tests/RunCMake/CPack/tests/PRE_POST_SCRIPTS/post.cmake
Normal file
2
Tests/RunCMake/CPack/tests/PRE_POST_SCRIPTS/post.cmake
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
message(STATUS "The message from ${CMAKE_CURRENT_LIST_FILE} and generator ${CPACK_GENERATOR}")
|
||||||
|
message(STATUS "Built packages: ${CPACK_PACKAGE_FILES}")
|
1
Tests/RunCMake/CPack/tests/PRE_POST_SCRIPTS/pre.cmake
Normal file
1
Tests/RunCMake/CPack/tests/PRE_POST_SCRIPTS/pre.cmake
Normal file
@ -0,0 +1 @@
|
|||||||
|
message(STATUS "The message from ${CMAKE_CURRENT_LIST_FILE} and generator ${CPACK_GENERATOR}")
|
9
Tests/RunCMake/CPack/tests/PRE_POST_SCRIPTS/test.cmake
Normal file
9
Tests/RunCMake/CPack/tests/PRE_POST_SCRIPTS/test.cmake
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
install(FILES CMakeLists.txt DESTINATION satu COMPONENT satu)
|
||||||
|
install(FILES CMakeLists.txt DESTINATION dua COMPONENT dua)
|
||||||
|
|
||||||
|
set(CPACK_PRE_BUILD_SCRIPTS "${CMAKE_CURRENT_LIST_DIR}/pre.cmake")
|
||||||
|
set(CPACK_POST_BUILD_SCRIPTS "${CMAKE_CURRENT_LIST_DIR}/post.cmake")
|
||||||
|
|
||||||
|
if(PACKAGING_TYPE STREQUAL "COMPONENT")
|
||||||
|
set(CPACK_COMPONENTS_ALL satu dua)
|
||||||
|
endif()
|
Loading…
Reference in New Issue
Block a user