cmCPackCygwinSourceGenerator.cxx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. cmStrCat(this->GetOption("CPACK_TEMPORARY_DIRECTORY"), ".tar.bz2");
  34. packageFileNames[0] = packageDirFileName;
  35. std::string output;
  36. // skip one parent up to the cmCPackTarBZip2Generator
  37. // to create tar.bz2 file with the list of source
  38. // files
  39. this->Compress = cmArchiveWrite::CompressBZip2;
  40. if (!this->cmCPackTarBZip2Generator::PackageFiles()) {
  41. return 0;
  42. }
  43. // Now create a tar file that contains the above .tar.bz2 file
  44. // and the CPACK_CYGWIN_PATCH_FILE and CPACK_TOPLEVEL_DIRECTORY
  45. // files
  46. std::string compressOutFile = packageDirFileName;
  47. // at this point compressOutFile is the full path to
  48. // _CPack_Package/.../package-2.5.0.tar.bz2
  49. // we want to create a tar _CPack_Package/.../package-2.5.0-1-src.tar.bz2
  50. // with these
  51. // _CPack_Package/.../package-2.5.0-1.patch
  52. // _CPack_Package/.../package-2.5.0-1.sh
  53. // _CPack_Package/.../package-2.5.0.tar.bz2
  54. // the -1 is CPACK_CYGWIN_PATCH_NUMBER
  55. // first copy the patch file and the .sh file
  56. // to the toplevel cpack temp dir
  57. // copy the patch file into place
  58. if (!this->GetOption("CPACK_CYGWIN_PATCH_FILE")) {
  59. cmCPackLogger(cmCPackLog::LOG_ERROR,
  60. "No patch file specified for cygwin sources.");
  61. return 0;
  62. }
  63. if (!cmSystemTools::CopyFileAlways(
  64. this->GetOption("CPACK_CYGWIN_PATCH_FILE"),
  65. this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) {
  66. cmCPackLogger(cmCPackLog::LOG_ERROR,
  67. "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,
  82. "problem copying: "
  83. << this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT") << "\nto\n"
  84. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
  85. return 0;
  86. }
  87. std::string outerTarFile =
  88. cmStrCat(this->GetOption("CPACK_TEMPORARY_DIRECTORY"), '-');
  89. const char* patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
  90. if (!patch) {
  91. cmCPackLogger(cmCPackLog::LOG_WARNING,
  92. "CPACK_CYGWIN_PATCH_NUMBER"
  93. << " not specified, defaulting to 1\n");
  94. patch = "1";
  95. }
  96. outerTarFile += patch;
  97. outerTarFile += "-src.tar.bz2";
  98. std::string tmpDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  99. std::string buildScript =
  100. cmStrCat(tmpDir, '/',
  101. cmSystemTools::GetFilenameName(
  102. this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT")));
  103. std::string patchFile =
  104. cmStrCat(tmpDir, '/',
  105. cmSystemTools::GetFilenameName(
  106. this->GetOption("CPACK_CYGWIN_PATCH_FILE")));
  107. std::string file = cmSystemTools::GetFilenameName(compressOutFile);
  108. std::string sourceTar =
  109. cmStrCat(cmSystemTools::GetFilenamePath(compressOutFile), '/', file);
  110. /* reset list of file to be packaged */
  111. files.clear();
  112. // a source release in cygwin should have the build script used
  113. // to build the package, the patch file that is different from the
  114. // regular upstream version of the sources, and a bziped tar file
  115. // of the original sources
  116. files.push_back(buildScript);
  117. files.push_back(patchFile);
  118. files.push_back(sourceTar);
  119. /* update the name of the produced package */
  120. packageFileNames[0] = outerTarFile;
  121. /* update the toplevel dir */
  122. toplevel = tmpDir;
  123. if (!this->cmCPackTarBZip2Generator::PackageFiles()) {
  124. return 0;
  125. }
  126. return 1;
  127. }
  128. const char* cmCPackCygwinSourceGenerator::GetPackagingInstallPrefix()
  129. {
  130. this->InstallPrefix =
  131. cmStrCat('/', this->GetOption("CPACK_PACKAGE_FILE_NAME"));
  132. return this->InstallPrefix.c_str();
  133. }
  134. const char* cmCPackCygwinSourceGenerator::GetOutputExtension()
  135. {
  136. this->OutputExtension = "-";
  137. const char* patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
  138. if (!patch) {
  139. cmCPackLogger(cmCPackLog::LOG_WARNING,
  140. "CPACK_CYGWIN_PATCH_NUMBER"
  141. << " not specified, defaulting to 1\n");
  142. patch = "1";
  143. }
  144. this->OutputExtension += patch;
  145. this->OutputExtension += "-src.tar.bz2";
  146. return this->OutputExtension.c_str();
  147. }