cmCPackPackageMakerGenerator.cxx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCPackPackageMakerGenerator.h"
  14. #include "cmake.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmLocalGenerator.h"
  17. #include "cmSystemTools.h"
  18. #include "cmMakefile.h"
  19. #include "cmGeneratedFileStream.h"
  20. #include "cmCPackLog.h"
  21. #include <cmsys/SystemTools.hxx>
  22. #include <cmsys/Glob.hxx>
  23. //----------------------------------------------------------------------
  24. cmCPackPackageMakerGenerator::cmCPackPackageMakerGenerator()
  25. {
  26. }
  27. //----------------------------------------------------------------------
  28. cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator()
  29. {
  30. }
  31. //----------------------------------------------------------------------
  32. int cmCPackPackageMakerGenerator::CompressFiles(const char* outFileName, const char* toplevel,
  33. const std::vector<std::string>& files)
  34. {
  35. (void) files; // TODO: Fix api to not need files.
  36. (void) toplevel; // TODO: Use toplevel
  37. // Create directory structure
  38. std::string resDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  39. resDir += "/Resources";
  40. std::string preflightDirName = resDir + "/PreFlight";
  41. std::string postflightDirName = resDir + "/PostFlight";
  42. if ( !cmsys::SystemTools::MakeDirectory(preflightDirName.c_str())
  43. || !cmsys::SystemTools::MakeDirectory(postflightDirName.c_str()) )
  44. {
  45. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating installer directories: " << preflightDirName.c_str() << " and "
  46. << postflightDirName.c_str() << std::endl);
  47. return 0;
  48. }
  49. if ( !this->CopyCreateResourceFile("License")
  50. || !this->CopyCreateResourceFile("ReadMe")
  51. || !this->CopyCreateResourceFile("Welcome")
  52. || !this->CopyResourcePlistFile("Info.plist")
  53. || !this->CopyResourcePlistFile("Description.plist") )
  54. {
  55. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files" << std::endl);
  56. return 0;
  57. }
  58. std::string packageDirFileName = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  59. packageDirFileName += ".pkg";
  60. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  61. tmpFile += "/PackageMakerOutput.log";
  62. cmOStringStream pkgCmd;
  63. /*
  64. pkgCmd << "sh -c '\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
  65. << "\" -build -p \"" << packageDirFileName << "\" -f \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY")
  66. << "\" -r \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Resources\" -i \""
  67. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Info.plist\" -d \""
  68. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Description.plist\"'";
  69. */
  70. pkgCmd << "/Users/kitware/Andy/CMake-CPack/foo.sh";
  71. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << pkgCmd.str().c_str() << std::endl);
  72. std::string output;
  73. int retVal = 1;
  74. //bool res = cmSystemTools::RunSingleCommand(pkgCmd.str().c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
  75. bool res = true;
  76. retVal = system(pkgCmd.str().c_str());
  77. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running package maker" << std::endl);
  78. if ( !res || retVal )
  79. {
  80. cmGeneratedFileStream ofs(tmpFile.c_str());
  81. ofs << "# Run command: " << pkgCmd.str().c_str() << std::endl
  82. << "# Output:" << std::endl
  83. << output.c_str() << std::endl;
  84. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running PackageMaker command: " << pkgCmd.str().c_str() << std::endl
  85. << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
  86. return 0;
  87. }
  88. tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  89. tmpFile += "/hdiutilOutput.log";
  90. cmOStringStream dmgCmd;
  91. dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE") << "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName
  92. << "\" \"" << outFileName << "\"";
  93. res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
  94. if ( !res || retVal )
  95. {
  96. cmGeneratedFileStream ofs(tmpFile.c_str());
  97. ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl
  98. << "# Output:" << std::endl
  99. << output.c_str() << std::endl;
  100. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: " << dmgCmd.str().c_str() << std::endl
  101. << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
  102. return 0;
  103. }
  104. return 1;
  105. }
  106. //----------------------------------------------------------------------
  107. int cmCPackPackageMakerGenerator::Initialize(const char* name, cmMakefile* mf)
  108. {
  109. int res = this->Superclass::Initialize(name, mf);
  110. cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackPackageMakerGenerator::Initialize()" << std::endl);
  111. std::vector<std::string> path;
  112. std::string pkgPath = "/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS";
  113. path.push_back(pkgPath);
  114. pkgPath = cmSystemTools::FindProgram("PackageMaker", path, false);
  115. if ( pkgPath.empty() )
  116. {
  117. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find PackageMaker compiler" << std::endl);
  118. return 0;
  119. }
  120. this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
  121. pkgPath = cmSystemTools::FindProgram("hdiutil", path, false);
  122. if ( pkgPath.empty() )
  123. {
  124. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find hdiutil compiler" << std::endl);
  125. return 0;
  126. }
  127. this->SetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str());
  128. return res;
  129. }
  130. //----------------------------------------------------------------------
  131. bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name)
  132. {
  133. std::string uname = cmSystemTools::UpperCase(name);
  134. std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname;
  135. const char* inFileName = this->GetOption(cpackVar.c_str());
  136. if ( !inFileName )
  137. {
  138. cmCPackLogger(cmCPackLog::LOG_ERROR, "CPack option: " << cpackVar.c_str() << " not specified. It should point to " << name << ".rtf, " << name << ".html, or " << name << ".txt file" << std::endl);
  139. return false;
  140. }
  141. if ( !cmSystemTools::FileExists(inFileName) )
  142. {
  143. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find " << name << " resource file: " << inFileName << std::endl);
  144. return false;
  145. }
  146. std::string ext = cmSystemTools::GetFilenameLastExtension(inFileName);
  147. if ( ext != ".rtfd" && ext != ".rtf" && ext != ".html" && ext != ".txt" )
  148. {
  149. cmCPackLogger(cmCPackLog::LOG_ERROR, "Bad file extension specified: " << ext << ". Currently only .rtfd, .rtf, .html, and .txt files allowed." << std::endl);
  150. return false;
  151. }
  152. std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  153. destFileName += "/Resources/";
  154. destFileName += name + ext;
  155. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << inFileName << " to " << destFileName.c_str() << std::endl);
  156. this->ConfigureFile(inFileName, destFileName.c_str());
  157. return true;
  158. }
  159. bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(const char* name)
  160. {
  161. std::string inFName = "CPack.";
  162. inFName += name;
  163. inFName += ".in";
  164. std::string inFileName = this->FindTemplate(inFName.c_str());
  165. if ( inFileName.empty() )
  166. {
  167. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: " << inFName << std::endl);
  168. return false;
  169. }
  170. std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  171. destFileName += "/";
  172. destFileName += name;
  173. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << inFileName.c_str() << " to " << destFileName.c_str() << std::endl);
  174. this->ConfigureFile(inFileName.c_str(), destFileName.c_str());
  175. return true;
  176. }