CPack/Archive: per component filenames support

Support for setting archive packager specific
per component filenames and monolithic package
filenames.
This commit is contained in:
Domen Vrankar 2017-05-16 23:52:58 +02:00
parent 6b05e028f1
commit 9e06e97d30
9 changed files with 100 additions and 17 deletions

View File

@ -54,6 +54,7 @@ All Modules
/module/CMakePrintSystemInformation
/module/CMakePushCheckState
/module/CMakeVerifyManifest
/module/CPackArchive
/module/CPackBundle
/module/CPackComponent
/module/CPackCygwin

View File

@ -0,0 +1 @@
.. cmake-module:: ../../Modules/CPackArchive.cmake

View File

@ -0,0 +1,6 @@
cpack-rpm-debuginfo-honor-package-filename
------------------------------------------
* The :module:`CPackArchive` module learned to modify filename per component.
See :variable:`CPACK_ARCHIVE_FILE_NAME` variable and its per component
version.

View File

@ -0,0 +1,39 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#.rst:
# CPackArchive
# ------------
#
# Archive CPack generator that supports packaging of sources and binaries in
# different formats:
#
# - 7Z - 7zip - (.7z)
# - TBZ2 (.tar.bz2)
# - TGZ (.tar.gz)
# - TXZ (.tar.xz)
# - TZ (.tar.Z)
# - ZIP (.zip)
#
# Variables specific to CPack Archive generator
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#
# .. variable:: CPACK_ARCHIVE_FILE_NAME
# CPACK_ARCHIVE_<component>_FILE_NAME
#
# Package file name without extension which is added automatically depending
# on the archive format.
#
# * Mandatory : YES
# * Default : ``<CPACK_PACKAGE_FILE_NAME>[-<component>].<extension>`` with
# spaces replaced by '-'
#
# .. variable:: CPACK_ARCHIVE_COMPONENT_INSTALL
#
# Enable component packaging for CPackArchive
#
# * Mandatory : NO
# * Default : OFF
#
# If enabled (ON) multiple packages are generated. By default a single package
# containing files of all components is generated.

View File

@ -25,6 +25,28 @@ cmCPackArchiveGenerator::~cmCPackArchiveGenerator()
{
}
std::string cmCPackArchiveGenerator::GetArchiveComponentFileName(
const std::string& component, bool isGroupName)
{
std::string componentUpper(cmSystemTools::UpperCase(component));
std::string packageFileName;
if (this->IsSet("CPACK_ARCHIVE_" + componentUpper + "_FILE_NAME")) {
packageFileName +=
this->GetOption("CPACK_ARCHIVE_" + componentUpper + "_FILE_NAME");
} else if (this->IsSet("CPACK_ARCHIVE_FILE_NAME")) {
packageFileName += GetComponentPackageFileName(
this->GetOption("CPACK_ARCHIVE_FILE_NAME"), component, isGroupName);
} else {
packageFileName += GetComponentPackageFileName(
this->GetOption("CPACK_PACKAGE_FILE_NAME"), component, isGroupName);
}
packageFileName += this->GetOutputExtension();
return packageFileName;
}
int cmCPackArchiveGenerator::InitializeInternal()
{
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
@ -101,11 +123,9 @@ int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup)
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: "
<< compGIt->first << std::endl);
// Begin the archive for this group
std::string packageFileName = std::string(toplevel);
packageFileName += "/" +
GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
compGIt->first, true) +
this->GetOutputExtension();
std::string packageFileName = std::string(toplevel) + "/" +
this->GetArchiveComponentFileName(compGIt->first, true);
// open a block in order to automatically close archive
// at the end of the block
{
@ -137,10 +157,9 @@ int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup)
std::string packageFileName = std::string(toplevel);
localToplevel += "/" + compIt->first;
packageFileName += "/" + GetComponentPackageFileName(
this->GetOption("CPACK_PACKAGE_FILE_NAME"),
compIt->first, false) +
this->GetOutputExtension();
packageFileName +=
"/" + this->GetArchiveComponentFileName(compIt->first, false);
{
DECLARE_AND_OPEN_ARCHIVE(packageFileName, archive);
// Add the files of this component to the archive
@ -161,10 +180,9 @@ int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup)
std::string packageFileName = std::string(toplevel);
localToplevel += "/" + compIt->first;
packageFileName += "/" +
GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
compIt->first, false) +
this->GetOutputExtension();
packageFileName +=
"/" + this->GetArchiveComponentFileName(compIt->first, false);
{
DECLARE_AND_OPEN_ARCHIVE(packageFileName, archive);
// Add the files of this component to the archive
@ -182,9 +200,16 @@ int cmCPackArchiveGenerator::PackageComponentsAllInOne()
// reset the package file names
packageFileNames.clear();
packageFileNames.push_back(std::string(toplevel));
packageFileNames[0] += "/" +
std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) +
this->GetOutputExtension();
packageFileNames[0] += "/";
if (this->IsSet("CPACK_ARCHIVE_FILE_NAME")) {
packageFileNames[0] += this->GetOption("CPACK_ARCHIVE_FILE_NAME");
} else {
packageFileNames[0] += this->GetOption("CPACK_PACKAGE_FILE_NAME");
}
packageFileNames[0] += this->GetOutputExtension();
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
"Packaging all groups in one package..."
"(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE is set)"

View File

@ -34,6 +34,11 @@ public:
// component support
bool SupportsComponentInstallation() const CM_OVERRIDE;
private:
// get archive component filename
std::string GetArchiveComponentFileName(const std::string& component,
bool isGroupName);
protected:
int InitializeInternal() CM_OVERRIDE;
/**

View File

@ -5,7 +5,7 @@ include("${RunCMake_SOURCE_DIR}/CPackTestHelpers.cmake")
# run_cpack_test args: TEST_NAME "GENERATORS" RUN_CMAKE_BUILD_STEP "PACKAGING_TYPES"
run_cpack_test(CUSTOM_BINARY_SPEC_FILE "RPM" false "MONOLITHIC;COMPONENT")
run_cpack_test(CUSTOM_NAMES "RPM;DEB" true "COMPONENT")
run_cpack_test(CUSTOM_NAMES "RPM;DEB;TGZ" true "COMPONENT")
run_cpack_test(DEBUGINFO "RPM" true "COMPONENT")
run_cpack_test(DEPENDENCIES "RPM;DEB" true "COMPONENT")
run_cpack_test(DIST "RPM" false "MONOLITHIC")

View File

@ -9,4 +9,7 @@ set(EXPECTED_FILE_CONTENT_3_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
if(GENERATOR_TYPE STREQUAL "DEB" OR GENERATOR_TYPE STREQUAL "RPM")
string(TOLOWER "${GENERATOR_TYPE}" file_extension_)
set(EXPECTED_FILE_3 "pkg_3_abc.${file_extension_}")
elseif(GENERATOR_TYPE STREQUAL "TGZ")
set(EXPECTED_FILE_2 "second.tar.gz")
set(EXPECTED_FILE_3 "pkg_3_abc.tar.gz")
endif()

View File

@ -7,6 +7,9 @@ if(GENERATOR_TYPE STREQUAL "DEB" OR GENERATOR_TYPE STREQUAL "RPM")
set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_2_PACKAGE_NAME "second")
string(TOLOWER "${GENERATOR_TYPE}" file_extension_)
set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_3_FILE_NAME "pkg_3_abc.${file_extension_}")
elseif(GENERATOR_TYPE STREQUAL "TGZ")
set(CPACK_ARCHIVE_PKG_2_FILE_NAME "second")
set(CPACK_ARCHIVE_PKG_3_FILE_NAME "pkg_3_abc")
endif()
install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_1)