2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2007-08-08 19:33:42 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2007-08-08 19:33:42 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2007-08-08 19:33:42 +04:00
|
|
|
#include "cmCPackRPMGenerator.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-09-07 01:21:35 +03:00
|
|
|
#include "cmCPackComponentGroup.h"
|
|
|
|
#include "cmCPackGenerator.h"
|
2007-08-08 19:33:42 +04:00
|
|
|
#include "cmCPackLog.h"
|
2010-08-23 18:14:40 +04:00
|
|
|
#include "cmSystemTools.h"
|
2007-08-08 19:33:42 +04:00
|
|
|
|
2016-09-07 01:21:35 +03:00
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
|
|
|
#include <ostream>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2007-08-08 19:33:42 +04:00
|
|
|
cmCPackRPMGenerator::cmCPackRPMGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCPackRPMGenerator::~cmCPackRPMGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-10-31 15:50:17 +03:00
|
|
|
int cmCPackRPMGenerator::InitializeInternal()
|
|
|
|
{
|
|
|
|
this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::IsOff(this->GetOption("CPACK_SET_DESTDIR"))) {
|
2010-08-23 18:14:40 +04:00
|
|
|
this->SetOption("CPACK_SET_DESTDIR", "I_ON");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-25 18:47:11 +03:00
|
|
|
/* Replace space in CPACK_PACKAGE_NAME in order to avoid
|
|
|
|
* rpmbuild scream on unwanted space in filename issue
|
|
|
|
* Moreover RPM file do not usually embed space in filename
|
|
|
|
*/
|
|
|
|
if (this->GetOption("CPACK_PACKAGE_NAME")) {
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string packageName = this->GetOption("CPACK_PACKAGE_NAME");
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(packageName.begin(), packageName.end(), ' ', '-');
|
2016-05-16 17:34:04 +03:00
|
|
|
this->SetOption("CPACK_PACKAGE_NAME", packageName.c_str());
|
2011-02-25 18:47:11 +03:00
|
|
|
}
|
|
|
|
/* same for CPACK_PACKAGE_FILE_NAME */
|
|
|
|
if (this->GetOption("CPACK_PACKAGE_FILE_NAME")) {
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string packageName = this->GetOption("CPACK_PACKAGE_FILE_NAME");
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(packageName.begin(), packageName.end(), ' ', '-');
|
2016-05-16 17:34:04 +03:00
|
|
|
this->SetOption("CPACK_PACKAGE_FILE_NAME", packageName.c_str());
|
2011-02-25 18:47:11 +03:00
|
|
|
}
|
2007-10-31 15:50:17 +03:00
|
|
|
return this->Superclass::InitializeInternal();
|
|
|
|
}
|
|
|
|
|
2016-05-15 04:01:34 +03:00
|
|
|
void cmCPackRPMGenerator::AddGeneratedPackageNames()
|
|
|
|
{
|
|
|
|
// add the generated packages to package file names list
|
|
|
|
std::string fileNames(this->GetOption("GEN_CPACK_OUTPUT_FILES"));
|
|
|
|
const char sep = ';';
|
|
|
|
std::string::size_type pos1 = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string::size_type pos2 = fileNames.find(sep, pos1 + 1);
|
|
|
|
while (pos2 != std::string::npos) {
|
|
|
|
packageFileNames.push_back(fileNames.substr(pos1, pos2 - pos1));
|
|
|
|
pos1 = pos2 + 1;
|
|
|
|
pos2 = fileNames.find(sep, pos1 + 1);
|
|
|
|
}
|
|
|
|
packageFileNames.push_back(fileNames.substr(pos1, pos2 - pos1));
|
2016-05-15 04:01:34 +03:00
|
|
|
}
|
|
|
|
|
2016-05-26 22:58:51 +03:00
|
|
|
int cmCPackRPMGenerator::PackageOnePack(std::string const& initialToplevel,
|
|
|
|
std::string const& packageName)
|
2011-03-23 20:28:05 +03:00
|
|
|
{
|
|
|
|
int retval = 1;
|
|
|
|
// Begin the archive for this pack
|
|
|
|
std::string localToplevel(initialToplevel);
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel));
|
2011-03-23 20:28:05 +03:00
|
|
|
std::string outputFileName(
|
2016-05-16 17:34:04 +03:00
|
|
|
GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
|
|
|
|
packageName, true) +
|
|
|
|
this->GetOutputExtension());
|
2011-03-23 20:28:05 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
localToplevel += "/" + packageName;
|
2011-03-23 20:28:05 +03:00
|
|
|
/* replace the TEMP DIRECTORY with the component one */
|
2016-05-16 17:34:04 +03:00
|
|
|
this->SetOption("CPACK_TEMPORARY_DIRECTORY", localToplevel.c_str());
|
|
|
|
packageFileName += "/" + outputFileName;
|
2011-03-23 20:28:05 +03:00
|
|
|
/* replace proposed CPACK_OUTPUT_FILE_NAME */
|
2016-05-16 17:34:04 +03:00
|
|
|
this->SetOption("CPACK_OUTPUT_FILE_NAME", outputFileName.c_str());
|
2011-03-23 20:28:05 +03:00
|
|
|
/* replace the TEMPORARY package file name */
|
|
|
|
this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
|
|
|
|
packageFileName.c_str());
|
|
|
|
// Tell CPackRPM.cmake the name of the component NAME.
|
2016-05-16 17:34:04 +03:00
|
|
|
this->SetOption("CPACK_RPM_PACKAGE_COMPONENT", packageName.c_str());
|
2012-10-24 23:37:18 +04:00
|
|
|
// Tell CPackRPM.cmake the path where the component is.
|
|
|
|
std::string component_path = "/";
|
|
|
|
component_path += packageName;
|
|
|
|
this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH",
|
|
|
|
component_path.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->ReadListFile("CPackRPM.cmake")) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackRPM.cmake"
|
|
|
|
<< std::endl);
|
2011-03-23 20:28:05 +03:00
|
|
|
retval = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-05-15 04:01:34 +03:00
|
|
|
|
2011-03-23 20:28:05 +03:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-02-06 23:23:10 +03:00
|
|
|
int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
|
2007-08-08 19:33:42 +04:00
|
|
|
{
|
2010-11-13 19:56:36 +03:00
|
|
|
int retval = 1;
|
2011-02-06 23:23:10 +03:00
|
|
|
/* Reset package file name list it will be populated during the
|
|
|
|
* component packaging run*/
|
|
|
|
packageFileNames.clear();
|
|
|
|
std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
|
2010-11-13 19:56:36 +03:00
|
|
|
|
2011-02-06 23:23:10 +03:00
|
|
|
// The default behavior is to have one package by component group
|
|
|
|
// unless CPACK_COMPONENTS_IGNORE_GROUP is specified.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!ignoreGroup) {
|
2011-02-06 23:23:10 +03:00
|
|
|
std::map<std::string, cmCPackComponentGroup>::iterator compGIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (compGIt = this->ComponentGroups.begin();
|
|
|
|
compGIt != this->ComponentGroups.end(); ++compGIt) {
|
2011-02-06 23:23:10 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< compGIt->first << std::endl);
|
|
|
|
retval &= PackageOnePack(initialTopLevel, compGIt->first);
|
|
|
|
}
|
2011-03-23 20:28:05 +03:00
|
|
|
// Handle Orphan components (components not belonging to any groups)
|
|
|
|
std::map<std::string, cmCPackComponent>::iterator compIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (compIt = this->Components.begin(); compIt != this->Components.end();
|
|
|
|
++compIt) {
|
2011-03-23 20:28:05 +03:00
|
|
|
// Does the component belong to a group?
|
2016-06-27 23:44:16 +03:00
|
|
|
if (compIt->second.Group == CM_NULLPTR) {
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_VERBOSE, "Component <"
|
2011-03-23 20:28:05 +03:00
|
|
|
<< compIt->second.Name
|
|
|
|
<< "> does not belong to any group, package it separately."
|
|
|
|
<< std::endl);
|
2016-05-16 17:34:04 +03:00
|
|
|
retval &= PackageOnePack(initialTopLevel, compIt->first);
|
2011-02-06 23:23:10 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 23:23:10 +03:00
|
|
|
// CPACK_COMPONENTS_IGNORE_GROUPS is set
|
|
|
|
// We build 1 package per component
|
2016-05-16 17:34:04 +03:00
|
|
|
else {
|
2010-11-13 19:56:36 +03:00
|
|
|
std::map<std::string, cmCPackComponent>::iterator compIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (compIt = this->Components.begin(); compIt != this->Components.end();
|
|
|
|
++compIt) {
|
|
|
|
retval &= PackageOnePack(initialTopLevel, compIt->first);
|
2010-11-13 19:56:36 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-05-15 04:01:34 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (retval) {
|
2016-05-15 04:01:34 +03:00
|
|
|
AddGeneratedPackageNames();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-05-15 04:01:34 +03:00
|
|
|
|
2011-02-06 23:23:10 +03:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2016-05-15 04:01:34 +03:00
|
|
|
int cmCPackRPMGenerator::PackageComponentsAllInOne(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& compInstDirName)
|
2011-02-06 23:23:10 +03:00
|
|
|
{
|
|
|
|
int retval = 1;
|
|
|
|
/* Reset package file name list it will be populated during the
|
|
|
|
* component packaging run*/
|
|
|
|
packageFileNames.clear();
|
|
|
|
std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
|
|
|
|
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
|
|
|
|
"Packaging all groups in one package..."
|
|
|
|
"(CPACK_COMPONENTS_ALL_[GROUPS_]IN_ONE_PACKAGE is set)"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
2011-02-06 23:23:10 +03:00
|
|
|
|
|
|
|
// The ALL GROUPS in ONE package case
|
|
|
|
std::string localToplevel(initialTopLevel);
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel));
|
2011-02-06 23:23:10 +03:00
|
|
|
std::string outputFileName(
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) +
|
|
|
|
this->GetOutputExtension());
|
2011-02-06 23:23:10 +03:00
|
|
|
// all GROUP in one vs all COMPONENT in one
|
2016-05-16 17:34:04 +03:00
|
|
|
localToplevel += "/" + compInstDirName;
|
2011-02-06 23:23:10 +03:00
|
|
|
|
|
|
|
/* replace the TEMP DIRECTORY with the component one */
|
2016-05-16 17:34:04 +03:00
|
|
|
this->SetOption("CPACK_TEMPORARY_DIRECTORY", localToplevel.c_str());
|
|
|
|
packageFileName += "/" + outputFileName;
|
2011-02-06 23:23:10 +03:00
|
|
|
/* replace proposed CPACK_OUTPUT_FILE_NAME */
|
2016-05-16 17:34:04 +03:00
|
|
|
this->SetOption("CPACK_OUTPUT_FILE_NAME", outputFileName.c_str());
|
2011-02-06 23:23:10 +03:00
|
|
|
/* replace the TEMPORARY package file name */
|
|
|
|
this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
|
2016-05-16 17:34:04 +03:00
|
|
|
packageFileName.c_str());
|
2016-05-15 04:01:34 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!compInstDirName.empty()) {
|
2016-05-15 04:01:34 +03:00
|
|
|
// Tell CPackRPM.cmake the path where the component is.
|
|
|
|
std::string component_path = "/";
|
|
|
|
component_path += compInstDirName;
|
|
|
|
this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH",
|
|
|
|
component_path.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-05-15 04:01:34 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ReadListFile("CPackRPM.cmake")) {
|
2016-05-15 04:01:34 +03:00
|
|
|
AddGeneratedPackageNames();
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackRPM.cmake"
|
|
|
|
<< std::endl);
|
2011-02-06 23:23:10 +03:00
|
|
|
retval = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 23:23:10 +03:00
|
|
|
|
2011-02-15 21:55:36 +03:00
|
|
|
return retval;
|
2011-02-06 23:23:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int cmCPackRPMGenerator::PackageFiles()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl);
|
2011-02-06 23:23:10 +03:00
|
|
|
|
|
|
|
/* Are we in the component packaging case */
|
2012-03-18 23:21:35 +04:00
|
|
|
if (WantsComponentInstallation()) {
|
2011-02-06 23:23:10 +03:00
|
|
|
// CASE 1 : COMPONENT ALL-IN-ONE package
|
2011-03-23 20:28:05 +03:00
|
|
|
// If ALL COMPONENTS in ONE package has been requested
|
2011-02-06 23:23:10 +03:00
|
|
|
// then the package file is unique and should be open here.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (componentPackageMethod == ONE_PACKAGE) {
|
2016-05-15 04:01:34 +03:00
|
|
|
return PackageComponentsAllInOne("ALL_COMPONENTS_IN_ONE");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-02-06 23:23:10 +03:00
|
|
|
// CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one)
|
|
|
|
// There will be 1 package for each component group
|
|
|
|
// however one may require to ignore component group and
|
|
|
|
// in this case you'll get 1 package for each component.
|
2016-08-18 20:47:32 +03:00
|
|
|
return PackageComponents(componentPackageMethod ==
|
|
|
|
ONE_PACKAGE_PER_COMPONENT);
|
2011-02-06 23:23:10 +03:00
|
|
|
}
|
|
|
|
// CASE 3 : NON COMPONENT package.
|
2016-08-18 20:47:32 +03:00
|
|
|
return PackageComponentsAllInOne("");
|
2007-08-08 19:33:42 +04:00
|
|
|
}
|
|
|
|
|
2010-11-15 22:54:19 +03:00
|
|
|
bool cmCPackRPMGenerator::SupportsComponentInstallation() const
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2016-06-02 00:29:53 +03:00
|
|
|
return IsOn("CPACK_RPM_COMPONENT_INSTALL");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-08-08 23:44:02 +04:00
|
|
|
|
2011-02-06 23:23:10 +03:00
|
|
|
std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& componentName)
|
|
|
|
{
|
2011-03-25 19:18:59 +03:00
|
|
|
if (componentPackageMethod == ONE_PACKAGE_PER_COMPONENT) {
|
2011-02-06 23:23:10 +03:00
|
|
|
return componentName;
|
|
|
|
}
|
|
|
|
|
2011-03-25 19:18:59 +03:00
|
|
|
if (componentPackageMethod == ONE_PACKAGE) {
|
2011-02-06 23:23:10 +03:00
|
|
|
return std::string("ALL_COMPONENTS_IN_ONE");
|
|
|
|
}
|
|
|
|
// We have to find the name of the COMPONENT GROUP
|
|
|
|
// the current COMPONENT belongs to.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string groupVar =
|
|
|
|
"CPACK_COMPONENT_" + cmSystemTools::UpperCase(componentName) + "_GROUP";
|
2016-06-27 23:44:16 +03:00
|
|
|
if (CM_NULLPTR != GetOption(groupVar)) {
|
2016-05-16 17:34:04 +03:00
|
|
|
return std::string(GetOption(groupVar));
|
2011-02-06 23:23:10 +03:00
|
|
|
}
|
2016-08-18 20:47:32 +03:00
|
|
|
return componentName;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|