cmCPackCygwinSourceGenerator.cxx 5.4 KB

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