Combine component packaging methods into an enum.

Also allow generators to override the default packaging method.
Add a ONE_PER_GROUP option so that method can be specified by the user without relying on defaults.
This commit is contained in:
Clinton Stimpson 2011-03-25 10:18:59 -06:00 committed by Brad King
parent 148b528f9d
commit 64a5e20999
5 changed files with 86 additions and 43 deletions

View File

@ -244,7 +244,7 @@ int cmCPackArchiveGenerator::PackageFiles()
// CASE 1 : COMPONENT ALL-IN-ONE package // CASE 1 : COMPONENT ALL-IN-ONE package
// If ALL COMPONENTS in ONE package has been requested // If ALL COMPONENTS in ONE package has been requested
// then the package file is unique and should be open here. // then the package file is unique and should be open here.
if (allComponentInOne) if (componentPackageMethod == ONE_PACKAGE)
{ {
return PackageComponentsAllInOne(); return PackageComponentsAllInOne();
} }
@ -254,7 +254,7 @@ int cmCPackArchiveGenerator::PackageFiles()
// in this case you'll get 1 package for each component. // in this case you'll get 1 package for each component.
else else
{ {
return PackageComponents(ignoreComponentGroup); return PackageComponents(componentPackageMethod == ONE_PACKAGE_PER_COMPONENT);
} }
} }

View File

@ -240,7 +240,7 @@ int cmCPackDebGenerator::PackageFiles()
// CASE 1 : COMPONENT ALL-IN-ONE package // CASE 1 : COMPONENT ALL-IN-ONE package
// If ALL GROUPS or ALL COMPONENTS in ONE package has been requested // If ALL GROUPS or ALL COMPONENTS in ONE package has been requested
// then the package file is unique and should be open here. // then the package file is unique and should be open here.
if (allComponentInOne) if (componentPackageMethod == ONE_PACKAGE)
{ {
return PackageComponentsAllInOne(); return PackageComponentsAllInOne();
} }
@ -250,7 +250,7 @@ int cmCPackDebGenerator::PackageFiles()
// in this case you'll get 1 package for each component. // in this case you'll get 1 package for each component.
else else
{ {
return PackageComponents(ignoreComponentGroup); return PackageComponents(componentPackageMethod == ONE_PACKAGE_PER_COMPONENT);
} }
} }
// CASE 3 : NON COMPONENT package. // CASE 3 : NON COMPONENT package.
@ -560,11 +560,11 @@ bool cmCPackDebGenerator::SupportsComponentInstallation() const
std::string cmCPackDebGenerator::GetComponentInstallDirNameSuffix( std::string cmCPackDebGenerator::GetComponentInstallDirNameSuffix(
const std::string& componentName) const std::string& componentName)
{ {
if (ignoreComponentGroup) { if (componentPackageMethod == ONE_PACKAGE_PER_COMPONENT) {
return componentName; return componentName;
} }
if (allComponentInOne) { if (componentPackageMethod == ONE_PACKAGE) {
return std::string("ALL_COMPONENTS_IN_ONE"); return std::string("ALL_COMPONENTS_IN_ONE");
} }
// We have to find the name of the COMPONENT GROUP // We have to find the name of the COMPONENT GROUP

View File

@ -36,8 +36,7 @@ cmCPackGenerator::cmCPackGenerator()
this->GeneratorVerbose = false; this->GeneratorVerbose = false;
this->MakefileMap = 0; this->MakefileMap = 0;
this->Logger = 0; this->Logger = 0;
this->allComponentInOne = false; this->componentPackageMethod = ONE_PACKAGE_PER_GROUP;
this->ignoreComponentGroup = false;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1263,14 +1262,23 @@ int cmCPackGenerator::CleanTemporaryDirectory()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int cmCPackGenerator::PrepareGroupingKind() int cmCPackGenerator::PrepareGroupingKind()
{ {
// The default behavior is to create 1 package by component group // find a component package method specified by the user
// unless the user asked to put all COMPONENTS in a single package ComponentPackageMethod method = UNKNOWN_COMPONENT_PACKAGE_METHOD;
allComponentInOne = (NULL != (this->GetOption(
"CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE")) if(this->GetOption("CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE"))
); {
ignoreComponentGroup = (NULL != (this->GetOption( method = ONE_PACKAGE;
"CPACK_COMPONENTS_IGNORE_GROUPS")) }
);
if(this->GetOption("CPACK_COMPONENTS_IGNORE_GROUPS"))
{
method = ONE_PACKAGE_PER_COMPONENT;
}
if(this->GetOption("CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP"))
{
method = ONE_PACKAGE_PER_GROUP;
}
std::string groupingType; std::string groupingType;
@ -1286,40 +1294,63 @@ int cmCPackGenerator::PrepareGroupingKind()
<< " requested component grouping = "<< groupingType <<std::endl); << " requested component grouping = "<< groupingType <<std::endl);
if (groupingType == "ALL_COMPONENTS_IN_ONE") if (groupingType == "ALL_COMPONENTS_IN_ONE")
{ {
allComponentInOne = true; method = ONE_PACKAGE;
} }
else if (groupingType == "IGNORE") else if (groupingType == "IGNORE")
{ {
ignoreComponentGroup = true; method = ONE_PACKAGE_PER_COMPONENT;
}
else if (groupingType == "ONE_PER_GROUP")
{
method = ONE_PACKAGE_PER_GROUP;
} }
else else
{ {
cmCPackLogger(cmCPackLog::LOG_WARNING, "[" cmCPackLogger(cmCPackLog::LOG_WARNING, "["
<< this->Name << "]" << this->Name << "]"
<< " requested component grouping type <"<< groupingType << " requested component grouping type <"<< groupingType
<< "> UNKNOWN not in (ALL_COMPONENTS_IN_ONE,IGNORE)" << "> UNKNOWN not in (ALL_COMPONENTS_IN_ONE,IGNORE,ONE_PER_GROUP)"
<< std::endl); << std::endl);
} }
} }
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "["
<< this->Name << "]"
<< " requested component grouping = ("
<< ", ALL_COMPONENTS_IN_ONE=" << allComponentInOne
<< ", IGNORE_GROUPS=" << ignoreComponentGroup
<< ")"
<< std::endl);
// Some components were defined but NO group // Some components were defined but NO group
// force ignoreGroups // fallback to default if not group based
if (this->ComponentGroups.empty() && (!this->Components.empty()) if(method == ONE_PACKAGE_PER_GROUP &&
&& (!ignoreComponentGroup)) { this->ComponentGroups.empty() && !this->Components.empty())
{
if(componentPackageMethod == ONE_PACKAGE)
{
method = ONE_PACKAGE;
}
else
{
method = ONE_PACKAGE_PER_COMPONENT;
}
cmCPackLogger(cmCPackLog::LOG_WARNING, "[" cmCPackLogger(cmCPackLog::LOG_WARNING, "["
<< this->Name << "]" << this->Name << "]"
<< " Some Components defined but NO component group:" << " One package per component group requested, but NO component groups exist:"
<< " Ignoring component group." << " Ignoring component group."
<< std::endl); << std::endl);
ignoreComponentGroup = true; }
}
// if user specified packaging method, override the default packaging method
if(method != UNKNOWN_COMPONENT_PACKAGE_METHOD)
{
componentPackageMethod = method;
}
const char* method_names[] =
{
"ALL_COMPONENTS_IN_ONE",
"IGNORE_GROUPS",
"ONE_PER_GROUP"
};
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "["
<< this->Name << "]"
<< " requested component grouping = " << method_names[componentPackageMethod]
<< std::endl);
return 1; return 1;
} }

View File

@ -125,7 +125,7 @@ protected:
* CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE * CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE
* CPACK_COMPONENTS_IGNORE_GROUPS * CPACK_COMPONENTS_IGNORE_GROUPS
* or * or
* CPACK_COMPONENTS_GROUPING * CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP
* @return 1 on success 0 on failure. * @return 1 on success 0 on failure.
*/ */
virtual int PrepareGroupingKind(); virtual int PrepareGroupingKind();
@ -237,16 +237,28 @@ protected:
*/ */
std::map<std::string, cmCPackComponent> Components; std::map<std::string, cmCPackComponent> Components;
std::map<std::string, cmCPackComponentGroup> ComponentGroups; std::map<std::string, cmCPackComponentGroup> ComponentGroups;
/** /**
* If true All component will be put in a single package. * If components are enabled, this enum represents the different
* ways of mapping components to package files.
*/ */
bool allComponentInOne; enum ComponentPackageMethod
{
/* one package for all components */
ONE_PACKAGE,
/* one package for each component */
ONE_PACKAGE_PER_COMPONENT,
/* one package for each group, with left over components in their own package */
ONE_PACKAGE_PER_GROUP,
UNKNOWN_COMPONENT_PACKAGE_METHOD
};
/** /**
* If true component grouping will be ignored. * The component package method
* You will still get 1 package for each component unless * The default is ONE_PACKAGE_PER_GROUP, and generators may override the default
* allComponentInOne is true. * before PrepareGroupingKind() is called.
*/ */
bool ignoreComponentGroup; ComponentPackageMethod componentPackageMethod;
cmCPackLog* Logger; cmCPackLog* Logger;
private: private:

View File

@ -205,7 +205,7 @@ int cmCPackRPMGenerator::PackageFiles()
// CASE 1 : COMPONENT ALL-IN-ONE package // CASE 1 : COMPONENT ALL-IN-ONE package
// If ALL COMPONENTS in ONE package has been requested // If ALL COMPONENTS in ONE package has been requested
// then the package file is unique and should be open here. // then the package file is unique and should be open here.
if (allComponentInOne) if (componentPackageMethod == ONE_PACKAGE)
{ {
return PackageComponentsAllInOne(); return PackageComponentsAllInOne();
} }
@ -215,7 +215,7 @@ int cmCPackRPMGenerator::PackageFiles()
// in this case you'll get 1 package for each component. // in this case you'll get 1 package for each component.
else else
{ {
return PackageComponents(ignoreComponentGroup); return PackageComponents(componentPackageMethod == ONE_PACKAGE_PER_COMPONENT);
} }
} }
// CASE 3 : NON COMPONENT package. // CASE 3 : NON COMPONENT package.
@ -252,11 +252,11 @@ bool cmCPackRPMGenerator::SupportsComponentInstallation() const
std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix( std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix(
const std::string& componentName) const std::string& componentName)
{ {
if (ignoreComponentGroup) { if (componentPackageMethod == ONE_PACKAGE_PER_COMPONENT) {
return componentName; return componentName;
} }
if (allComponentInOne) { if (componentPackageMethod == ONE_PACKAGE) {
return std::string("ALL_COMPONENTS_IN_ONE"); return std::string("ALL_COMPONENTS_IN_ONE");
} }
// We have to find the name of the COMPONENT GROUP // We have to find the name of the COMPONENT GROUP