cmCPackCygwinSourceGenerator.cxx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 "cmCPackCygwinSourceGenerator.h"
  11. #include "cmCPackLog.h"
  12. #include "cmGeneratedFileStream.h"
  13. #include "cmGlobalGenerator.h"
  14. #include "cmMakefile.h"
  15. #include "cmSystemTools.h"
  16. #include "cmake.h"
  17. #include <cmsys/SystemTools.hxx>
  18. // Includes needed for implementation of RenameFile. This is not in
  19. // system tools because it is not implemented robustly enough to move
  20. // files across directories.
  21. #ifdef _WIN32
  22. #include <sys/stat.h>
  23. #include <windows.h>
  24. #endif
  25. cmCPackCygwinSourceGenerator::cmCPackCygwinSourceGenerator()
  26. {
  27. }
  28. cmCPackCygwinSourceGenerator::~cmCPackCygwinSourceGenerator()
  29. {
  30. }
  31. int cmCPackCygwinSourceGenerator::InitializeInternal()
  32. {
  33. this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
  34. return this->Superclass::InitializeInternal();
  35. }
  36. int cmCPackCygwinSourceGenerator::PackageFiles()
  37. {
  38. // Create a tar file of the sources
  39. std::string packageDirFileName =
  40. this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  41. packageDirFileName += ".tar.bz2";
  42. packageFileNames[0] = packageDirFileName;
  43. std::string output;
  44. // skip one parent up to the cmCPackTarBZip2Generator
  45. // to create tar.bz2 file with the list of source
  46. // files
  47. this->Compress = cmArchiveWrite::CompressBZip2;
  48. if (!this->cmCPackTarBZip2Generator::PackageFiles()) {
  49. return 0;
  50. }
  51. // Now create a tar file that contains the above .tar.bz2 file
  52. // and the CPACK_CYGWIN_PATCH_FILE and CPACK_TOPLEVEL_DIRECTORY
  53. // files
  54. std::string compressOutFile = packageDirFileName;
  55. // at this point compressOutFile is the full path to
  56. // _CPack_Package/.../package-2.5.0.tar.bz2
  57. // we want to create a tar _CPack_Package/.../package-2.5.0-1-src.tar.bz2
  58. // with these
  59. // _CPack_Package/.../package-2.5.0-1.patch
  60. // _CPack_Package/.../package-2.5.0-1.sh
  61. // _CPack_Package/.../package-2.5.0.tar.bz2
  62. // the -1 is CPACK_CYGWIN_PATCH_NUMBER
  63. // first copy the patch file and the .sh file
  64. // to the toplevel cpack temp dir
  65. // copy the patch file into place
  66. if (!this->GetOption("CPACK_CYGWIN_PATCH_FILE")) {
  67. cmCPackLogger(cmCPackLog::LOG_ERROR,
  68. "No patch file specified for cygwin sources.");
  69. return 0;
  70. }
  71. if (!cmSystemTools::CopyFileAlways(
  72. this->GetOption("CPACK_CYGWIN_PATCH_FILE"),
  73. this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) {
  74. cmCPackLogger(cmCPackLog::LOG_ERROR, "problem copying: ["
  75. << this->GetOption("CPACK_CYGWIN_PATCH_FILE") << "]\nto\n["
  76. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
  77. return 0;
  78. }
  79. if (!this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT")) {
  80. cmCPackLogger(cmCPackLog::LOG_ERROR,
  81. "No build script specified for cygwin sources.");
  82. return 0;
  83. }
  84. // copy the build script into place
  85. if (!cmSystemTools::CopyFileAlways(
  86. this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"),
  87. this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) {
  88. cmCPackLogger(cmCPackLog::LOG_ERROR, "problem copying: "
  89. << this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT") << "\nto\n"
  90. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
  91. return 0;
  92. }
  93. std::string outerTarFile = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  94. outerTarFile += "-";
  95. const char* patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
  96. if (!patch) {
  97. cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_CYGWIN_PATCH_NUMBER"
  98. << " not specified, defaulting to 1\n");
  99. patch = "1";
  100. }
  101. outerTarFile += patch;
  102. outerTarFile += "-src.tar.bz2";
  103. std::string tmpDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  104. std::string buildScript = tmpDir;
  105. buildScript += "/";
  106. buildScript += cmSystemTools::GetFilenameName(
  107. this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"));
  108. std::string patchFile = tmpDir;
  109. patchFile += "/";
  110. patchFile +=
  111. cmSystemTools::GetFilenameName(this->GetOption("CPACK_CYGWIN_PATCH_FILE"));
  112. std::string file = cmSystemTools::GetFilenameName(compressOutFile);
  113. std::string sourceTar = cmSystemTools::GetFilenamePath(compressOutFile);
  114. sourceTar += "/";
  115. sourceTar += file;
  116. /* reset list of file to be packaged */
  117. files.clear();
  118. // a source release in cygwin should have the build script used
  119. // to build the package, the patch file that is different from the
  120. // regular upstream version of the sources, and a bziped tar file
  121. // of the original sources
  122. files.push_back(buildScript);
  123. files.push_back(patchFile);
  124. files.push_back(sourceTar);
  125. /* update the name of the produced package */
  126. packageFileNames[0] = outerTarFile;
  127. /* update the toplevel dir */
  128. toplevel = tmpDir;
  129. if (!this->cmCPackTarBZip2Generator::PackageFiles()) {
  130. return 0;
  131. }
  132. return 1;
  133. }
  134. const char* cmCPackCygwinSourceGenerator::GetPackagingInstallPrefix()
  135. {
  136. this->InstallPrefix = "/";
  137. this->InstallPrefix += this->GetOption("CPACK_PACKAGE_FILE_NAME");
  138. return this->InstallPrefix.c_str();
  139. }
  140. const char* cmCPackCygwinSourceGenerator::GetOutputExtension()
  141. {
  142. this->OutputExtension = "-";
  143. const char* patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
  144. if (!patch) {
  145. cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_CYGWIN_PATCH_NUMBER"
  146. << " not specified, defaulting to 1\n");
  147. patch = "1";
  148. }
  149. this->OutputExtension += patch;
  150. this->OutputExtension += "-src.tar.bz2";
  151. return this->OutputExtension.c_str();
  152. }