Sfoglia il codice sorgente

Merge topic 'cpack-archive-per-component-filename'

9e06e97d CPack/Archive: per component filenames support

Acked-by: Kitware Robot <[email protected]>
Merge-request: !859
Brad King 8 anni fa
parent
commit
44f8f839cb

+ 1 - 0
Help/manual/cmake-modules.7.rst

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

+ 1 - 0
Help/module/CPackArchive.rst

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

+ 6 - 0
Help/release/dev/cpack-archive-per-component-filename.rst

@@ -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.

+ 39 - 0
Modules/CPackArchive.cmake

@@ -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.

+ 41 - 16
Source/CPack/cmCPackArchiveGenerator.cxx

@@ -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)"

+ 5 - 0
Source/CPack/cmCPackArchiveGenerator.h

@@ -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;
   /**

+ 1 - 1
Tests/RunCMake/CPack/RunCMakeTest.cmake

@@ -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")

+ 3 - 0
Tests/RunCMake/CPack/tests/CUSTOM_NAMES/ExpectedFiles.cmake

@@ -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()

+ 3 - 0
Tests/RunCMake/CPack/tests/CUSTOM_NAMES/test.cmake

@@ -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)