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