cmCPackCygwinSourceGenerator.cxx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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()
  24. {
  25. }
  26. int cmCPackCygwinSourceGenerator::InitializeInternal()
  27. {
  28. this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
  29. return this->Superclass::InitializeInternal();
  30. }
  31. int cmCPackCygwinSourceGenerator::PackageFiles()
  32. {
  33. // Create a tar file of the sources
  34. std::string packageDirFileName =
  35. cmStrCat(this->GetOption("CPACK_TEMPORARY_DIRECTORY"), ".tar.bz2");
  36. packageFileNames[0] = packageDirFileName;
  37. std::string output;
  38. // create tar.bz2 file with the list of source files
  39. if (!this->cmCPackArchiveGenerator::PackageFiles()) {
  40. return 0;
  41. }
  42. // Now create a tar file that contains the above .tar.bz2 file
  43. // and the CPACK_CYGWIN_PATCH_FILE and CPACK_TOPLEVEL_DIRECTORY
  44. // files
  45. std::string compressOutFile = packageDirFileName;
  46. // at this point compressOutFile is the full path to
  47. // _CPack_Package/.../package-2.5.0.tar.bz2
  48. // we want to create a tar _CPack_Package/.../package-2.5.0-1-src.tar.bz2
  49. // with these
  50. // _CPack_Package/.../package-2.5.0-1.patch
  51. // _CPack_Package/.../package-2.5.0-1.sh
  52. // _CPack_Package/.../package-2.5.0.tar.bz2
  53. // the -1 is CPACK_CYGWIN_PATCH_NUMBER
  54. // first copy the patch file and the .sh file
  55. // to the toplevel cpack temp dir
  56. // copy the patch file into place
  57. if (!this->GetOption("CPACK_CYGWIN_PATCH_FILE")) {
  58. cmCPackLogger(cmCPackLog::LOG_ERROR,
  59. "No patch file specified for cygwin sources.");
  60. return 0;
  61. }
  62. if (!cmSystemTools::CopyFileAlways(
  63. this->GetOption("CPACK_CYGWIN_PATCH_FILE"),
  64. this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) {
  65. cmCPackLogger(cmCPackLog::LOG_ERROR,
  66. "problem copying: ["
  67. << this->GetOption("CPACK_CYGWIN_PATCH_FILE") << "]\nto\n["
  68. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
  69. return 0;
  70. }
  71. if (!this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT")) {
  72. cmCPackLogger(cmCPackLog::LOG_ERROR,
  73. "No build script specified for cygwin sources.");
  74. return 0;
  75. }
  76. // copy the build script into place
  77. if (!cmSystemTools::CopyFileAlways(
  78. this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"),
  79. this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) {
  80. cmCPackLogger(cmCPackLog::LOG_ERROR,
  81. "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 =
  87. cmStrCat(this->GetOption("CPACK_TEMPORARY_DIRECTORY"), '-');
  88. cmValue patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
  89. if (!patch) {
  90. cmCPackLogger(cmCPackLog::LOG_WARNING,
  91. "CPACK_CYGWIN_PATCH_NUMBER"
  92. << " not specified, defaulting to 1\n");
  93. outerTarFile += "1";
  94. } else {
  95. outerTarFile += patch;
  96. }
  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->cmCPackArchiveGenerator::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. cmValue 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. this->OutputExtension += "1";
  143. } else {
  144. this->OutputExtension += patch;
  145. }
  146. this->OutputExtension += "-src.tar.bz2";
  147. return this->OutputExtension.c_str();
  148. }