1
0

cmCPackPackageMakerGenerator.cxx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
  64. << "\" -build -p \"" << packageDirFileName << "\" -f \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY")
  65. << "\" -r \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Resources\" -i \""
  66. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Info.plist\" -d \""
  67. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Description.plist\"";
  68. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << pkgCmd.str().c_str() << std::endl);
  69. std::string output;
  70. int retVal = 1;
  71. //bool res = cmSystemTools::RunSingleCommand(pkgCmd.str().c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
  72. bool res = true;
  73. retVal = system(pkgCmd.str().c_str());
  74. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running package maker" << std::endl);
  75. if ( !res || retVal )
  76. {
  77. cmGeneratedFileStream ofs(tmpFile.c_str());
  78. ofs << "# Run command: " << pkgCmd.str().c_str() << std::endl
  79. << "# Output:" << std::endl
  80. << output.c_str() << std::endl;
  81. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running PackageMaker command: " << pkgCmd.str().c_str() << std::endl
  82. << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
  83. return 0;
  84. }
  85. tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  86. tmpFile += "/hdiutilOutput.log";
  87. cmOStringStream dmgCmd;
  88. dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE") << "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName
  89. << "\" \"" << outFileName << "\"";
  90. res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
  91. if ( !res || retVal )
  92. {
  93. cmGeneratedFileStream ofs(tmpFile.c_str());
  94. ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl
  95. << "# Output:" << std::endl
  96. << output.c_str() << std::endl;
  97. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: " << dmgCmd.str().c_str() << std::endl
  98. << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
  99. return 0;
  100. }
  101. return 1;
  102. }
  103. //----------------------------------------------------------------------
  104. int cmCPackPackageMakerGenerator::Initialize(const char* name, cmMakefile* mf)
  105. {
  106. int res = this->Superclass::Initialize(name, mf);
  107. cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackPackageMakerGenerator::Initialize()" << std::endl);
  108. std::vector<std::string> path;
  109. std::string pkgPath = "/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS";
  110. path.push_back(pkgPath);
  111. pkgPath = cmSystemTools::FindProgram("PackageMaker", path, false);
  112. if ( pkgPath.empty() )
  113. {
  114. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find PackageMaker compiler" << std::endl);
  115. return 0;
  116. }
  117. this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
  118. pkgPath = cmSystemTools::FindProgram("hdiutil", path, false);
  119. if ( pkgPath.empty() )
  120. {
  121. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find hdiutil compiler" << std::endl);
  122. return 0;
  123. }
  124. this->SetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str());
  125. return res;
  126. }
  127. //----------------------------------------------------------------------
  128. bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name)
  129. {
  130. std::string uname = cmSystemTools::UpperCase(name);
  131. std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname;
  132. const char* inFileName = this->GetOption(cpackVar.c_str());
  133. if ( !inFileName )
  134. {
  135. 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);
  136. return false;
  137. }
  138. if ( !cmSystemTools::FileExists(inFileName) )
  139. {
  140. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find " << name << " resource file: " << inFileName << std::endl);
  141. return false;
  142. }
  143. std::string ext = cmSystemTools::GetFilenameLastExtension(inFileName);
  144. if ( ext != ".rtfd" && ext != ".rtf" && ext != ".html" && ext != ".txt" )
  145. {
  146. cmCPackLogger(cmCPackLog::LOG_ERROR, "Bad file extension specified: " << ext << ". Currently only .rtfd, .rtf, .html, and .txt files allowed." << std::endl);
  147. return false;
  148. }
  149. std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  150. destFileName += "/Resources/";
  151. destFileName += name + ext;
  152. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << inFileName << " to " << destFileName.c_str() << std::endl);
  153. this->ConfigureFile(inFileName, destFileName.c_str());
  154. return true;
  155. }
  156. bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(const char* name)
  157. {
  158. std::string inFName = "CPack.";
  159. inFName += name;
  160. inFName += ".in";
  161. std::string inFileName = this->FindTemplate(inFName.c_str());
  162. if ( inFileName.empty() )
  163. {
  164. cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: " << inFName << std::endl);
  165. return false;
  166. }
  167. std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  168. destFileName += "/";
  169. destFileName += name;
  170. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << inFileName.c_str() << " to " << destFileName.c_str() << std::endl);
  171. this->ConfigureFile(inFileName.c_str(), destFileName.c_str());
  172. return true;
  173. }