cmCPackRPMGenerator.cxx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCPackRPMGenerator.h"
  11. #include "cmCPackLog.h"
  12. #include "cmSystemTools.h"
  13. //----------------------------------------------------------------------
  14. cmCPackRPMGenerator::cmCPackRPMGenerator()
  15. {
  16. }
  17. //----------------------------------------------------------------------
  18. cmCPackRPMGenerator::~cmCPackRPMGenerator()
  19. {
  20. }
  21. //----------------------------------------------------------------------
  22. int cmCPackRPMGenerator::InitializeInternal()
  23. {
  24. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
  25. if (cmSystemTools::IsOff(this->GetOption("CPACK_SET_DESTDIR")))
  26. {
  27. this->SetOption("CPACK_SET_DESTDIR", "I_ON");
  28. }
  29. return this->Superclass::InitializeInternal();
  30. }
  31. //----------------------------------------------------------------------
  32. int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
  33. {
  34. int retval = 1;
  35. /* Reset package file name list it will be populated during the
  36. * component packaging run*/
  37. packageFileNames.clear();
  38. std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
  39. // The default behavior is to have one package by component group
  40. // unless CPACK_COMPONENTS_IGNORE_GROUP is specified.
  41. if (!ignoreGroup)
  42. {
  43. std::map<std::string, cmCPackComponentGroup>::iterator compGIt;
  44. for (compGIt=this->ComponentGroups.begin();
  45. compGIt!=this->ComponentGroups.end(); ++compGIt)
  46. {
  47. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: "
  48. << compGIt->first
  49. << std::endl);
  50. // Begin the archive for this group
  51. std::string localToplevel(initialTopLevel);
  52. std::string packageFileName(
  53. cmSystemTools::GetParentDirectory(toplevel.c_str())
  54. );
  55. std::string outputFileName(
  56. GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
  57. compGIt->first,
  58. true)
  59. + this->GetOutputExtension()
  60. );
  61. localToplevel += "/"+ compGIt->first;
  62. /* replace the TEMP DIRECTORY with the component one */
  63. this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
  64. packageFileName += "/"+ outputFileName;
  65. /* replace proposed CPACK_OUTPUT_FILE_NAME */
  66. this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
  67. /* replace the TEMPORARY package file name */
  68. this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  69. packageFileName.c_str());
  70. // Tell CPackRPM.cmake the name of the component GROUP.
  71. this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",compGIt->first.c_str());
  72. if (!this->ReadListFile("CPackRPM.cmake"))
  73. {
  74. cmCPackLogger(cmCPackLog::LOG_ERROR,
  75. "Error while execution CPackRPM.cmake" << std::endl);
  76. retval = 0;
  77. }
  78. // add the generated package to package file names list
  79. packageFileNames.push_back(packageFileName);
  80. }
  81. }
  82. // CPACK_COMPONENTS_IGNORE_GROUPS is set
  83. // We build 1 package per component
  84. else
  85. {
  86. std::map<std::string, cmCPackComponent>::iterator compIt;
  87. for (compIt=this->Components.begin();
  88. compIt!=this->Components.end(); ++compIt )
  89. {
  90. std::string localToplevel(initialTopLevel);
  91. std::string packageFileName(
  92. cmSystemTools::GetParentDirectory(toplevel.c_str())
  93. );
  94. std::string outputFileName(
  95. GetComponentPackageFileName(this->GetOption("CPACK_PACKAGE_FILE_NAME"),
  96. compIt->first,
  97. false)
  98. + this->GetOutputExtension());
  99. localToplevel += "/"+ compIt->first;
  100. /* replace the TEMP DIRECTORY with the component one */
  101. this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
  102. packageFileName += "/"+ outputFileName;
  103. /* replace proposed CPACK_OUTPUT_FILE_NAME */
  104. this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
  105. /* replace the TEMPORARY package file name */
  106. this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  107. packageFileName.c_str());
  108. this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",compIt->first.c_str());
  109. if (!this->ReadListFile("CPackRPM.cmake"))
  110. {
  111. cmCPackLogger(cmCPackLog::LOG_ERROR,
  112. "Error while execution CPackRPM.cmake" << std::endl);
  113. retval = 0;
  114. }
  115. // add the generated package to package file names list
  116. packageFileNames.push_back(packageFileName);
  117. }
  118. }
  119. return retval;
  120. }
  121. //----------------------------------------------------------------------
  122. int cmCPackRPMGenerator::PackageComponentsAllInOne(bool allComponent)
  123. {
  124. int retval = 1;
  125. std::string compInstDirName;
  126. /* Reset package file name list it will be populated during the
  127. * component packaging run*/
  128. packageFileNames.clear();
  129. std::string initialTopLevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
  130. // all GROUP in one vs all COMPONENT in one
  131. if (allComponent)
  132. {
  133. compInstDirName = "ALL_COMPONENTS_IN_ONE";
  134. }
  135. else
  136. {
  137. compInstDirName = "ALL_GROUPS_IN_ONE";
  138. }
  139. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  140. "Packaging all groups in one package..."
  141. "(CPACK_COMPONENTS_ALL_[GROUPS_]IN_ONE_PACKAGE is set)"
  142. << std::endl);
  143. // The ALL GROUPS in ONE package case
  144. std::string localToplevel(initialTopLevel);
  145. std::string packageFileName(
  146. cmSystemTools::GetParentDirectory(toplevel.c_str())
  147. );
  148. std::string outputFileName(
  149. std::string(this->GetOption("CPACK_PACKAGE_FILE_NAME"))
  150. + this->GetOutputExtension()
  151. );
  152. // all GROUP in one vs all COMPONENT in one
  153. localToplevel += "/"+compInstDirName;
  154. /* replace the TEMP DIRECTORY with the component one */
  155. this->SetOption("CPACK_TEMPORARY_DIRECTORY",localToplevel.c_str());
  156. packageFileName += "/"+ outputFileName;
  157. /* replace proposed CPACK_OUTPUT_FILE_NAME */
  158. this->SetOption("CPACK_OUTPUT_FILE_NAME",outputFileName.c_str());
  159. /* replace the TEMPORARY package file name */
  160. this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  161. packageFileName.c_str());
  162. // Tell CPackRPM.cmake the name of the component GROUP.
  163. this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",compInstDirName.c_str());
  164. if (!this->ReadListFile("CPackRPM.cmake"))
  165. {
  166. cmCPackLogger(cmCPackLog::LOG_ERROR,
  167. "Error while execution CPackRPM.cmake" << std::endl);
  168. retval = 0;
  169. }
  170. // add the generated package to package file names list
  171. packageFileNames.push_back(packageFileName);
  172. return retval;
  173. }
  174. //----------------------------------------------------------------------
  175. int cmCPackRPMGenerator::PackageFiles()
  176. {
  177. int retval = 1;
  178. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: "
  179. << toplevel << std::endl);
  180. /* Are we in the component packaging case */
  181. if (SupportsComponentInstallation()) {
  182. // CASE 1 : COMPONENT ALL-IN-ONE package
  183. // If ALL GROUPS or ALL COMPONENTS in ONE package has been requested
  184. // then the package file is unique and should be open here.
  185. if (allComponentInOne ||
  186. (allGroupInOne && (!this->ComponentGroups.empty()))
  187. )
  188. {
  189. return PackageComponentsAllInOne(allComponentInOne);
  190. }
  191. // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one)
  192. // There will be 1 package for each component group
  193. // however one may require to ignore component group and
  194. // in this case you'll get 1 package for each component.
  195. else if ((!this->ComponentGroups.empty()) || (ignoreComponentGroup))
  196. {
  197. return PackageComponents(ignoreComponentGroup);
  198. }
  199. }
  200. // CASE 3 : NON COMPONENT package.
  201. else
  202. {
  203. if (!this->ReadListFile("CPackRPM.cmake"))
  204. {
  205. cmCPackLogger(cmCPackLog::LOG_ERROR,
  206. "Error while execution CPackRPM.cmake" << std::endl);
  207. retval = 0;
  208. }
  209. }
  210. if (!this->IsSet("RPMBUILD_EXECUTABLE"))
  211. {
  212. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find rpmbuild" << std::endl);
  213. retval = 0;
  214. }
  215. return retval;
  216. }
  217. bool cmCPackRPMGenerator::SupportsComponentInstallation() const
  218. {
  219. if (IsOn("CPACK_RPM_COMPONENT_INSTALL"))
  220. {
  221. return true;
  222. }
  223. else
  224. {
  225. return false;
  226. }
  227. }
  228. std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix(
  229. const std::string& componentName)
  230. {
  231. if (ignoreComponentGroup) {
  232. return componentName;
  233. }
  234. if (allComponentInOne) {
  235. return std::string("ALL_COMPONENTS_IN_ONE");
  236. }
  237. // We have to find the name of the COMPONENT GROUP
  238. // the current COMPONENT belongs to.
  239. std::string groupVar = "CPACK_COMPONENT_" +
  240. cmSystemTools::UpperCase(componentName) + "_GROUP";
  241. if (NULL != GetOption(groupVar.c_str()))
  242. {
  243. if (allGroupInOne)
  244. {
  245. return std::string("ALL_GROUPS_IN_ONE");
  246. }
  247. else
  248. {
  249. return std::string(GetOption(groupVar.c_str()));
  250. }
  251. }
  252. else
  253. {
  254. return componentName;
  255. }
  256. }