cmCPackDragNDropGenerator: use a string instead of a stream for commands

This commit is contained in:
Ben Boeckel
2023-07-26 15:40:26 -04:00
parent f5d04b5bf0
commit e1b70d7286
3 changed files with 70 additions and 65 deletions

View File

@@ -196,15 +196,11 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir)
// sign the files supplied by the user, ie. frameworks.
for (auto const& file : relFiles) {
std::ostringstream temp_sign_file_cmd;
temp_sign_file_cmd << this->GetOption("CPACK_COMMAND_CODESIGN");
temp_sign_file_cmd << " " << sign_parameter << " -s \""
<< cpack_apple_cert_app;
temp_sign_file_cmd << "\" -i ";
temp_sign_file_cmd << this->GetOption("CPACK_APPLE_BUNDLE_ID");
temp_sign_file_cmd << " \"";
temp_sign_file_cmd << bundle_path;
temp_sign_file_cmd << file << "\"";
auto temp_sign_file_cmd =
cmStrCat(this->GetOption("CPACK_COMMAND_CODESIGN"), ' ',
sign_parameter, " -s \"", cpack_apple_cert_app, "\" -i ",
this->GetOption("CPACK_APPLE_BUNDLE_ID"), " \"", bundle_path,
file, '"');
if (!this->RunCommand(temp_sign_file_cmd, &output)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
@@ -216,11 +212,9 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir)
}
// sign main binary
std::ostringstream temp_sign_binary_cmd;
temp_sign_binary_cmd << this->GetOption("CPACK_COMMAND_CODESIGN");
temp_sign_binary_cmd << " " << sign_parameter << " -s \""
<< cpack_apple_cert_app;
temp_sign_binary_cmd << "\" \"" << bundle_path << "\"";
auto temp_sign_binary_cmd =
cmStrCat(this->GetOption("CPACK_COMMAND_CODESIGN"), ' ', sign_parameter,
" -s \"", cpack_apple_cert_app, "\" \"", bundle_path, '"');
if (!this->RunCommand(temp_sign_binary_cmd, &output)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
@@ -232,15 +226,15 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir)
}
// sign app bundle
std::ostringstream temp_codesign_cmd;
temp_codesign_cmd << this->GetOption("CPACK_COMMAND_CODESIGN");
temp_codesign_cmd << " " << sign_parameter << " -s \""
<< cpack_apple_cert_app << "\"";
auto temp_codesign_cmd =
cmStrCat(this->GetOption("CPACK_COMMAND_CODESIGN"), ' ', sign_parameter,
" -s \"", cpack_apple_cert_app, "\"");
if (this->GetOption("CPACK_BUNDLE_APPLE_ENTITLEMENTS")) {
temp_codesign_cmd << " --entitlements ";
temp_codesign_cmd << this->GetOption("CPACK_BUNDLE_APPLE_ENTITLEMENTS");
temp_codesign_cmd +=
cmStrCat(" --entitlements ",
this->GetOption("CPACK_BUNDLE_APPLE_ENTITLEMENTS"));
}
temp_codesign_cmd << " \"" << bundle_path << "\"";
temp_codesign_cmd += cmStrCat(" \"", bundle_path, '"');
if (!this->RunCommand(temp_codesign_cmd, &output)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,

View File

@@ -243,18 +243,18 @@ bool cmCPackDragNDropGenerator::CreateEmptyFile(std::ostringstream& target,
return true;
}
bool cmCPackDragNDropGenerator::RunCommand(std::ostringstream& command,
bool cmCPackDragNDropGenerator::RunCommand(std::string const& command,
std::string* output)
{
int exit_code = 1;
bool result = cmSystemTools::RunSingleCommand(
command.str(), output, output, &exit_code, nullptr, this->GeneratorVerbose,
command, output, output, &exit_code, nullptr, this->GeneratorVerbose,
cmDuration::zero());
if (!result || exit_code) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Error executing: " << command.str() << std::endl);
"Error executing: " << command << std::endl);
return false;
}
@@ -412,15 +412,21 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), "/temp.dmg");
std::string create_error;
std::ostringstream temp_image_command;
temp_image_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
temp_image_command << " create";
temp_image_command << " -ov";
temp_image_command << " -srcfolder \"" << staging.str() << "\"";
temp_image_command << " -volname \"" << cpack_dmg_volume_name << "\"";
temp_image_command << " -fs \"" << cpack_dmg_filesystem << "\"";
temp_image_command << " -format " << temp_image_format;
temp_image_command << " \"" << temp_image << "\"";
auto temp_image_command =
cmStrCat(this->GetOption("CPACK_COMMAND_HDIUTIL"),
" create"
" -ov"
" -srcfolder \"",
staging.str(),
"\""
" -volname \"",
cpack_dmg_volume_name,
"\""
" -fs \"",
cpack_dmg_filesystem,
"\""
" -format ",
temp_image_format, " \"", temp_image, "\"");
if (!this->RunCommand(temp_image_command, &create_error)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
@@ -436,10 +442,10 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
// before we exit.
bool had_error = false;
std::ostringstream attach_command;
attach_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
attach_command << " attach";
attach_command << " \"" << temp_image << "\"";
auto attach_command = cmStrCat(this->GetOption("CPACK_COMMAND_HDIUTIL"),
" attach"
" \"",
temp_image, "\"");
std::string attach_output;
if (!this->RunCommand(attach_command, &attach_output)) {
@@ -468,10 +474,10 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
// Optionally set the custom icon flag for the image ...
if (!had_error && !cpack_package_icon->empty()) {
std::string error;
std::ostringstream setfile_command;
setfile_command << this->GetOption("CPACK_COMMAND_SETFILE");
setfile_command << " -a C";
setfile_command << " \"" << temp_mount << "\"";
auto setfile_command = cmStrCat(this->GetOption("CPACK_COMMAND_SETFILE"),
" -a C"
" \"",
temp_mount, "\"");
if (!this->RunCommand(setfile_command, &error)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
@@ -486,10 +492,12 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
// Optionally we can execute a custom apple script to generate
// the .DS_Store for the volume folder ...
if (!had_error && !cpack_dmg_ds_store_setup_script->empty()) {
std::ostringstream setup_script_command;
setup_script_command << "osascript"
<< " \"" << cpack_dmg_ds_store_setup_script << "\""
<< " \"" << temp_mount_name << "\"";
auto setup_script_command = cmStrCat("osascript"
" \"",
cpack_dmg_ds_store_setup_script,
"\""
" \"",
temp_mount_name, "\"");
std::string error;
if (!this->RunCommand(setup_script_command, &error)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
@@ -501,10 +509,10 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
}
}
std::ostringstream detach_command;
detach_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
detach_command << " detach";
detach_command << " \"" << temp_mount << "\"";
auto detach_command = cmStrCat(this->GetOption("CPACK_COMMAND_HDIUTIL"),
" detach"
" \"",
temp_mount, '\"');
if (!this->RunCommand(detach_command)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
@@ -519,14 +527,15 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
}
// Create the final compressed read-only disk image ...
std::ostringstream final_image_command;
final_image_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
final_image_command << " convert \"" << temp_image << "\"";
final_image_command << " -format ";
final_image_command << cpack_dmg_format;
final_image_command << " -imagekey";
final_image_command << " zlib-level=9";
final_image_command << " -o \"" << output_file << "\"";
auto final_image_command = cmStrCat(this->GetOption("CPACK_COMMAND_HDIUTIL"),
" convert \"", temp_image,
"\""
" -format ",
cpack_dmg_format,
" -imagekey"
" zlib-level=9"
" -o \"",
output_file, "\"");
std::string convert_error;
@@ -667,13 +676,15 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
this->WriteRezXML(sla_xml, rez);
// Create the final compressed read-only disk image ...
std::ostringstream embed_sla_command;
embed_sla_command << this->GetOption("CPACK_COMMAND_HDIUTIL");
embed_sla_command << " udifrez";
embed_sla_command << " -xml";
embed_sla_command << " \"" << sla_xml << "\"";
embed_sla_command << " FIXME_WHY_IS_THIS_ARGUMENT_NEEDED";
embed_sla_command << " \"" << output_file << "\"";
auto embed_sla_command = cmStrCat(this->GetOption("CPACK_COMMAND_HDIUTIL"),
" udifrez"
" -xml"
" \"",
sla_xml,
"\""
" FIXME_WHY_IS_THIS_ARGUMENT_NEEDED"
" \"",
output_file, "\"");
std::string embed_error;
if (!this->RunCommand(embed_sla_command, &embed_error)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,

View File

@@ -33,7 +33,7 @@ protected:
bool CopyFile(std::ostringstream& source, std::ostringstream& target);
bool CreateEmptyFile(std::ostringstream& target, size_t size);
bool RunCommand(std::ostringstream& command, std::string* output = nullptr);
bool RunCommand(std::string const& command, std::string* output = nullptr);
std::string GetComponentInstallDirNameSuffix(
const std::string& componentName) override;