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"
|
|
|
|
#include "cmCPackLog.h"
|
2010-08-23 18:14:40 +04:00
|
|
|
#include "cmSystemTools.h"
|
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");
|
2010-08-23 18:14:40 +04:00
|
|
|
if (cmSystemTools::IsOff(this->GetOption("CPACK_SET_DESTDIR")))
|
|
|
|
{
|
|
|
|
this->SetOption("CPACK_SET_DESTDIR", "I_ON");
|
|
|
|
}
|
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")) {
|
|
|
|
std::string packageName=this->GetOption("CPACK_PACKAGE_NAME");
|
|
|
|
cmSystemTools::ReplaceString(packageName," ","-");
|
|
|
|
this->SetOption("CPACK_PACKAGE_NAME",packageName.c_str());
|
|
|
|
}
|
|
|
|
/* same for CPACK_PACKAGE_FILE_NAME */
|
|
|
|
if (this->GetOption("CPACK_PACKAGE_FILE_NAME")) {
|
|
|
|
std::string packageName=this->GetOption("CPACK_PACKAGE_FILE_NAME");
|
|
|
|
cmSystemTools::ReplaceString(packageName," ","-");
|
|
|
|
this->SetOption("CPACK_PACKAGE_FILE_NAME",packageName.c_str());
|
|
|
|
}
|
2007-10-31 15:50:17 +03:00
|
|
|
return this->Superclass::InitializeInternal();
|
|
|
|
}
|
|
|
|
|
2007-08-08 19:33:42 +04:00
|
|
|
//----------------------------------------------------------------------
|
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.
|
|
|
|
if (!ignoreGroup)
|
|
|
|
{
|
|
|
|
std::map<std::string, cmCPackComponentGroup>::iterator compGIt;
|
|
|
|
for (compGIt=this->ComponentGroups.begin();
|
|
|
|
compGIt!=this->ComponentGroups.end(); ++compGIt)
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: "
|
|
|
|
<< compGIt->first
|
|
|
|
<< std::endl);
|
|
|
|
// Begin the archive for this group
|
|
|
|
std::string localToplevel(initialTopLevel);
|
|
|
|
std::string packageFileName(
|
|
|
|
cmSystemTools::GetParentDirectory(toplevel.c_str())
|
|
|
|
);
|
|
|
|
std::string outputFileName(
|
2011-02-23 01:49:49 +03:00
|
|
|
GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
|
|
|
|
compGIt->first,
|
|
|
|
true)
|
|
|
|
+ this->GetOutputExtension()
|
2011-02-06 23:23:10 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
localToplevel += "/"+ compGIt->first;
|
|
|
|
/* replace the TEMP DIRECTORY with the component one */
|
|
|
|
this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
|
|
|
|
packageFileName += "/"+ outputFileName;
|
|
|
|
/* replace proposed CPACK_OUTPUT_FILE_NAME */
|
|
|
|
this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
|
|
|
|
/* replace the TEMPORARY package file name */
|
|
|
|
this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
|
|
|
|
packageFileName.c_str());
|
|
|
|
// Tell CPackRPM.cmake the name of the component GROUP.
|
|
|
|
this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",compGIt->first.c_str());
|
|
|
|
if (!this->ReadListFile("CPackRPM.cmake"))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Error while execution CPackRPM.cmake" << std::endl);
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
// add the generated package to package file names list
|
|
|
|
packageFileNames.push_back(packageFileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CPACK_COMPONENTS_IGNORE_GROUPS is set
|
|
|
|
// We build 1 package per component
|
|
|
|
else
|
2010-11-13 19:56:36 +03:00
|
|
|
{
|
|
|
|
std::map<std::string, cmCPackComponent>::iterator compIt;
|
|
|
|
for (compIt=this->Components.begin();
|
2011-02-06 23:23:10 +03:00
|
|
|
compIt!=this->Components.end(); ++compIt )
|
2010-11-13 19:56:36 +03:00
|
|
|
{
|
|
|
|
std::string localToplevel(initialTopLevel);
|
2010-11-15 22:54:19 +03:00
|
|
|
std::string packageFileName(
|
|
|
|
cmSystemTools::GetParentDirectory(toplevel.c_str())
|
|
|
|
);
|
|
|
|
std::string outputFileName(
|
2011-02-23 01:49:49 +03:00
|
|
|
GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
|
|
|
|
compIt->first,
|
|
|
|
false)
|
|
|
|
+ this->GetOutputExtension());
|
2010-11-13 19:56:36 +03:00
|
|
|
|
|
|
|
localToplevel += "/"+ compIt->first;
|
|
|
|
/* replace the TEMP DIRECTORY with the component one */
|
|
|
|
this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
|
|
|
|
packageFileName += "/"+ outputFileName;
|
|
|
|
/* replace proposed CPACK_OUTPUT_FILE_NAME */
|
|
|
|
this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
|
|
|
|
/* replace the TEMPORARY package file name */
|
2010-11-15 22:54:19 +03:00
|
|
|
this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
|
|
|
|
packageFileName.c_str());
|
2010-11-13 19:56:36 +03:00
|
|
|
|
|
|
|
this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",compIt->first.c_str());
|
|
|
|
if (!this->ReadListFile("CPackRPM.cmake"))
|
|
|
|
{
|
2010-11-15 22:54:19 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Error while execution CPackRPM.cmake" << std::endl);
|
2010-11-13 19:56:36 +03:00
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
// add the generated package to package file names list
|
|
|
|
packageFileNames.push_back(packageFileName);
|
|
|
|
}
|
|
|
|
}
|
2011-02-06 23:23:10 +03:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCPackRPMGenerator::PackageComponentsAllInOne(bool allComponent)
|
|
|
|
{
|
|
|
|
int retval = 1;
|
|
|
|
std::string compInstDirName;
|
|
|
|
/* Reset package file name list it will be populated during the
|
|
|
|
* component packaging run*/
|
|
|
|
packageFileNames.clear();
|
|
|
|
std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
|
|
|
|
|
|
|
|
// all GROUP in one vs all COMPONENT in one
|
|
|
|
if (allComponent)
|
|
|
|
{
|
|
|
|
compInstDirName = "ALL_COMPONENTS_IN_ONE";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
compInstDirName = "ALL_GROUPS_IN_ONE";
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
|
|
|
|
"Packaging all groups in one package..."
|
|
|
|
"(CPACK_COMPONENTS_ALL_[GROUPS_]IN_ONE_PACKAGE is set)"
|
|
|
|
<< std::endl);
|
|
|
|
|
|
|
|
// The ALL GROUPS in ONE package case
|
|
|
|
std::string localToplevel(initialTopLevel);
|
|
|
|
std::string packageFileName(
|
|
|
|
cmSystemTools::GetParentDirectory(toplevel.c_str())
|
|
|
|
);
|
|
|
|
std::string outputFileName(
|
|
|
|
std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
|
2011-02-23 00:56:26 +03:00
|
|
|
+ this->GetOutputExtension()
|
2011-02-06 23:23:10 +03:00
|
|
|
);
|
|
|
|
// all GROUP in one vs all COMPONENT in one
|
|
|
|
localToplevel += "/"+compInstDirName;
|
|
|
|
|
|
|
|
/* replace the TEMP DIRECTORY with the component one */
|
|
|
|
this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
|
|
|
|
packageFileName += "/"+ outputFileName;
|
|
|
|
/* replace proposed CPACK_OUTPUT_FILE_NAME */
|
|
|
|
this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
|
|
|
|
/* replace the TEMPORARY package file name */
|
|
|
|
this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
|
|
|
|
packageFileName.c_str());
|
|
|
|
// Tell CPackRPM.cmake the name of the component GROUP.
|
|
|
|
this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",compInstDirName.c_str());
|
|
|
|
if (!this->ReadListFile("CPackRPM.cmake"))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Error while execution CPackRPM.cmake" << std::endl);
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
// add the generated package to package file names list
|
|
|
|
packageFileNames.push_back(packageFileName);
|
|
|
|
|
2011-02-15 21:55:36 +03:00
|
|
|
return retval;
|
2011-02-06 23:23:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCPackRPMGenerator::PackageFiles()
|
|
|
|
{
|
|
|
|
int retval = 1;
|
|
|
|
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: "
|
|
|
|
<< toplevel << std::endl);
|
|
|
|
|
|
|
|
/* Are we in the component packaging case */
|
|
|
|
if (SupportsComponentInstallation()) {
|
|
|
|
// CASE 1 : COMPONENT ALL-IN-ONE package
|
|
|
|
// If ALL GROUPS or ALL COMPONENTS in ONE package has been requested
|
|
|
|
// then the package file is unique and should be open here.
|
|
|
|
if (allComponentInOne ||
|
|
|
|
(allGroupInOne && (!this->ComponentGroups.empty()))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return PackageComponentsAllInOne(allComponentInOne);
|
|
|
|
}
|
|
|
|
// 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.
|
|
|
|
else if ((!this->ComponentGroups.empty()) || (ignoreComponentGroup))
|
|
|
|
{
|
|
|
|
return PackageComponents(ignoreComponentGroup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CASE 3 : NON COMPONENT package.
|
2010-11-13 19:56:36 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!this->ReadListFile("CPackRPM.cmake"))
|
|
|
|
{
|
2010-11-15 22:54:19 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Error while execution CPackRPM.cmake" << std::endl);
|
2010-11-13 19:56:36 +03:00
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-08 19:33:42 +04:00
|
|
|
if (!this->IsSet("RPMBUILD_EXECUTABLE"))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find rpmbuild" << std::endl);
|
2010-11-13 19:56:36 +03:00
|
|
|
retval = 0;
|
2007-08-08 19:33:42 +04:00
|
|
|
}
|
2010-11-13 19:56:36 +03:00
|
|
|
return retval;
|
2007-08-08 19:33:42 +04:00
|
|
|
}
|
|
|
|
|
2010-11-15 22:54:19 +03:00
|
|
|
bool cmCPackRPMGenerator::SupportsComponentInstallation() const
|
|
|
|
{
|
2010-12-12 14:55:02 +03:00
|
|
|
if (IsOn("CPACK_RPM_COMPONENT_INSTALL"))
|
2010-11-15 22:54:19 +03:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2007-08-08 23:44:02 +04:00
|
|
|
|
2011-02-06 23:23:10 +03:00
|
|
|
std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix(
|
|
|
|
const std::string& componentName)
|
|
|
|
{
|
|
|
|
if (ignoreComponentGroup) {
|
|
|
|
return componentName;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allComponentInOne) {
|
|
|
|
return std::string("ALL_COMPONENTS_IN_ONE");
|
|
|
|
}
|
|
|
|
// We have to find the name of the COMPONENT GROUP
|
|
|
|
// the current COMPONENT belongs to.
|
|
|
|
std::string groupVar = "CPACK_COMPONENT_" +
|
|
|
|
cmSystemTools::UpperCase(componentName) + "_GROUP";
|
|
|
|
if (NULL != GetOption(groupVar.c_str()))
|
|
|
|
{
|
|
|
|
if (allGroupInOne)
|
|
|
|
{
|
|
|
|
return std::string("ALL_GROUPS_IN_ONE");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return std::string(GetOption(groupVar.c_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return componentName;
|
|
|
|
}
|
|
|
|
}
|