2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2006-01-02 07:21:05 +03:00
|
|
|
#include "cmCPackPackageMakerGenerator.h"
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
#include "cmCPackComponentGroup.h"
|
2006-01-03 00:14:21 +03:00
|
|
|
#include "cmCPackLog.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmSystemTools.h"
|
2016-06-09 00:35:31 +03:00
|
|
|
#include "cmXMLWriter.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmake.h"
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/Glob.hxx>
|
|
|
|
#include <cmsys/SystemTools.hxx>
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2014-12-26 20:48:53 +03:00
|
|
|
#include <assert.h>
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static inline unsigned int getVersion(unsigned int major, unsigned int minor)
|
2014-12-26 20:48:53 +03:00
|
|
|
{
|
|
|
|
assert(major < 256 && minor < 256);
|
|
|
|
return ((major & 0xFF) << 16 | minor);
|
|
|
|
}
|
|
|
|
|
2006-01-02 07:21:05 +03:00
|
|
|
cmCPackPackageMakerGenerator::cmCPackPackageMakerGenerator()
|
|
|
|
{
|
2007-11-05 22:34:36 +03:00
|
|
|
this->PackageMakerVersion = 0.0;
|
2014-12-26 20:48:53 +03:00
|
|
|
this->PackageCompatibilityVersion = getVersion(10, 4);
|
2006-01-02 07:21:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
bool cmCPackPackageMakerGenerator::SupportsComponentInstallation() const
|
|
|
|
{
|
2014-12-26 20:48:53 +03:00
|
|
|
return this->PackageCompatibilityVersion >= getVersion(10, 4);
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
|
|
|
|
2010-08-11 21:48:39 +04:00
|
|
|
int cmCPackPackageMakerGenerator::PackageFiles()
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2010-08-11 21:48:39 +04:00
|
|
|
// TODO: Use toplevel
|
|
|
|
// It is used! Is this an obsolete comment?
|
2008-06-18 15:08:33 +04:00
|
|
|
|
|
|
|
std::string resDir; // Where this package's resources will go.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string packageDirFileName =
|
|
|
|
this->GetOption("CPACK_TEMPORARY_DIRECTORY");
|
|
|
|
if (this->Components.empty()) {
|
2008-06-18 15:08:33 +04:00
|
|
|
packageDirFileName += ".pkg";
|
|
|
|
resDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
resDir += "/Resources";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-06-18 15:08:33 +04:00
|
|
|
packageDirFileName += ".mpkg";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmsys::SystemTools::MakeDirectory(packageDirFileName.c_str())) {
|
2008-06-18 15:08:33 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2016-05-16 17:34:04 +03:00
|
|
|
"unable to create package directory " << packageDirFileName
|
|
|
|
<< std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-18 15:08:33 +04:00
|
|
|
|
|
|
|
resDir = packageDirFileName;
|
|
|
|
resDir += "/Contents";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmsys::SystemTools::MakeDirectory(resDir.c_str())) {
|
2008-06-18 15:08:33 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2012-08-13 21:42:58 +04:00
|
|
|
"unable to create package subdirectory " << resDir
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-18 15:08:33 +04:00
|
|
|
|
|
|
|
resDir += "/Resources";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmsys::SystemTools::MakeDirectory(resDir.c_str())) {
|
2008-06-18 15:08:33 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2012-08-13 21:42:58 +04:00
|
|
|
"unable to create package subdirectory " << resDir
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-18 15:08:33 +04:00
|
|
|
|
|
|
|
resDir += "/en.lproj";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-18 15:08:33 +04:00
|
|
|
|
2008-02-19 22:26:20 +03:00
|
|
|
const char* preflight = this->GetOption("CPACK_PREFLIGHT_SCRIPT");
|
|
|
|
const char* postflight = this->GetOption("CPACK_POSTFLIGHT_SCRIPT");
|
|
|
|
const char* postupgrade = this->GetOption("CPACK_POSTUPGRADE_SCRIPT");
|
2012-10-27 21:07:31 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Components.empty()) {
|
2012-10-27 21:07:31 +04:00
|
|
|
// Create directory structure
|
|
|
|
std::string preflightDirName = resDir + "/PreFlight";
|
|
|
|
std::string postflightDirName = resDir + "/PostFlight";
|
|
|
|
// if preflight or postflight scripts not there create directories
|
|
|
|
// of the same name, I think this makes it work
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!preflight) {
|
|
|
|
if (!cmsys::SystemTools::MakeDirectory(preflightDirName.c_str())) {
|
2012-10-27 21:07:31 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem creating installer directory: "
|
2016-06-07 00:53:32 +03:00
|
|
|
<< preflightDirName << std::endl);
|
2012-10-27 21:07:31 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!postflight) {
|
|
|
|
if (!cmsys::SystemTools::MakeDirectory(postflightDirName.c_str())) {
|
2012-10-27 21:07:31 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem creating installer directory: "
|
2016-06-07 00:53:32 +03:00
|
|
|
<< postflightDirName << std::endl);
|
2012-10-27 21:07:31 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-27 21:07:31 +04:00
|
|
|
// if preflight, postflight, or postupgrade are set
|
|
|
|
// then copy them into the resource directory and make
|
|
|
|
// them executable
|
2016-05-16 17:34:04 +03:00
|
|
|
if (preflight) {
|
2016-09-04 17:55:05 +03:00
|
|
|
this->CopyInstallScript(resDir, preflight, "preflight");
|
2008-02-19 22:26:20 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (postflight) {
|
2016-09-04 17:55:05 +03:00
|
|
|
this->CopyInstallScript(resDir, postflight, "postflight");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (postupgrade) {
|
2016-09-04 17:55:05 +03:00
|
|
|
this->CopyInstallScript(resDir, postupgrade, "postupgrade");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
} else if (postflight) {
|
2012-10-27 21:07:31 +04:00
|
|
|
// create a postflight component to house the script
|
|
|
|
this->PostFlightComponent.Name = "PostFlight";
|
|
|
|
this->PostFlightComponent.DisplayName = "PostFlight";
|
|
|
|
this->PostFlightComponent.Description = "PostFlight";
|
|
|
|
this->PostFlightComponent.IsHidden = true;
|
|
|
|
|
|
|
|
// empty directory for pkg contents
|
|
|
|
std::string packageDir = toplevel + "/" + PostFlightComponent.Name;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmsys::SystemTools::MakeDirectory(packageDir.c_str())) {
|
2008-02-19 22:26:20 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2012-10-27 21:07:31 +04:00
|
|
|
"Problem creating component packages directory: "
|
2016-06-07 00:53:32 +03:00
|
|
|
<< packageDir << std::endl);
|
2008-02-19 22:26:20 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-27 21:07:31 +04:00
|
|
|
|
|
|
|
// create package
|
|
|
|
std::string packageFileDir = packageDirFileName + "/Contents/Packages/";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmsys::SystemTools::MakeDirectory(packageFileDir.c_str())) {
|
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem creating component PostFlight Packages directory: "
|
2016-06-07 00:53:32 +03:00
|
|
|
<< packageFileDir << std::endl);
|
2012-10-27 21:07:31 +04:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
std::string packageFile =
|
|
|
|
packageFileDir + this->GetPackageName(PostFlightComponent);
|
|
|
|
if (!this->GenerateComponentPackage(
|
|
|
|
packageFile.c_str(), packageDir.c_str(), PostFlightComponent)) {
|
2012-10-27 21:07:31 +04:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-27 21:07:31 +04:00
|
|
|
|
|
|
|
// copy postflight script into resource directory of .pkg
|
|
|
|
std::string resourceDir = packageFile + "/Contents/Resources";
|
2016-09-04 17:55:05 +03:00
|
|
|
this->CopyInstallScript(resourceDir, postflight, "postflight");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Components.empty()) {
|
2008-07-09 21:38:56 +04:00
|
|
|
// Create the directory where component packages will be built.
|
2008-06-18 15:08:33 +04:00
|
|
|
std::string basePackageDir = packageDirFileName;
|
|
|
|
basePackageDir += "/Contents/Packages";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str())) {
|
2008-06-17 19:39:26 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem creating component packages directory: "
|
2016-06-07 00:53:32 +03:00
|
|
|
<< basePackageDir << std::endl);
|
2008-06-17 19:39:26 +04:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
2008-07-09 21:38:56 +04:00
|
|
|
// Create the directory where downloaded component packages will
|
|
|
|
// be placed.
|
2008-10-01 17:04:27 +04:00
|
|
|
const char* userUploadDirectory =
|
|
|
|
this->GetOption("CPACK_UPLOAD_DIRECTORY");
|
2008-07-09 21:38:56 +04:00
|
|
|
std::string uploadDirectory;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (userUploadDirectory && *userUploadDirectory) {
|
2008-07-09 21:38:56 +04:00
|
|
|
uploadDirectory = userUploadDirectory;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
uploadDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY");
|
2008-07-09 21:38:56 +04:00
|
|
|
uploadDirectory += "/CPackUploads";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-09 21:38:56 +04:00
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
// Create packages for each component
|
2008-07-09 21:38:56 +04:00
|
|
|
bool warnedAboutDownloadCompatibility = false;
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
std::map<std::string, cmCPackComponent>::iterator compIt;
|
|
|
|
for (compIt = this->Components.begin(); compIt != this->Components.end();
|
2016-05-16 17:34:04 +03:00
|
|
|
++compIt) {
|
2008-07-09 21:38:56 +04:00
|
|
|
std::string packageFile;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (compIt->second.IsDownloaded) {
|
2014-12-26 20:48:53 +03:00
|
|
|
if (this->PackageCompatibilityVersion >= getVersion(10, 5) &&
|
2016-05-16 17:34:04 +03:00
|
|
|
this->PackageMakerVersion >= 3.0) {
|
2008-07-09 21:38:56 +04:00
|
|
|
// Build this package within the upload directory.
|
|
|
|
packageFile = uploadDirectory;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileExists(uploadDirectory.c_str())) {
|
|
|
|
if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str())) {
|
2008-07-09 21:38:56 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2012-08-13 21:42:58 +04:00
|
|
|
"Unable to create package upload directory "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< uploadDirectory << std::endl);
|
2008-07-09 21:38:56 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!warnedAboutDownloadCompatibility) {
|
|
|
|
if (this->PackageCompatibilityVersion < getVersion(10, 5)) {
|
2008-10-01 17:04:27 +04:00
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_WARNING,
|
|
|
|
"CPack warning: please set CPACK_OSX_PACKAGE_VERSION to 10.5 "
|
|
|
|
"or greater enable downloaded packages. CPack will build a "
|
|
|
|
"non-downloaded package."
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
|
|
|
}
|
2008-07-09 21:38:56 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->PackageMakerVersion < 3) {
|
2008-07-09 21:38:56 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_WARNING,
|
2016-05-16 17:34:04 +03:00
|
|
|
"CPack warning: unable to build downloaded "
|
2008-10-01 17:04:27 +04:00
|
|
|
"packages with PackageMaker versions prior "
|
|
|
|
"to 3.0. CPack will build a non-downloaded package."
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
|
|
|
}
|
2008-07-09 21:38:56 +04:00
|
|
|
|
|
|
|
warnedAboutDownloadCompatibility = true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-09 21:38:56 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (packageFile.empty()) {
|
2008-07-09 21:38:56 +04:00
|
|
|
// Build this package within the overall distribution
|
|
|
|
// metapackage.
|
|
|
|
packageFile = basePackageDir;
|
|
|
|
|
|
|
|
// We're not downloading this component, even if the user
|
|
|
|
// requested it.
|
|
|
|
compIt->second.IsDownloaded = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-09 21:38:56 +04:00
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
packageFile += '/';
|
|
|
|
packageFile += GetPackageName(compIt->second);
|
|
|
|
|
|
|
|
std::string packageDir = toplevel;
|
|
|
|
packageDir += '/';
|
|
|
|
packageDir += compIt->first;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->GenerateComponentPackage(
|
|
|
|
packageFile.c_str(), packageDir.c_str(), compIt->second)) {
|
2008-06-17 19:39:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
this->SetOption("CPACK_MODULE_VERSION_SUFFIX", "");
|
|
|
|
|
|
|
|
// Copy or create all of the resource files we need.
|
2016-09-04 17:55:05 +03:00
|
|
|
if (!this->CopyCreateResourceFile("License", resDir) ||
|
|
|
|
!this->CopyCreateResourceFile("ReadMe", resDir) ||
|
|
|
|
!this->CopyCreateResourceFile("Welcome", resDir) ||
|
2016-05-16 17:34:04 +03:00
|
|
|
!this->CopyResourcePlistFile("Info.plist") ||
|
|
|
|
!this->CopyResourcePlistFile("Description.plist")) {
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Components.empty()) {
|
2008-06-18 15:08:33 +04:00
|
|
|
// Use PackageMaker to build the package.
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream pkgCmd;
|
2008-06-18 15:08:33 +04:00
|
|
|
pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
|
|
|
|
<< "\" -build -p \"" << packageDirFileName << "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Components.empty()) {
|
2008-06-18 15:08:33 +04:00
|
|
|
pkgCmd << " -f \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY");
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-06-18 15:08:33 +04:00
|
|
|
pkgCmd << " -mi \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY")
|
|
|
|
<< "/packages/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-18 15:08:33 +04:00
|
|
|
pkgCmd << "\" -r \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
|
|
|
|
<< "/Resources\" -i \""
|
2012-08-13 21:42:58 +04:00
|
|
|
<< this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
|
2008-06-18 15:08:33 +04:00
|
|
|
<< "/Info.plist\" -d \""
|
2008-07-09 21:38:56 +04:00
|
|
|
<< this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
|
2008-06-18 15:08:33 +04:00
|
|
|
<< "/Description.plist\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->PackageMakerVersion > 2.0) {
|
2008-06-18 15:08:33 +04:00
|
|
|
pkgCmd << " -v";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-18 15:08:33 +04:00
|
|
|
if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str()))
|
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-06-18 15:08:33 +04:00
|
|
|
// We have built the package in place. Generate the
|
|
|
|
// distribution.dist file to describe it for the installer.
|
2008-06-17 19:39:26 +04:00
|
|
|
WriteDistributionFile(packageDirFileName.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
2006-01-02 07:21:05 +03:00
|
|
|
tmpFile += "/hdiutilOutput.log";
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream dmgCmd;
|
2006-03-09 00:33:39 +03:00
|
|
|
dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE")
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName
|
|
|
|
<< "\" \"" << packageFileNames[0] << "\"";
|
2008-06-17 19:39:26 +04:00
|
|
|
std::string output;
|
|
|
|
int retVal = 1;
|
2012-03-09 20:39:01 +04:00
|
|
|
int numTries = 10;
|
2011-02-03 18:21:32 +03:00
|
|
|
bool res = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (numTries > 0) {
|
|
|
|
res =
|
|
|
|
cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &output,
|
|
|
|
&retVal, 0, this->GeneratorVerbose, 0);
|
|
|
|
if (res && !retVal) {
|
2009-10-04 17:54:55 +04:00
|
|
|
numTries = -1;
|
2012-03-09 20:39:01 +04:00
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-03-09 20:39:01 +04:00
|
|
|
cmSystemTools::Delay(500);
|
2009-10-04 17:54:55 +04:00
|
|
|
numTries--;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!res || retVal) {
|
2006-01-02 07:21:05 +03:00
|
|
|
cmGeneratedFileStream ofs(tmpFile.c_str());
|
2016-06-07 00:53:32 +03:00
|
|
|
ofs << "# Run command: " << dmgCmd.str() << std::endl
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "# Output:" << std::endl
|
2016-06-07 00:53:32 +03:00
|
|
|
<< output << std::endl;
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: "
|
2016-06-07 00:53:32 +03:00
|
|
|
<< dmgCmd.str() << std::endl
|
|
|
|
<< "Please check " << tmpFile << " for errors"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-01-02 07:21:05 +03:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-04-15 21:02:18 +04:00
|
|
|
int cmCPackPackageMakerGenerator::InitializeInternal()
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2013-11-02 20:24:53 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
|
|
|
|
|
2012-03-04 00:03:50 +04:00
|
|
|
// Starting with Xcode 4.3, PackageMaker is a separate app, and you
|
|
|
|
// can put it anywhere you want. So... use a variable for its location.
|
|
|
|
// People who put it in unexpected places can use the variable to tell
|
|
|
|
// us where it is.
|
|
|
|
//
|
|
|
|
// Use the following locations, in "most recent installation" order,
|
|
|
|
// to search for the PackageMaker app. Assume people who copy it into
|
|
|
|
// the new Xcode 4.3 app in "/Applications" will copy it into the nested
|
|
|
|
// Applications folder inside the Xcode bundle itself. Or directly in
|
|
|
|
// the "/Applications" directory.
|
|
|
|
//
|
|
|
|
// If found, save result in the CPACK_INSTALLER_PROGRAM variable.
|
|
|
|
|
|
|
|
std::vector<std::string> paths;
|
2016-05-16 17:34:04 +03:00
|
|
|
paths.push_back("/Applications/Xcode.app/Contents/Applications"
|
|
|
|
"/PackageMaker.app/Contents/MacOS");
|
|
|
|
paths.push_back("/Applications/Utilities"
|
|
|
|
"/PackageMaker.app/Contents/MacOS");
|
|
|
|
paths.push_back("/Applications"
|
|
|
|
"/PackageMaker.app/Contents/MacOS");
|
|
|
|
paths.push_back("/Developer/Applications/Utilities"
|
|
|
|
"/PackageMaker.app/Contents/MacOS");
|
|
|
|
paths.push_back("/Developer/Applications"
|
|
|
|
"/PackageMaker.app/Contents/MacOS");
|
2012-03-04 00:03:50 +04:00
|
|
|
|
|
|
|
std::string pkgPath;
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* inst_program = this->GetOption("CPACK_INSTALLER_PROGRAM");
|
|
|
|
if (inst_program && *inst_program) {
|
2012-03-04 00:03:50 +04:00
|
|
|
pkgPath = inst_program;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2012-03-04 00:03:50 +04:00
|
|
|
pkgPath = cmSystemTools::FindProgram("PackageMaker", paths, false);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pkgPath.empty()) {
|
2012-03-04 00:03:50 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find PackageMaker compiler"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
2006-03-21 00:24:43 +03:00
|
|
|
return 0;
|
2012-03-04 00:03:50 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
|
|
|
|
}
|
2012-03-04 00:03:50 +04:00
|
|
|
|
2012-03-13 22:01:19 +04:00
|
|
|
// Get path to the real PackageMaker, not a symlink:
|
2016-09-04 17:55:05 +03:00
|
|
|
pkgPath = cmSystemTools::GetRealPath(pkgPath);
|
2012-03-13 22:01:19 +04:00
|
|
|
// Up from there to find the version.plist file in the "Contents" dir:
|
2012-03-04 00:03:50 +04:00
|
|
|
std::string contents_dir;
|
|
|
|
contents_dir = cmSystemTools::GetFilenamePath(pkgPath);
|
|
|
|
contents_dir = cmSystemTools::GetFilenamePath(contents_dir);
|
|
|
|
|
|
|
|
std::string versionFile = contents_dir + "/version.plist";
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileExists(versionFile.c_str())) {
|
2012-03-04 00:03:50 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Cannot find PackageMaker compiler version file: "
|
2016-06-07 00:53:32 +03:00
|
|
|
<< versionFile << std::endl);
|
2012-03-04 00:03:50 +04:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-03-04 00:03:50 +04:00
|
|
|
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream ifs(versionFile.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!ifs) {
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Cannot open PackageMaker compiler version file"
|
|
|
|
<< std::endl);
|
2006-03-03 23:04:28 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-03-04 00:03:50 +04:00
|
|
|
|
2006-03-03 23:04:28 +03:00
|
|
|
// Check the PackageMaker version
|
|
|
|
cmsys::RegularExpression rexKey("<key>CFBundleShortVersionString</key>");
|
2006-03-08 21:59:33 +03:00
|
|
|
cmsys::RegularExpression rexVersion("<string>([0-9]+.[0-9.]+)</string>");
|
2006-03-03 23:04:28 +03:00
|
|
|
std::string line;
|
|
|
|
bool foundKey = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(ifs, line)) {
|
|
|
|
if (rexKey.find(line)) {
|
2006-03-03 23:04:28 +03:00
|
|
|
foundKey = true;
|
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!foundKey) {
|
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_ERROR,
|
2006-03-09 00:33:39 +03:00
|
|
|
"Cannot find CFBundleShortVersionString in the PackageMaker compiler "
|
2016-05-16 17:34:04 +03:00
|
|
|
"version file"
|
|
|
|
<< std::endl);
|
2006-03-03 23:04:28 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!cmSystemTools::GetLineFromStream(ifs, line) || !rexVersion.find(line)) {
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Problem reading the PackageMaker compiler version file: "
|
2016-06-07 00:53:32 +03:00
|
|
|
<< versionFile << std::endl);
|
2006-03-03 23:04:28 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-03 23:04:28 +03:00
|
|
|
this->PackageMakerVersion = atof(rexVersion.match(1).c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->PackageMakerVersion < 1.0) {
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Require PackageMaker 1.0 or higher"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
2006-03-03 23:04:28 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "PackageMaker version is: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< this->PackageMakerVersion << std::endl);
|
2006-03-03 23:04:28 +03:00
|
|
|
|
2008-07-09 21:38:56 +04:00
|
|
|
// Determine the package compatibility version. If it wasn't
|
|
|
|
// specified by the user, we define it based on which features the
|
|
|
|
// user requested.
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* packageCompat = this->GetOption("CPACK_OSX_PACKAGE_VERSION");
|
|
|
|
if (packageCompat && *packageCompat) {
|
2014-12-26 20:48:53 +03:00
|
|
|
unsigned int majorVersion = 10;
|
|
|
|
unsigned int minorVersion = 5;
|
|
|
|
int res = sscanf(packageCompat, "%u.%u", &majorVersion, &minorVersion);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (res == 2) {
|
2014-12-26 20:48:53 +03:00
|
|
|
this->PackageCompatibilityVersion =
|
|
|
|
getVersion(majorVersion, minorVersion);
|
2008-07-09 21:38:56 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->GetOption("CPACK_DOWNLOAD_SITE")) {
|
2008-07-09 21:38:56 +04:00
|
|
|
this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.5");
|
2014-12-26 20:48:53 +03:00
|
|
|
this->PackageCompatibilityVersion = getVersion(10, 5);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->GetOption("CPACK_COMPONENTS_ALL")) {
|
2008-07-09 21:38:56 +04:00
|
|
|
this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.4");
|
2014-12-26 20:48:53 +03:00
|
|
|
this->PackageCompatibilityVersion = getVersion(10, 4);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-07-09 21:38:56 +04:00
|
|
|
this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.3");
|
2014-12-26 20:48:53 +03:00
|
|
|
this->PackageCompatibilityVersion = getVersion(10, 3);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-09 21:38:56 +04:00
|
|
|
|
2012-03-04 00:03:50 +04:00
|
|
|
std::vector<std::string> no_paths;
|
|
|
|
pkgPath = cmSystemTools::FindProgram("hdiutil", no_paths, false);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pkgPath.empty()) {
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find hdiutil compiler"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE",
|
2006-05-12 22:44:24 +04:00
|
|
|
pkgPath.c_str());
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2006-04-15 21:02:18 +04:00
|
|
|
return this->Superclass::InitializeInternal();
|
2006-01-02 07:21:05 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCPackPackageMakerGenerator::RunPackageMaker(const char* command,
|
|
|
|
const char* packageFile)
|
2008-06-17 19:39:26 +04:00
|
|
|
{
|
|
|
|
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
tmpFile += "/PackageMakerOutput.log";
|
|
|
|
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl);
|
|
|
|
std::string output;
|
|
|
|
int retVal = 1;
|
2015-04-20 22:36:57 +03:00
|
|
|
bool res = cmSystemTools::RunSingleCommand(
|
2016-05-16 17:34:04 +03:00
|
|
|
command, &output, &output, &retVal, 0, this->GeneratorVerbose, 0);
|
2008-06-17 19:39:26 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running package maker"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
|
|
|
if (!res || retVal) {
|
2008-06-17 19:39:26 +04:00
|
|
|
cmGeneratedFileStream ofs(tmpFile.c_str());
|
|
|
|
ofs << "# Run command: " << command << std::endl
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "# Output:" << std::endl
|
2016-06-07 00:53:32 +03:00
|
|
|
<< output << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_ERROR, "Problem running PackageMaker command: "
|
|
|
|
<< command << std::endl
|
2016-06-07 00:53:32 +03:00
|
|
|
<< "Please check " << tmpFile << " for errors" << std::endl);
|
2008-06-17 19:39:26 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
// sometimes the command finishes but the directory is not yet
|
|
|
|
// created, so try 10 times to see if it shows up
|
|
|
|
int tries = 10;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (tries > 0 && !cmSystemTools::FileExists(packageFile)) {
|
2008-06-17 19:39:26 +04:00
|
|
|
cmSystemTools::Delay(500);
|
|
|
|
tries--;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!cmSystemTools::FileExists(packageFile)) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem running PackageMaker command: "
|
|
|
|
<< command << std::endl
|
|
|
|
<< "Package not created: " << packageFile << std::endl);
|
2008-06-17 19:39:26 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCPackPackageMakerGenerator::GenerateComponentPackage(
|
|
|
|
const char* packageFile, const char* packageDir,
|
|
|
|
const cmCPackComponent& component)
|
2008-06-17 19:39:26 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Building component package: "
|
|
|
|
<< packageFile << std::endl);
|
2008-06-17 19:39:26 +04:00
|
|
|
|
2008-07-09 21:38:56 +04:00
|
|
|
// The command that will be used to run PackageMaker
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream pkgCmd;
|
2008-07-09 21:38:56 +04:00
|
|
|
|
2014-12-26 20:48:53 +03:00
|
|
|
if (this->PackageCompatibilityVersion < getVersion(10, 5) ||
|
2016-05-16 17:34:04 +03:00
|
|
|
this->PackageMakerVersion < 3.0) {
|
2008-07-09 21:38:56 +04:00
|
|
|
// Create Description.plist and Info.plist files for normal Mac OS
|
|
|
|
// X packages, which work on Mac OS X 10.3 and newer.
|
|
|
|
std::string descriptionFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
descriptionFile += '/' + component.Name + "-Description.plist";
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ofstream out(descriptionFile.c_str());
|
2016-06-09 00:35:31 +03:00
|
|
|
cmXMLWriter xout(out);
|
|
|
|
xout.StartDocument();
|
|
|
|
xout.Doctype("plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\""
|
|
|
|
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
|
|
|
|
xout.StartElement("plist");
|
|
|
|
xout.Attribute("version", "1.4");
|
|
|
|
xout.StartElement("dict");
|
|
|
|
xout.Element("key", "IFPkgDescriptionTitle");
|
|
|
|
xout.Element("string", component.DisplayName);
|
|
|
|
xout.Element("key", "IFPkgDescriptionVersion");
|
|
|
|
xout.Element("string", this->GetOption("CPACK_PACKAGE_VERSION"));
|
|
|
|
xout.Element("key", "IFPkgDescriptionDescription");
|
|
|
|
xout.Element("string", component.Description);
|
|
|
|
xout.EndElement(); // dict
|
|
|
|
xout.EndElement(); // plist
|
|
|
|
xout.EndDocument();
|
2008-07-09 21:38:56 +04:00
|
|
|
out.close();
|
|
|
|
|
|
|
|
// Create the Info.plist file for this component
|
|
|
|
std::string moduleVersionSuffix = ".";
|
|
|
|
moduleVersionSuffix += component.Name;
|
2012-08-13 21:42:58 +04:00
|
|
|
this->SetOption("CPACK_MODULE_VERSION_SUFFIX",
|
2008-10-01 17:04:27 +04:00
|
|
|
moduleVersionSuffix.c_str());
|
2008-07-09 21:38:56 +04:00
|
|
|
std::string infoFileName = component.Name;
|
|
|
|
infoFileName += "-Info.plist";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->CopyResourcePlistFile("Info.plist", infoFileName.c_str())) {
|
2008-07-09 21:38:56 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-09 21:38:56 +04:00
|
|
|
|
|
|
|
pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
|
|
|
|
<< "\" -build -p \"" << packageFile << "\""
|
|
|
|
<< " -f \"" << packageDir << "\""
|
2016-05-16 17:34:04 +03:00
|
|
|
<< " -i \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/"
|
|
|
|
<< infoFileName << "\""
|
2012-08-13 21:42:58 +04:00
|
|
|
<< " -d \"" << descriptionFile << "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-07-09 21:38:56 +04:00
|
|
|
// Create a "flat" package on Mac OS X 10.5 and newer. Flat
|
|
|
|
// packages are stored in a single file, rather than a directory
|
|
|
|
// like normal packages, and can be downloaded by the installer
|
|
|
|
// on-the-fly in Mac OS X 10.5 or newer. Thus, we need to create
|
|
|
|
// flat packages when the packages will be downloaded on the fly.
|
|
|
|
std::string pkgId = "com.";
|
|
|
|
pkgId += this->GetOption("CPACK_PACKAGE_VENDOR");
|
|
|
|
pkgId += '.';
|
|
|
|
pkgId += this->GetOption("CPACK_PACKAGE_NAME");
|
|
|
|
pkgId += '.';
|
|
|
|
pkgId += component.Name;
|
|
|
|
|
|
|
|
pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
|
|
|
|
<< "\" --root \"" << packageDir << "\""
|
2016-05-16 17:34:04 +03:00
|
|
|
<< " --id " << pkgId << " --target "
|
|
|
|
<< this->GetOption("CPACK_OSX_PACKAGE_VERSION") << " --out \""
|
|
|
|
<< packageFile << "\"";
|
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
// Run PackageMaker
|
2008-06-17 19:39:26 +04:00
|
|
|
return RunPackageMaker(pkgCmd.str().c_str(), packageFile);
|
|
|
|
}
|