cmCPackCygwinSourceGenerator.cxx 6.2 KB

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