diff options
author | Eric NOULARD <eric.noulard@gmail.com> | 2011-02-06 20:23:10 (GMT) |
---|---|---|
committer | Eric NOULARD <eric.noulard@gmail.com> | 2011-02-06 20:23:10 (GMT) |
commit | 494bb8ada786be70f39807a574bea6a1ef98654d (patch) | |
tree | e7cf92bee0c90b6c8a3dcb97e36d8152f6f8698c /Source/CPack/cmCPackRPMGenerator.cxx | |
parent | 76976a59e9edc550fbf5b7b7ac4dbc381c02d139 (diff) | |
download | CMake-494bb8ada786be70f39807a574bea6a1ef98654d.zip CMake-494bb8ada786be70f39807a574bea6a1ef98654d.tar.gz CMake-494bb8ada786be70f39807a574bea6a1ef98654d.tar.bz2 |
CPackRPM honors all the different ways of packaging components
RPM cannot easily 'merge' differents directory into a single RPM
with shared prefix. So more flexibility has been added to generic
CPackGenerator in order to let the specific generator chose the
local installation directory for each component.
Diffstat (limited to 'Source/CPack/cmCPackRPMGenerator.cxx')
-rw-r--r-- | Source/CPack/cmCPackRPMGenerator.cxx | 188 |
1 files changed, 172 insertions, 16 deletions
diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx index a5db78f..a5a9753 100644 --- a/Source/CPack/cmCPackRPMGenerator.cxx +++ b/Source/CPack/cmCPackRPMGenerator.cxx @@ -35,26 +35,63 @@ int cmCPackRPMGenerator::InitializeInternal() } //---------------------------------------------------------------------- -int cmCPackRPMGenerator::PackageFiles() +int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) { int retval = 1; - /* Digest Component grouping specification */ - retval = PrepareGroupingKind(); - cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " - << toplevel << std::endl); + /* Reset package file name list it will be populated during the + * component packaging run*/ + packageFileNames.clear(); + std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY")); - /* Are we in the component packaging case */ - if (SupportsComponentInstallation() & (!this->ComponentGroups.empty())) + // 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( + std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) + +"-"+compGIt->first + this->GetOutputExtension() + ); + + 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 { - /* Reset package file name list it will be populated during the - * component packaging run*/ - packageFileNames.clear(); - std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY")); - /* One Package per component CASE */ - /* Iterate over components */ std::map<std::string, cmCPackComponent>::iterator compIt; for (compIt=this->Components.begin(); - compIt!=this->Components.end(); ++compIt ) + compIt!=this->Components.end(); ++compIt ) { std::string localToplevel(initialTopLevel); std::string packageFileName( @@ -82,12 +119,101 @@ int cmCPackRPMGenerator::PackageFiles() "Error while execution CPackRPM.cmake" << std::endl); retval = 0; } - // add the generated package to package file names list packageFileNames.push_back(packageFileName); } } - /* This is the non component case */ + 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")) + +"-ALL"+ this->GetOutputExtension() + ); + // 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); + + return 1; +} + +//---------------------------------------------------------------------- +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. else { if (!this->ReadListFile("CPackRPM.cmake")) @@ -118,3 +244,33 @@ bool cmCPackRPMGenerator::SupportsComponentInstallation() const } } +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; + } + } |