123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- #include "cmCPackRPMGenerator.h"
- #include <algorithm>
- #include <ctype.h>
- #include <map>
- #include <ostream>
- #include <utility>
- #include <vector>
- #include "cmCPackComponentGroup.h"
- #include "cmCPackGenerator.h"
- #include "cmCPackLog.h"
- #include "cmSystemTools.h"
- cmCPackRPMGenerator::cmCPackRPMGenerator()
- {
- }
- cmCPackRPMGenerator::~cmCPackRPMGenerator()
- {
- }
- int cmCPackRPMGenerator::InitializeInternal()
- {
- this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
- if (cmSystemTools::IsOff(this->GetOption("CPACK_SET_DESTDIR"))) {
- this->SetOption("CPACK_SET_DESTDIR", "I_ON");
- }
-
- if (this->GetOption("CPACK_PACKAGE_NAME")) {
- std::string packageName = this->GetOption("CPACK_PACKAGE_NAME");
- std::replace(packageName.begin(), packageName.end(), ' ', '-');
- this->SetOption("CPACK_PACKAGE_NAME", packageName.c_str());
- }
-
- if (this->GetOption("CPACK_PACKAGE_FILE_NAME")) {
- std::string packageName = this->GetOption("CPACK_PACKAGE_FILE_NAME");
- std::replace(packageName.begin(), packageName.end(), ' ', '-');
- this->SetOption("CPACK_PACKAGE_FILE_NAME", packageName.c_str());
- }
- return this->Superclass::InitializeInternal();
- }
- void cmCPackRPMGenerator::AddGeneratedPackageNames()
- {
-
- std::string fileNames(this->GetOption("GEN_CPACK_OUTPUT_FILES"));
- const char sep = ';';
- std::string::size_type pos1 = 0;
- 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));
- }
- int cmCPackRPMGenerator::PackageOnePack(std::string const& initialToplevel,
- std::string const& packageName)
- {
- int retval = 1;
-
- std::string localToplevel(initialToplevel);
- std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel));
- std::string outputFileName(
- GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
- packageName, true) +
- this->GetOutputExtension());
- localToplevel += "/" + packageName;
-
- this->SetOption("CPACK_TEMPORARY_DIRECTORY", localToplevel.c_str());
- packageFileName += "/" + outputFileName;
-
- this->SetOption("CPACK_OUTPUT_FILE_NAME", outputFileName.c_str());
-
- this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
- packageFileName.c_str());
-
- this->SetOption("CPACK_RPM_PACKAGE_COMPONENT", packageName.c_str());
-
- std::string component_path = "/";
- component_path += packageName;
- this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH",
- component_path.c_str());
- if (!this->ReadListFile("CPackRPM.cmake")) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackRPM.cmake"
- << std::endl);
- retval = 0;
- }
- return retval;
- }
- int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
- {
- int retval = 1;
-
- packageFileNames.clear();
- std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
- const char* mainComponent = this->GetOption("CPACK_RPM_MAIN_COMPONENT");
- if (this->IsOn("CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE") &&
- !this->IsOn("CPACK_RPM_DEBUGINFO_PACKAGE")) {
-
-
- bool shouldSet = true;
- if (ignoreGroup) {
- std::map<std::string, cmCPackComponent>::iterator compIt;
- for (compIt = this->Components.begin(); compIt != this->Components.end();
- ++compIt) {
- std::string component(compIt->first);
- std::transform(component.begin(), component.end(), component.begin(),
- ::toupper);
- if (this->IsOn("CPACK_RPM_" + compIt->first + "_DEBUGINFO_PACKAGE") ||
- this->IsOn("CPACK_RPM_" + component + "_DEBUGINFO_PACKAGE")) {
- shouldSet = false;
- break;
- }
- }
- } else {
- std::map<std::string, cmCPackComponentGroup>::iterator compGIt;
- for (compGIt = this->ComponentGroups.begin();
- compGIt != this->ComponentGroups.end(); ++compGIt) {
- std::string component(compGIt->first);
- std::transform(component.begin(), component.end(), component.begin(),
- ::toupper);
- if (this->IsOn("CPACK_RPM_" + compGIt->first + "_DEBUGINFO_PACKAGE") ||
- this->IsOn("CPACK_RPM_" + component + "_DEBUGINFO_PACKAGE")) {
- shouldSet = false;
- break;
- }
- }
- if (shouldSet) {
- std::map<std::string, cmCPackComponent>::iterator compIt;
- for (compIt = this->Components.begin();
- compIt != this->Components.end(); ++compIt) {
-
- if (compIt->second.Group == nullptr) {
- std::string component(compIt->first);
- std::transform(component.begin(), component.end(),
- component.begin(), ::toupper);
- if (this->IsOn("CPACK_RPM_" + compIt->first +
- "_DEBUGINFO_PACKAGE") ||
- this->IsOn("CPACK_RPM_" + component + "_DEBUGINFO_PACKAGE")) {
- shouldSet = false;
- break;
- }
- }
- }
- }
- }
- if (shouldSet) {
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Setting "
- << "CPACK_RPM_DEBUGINFO_PACKAGE because "
- << "CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE is set but "
- << " none of the "
- << "CPACK_RPM_<component>_DEBUGINFO_PACKAGE variables "
- << "are set." << std::endl);
- this->SetOption("CPACK_RPM_DEBUGINFO_PACKAGE", "ON");
- }
- }
- if (mainComponent) {
- if (this->IsOn("CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE")) {
- this->SetOption("GENERATE_SPEC_PARTS", "ON");
- }
- std::string mainComponentUpper(mainComponent);
- std::transform(mainComponentUpper.begin(), mainComponentUpper.end(),
- mainComponentUpper.begin(), ::toupper);
-
-
- if (!ignoreGroup) {
- std::map<std::string, cmCPackComponentGroup>::iterator mainCompGIt =
- this->ComponentGroups.end();
- std::map<std::string, cmCPackComponentGroup>::iterator compGIt;
- for (compGIt = this->ComponentGroups.begin();
- compGIt != this->ComponentGroups.end(); ++compGIt) {
- std::string component(compGIt->first);
- std::transform(component.begin(), component.end(), component.begin(),
- ::toupper);
- if (mainComponentUpper == component) {
-
- mainCompGIt = compGIt;
- continue;
- }
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: "
- << compGIt->first << std::endl);
- retval &= PackageOnePack(initialTopLevel, compGIt->first);
- }
-
- std::map<std::string, cmCPackComponent>::iterator mainCompIt =
- this->Components.end();
- std::map<std::string, cmCPackComponent>::iterator compIt;
- for (compIt = this->Components.begin(); compIt != this->Components.end();
- ++compIt) {
-
- if (compIt->second.Group == nullptr) {
- std::string component(compIt->first);
- std::transform(component.begin(), component.end(), component.begin(),
- ::toupper);
- if (mainComponentUpper == component) {
-
- mainCompIt = compIt;
- continue;
- }
- cmCPackLogger(
- cmCPackLog::LOG_VERBOSE, "Component <"
- << compIt->second.Name
- << "> does not belong to any group, package it separately."
- << std::endl);
- retval &= PackageOnePack(initialTopLevel, compIt->first);
- }
- }
- if (retval) {
- this->SetOption("GENERATE_SPEC_PARTS", "OFF");
- if (mainCompGIt != this->ComponentGroups.end()) {
- retval &= PackageOnePack(initialTopLevel, mainCompGIt->first);
- } else if (mainCompIt != this->Components.end()) {
- retval &= PackageOnePack(initialTopLevel, mainCompIt->first);
- } else {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_RPM_MAIN_COMPONENT set"
- << " to non existing component.\n");
- retval = 0;
- }
- }
- }
-
-
- else {
- std::map<std::string, cmCPackComponent>::iterator mainCompIt =
- this->Components.end();
- std::map<std::string, cmCPackComponent>::iterator compIt;
- for (compIt = this->Components.begin(); compIt != this->Components.end();
- ++compIt) {
- std::string component(compIt->first);
- std::transform(component.begin(), component.end(), component.begin(),
- ::toupper);
- if (mainComponentUpper == component) {
-
- mainCompIt = compIt;
- continue;
- }
- retval &= PackageOnePack(initialTopLevel, compIt->first);
- }
- if (retval) {
- this->SetOption("GENERATE_SPEC_PARTS", "OFF");
- if (mainCompIt != this->Components.end()) {
- retval &= PackageOnePack(initialTopLevel, mainCompIt->first);
- } else {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_RPM_MAIN_COMPONENT set"
- << " to non existing component.\n");
- retval = 0;
- }
- }
- }
- } else if (!this->IsOn("CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE") ||
- this->Components.size() == 1) {
-
-
- 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);
- retval &= PackageOnePack(initialTopLevel, compGIt->first);
- }
-
- std::map<std::string, cmCPackComponent>::iterator compIt;
- for (compIt = this->Components.begin(); compIt != this->Components.end();
- ++compIt) {
-
- if (compIt->second.Group == nullptr) {
- cmCPackLogger(
- cmCPackLog::LOG_VERBOSE, "Component <"
- << compIt->second.Name
- << "> does not belong to any group, package it separately."
- << std::endl);
- retval &= PackageOnePack(initialTopLevel, compIt->first);
- }
- }
- }
-
-
- else {
- std::map<std::string, cmCPackComponent>::iterator compIt;
- for (compIt = this->Components.begin(); compIt != this->Components.end();
- ++compIt) {
- retval &= PackageOnePack(initialTopLevel, compIt->first);
- }
- }
- } else {
- cmCPackLogger(
- cmCPackLog::LOG_ERROR, "CPACK_RPM_MAIN_COMPONENT not set but"
- << " it is mandatory with CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE"
- << " being set.\n");
- retval = 0;
- }
- if (retval) {
- AddGeneratedPackageNames();
- }
- return retval;
- }
- int cmCPackRPMGenerator::PackageComponentsAllInOne(
- const std::string& compInstDirName)
- {
- int retval = 1;
-
- packageFileNames.clear();
- std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
- if (this->IsOn("CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE")) {
- this->SetOption("CPACK_RPM_DEBUGINFO_PACKAGE", "ON");
- }
- cmCPackLogger(cmCPackLog::LOG_VERBOSE,
- "Packaging all groups in one package..."
- "(CPACK_COMPONENTS_ALL_[GROUPS_]IN_ONE_PACKAGE is set)"
- << std::endl);
-
- std::string localToplevel(initialTopLevel);
- std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel));
- std::string outputFileName(
- std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME")) +
- this->GetOutputExtension());
-
- localToplevel += "/" + compInstDirName;
-
- this->SetOption("CPACK_TEMPORARY_DIRECTORY", localToplevel.c_str());
- packageFileName += "/" + outputFileName;
-
- this->SetOption("CPACK_OUTPUT_FILE_NAME", outputFileName.c_str());
-
- this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
- packageFileName.c_str());
- if (!compInstDirName.empty()) {
-
- std::string component_path = "/";
- component_path += compInstDirName;
- this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH",
- component_path.c_str());
- }
- if (this->ReadListFile("CPackRPM.cmake")) {
- AddGeneratedPackageNames();
- } else {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackRPM.cmake"
- << std::endl);
- retval = 0;
- }
- return retval;
- }
- int cmCPackRPMGenerator::PackageFiles()
- {
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl);
-
- if (WantsComponentInstallation()) {
-
-
-
- if (componentPackageMethod == ONE_PACKAGE) {
- return PackageComponentsAllInOne("ALL_COMPONENTS_IN_ONE");
- }
-
-
-
-
- return PackageComponents(componentPackageMethod ==
- ONE_PACKAGE_PER_COMPONENT);
- }
-
- return PackageComponentsAllInOne("");
- }
- bool cmCPackRPMGenerator::SupportsComponentInstallation() const
- {
- return IsOn("CPACK_RPM_COMPONENT_INSTALL");
- }
- std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix(
- const std::string& componentName)
- {
- if (componentPackageMethod == ONE_PACKAGE_PER_COMPONENT) {
- return componentName;
- }
- if (componentPackageMethod == ONE_PACKAGE) {
- return std::string("ALL_COMPONENTS_IN_ONE");
- }
-
-
- std::string groupVar =
- "CPACK_COMPONENT_" + cmSystemTools::UpperCase(componentName) + "_GROUP";
- if (nullptr != GetOption(groupVar)) {
- return std::string(GetOption(groupVar));
- }
- return componentName;
- }
|