cmCPackCygwinSourceGenerator.cxx 6.1 KB

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