| 1 | /**************************************************************************/ |
| 2 | /* export_plugin.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "export_plugin.h" |
| 32 | |
| 33 | #include "logo_svg.gen.h" |
| 34 | #include "run_icon_svg.gen.h" |
| 35 | |
| 36 | #include "core/io/image_loader.h" |
| 37 | #include "core/io/plist.h" |
| 38 | #include "core/string/translation_server.h" |
| 39 | #include "drivers/png/png_driver_common.h" |
| 40 | #include "editor/editor_node.h" |
| 41 | #include "editor/editor_string_names.h" |
| 42 | #include "editor/export/codesign.h" |
| 43 | #include "editor/export/lipo.h" |
| 44 | #include "editor/export/macho.h" |
| 45 | #include "editor/file_system/editor_paths.h" |
| 46 | #include "editor/import/resource_importer_texture_settings.h" |
| 47 | #include "editor/themes/editor_scale.h" |
| 48 | #include "scene/resources/image_texture.h" |
| 49 | |
| 50 | #include "modules/svg/image_loader_svg.h" |
| 51 | |
| 52 | void EditorExportPlatformMacOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const { |
| 53 | r_features->push_back(p_preset->get("binary_format/architecture")); |
| 54 | String architecture = p_preset->get("binary_format/architecture"); |
| 55 | |
| 56 | if (architecture == "universal" || architecture == "x86_64") { |
| 57 | r_features->push_back("s3tc"); |
| 58 | r_features->push_back("bptc"); |
| 59 | } else if (architecture == "arm64") { |
| 60 | r_features->push_back("etc2"); |
| 61 | r_features->push_back("astc"); |
| 62 | } else { |
| 63 | ERR_PRINT("Invalid architecture"); |
| 64 | } |
| 65 | |
| 66 | if (!p_preset->is_dedicated_server() && p_preset->get("shader_baker/enabled")) { |
| 67 | // Don't use the shader baker if exporting as a dedicated server, as no rendering is performed. |
| 68 | r_features->push_back("shader_baker"); |
| 69 | } |
| 70 | |
| 71 | if (architecture == "universal") { |
| 72 | r_features->push_back("x86_64"); |
| 73 | r_features->push_back("arm64"); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | String EditorExportPlatformMacOS::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const { |
| 78 | if (p_preset) { |
| 79 | int dist_type = p_preset->get("export/distribution_type"); |
| 80 | bool ad_hoc = false; |
| 81 | int codesign_tool = p_preset->get("codesign/codesign"); |
| 82 | int notary_tool = p_preset->get("notarization/notarization"); |
| 83 | switch (codesign_tool) { |
| 84 | case 1: { // built-in ad-hoc |
| 85 | ad_hoc = true; |
| 86 | } break; |
| 87 | case 2: { // "rcodesign" |
| 88 | ad_hoc = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty() || p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty(); |
| 89 | } break; |
| 90 | #ifdef MACOS_ENABLED |
| 91 | case 3: { // "codesign" |
| 92 | ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-"); |
| 93 | } break; |
| 94 | #endif |
| 95 | default: { |
| 96 | }; |
| 97 | } |
| 98 | |
| 99 | if (p_name == "application/bundle_identifier") { |
| 100 | String identifier = p_preset->get("application/bundle_identifier"); |
| 101 | String pn_err; |
| 102 | if (!is_package_name_valid(identifier, &pn_err)) { |
| 103 | return TTR("Invalid bundle identifier:") + " " + pn_err; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if (p_name == "shader_baker/enabled" && bool(p_preset->get("shader_baker/enabled"))) { |
| 108 | String export_renderer = GLOBAL_GET("rendering/renderer/rendering_method"); |
| 109 | if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") { |
| 110 | return TTR("\"Shader Baker\" is not supported when using the Compatibility renderer."); |
| 111 | } else if (OS::get_singleton()->get_current_rendering_method() != export_renderer) { |
| 112 | return vformat(TTR("The editor is currently using a different renderer than what the target platform will use. \"Shader Baker\" won't be able to include core shaders. Switch to the \"%s\" renderer temporarily to fix this."), export_renderer); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | if (p_name == "codesign/certificate_file" || p_name == "codesign/certificate_password" || p_name == "codesign/identity") { |
| 117 | if (dist_type == 2) { |
| 118 | if (ad_hoc) { |
| 119 | return TTR("App Store distribution with ad-hoc code signing is not supported."); |
| 120 | } |
| 121 | } else if (notary_tool > 0 && ad_hoc) { |
| 122 | return TTR("Notarization with an ad-hoc signature is not supported."); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | if (p_name == "codesign/apple_team_id") { |
| 127 | String team_id = p_preset->get("codesign/apple_team_id"); |
| 128 | if (team_id.is_empty()) { |
| 129 | if (dist_type == 2) { |
| 130 | return TTR("Apple Team ID is required for App Store distribution."); |
| 131 | } else if (notary_tool > 0) { |
| 132 | return TTR("Apple Team ID is required for notarization."); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if (p_name == "codesign/provisioning_profile" && dist_type == 2) { |
| 138 | String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE); |
| 139 | if (pprof.is_empty()) { |
| 140 | return TTR("Provisioning profile is required for App Store distribution."); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if (p_name == "codesign/installer_identity" && dist_type == 2) { |
| 145 | String ident = p_preset->get("codesign/installer_identity"); |
| 146 | if (ident.is_empty()) { |
| 147 | return TTR("Installer signing identity is required for App Store distribution."); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if (p_name == "codesign/entitlements/app_sandbox/enabled" && dist_type == 2) { |
| 152 | bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled"); |
| 153 | if (!sandbox) { |
| 154 | return TTR("App sandbox is required for App Store distribution."); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | if (p_name == "codesign/codesign") { |
| 159 | if (dist_type == 2) { |
| 160 | if (codesign_tool == 2 && ClassDB::class_exists("CSharpScript")) { |
| 161 | return TTR("'rcodesign' doesn't support signing applications with embedded dynamic libraries (GDExtension or .NET)."); |
| 162 | } |
| 163 | if (codesign_tool == 0) { |
| 164 | return TTR("Code signing is required for App Store distribution."); |
| 165 | } |
| 166 | if (codesign_tool == 1) { |
| 167 | return TTR("App Store distribution with ad-hoc code signing is not supported."); |
| 168 | } |
| 169 | } else if (notary_tool > 0) { |
| 170 | if (codesign_tool == 0) { |
| 171 | return TTR("Code signing is required for notarization."); |
| 172 | } |
| 173 | if (codesign_tool == 1) { |
| 174 | return TTR("Notarization with an ad-hoc signature is not supported."); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | if (notary_tool == 2 || notary_tool == 3) { |
| 180 | if (p_name == "notarization/apple_id_name" || p_name == "notarization/api_uuid") { |
| 181 | String apple_id = p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID); |
| 182 | String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID); |
| 183 | if (apple_id.is_empty() && api_uuid.is_empty()) { |
| 184 | return TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified."); |
| 185 | } |
| 186 | if (!apple_id.is_empty() && !api_uuid.is_empty()) { |
| 187 | return TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time."); |
| 188 | } |
| 189 | } |
| 190 | if (p_name == "notarization/apple_id_password") { |
| 191 | String apple_id = p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID); |
| 192 | String apple_pass = p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS); |
| 193 | if (!apple_id.is_empty() && apple_pass.is_empty()) { |
| 194 | return TTR("Apple ID password not specified."); |
| 195 | } |
| 196 | } |
| 197 | if (p_name == "notarization/api_key_id") { |
| 198 | String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID); |
| 199 | String api_key = p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID); |
| 200 | if (!api_uuid.is_empty() && api_key.is_empty()) { |
| 201 | return TTR("App Store Connect API key ID not specified."); |
| 202 | } |
| 203 | } |
| 204 | } else if (notary_tool == 1) { |
| 205 | if (p_name == "notarization/api_uuid") { |
| 206 | String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID); |
| 207 | if (api_uuid.is_empty()) { |
| 208 | return TTR("App Store Connect issuer ID name not specified."); |
| 209 | } |
| 210 | } |
| 211 | if (p_name == "notarization/api_key_id") { |
| 212 | String api_key = p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID); |
| 213 | if (api_key.is_empty()) { |
| 214 | return TTR("App Store Connect API key ID not specified."); |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | if (codesign_tool > 0) { |
| 220 | if (p_name == "privacy/microphone_usage_description") { |
| 221 | String discr = p_preset->get("privacy/microphone_usage_description"); |
| 222 | bool enabled = p_preset->get("codesign/entitlements/audio_input"); |
| 223 | if (enabled && discr.is_empty()) { |
| 224 | return TTR("Microphone access is enabled, but usage description is not specified."); |
| 225 | } |
| 226 | } |
| 227 | if (p_name == "privacy/camera_usage_description") { |
| 228 | String discr = p_preset->get("privacy/camera_usage_description"); |
| 229 | bool enabled = p_preset->get("codesign/entitlements/camera"); |
| 230 | if (enabled && discr.is_empty()) { |
| 231 | return TTR("Camera access is enabled, but usage description is not specified."); |
| 232 | } |
| 233 | } |
| 234 | if (p_name == "privacy/location_usage_description") { |
| 235 | String discr = p_preset->get("privacy/location_usage_description"); |
| 236 | bool enabled = p_preset->get("codesign/entitlements/location"); |
| 237 | if (enabled && discr.is_empty()) { |
| 238 | return TTR("Location information access is enabled, but usage description is not specified."); |
| 239 | } |
| 240 | } |
| 241 | if (p_name == "privacy/address_book_usage_description") { |
| 242 | String discr = p_preset->get("privacy/address_book_usage_description"); |
| 243 | bool enabled = p_preset->get("codesign/entitlements/address_book"); |
| 244 | if (enabled && discr.is_empty()) { |
| 245 | return TTR("Address book access is enabled, but usage description is not specified."); |
| 246 | } |
| 247 | } |
| 248 | if (p_name == "privacy/calendar_usage_description") { |
| 249 | String discr = p_preset->get("privacy/calendar_usage_description"); |
| 250 | bool enabled = p_preset->get("codesign/entitlements/calendars"); |
| 251 | if (enabled && discr.is_empty()) { |
| 252 | return TTR("Calendar access is enabled, but usage description is not specified."); |
| 253 | } |
| 254 | } |
| 255 | if (p_name == "privacy/photos_library_usage_description") { |
| 256 | String discr = p_preset->get("privacy/photos_library_usage_description"); |
| 257 | bool enabled = p_preset->get("codesign/entitlements/photos_library"); |
| 258 | if (enabled && discr.is_empty()) { |
| 259 | return TTR("Photo library access is enabled, but usage description is not specified."); |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | return String(); |
| 265 | } |
| 266 | |
| 267 | bool EditorExportPlatformMacOS::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const { |
| 268 | // Hide irrelevant code signing options. |
| 269 | if (p_preset) { |
| 270 | int codesign_tool = p_preset->get("codesign/codesign"); |
| 271 | switch (codesign_tool) { |
| 272 | case 1: { // built-in ad-hoc |
| 273 | if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options" || p_option == "codesign/team_id") { |
| 274 | return false; |
| 275 | } |
| 276 | } break; |
| 277 | case 2: { // "rcodesign" |
| 278 | if (p_option == "codesign/identity") { |
| 279 | return false; |
| 280 | } |
| 281 | } break; |
| 282 | #ifdef MACOS_ENABLED |
| 283 | case 3: { // "codesign" |
| 284 | if (p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password") { |
| 285 | return false; |
| 286 | } |
| 287 | } break; |
| 288 | #endif |
| 289 | default: { // disabled |
| 290 | if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options" || p_option.begins_with("codesign/entitlements") || p_option == "codesign/team_id") { |
| 291 | return false; |
| 292 | } |
| 293 | } break; |
| 294 | } |
| 295 | |
| 296 | // Distribution type. |
| 297 | int dist_type = p_preset->get("export/distribution_type"); |
| 298 | if (dist_type != 2 && p_option == "codesign/installer_identity") { |
| 299 | return false; |
| 300 | } |
| 301 | |
| 302 | if (dist_type == 2 && p_option.begins_with("notarization/")) { |
| 303 | return false; |
| 304 | } |
| 305 | |
| 306 | if (dist_type != 2 && p_option == "codesign/provisioning_profile") { |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | #ifndef MACOS_ENABLED |
| 311 | if (p_option == "application/liquid_glass_icon") { |
| 312 | return false; |
| 313 | } |
| 314 | #endif |
| 315 | |
| 316 | String custom_prof = p_preset->get("codesign/entitlements/custom_file"); |
| 317 | if (!custom_prof.is_empty() && p_option != "codesign/entitlements/custom_file" && p_option.begins_with("codesign/entitlements/")) { |
| 318 | return false; |
| 319 | } |
| 320 | |
| 321 | // Hide sandbox entitlements. |
| 322 | bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled"); |
| 323 | if (!sandbox && p_option != "codesign/entitlements/app_sandbox/enabled" && p_option.begins_with("codesign/entitlements/app_sandbox/")) { |
| 324 | return false; |
| 325 | } |
| 326 | |
| 327 | // Hide SSH options. |
| 328 | bool ssh = p_preset->get("ssh_remote_deploy/enabled"); |
| 329 | if (!ssh && p_option != "ssh_remote_deploy/enabled" && p_option.begins_with("ssh_remote_deploy/")) { |
| 330 | return false; |
| 331 | } |
| 332 | |
| 333 | // Hide irrelevant notarization options. |
| 334 | int notary_tool = p_preset->get("notarization/notarization"); |
| 335 | switch (notary_tool) { |
| 336 | case 1: { // "rcodesign" |
| 337 | if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password") { |
| 338 | return false; |
| 339 | } |
| 340 | } break; |
| 341 | case 2: { // "notarytool" |
| 342 | // All options are visible. |
| 343 | } break; |
| 344 | default: { // disabled |
| 345 | if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/api_uuid" || p_option == "notarization/api_key" || p_option == "notarization/api_key_id") { |
| 346 | return false; |
| 347 | } |
| 348 | } break; |
| 349 | } |
| 350 | |
| 351 | bool advanced_options_enabled = p_preset->are_advanced_options_enabled(); |
| 352 | if (p_option.begins_with("privacy") || |
| 353 | p_option == "codesign/entitlements/additional" || |
| 354 | p_option == "custom_template/debug" || |
| 355 | p_option == "custom_template/release" || |
| 356 | p_option == "application/additional_plist_content" || |
| 357 | p_option == "application/export_angle" || |
| 358 | p_option == "application/icon_interpolation" || |
| 359 | p_option == "application/signature" || |
| 360 | p_option == "display/high_res" || |
| 361 | p_option == "xcode/platform_build" || |
| 362 | p_option == "xcode/sdk_build" || |
| 363 | p_option == "xcode/sdk_name" || |
| 364 | p_option == "xcode/sdk_version" || |
| 365 | p_option == "xcode/xcode_build" || |
| 366 | p_option == "xcode/xcode_version") { |
| 367 | return advanced_options_enabled; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | // These entitlements are required to run managed code, and are always enabled in Mono builds. |
| 372 | if (ClassDB::class_exists("CSharpScript")) { |
| 373 | if (p_option == "codesign/entitlements/allow_jit_code_execution" || p_option == "codesign/entitlements/allow_unsigned_executable_memory" || p_option == "codesign/entitlements/allow_dyld_environment_variables") { |
| 374 | return false; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | // Hide unsupported .NET embedding option. |
| 379 | if (p_option == "dotnet/embed_build_outputs") { |
| 380 | return false; |
| 381 | } |
| 382 | |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | List<String> EditorExportPlatformMacOS::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const { |
| 387 | List<String> list; |
| 388 | |
| 389 | if (p_preset.is_valid()) { |
| 390 | int dist_type = p_preset->get("export/distribution_type"); |
| 391 | if (dist_type == 0) { |
| 392 | #ifdef MACOS_ENABLED |
| 393 | list.push_back("dmg"); |
| 394 | #endif |
| 395 | list.push_back("zip"); |
| 396 | list.push_back("app"); |
| 397 | } else if (dist_type == 1) { |
| 398 | #ifdef MACOS_ENABLED |
| 399 | list.push_back("dmg"); |
| 400 | #endif |
| 401 | list.push_back("zip"); |
| 402 | list.push_back("app"); |
| 403 | } else if (dist_type == 2) { |
| 404 | #ifdef MACOS_ENABLED |
| 405 | list.push_back("pkg"); |
| 406 | #endif |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | return list; |
| 411 | } |
| 412 | |
| 413 | struct DataCollectionInfo { |
| 414 | String prop_name; |
| 415 | String type_name; |
| 416 | }; |
| 417 | |
| 418 | static const DataCollectionInfo data_collect_type_info[] = { |
| 419 | { "name", "NSPrivacyCollectedDataTypeName" }, |
| 420 | { "email_address", "NSPrivacyCollectedDataTypeEmailAddress" }, |
| 421 | { "phone_number", "NSPrivacyCollectedDataTypePhoneNumber" }, |
| 422 | { "physical_address", "NSPrivacyCollectedDataTypePhysicalAddress" }, |
| 423 | { "other_contact_info", "NSPrivacyCollectedDataTypeOtherUserContactInfo" }, |
| 424 | { "health", "NSPrivacyCollectedDataTypeHealth" }, |
| 425 | { "fitness", "NSPrivacyCollectedDataTypeFitness" }, |
| 426 | { "payment_info", "NSPrivacyCollectedDataTypePaymentInfo" }, |
| 427 | { "credit_info", "NSPrivacyCollectedDataTypeCreditInfo" }, |
| 428 | { "other_financial_info", "NSPrivacyCollectedDataTypeOtherFinancialInfo" }, |
| 429 | { "precise_location", "NSPrivacyCollectedDataTypePreciseLocation" }, |
| 430 | { "coarse_location", "NSPrivacyCollectedDataTypeCoarseLocation" }, |
| 431 | { "sensitive_info", "NSPrivacyCollectedDataTypeSensitiveInfo" }, |
| 432 | { "contacts", "NSPrivacyCollectedDataTypeContacts" }, |
| 433 | { "emails_or_text_messages", "NSPrivacyCollectedDataTypeEmailsOrTextMessages" }, |
| 434 | { "photos_or_videos", "NSPrivacyCollectedDataTypePhotosorVideos" }, |
| 435 | { "audio_data", "NSPrivacyCollectedDataTypeAudioData" }, |
| 436 | { "gameplay_content", "NSPrivacyCollectedDataTypeGameplayContent" }, |
| 437 | { "customer_support", "NSPrivacyCollectedDataTypeCustomerSupport" }, |
| 438 | { "other_user_content", "NSPrivacyCollectedDataTypeOtherUserContent" }, |
| 439 | { "browsing_history", "NSPrivacyCollectedDataTypeBrowsingHistory" }, |
| 440 | { "search_history", "NSPrivacyCollectedDataTypeSearchHistory" }, |
| 441 | { "user_id", "NSPrivacyCollectedDataTypeUserID" }, |
| 442 | { "device_id", "NSPrivacyCollectedDataTypeDeviceID" }, |
| 443 | { "purchase_history", "NSPrivacyCollectedDataTypePurchaseHistory" }, |
| 444 | { "product_interaction", "NSPrivacyCollectedDataTypeProductInteraction" }, |
| 445 | { "advertising_data", "NSPrivacyCollectedDataTypeAdvertisingData" }, |
| 446 | { "other_usage_data", "NSPrivacyCollectedDataTypeOtherUsageData" }, |
| 447 | { "crash_data", "NSPrivacyCollectedDataTypeCrashData" }, |
| 448 | { "performance_data", "NSPrivacyCollectedDataTypePerformanceData" }, |
| 449 | { "other_diagnostic_data", "NSPrivacyCollectedDataTypeOtherDiagnosticData" }, |
| 450 | { "environment_scanning", "NSPrivacyCollectedDataTypeEnvironmentScanning" }, |
| 451 | { "hands", "NSPrivacyCollectedDataTypeHands" }, |
| 452 | { "head", "NSPrivacyCollectedDataTypeHead" }, |
| 453 | { "other_data_types", "NSPrivacyCollectedDataTypeOtherDataTypes" }, |
| 454 | }; |
| 455 | |
| 456 | static const DataCollectionInfo data_collect_purpose_info[] = { |
| 457 | { "Analytics", "NSPrivacyCollectedDataTypePurposeAnalytics" }, |
| 458 | { "App Functionality", "NSPrivacyCollectedDataTypePurposeAppFunctionality" }, |
| 459 | { "Developer Advertising", "NSPrivacyCollectedDataTypePurposeDeveloperAdvertising" }, |
| 460 | { "Third-party Advertising", "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising" }, |
| 461 | { "Product Personalization", "NSPrivacyCollectedDataTypePurposeProductPersonalization" }, |
| 462 | { "Other", "NSPrivacyCollectedDataTypePurposeOther" }, |
| 463 | }; |
| 464 | |
| 465 | void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options) const { |
| 466 | #ifdef MACOS_ENABLED |
| 467 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution,App Store"), 1, true)); |
| 468 | #else |
| 469 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution"), 1, true)); |
| 470 | #endif |
| 471 | |
| 472 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "binary_format/architecture", PROPERTY_HINT_ENUM, "universal,x86_64,arm64", PROPERTY_USAGE_STORAGE), "universal")); |
| 473 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), "")); |
| 474 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), "")); |
| 475 | |
| 476 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "debug/export_console_wrapper", PROPERTY_HINT_ENUM, "No,Debug Only,Debug and Release"), 1)); |
| 477 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/liquid_glass_icon", PROPERTY_HINT_FILE, "*.icon"), "")); |
| 478 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.icns,*.png,*.webp,*.svg"), "")); |
| 479 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4)); |
| 480 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "", false, true)); |
| 481 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "")); |
| 482 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_category", PROPERTY_HINT_ENUM, "Business,Developer-tools,Education,Entertainment,Finance,Games,Action-games,Adventure-games,Arcade-games,Board-games,Card-games,Casino-games,Dice-games,Educational-games,Family-games,Kids-games,Music-games,Puzzle-games,Racing-games,Role-playing-games,Simulation-games,Sports-games,Strategy-games,Trivia-games,Word-games,Graphics-design,Healthcare-fitness,Lifestyle,Medical,Music,News,Photography,Productivity,Reference,Social-networking,Sports,Travel,Utilities,Video,Weather"), "Games")); |
| 483 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), "")); |
| 484 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), "")); |
| 485 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), "")); |
| 486 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "application/copyright_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 487 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version_x86_64"), "10.12")); |
| 488 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version_arm64"), "11.00")); |
| 489 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_angle", PROPERTY_HINT_ENUM, "Auto,Yes,No"), 0, true)); |
| 490 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), true)); |
| 491 | |
| 492 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "shader_baker/enabled"), false)); |
| 493 | |
| 494 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/additional_plist_content", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), "")); |
| 495 | |
| 496 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/platform_build"), "14C18")); |
| 497 | // TODO(sgc): Need to set appropriate version when using Metal |
| 498 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_version"), "13.1")); |
| 499 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_build"), "22C55")); |
| 500 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_name"), "macosx13.1")); |
| 501 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_version"), "1420")); |
| 502 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_build"), "14C18")); |
| 503 | |
| 504 | #ifdef MACOS_ENABLED |
| 505 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign,Xcode codesign"), 3, true)); |
| 506 | #else |
| 507 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign"), 1, true, true)); |
| 508 | #endif |
| 509 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/installer_identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "3rd Party Mac Developer Installer: (ID)"), "", false, true)); |
| 510 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/apple_team_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "ID"), "", false, true)); |
| 511 | // "codesign" only options: |
| 512 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), "")); |
| 513 | // "rcodesign" only options: |
| 514 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_file", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "")); |
| 515 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_password", PROPERTY_HINT_PASSWORD, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "")); |
| 516 | // "codesign" and "rcodesign" only options: |
| 517 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/provisioning_profile", PROPERTY_HINT_GLOBAL_FILE, "*.provisionprofile", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true)); |
| 518 | |
| 519 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), "", true)); |
| 520 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false)); |
| 521 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false)); |
| 522 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false)); |
| 523 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false)); |
| 524 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false)); |
| 525 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false)); |
| 526 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/location"), false)); |
| 527 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/address_book"), false)); |
| 528 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/calendars"), false)); |
| 529 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/photos_library"), false)); |
| 530 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/apple_events"), false)); |
| 531 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/debugging"), false)); |
| 532 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/enabled"), false, true, true)); |
| 533 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_server"), false)); |
| 534 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_client"), false)); |
| 535 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_usb"), false)); |
| 536 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_bluetooth"), false)); |
| 537 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_downloads", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0)); |
| 538 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_pictures", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0)); |
| 539 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_music", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0)); |
| 540 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_movies", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0)); |
| 541 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_user_selected", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0)); |
| 542 | r_options->push_back(ExportOption(PropertyInfo(Variant::ARRAY, "codesign/entitlements/app_sandbox/helper_executables", PROPERTY_HINT_ARRAY_TYPE, itos(Variant::STRING) + "/" + itos(PROPERTY_HINT_GLOBAL_FILE) + ":"), Array())); |
| 543 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/additional", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), "")); |
| 544 | r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray())); |
| 545 | |
| 546 | #ifdef MACOS_ENABLED |
| 547 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign,Xcode notarytool"), 0, true)); |
| 548 | #else |
| 549 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign"), 0, true)); |
| 550 | #endif |
| 551 | // "notarytool" only options: |
| 552 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple ID email", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true)); |
| 553 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_password", PROPERTY_HINT_PASSWORD, "Enable two-factor authentication and provide app-specific password", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true)); |
| 554 | // "notarytool" and "rcodesign" only options: |
| 555 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_uuid", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect issuer ID UUID", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true)); |
| 556 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_GLOBAL_FILE, "*.p8", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true)); |
| 557 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect API key ID", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true)); |
| 558 | |
| 559 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/microphone_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the microphone"), "", false, true)); |
| 560 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 561 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/camera_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the camera"), "", false, true)); |
| 562 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 563 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/location_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the location information"), "", false, true)); |
| 564 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/location_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 565 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/address_book_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the address book"), "", false, true)); |
| 566 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/address_book_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 567 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/calendar_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the calendar"), "", false, true)); |
| 568 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/calendar_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 569 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/photos_library_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the photo library"), "", false, true)); |
| 570 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photos_library_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 571 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/desktop_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Desktop folder"), "", false, true)); |
| 572 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/desktop_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 573 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/documents_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Documents folder"), "", false, true)); |
| 574 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/documents_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 575 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/downloads_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Downloads folder"), "", false, true)); |
| 576 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/downloads_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 577 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/network_volumes_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use network volumes"), "", false, true)); |
| 578 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/network_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 579 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/removable_volumes_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use removable volumes"), "", false, true)); |
| 580 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/removable_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 581 | |
| 582 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "privacy/tracking_enabled"), false)); |
| 583 | r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "privacy/tracking_domains"), Vector<String>())); |
| 584 | |
| 585 | { |
| 586 | String hint; |
| 587 | for (uint64_t i = 0; i < std_size(data_collect_purpose_info); ++i) { |
| 588 | if (i != 0) { |
| 589 | hint += ","; |
| 590 | } |
| 591 | hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i)); |
| 592 | } |
| 593 | for (uint64_t i = 0; i < std_size(data_collect_type_info); ++i) { |
| 594 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false)); |
| 595 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false)); |
| 596 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false)); |
| 597 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[i].prop_name), PROPERTY_HINT_FLAGS, hint), 0)); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | String run_script = "#!/usr/bin/env bash\n" |
| 602 | "unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"\n" |
| 603 | "open \"{temp_dir}/{exe_name}.app\" --args {cmd_args}"; |
| 604 | |
| 605 | String cleanup_script = "#!/usr/bin/env bash\n" |
| 606 | "pkill -x -f \"{temp_dir}/{exe_name}.app/Contents/MacOS/{exe_name} {cmd_args}\"\n" |
| 607 | "rm -rf \"{temp_dir}\""; |
| 608 | |
| 609 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true)); |
| 610 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/host"), "user@host_ip")); |
| 611 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/port"), "22")); |
| 612 | |
| 613 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_ssh", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), "")); |
| 614 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_scp", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), "")); |
| 615 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/run_script", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), run_script)); |
| 616 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/cleanup_script", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), cleanup_script)); |
| 617 | } |
| 618 | |
| 619 | void _rgba8_to_packbits_encode(int p_ch, int p_size, Vector<uint8_t> &p_source, Vector<uint8_t> &p_dest) { |
| 620 | int src_len = p_size * p_size; |
| 621 | |
| 622 | Vector<uint8_t> result; |
| 623 | |
| 624 | int i = 0; |
| 625 | const uint8_t *src = p_source.ptr(); |
| 626 | while (i < src_len) { |
| 627 | Vector<uint8_t> seq; |
| 628 | |
| 629 | uint8_t count = 0; |
| 630 | while (count <= 0x7f && i < src_len) { |
| 631 | if (i + 2 < src_len && src[i * 4 + p_ch] == src[(i + 1) * 4 + p_ch] && src[i] == src[(i + 2) * 4 + p_ch]) { |
| 632 | break; |
| 633 | } |
| 634 | seq.push_back(src[i * 4 + p_ch]); |
| 635 | i++; |
| 636 | count++; |
| 637 | } |
| 638 | if (!seq.is_empty()) { |
| 639 | result.push_back(count - 1); |
| 640 | result.append_array(seq); |
| 641 | } |
| 642 | if (i >= src_len) { |
| 643 | break; |
| 644 | } |
| 645 | |
| 646 | uint8_t rep = src[i * 4 + p_ch]; |
| 647 | count = 0; |
| 648 | while (count <= 0x7f && i < src_len && src[i * 4 + p_ch] == rep) { |
| 649 | i++; |
| 650 | count++; |
| 651 | } |
| 652 | if (count >= 3) { |
| 653 | result.push_back(0x80 + count - 3); |
| 654 | result.push_back(rep); |
| 655 | } else { |
| 656 | result.push_back(count - 1); |
| 657 | for (int j = 0; j < count; j++) { |
| 658 | result.push_back(rep); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | int ofs = p_dest.size(); |
| 664 | p_dest.resize(p_dest.size() + result.size()); |
| 665 | memcpy(&p_dest.write[ofs], result.ptr(), result.size()); |
| 666 | } |
| 667 | |
| 668 | void EditorExportPlatformMacOS::_make_icon(const Ref<EditorExportPreset> &p_preset, const Ref<Image> &p_icon, Vector<uint8_t> &p_data) { |
| 669 | Vector<uint8_t> data; |
| 670 | |
| 671 | data.resize(8); |
| 672 | data.write[0] = 'i'; |
| 673 | data.write[1] = 'c'; |
| 674 | data.write[2] = 'n'; |
| 675 | data.write[3] = 's'; |
| 676 | |
| 677 | struct MacOSIconInfo { |
| 678 | const char *name; |
| 679 | const char *mask_name; |
| 680 | bool is_png; |
| 681 | int size; |
| 682 | }; |
| 683 | |
| 684 | static const MacOSIconInfo icon_infos[] = { |
| 685 | { "ic10", "", true, 1024 }, //1024×1024 32-bit PNG and 512×512@2x 32-bit "retina" PNG |
| 686 | { "ic09", "", true, 512 }, //512×512 32-bit PNG |
| 687 | { "ic14", "", true, 512 }, //256×256@2x 32-bit "retina" PNG |
| 688 | { "ic08", "", true, 256 }, //256×256 32-bit PNG |
| 689 | { "ic13", "", true, 256 }, //128×128@2x 32-bit "retina" PNG |
| 690 | { "ic07", "", true, 128 }, //128×128 32-bit PNG |
| 691 | { "ic12", "", true, 64 }, //32×32@2× 32-bit "retina" PNG |
| 692 | { "ic11", "", true, 32 }, //16×16@2× 32-bit "retina" PNG |
| 693 | { "il32", "l8mk", false, 32 }, //32×32 24-bit RLE + 8-bit uncompressed mask |
| 694 | { "is32", "s8mk", false, 16 } //16×16 24-bit RLE + 8-bit uncompressed mask |
| 695 | }; |
| 696 | |
| 697 | for (uint64_t i = 0; i < std_size(icon_infos); ++i) { |
| 698 | Ref<Image> copy = p_icon->duplicate(); |
| 699 | copy->convert(Image::FORMAT_RGBA8); |
| 700 | copy->resize(icon_infos[i].size, icon_infos[i].size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int())); |
| 701 | |
| 702 | if (icon_infos[i].is_png) { |
| 703 | // Encode PNG icon. |
| 704 | Vector<uint8_t> png_buffer; |
| 705 | Error err = PNGDriverCommon::image_to_png(copy, png_buffer); |
| 706 | if (err == OK) { |
| 707 | int ofs = data.size(); |
| 708 | uint64_t len = png_buffer.size(); |
| 709 | data.resize(data.size() + len + 8); |
| 710 | memcpy(&data.write[ofs + 8], png_buffer.ptr(), len); |
| 711 | len += 8; |
| 712 | len = BSWAP32(len); |
| 713 | memcpy(&data.write[ofs], icon_infos[i].name, 4); |
| 714 | encode_uint32(len, &data.write[ofs + 4]); |
| 715 | } |
| 716 | } else { |
| 717 | Vector<uint8_t> src_data = copy->get_data(); |
| 718 | |
| 719 | // Encode 24-bit RGB RLE icon. |
| 720 | { |
| 721 | int ofs = data.size(); |
| 722 | data.resize(data.size() + 8); |
| 723 | |
| 724 | _rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // Encode R. |
| 725 | _rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // Encode G. |
| 726 | _rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // Encode B. |
| 727 | |
| 728 | // Note: workaround for macOS icon decoder bug corrupting last RLE encoded value. |
| 729 | data.push_back(0x00); |
| 730 | |
| 731 | int len = data.size() - ofs; |
| 732 | len = BSWAP32(len); |
| 733 | memcpy(&data.write[ofs], icon_infos[i].name, 4); |
| 734 | encode_uint32(len, &data.write[ofs + 4]); |
| 735 | } |
| 736 | |
| 737 | // Encode 8-bit mask uncompressed icon. |
| 738 | { |
| 739 | int ofs = data.size(); |
| 740 | int len = copy->get_width() * copy->get_height(); |
| 741 | data.resize(data.size() + len + 8); |
| 742 | |
| 743 | for (int j = 0; j < len; j++) { |
| 744 | data.write[ofs + 8 + j] = src_data.ptr()[j * 4 + 3]; |
| 745 | } |
| 746 | len += 8; |
| 747 | len = BSWAP32(len); |
| 748 | memcpy(&data.write[ofs], icon_infos[i].mask_name, 4); |
| 749 | encode_uint32(len, &data.write[ofs + 4]); |
| 750 | } |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | uint32_t total_len = data.size(); |
| 755 | total_len = BSWAP32(total_len); |
| 756 | encode_uint32(total_len, &data.write[4]); |
| 757 | |
| 758 | p_data = data; |
| 759 | } |
| 760 | |
| 761 | void EditorExportPlatformMacOS::_fix_privacy_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist) { |
| 762 | String str = String::utf8((const char *)plist.ptr(), plist.size()); |
| 763 | String strnew; |
| 764 | Vector<String> lines = str.split("\n"); |
| 765 | for (int i = 0; i < lines.size(); i++) { |
| 766 | if (lines[i].find("$priv_collection") != -1) { |
| 767 | bool section_opened = false; |
| 768 | for (uint64_t j = 0; j < std_size(data_collect_type_info); ++j) { |
| 769 | bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name)); |
| 770 | bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name)); |
| 771 | bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name)); |
| 772 | int purposes = p_preset->get(vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[j].prop_name)); |
| 773 | if (data_collected) { |
| 774 | if (!section_opened) { |
| 775 | section_opened = true; |
| 776 | strnew += "\t<key>NSPrivacyCollectedDataTypes</key>\n"; |
| 777 | strnew += "\t<array>\n"; |
| 778 | } |
| 779 | strnew += "\t\t<dict>\n"; |
| 780 | strnew += "\t\t\t<key>NSPrivacyCollectedDataType</key>\n"; |
| 781 | strnew += vformat("\t\t\t<string>%s</string>\n", data_collect_type_info[j].type_name); |
| 782 | strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeLinked</key>\n"; |
| 783 | if (linked) { |
| 784 | strnew += "\t\t\t\t<true/>\n"; |
| 785 | } else { |
| 786 | strnew += "\t\t\t\t<false/>\n"; |
| 787 | } |
| 788 | strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeTracking</key>\n"; |
| 789 | if (tracking) { |
| 790 | strnew += "\t\t\t\t<true/>\n"; |
| 791 | } else { |
| 792 | strnew += "\t\t\t\t<false/>\n"; |
| 793 | } |
| 794 | if (purposes != 0) { |
| 795 | strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n"; |
| 796 | strnew += "\t\t\t\t<array>\n"; |
| 797 | for (uint64_t k = 0; k < std_size(data_collect_purpose_info); ++k) { |
| 798 | if (purposes & (1 << k)) { |
| 799 | strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name); |
| 800 | } |
| 801 | } |
| 802 | strnew += "\t\t\t\t</array>\n"; |
| 803 | } |
| 804 | strnew += "\t\t\t</dict>\n"; |
| 805 | } |
| 806 | } |
| 807 | if (section_opened) { |
| 808 | strnew += "\t</array>\n"; |
| 809 | } |
| 810 | } else if (lines[i].find("$priv_tracking") != -1) { |
| 811 | bool tracking = p_preset->get("privacy/tracking_enabled"); |
| 812 | strnew += "\t<key>NSPrivacyTracking</key>\n"; |
| 813 | if (tracking) { |
| 814 | strnew += "\t<true/>\n"; |
| 815 | } else { |
| 816 | strnew += "\t<false/>\n"; |
| 817 | } |
| 818 | Vector<String> tracking_domains = p_preset->get("privacy/tracking_domains"); |
| 819 | if (!tracking_domains.is_empty()) { |
| 820 | strnew += "\t<key>NSPrivacyTrackingDomains</key>\n"; |
| 821 | strnew += "\t<array>\n"; |
| 822 | for (const String &E : tracking_domains) { |
| 823 | strnew += "\t\t<string>" + E + "</string>\n"; |
| 824 | } |
| 825 | strnew += "\t</array>\n"; |
| 826 | } |
| 827 | } else { |
| 828 | strnew += lines[i] + "\n"; |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | CharString cs = strnew.utf8(); |
| 833 | plist.resize(cs.size() - 1); |
| 834 | for (int i = 0; i < cs.size() - 1; i++) { |
| 835 | plist.write[i] = cs[i]; |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | void EditorExportPlatformMacOS::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary, bool p_lg_icon_exported, const String &p_lg_icon) { |
| 840 | String str = String::utf8((const char *)plist.ptr(), plist.size()); |
| 841 | String strnew; |
| 842 | Vector<String> lines = str.split("\n"); |
| 843 | for (int i = 0; i < lines.size(); i++) { |
| 844 | if (lines[i].contains("$binary")) { |
| 845 | strnew += lines[i].replace("$binary", p_binary) + "\n"; |
| 846 | } else if (lines[i].contains("$name")) { |
| 847 | strnew += lines[i].replace("$name", get_project_setting(p_preset, "application/config/name").operator String().xml_escape(true)) + "\n"; |
| 848 | } else if (lines[i].contains("$bundle_identifier")) { |
| 849 | strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n"; |
| 850 | } else if (lines[i].contains("$short_version")) { |
| 851 | strnew += lines[i].replace("$short_version", p_preset->get_version("application/short_version")) + "\n"; |
| 852 | } else if (lines[i].contains("$version")) { |
| 853 | strnew += lines[i].replace("$version", p_preset->get_version("application/version")) + "\n"; |
| 854 | } else if (lines[i].contains("$signature")) { |
| 855 | strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n"; |
| 856 | } else if (lines[i].contains("$app_category")) { |
| 857 | String cat = p_preset->get("application/app_category"); |
| 858 | strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n"; |
| 859 | } else if (lines[i].contains("$copyright")) { |
| 860 | strnew += lines[i].replace("$copyright", p_preset->get("application/copyright").operator String().xml_escape(true)) + "\n"; |
| 861 | } else if (lines[i].contains("$min_version_arm64")) { |
| 862 | strnew += lines[i].replace("$min_version_arm64", p_preset->get("application/min_macos_version_arm64")) + "\n"; |
| 863 | } else if (lines[i].contains("$min_version_x86_64")) { |
| 864 | strnew += lines[i].replace("$min_version_x86_64", p_preset->get("application/min_macos_version_x86_64")) + "\n"; |
| 865 | } else if (lines[i].contains("$min_version")) { |
| 866 | strnew += lines[i].replace("$min_version", p_preset->get("application/min_macos_version_x86_64")) + "\n"; // Old template, use x86-64 version for both. |
| 867 | } else if (lines[i].contains("$highres")) { |
| 868 | strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "\t<true/>" : "\t<false/>") + "\n"; |
| 869 | } else if (lines[i].contains("$additional_plist_content")) { |
| 870 | strnew += lines[i].replace("$additional_plist_content", p_preset->get("application/additional_plist_content")) + "\n"; |
| 871 | } else if (lines[i].contains("$platfbuild")) { |
| 872 | strnew += lines[i].replace("$platfbuild", p_preset->get("xcode/platform_build")) + "\n"; |
| 873 | } else if (lines[i].contains("$sdkver")) { |
| 874 | strnew += lines[i].replace("$sdkver", p_preset->get("xcode/sdk_version")) + "\n"; |
| 875 | } else if (lines[i].contains("$sdkname")) { |
| 876 | strnew += lines[i].replace("$sdkname", p_preset->get("xcode/sdk_name")) + "\n"; |
| 877 | } else if (lines[i].contains("$sdkbuild")) { |
| 878 | strnew += lines[i].replace("$sdkbuild", p_preset->get("xcode/sdk_build")) + "\n"; |
| 879 | } else if (lines[i].contains("$xcodever")) { |
| 880 | strnew += lines[i].replace("$xcodever", p_preset->get("xcode/xcode_version")) + "\n"; |
| 881 | } else if (lines[i].contains("$xcodebuild")) { |
| 882 | strnew += lines[i].replace("$xcodebuild", p_preset->get("xcode/xcode_build")) + "\n"; |
| 883 | } else if (lines[i].contains("$liquid_glass_icon")) { |
| 884 | if (p_lg_icon_exported) { |
| 885 | strnew += lines[i].replace("$liquid_glass_icon", "\t<key>CFBundleIconName</key>\n\t<string>" + p_lg_icon + "</string>\n"); |
| 886 | } else { |
| 887 | strnew += lines[i].replace("$liquid_glass_icon", ""); |
| 888 | } |
| 889 | } else if (lines[i].contains("$usage_descriptions")) { |
| 890 | String descriptions; |
| 891 | if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) { |
| 892 | descriptions += "\t<key>NSMicrophoneUsageDescription</key>\n"; |
| 893 | descriptions += "\t<string>" + p_preset->get("privacy/microphone_usage_description").operator String().xml_escape(true) + "</string>\n"; |
| 894 | } |
| 895 | if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) { |
| 896 | descriptions += "\t<key>NSCameraUsageDescription</key>\n"; |
| 897 | descriptions += "\t<string>" + p_preset->get("privacy/camera_usage_description").operator String().xml_escape(true) + "</string>\n"; |
| 898 | } |
| 899 | if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) { |
| 900 | descriptions += "\t<key>NSLocationUsageDescription</key>\n"; |
| 901 | descriptions += "\t<string>" + p_preset->get("privacy/location_usage_description").operator String().xml_escape(true) + "</string>\n"; |
| 902 | } |
| 903 | if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) { |
| 904 | descriptions += "\t<key>NSContactsUsageDescription</key>\n"; |
| 905 | descriptions += "\t<string>" + p_preset->get("privacy/address_book_usage_description").operator String().xml_escape(true) + "</string>\n"; |
| 906 | } |
| 907 | if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) { |
| 908 | descriptions += "\t<key>NSCalendarsUsageDescription</key>\n"; |
| 909 | descriptions += "\t<string>" + p_preset->get("privacy/calendar_usage_description").operator String().xml_escape(true) + "</string>\n"; |
| 910 | } |
| 911 | if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) { |
| 912 | descriptions += "\t<key>NSPhotoLibraryUsageDescription</key>\n"; |
| 913 | descriptions += "\t<string>" + p_preset->get("privacy/photos_library_usage_description").operator String().xml_escape(true) + "</string>\n"; |
| 914 | } |
| 915 | if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) { |
| 916 | descriptions += "\t<key>NSDesktopFolderUsageDescription</key>\n"; |
| 917 | descriptions += "\t<string>" + p_preset->get("privacy/desktop_folder_usage_description").operator String().xml_escape(true) + "</string>\n"; |
| 918 | } |
| 919 | if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) { |
| 920 | descriptions += "\t<key>NSDocumentsFolderUsageDescription</key>\n"; |
| 921 | descriptions += "\t<string>" + p_preset->get("privacy/documents_folder_usage_description").operator String().xml_escape(true) + "</string>\n"; |
| 922 | } |
| 923 | if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) { |
| 924 | descriptions += "\t<key>NSDownloadsFolderUsageDescription</key>\n"; |
| 925 | descriptions += "\t<string>" + p_preset->get("privacy/downloads_folder_usage_description").operator String().xml_escape(true) + "</string>\n"; |
| 926 | } |
| 927 | if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) { |
| 928 | descriptions += "\t<key>NSNetworkVolumesUsageDescription</key>\n"; |
| 929 | descriptions += "\t<string>" + p_preset->get("privacy/network_volumes_usage_description").operator String().xml_escape(true) + "</string>\n"; |
| 930 | } |
| 931 | if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) { |
| 932 | descriptions += "\t<key>NSRemovableVolumesUsageDescription</key>\n"; |
| 933 | descriptions += "\t<string>" + p_preset->get("privacy/removable_volumes_usage_description").operator String().xml_escape(true) + "</string>\n"; |
| 934 | } |
| 935 | if (!descriptions.is_empty()) { |
| 936 | strnew += lines[i].replace("$usage_descriptions", descriptions); |
| 937 | } |
| 938 | } else { |
| 939 | strnew += lines[i] + "\n"; |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | CharString cs = strnew.utf8(); |
| 944 | plist.resize(cs.size() - 1); |
| 945 | for (int i = 0; i < cs.size() - 1; i++) { |
| 946 | plist.write[i] = cs[i]; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | Error EditorExportPlatformMacOS::_export_liquid_glass_icon(const Ref<EditorExportPreset> &p_preset, const String &p_app_path, const String &p_icon_path) { |
| 951 | String actool = EDITOR_GET("export/macos/actool").operator String(); |
| 952 | if (actool.is_empty()) { |
| 953 | actool = "actool"; |
| 954 | } |
| 955 | |
| 956 | List<String> args; |
| 957 | args.push_back("--version"); |
| 958 | String str; |
| 959 | String err_str; |
| 960 | int exitcode = 0; |
| 961 | |
| 962 | Error err = OS::get_singleton()->execute(actool, args, &str, &exitcode, true); |
| 963 | if (err != OK) { |
| 964 | add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not start 'actool' executable.")); |
| 965 | return err; |
| 966 | } |
| 967 | PList info_plist; |
| 968 | if (!info_plist.load_string(str, err_str)) { |
| 969 | print_verbose(str); |
| 970 | add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not read 'actool' version.")); |
| 971 | return err; |
| 972 | } |
| 973 | if (info_plist.get_root()->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && info_plist.get_root()->data_dict.has("com.apple.actool.version")) { |
| 974 | Ref<PListNode> dict = info_plist.get_root()->data_dict["com.apple.actool.version"]; |
| 975 | if (dict->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && dict->data_dict.has("short-bundle-version")) { |
| 976 | float version = String::utf8(dict->data_dict["short-bundle-version"]->data_string.get_data()).to_float(); |
| 977 | if (version < 26.0) { |
| 978 | add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), vformat(TTR("At least version 26.0 of 'actool' is required (version %f found)."), version)); |
| 979 | return ERR_UNAVAILABLE; |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | str.clear(); |
| 984 | |
| 985 | String plist = EditorPaths::get_singleton()->get_temp_dir().path_join("assetcatalog.plist"); |
| 986 | args.clear(); |
| 987 | args.push_back(ProjectSettings::get_singleton()->globalize_path(p_icon_path)); |
| 988 | args.push_back("--compile"); |
| 989 | args.push_back(p_app_path + "/Contents/Resources/"); |
| 990 | args.push_back("--output-format"); |
| 991 | args.push_back("human-readable-text"); |
| 992 | args.push_back("--lightweight-asset-runtime-mode"); |
| 993 | args.push_back("enabled"); |
| 994 | args.push_back("--app-icon"); |
| 995 | args.push_back(p_icon_path.get_file().get_basename()); |
| 996 | args.push_back("--include-all-app-icons"); |
| 997 | args.push_back("--enable-on-demand-resources"); |
| 998 | args.push_back("NO"); |
| 999 | args.push_back("--development-region"); |
| 1000 | args.push_back("en"); |
| 1001 | args.push_back("--target-device"); |
| 1002 | args.push_back("mac"); |
| 1003 | args.push_back("--minimum-deployment-target"); |
| 1004 | args.push_back("26"); |
| 1005 | args.push_back("--platform"); |
| 1006 | args.push_back("macosx"); |
| 1007 | args.push_back("--output-partial-info-plist"); |
| 1008 | args.push_back(plist); |
| 1009 | |
| 1010 | err = OS::get_singleton()->execute(actool, args, &str, &exitcode, true); |
| 1011 | if (err != OK || str.contains("error:") || !FileAccess::exists(p_app_path + "/Contents/Resources/Assets.car") || !FileAccess::exists(plist)) { |
| 1012 | print_verbose(str); |
| 1013 | add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not export liquid glass icon:") + "\n" + str); |
| 1014 | return err; |
| 1015 | } |
| 1016 | |
| 1017 | return OK; |
| 1018 | } |
| 1019 | |
| 1020 | /** |
| 1021 | * If we're running the macOS version of the Godot editor we'll: |
| 1022 | * - export our application bundle to a temporary folder |
| 1023 | * - attempt to code sign it |
| 1024 | * - and then wrap it up in a DMG |
| 1025 | */ |
| 1026 | |
| 1027 | Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path) { |
| 1028 | int notary_tool = p_preset->get("notarization/notarization"); |
| 1029 | switch (notary_tool) { |
| 1030 | case 1: { // "rcodesign" |
| 1031 | print_verbose("using rcodesign notarization..."); |
| 1032 | |
| 1033 | String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String(); |
| 1034 | if (rcodesign.is_empty()) { |
| 1035 | add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).")); |
| 1036 | return Error::FAILED; |
| 1037 | } |
| 1038 | |
| 1039 | List<String> args; |
| 1040 | |
| 1041 | args.push_back("notary-submit"); |
| 1042 | |
| 1043 | if (p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) == "") { |
| 1044 | add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect issuer ID name not specified.")); |
| 1045 | return Error::FAILED; |
| 1046 | } |
| 1047 | if (p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY) == "") { |
| 1048 | add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified.")); |
| 1049 | return Error::FAILED; |
| 1050 | } |
| 1051 | |
| 1052 | args.push_back("--api-issuer"); |
| 1053 | args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID)); |
| 1054 | |
| 1055 | args.push_back("--api-key"); |
| 1056 | args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID)); |
| 1057 | |
| 1058 | if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) { |
| 1059 | args.push_back("--api-key-path"); |
| 1060 | args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY)); |
| 1061 | } |
| 1062 | |
| 1063 | args.push_back(p_path); |
| 1064 | |
| 1065 | String str; |
| 1066 | int exitcode = 0; |
| 1067 | |
| 1068 | Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true); |
| 1069 | if (err != OK) { |
| 1070 | add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start rcodesign executable.")); |
| 1071 | return err; |
| 1072 | } |
| 1073 | |
| 1074 | int rq_offset = str.find("created submission ID:"); |
| 1075 | if (exitcode != 0 || rq_offset == -1) { |
| 1076 | print_line("rcodesign (" + p_path + "):\n" + str); |
| 1077 | add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details.")); |
| 1078 | return Error::FAILED; |
| 1079 | } else { |
| 1080 | print_verbose("rcodesign (" + p_path + "):\n" + str); |
| 1081 | int next_nl = str.find_char('\n', rq_offset); |
| 1082 | String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 23) : str.substr(rq_offset + 23, next_nl - rq_offset - 23); |
| 1083 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid)); |
| 1084 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour.")); |
| 1085 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check the progress manually by opening a Terminal and running the following command:")); |
| 1086 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign notary-log --api-issuer <API UUID> --api-key <API key> <request UUID>\""); |
| 1087 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):")); |
| 1088 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign staple <app path>\""); |
| 1089 | } |
| 1090 | } break; |
| 1091 | #ifdef MACOS_ENABLED |
| 1092 | case 2: { // "notarytool" |
| 1093 | print_verbose("using notarytool notarization..."); |
| 1094 | |
| 1095 | if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) { |
| 1096 | add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed.")); |
| 1097 | return Error::FAILED; |
| 1098 | } |
| 1099 | |
| 1100 | List<String> args; |
| 1101 | |
| 1102 | args.push_back("notarytool"); |
| 1103 | args.push_back("submit"); |
| 1104 | |
| 1105 | args.push_back(p_path); |
| 1106 | |
| 1107 | if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) == "" && p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) == "") { |
| 1108 | add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified.")); |
| 1109 | return Error::FAILED; |
| 1110 | } |
| 1111 | if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) != "" && p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) != "") { |
| 1112 | add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.")); |
| 1113 | return Error::FAILED; |
| 1114 | } |
| 1115 | |
| 1116 | if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) != "") { |
| 1117 | if (p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS) == "") { |
| 1118 | add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified.")); |
| 1119 | return Error::FAILED; |
| 1120 | } |
| 1121 | args.push_back("--apple-id"); |
| 1122 | args.push_back(p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID)); |
| 1123 | |
| 1124 | args.push_back("--password"); |
| 1125 | args.push_back(p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS)); |
| 1126 | } else { |
| 1127 | if (p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID) == "") { |
| 1128 | add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified.")); |
| 1129 | return Error::FAILED; |
| 1130 | } |
| 1131 | args.push_back("--issuer"); |
| 1132 | args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID)); |
| 1133 | |
| 1134 | if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) { |
| 1135 | args.push_back("--key"); |
| 1136 | args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY)); |
| 1137 | } |
| 1138 | |
| 1139 | args.push_back("--key-id"); |
| 1140 | args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID)); |
| 1141 | } |
| 1142 | |
| 1143 | args.push_back("--no-progress"); |
| 1144 | |
| 1145 | if (p_preset->get("codesign/apple_team_id")) { |
| 1146 | args.push_back("--team-id"); |
| 1147 | args.push_back(p_preset->get("codesign/apple_team_id")); |
| 1148 | } |
| 1149 | |
| 1150 | String str; |
| 1151 | int exitcode = 0; |
| 1152 | Error err = OS::get_singleton()->execute("xcrun", args, &str, &exitcode, true); |
| 1153 | if (err != OK) { |
| 1154 | add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable.")); |
| 1155 | return err; |
| 1156 | } |
| 1157 | |
| 1158 | int rq_offset = str.find("id:"); |
| 1159 | if (exitcode != 0 || rq_offset == -1) { |
| 1160 | print_line("notarytool (" + p_path + "):\n" + str); |
| 1161 | add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details.")); |
| 1162 | return Error::FAILED; |
| 1163 | } else { |
| 1164 | print_verbose("notarytool (" + p_path + "):\n" + str); |
| 1165 | int next_nl = str.find_char('\n', rq_offset); |
| 1166 | String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 4) : str.substr(rq_offset + 4, next_nl - rq_offset - 4); |
| 1167 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid)); |
| 1168 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour.")); |
| 1169 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("See instructions on finding your team ID: https://developer.apple.com/help/glossary/team-id")); |
| 1170 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check the progress manually by opening a Terminal and running the following command:")); |
| 1171 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request UUID> --issuer <API UUID> --key-id <API key ID> --key <API key path>\" or"); |
| 1172 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request UUID> --team-id <team ID> --apple-id <your email> --password <app-specific password>\""); |
| 1173 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):")); |
| 1174 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple <app path>\""); |
| 1175 | } |
| 1176 | } break; |
| 1177 | #endif |
| 1178 | default: { |
| 1179 | }; |
| 1180 | } |
| 1181 | return OK; |
| 1182 | } |
| 1183 | |
| 1184 | void EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_warn, bool p_set_id) { |
| 1185 | int codesign_tool = p_preset->get("codesign/codesign"); |
| 1186 | switch (codesign_tool) { |
| 1187 | case 1: { // built-in ad-hoc |
| 1188 | print_verbose("using built-in codesign..."); |
| 1189 | String error_msg; |
| 1190 | Error err = CodeSign::codesign(false, true, p_path, p_ent_path, error_msg); |
| 1191 | if (err != OK) { |
| 1192 | add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Built-in CodeSign failed with error \"%s\"."), error_msg)); |
| 1193 | return; |
| 1194 | } |
| 1195 | } break; |
| 1196 | case 2: { // "rcodesign" |
| 1197 | print_verbose("using rcodesign codesign..."); |
| 1198 | |
| 1199 | String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String(); |
| 1200 | if (rcodesign.is_empty()) { |
| 1201 | add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xrcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).")); |
| 1202 | return; |
| 1203 | } |
| 1204 | |
| 1205 | List<String> args; |
| 1206 | args.push_back("sign"); |
| 1207 | |
| 1208 | if (!p_ent_path.is_empty()) { |
| 1209 | args.push_back("--entitlements-xml-path"); |
| 1210 | args.push_back(p_ent_path); |
| 1211 | } |
| 1212 | |
| 1213 | String certificate_file = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE); |
| 1214 | String certificate_pass = p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS); |
| 1215 | if (!certificate_file.is_empty() && !certificate_pass.is_empty()) { |
| 1216 | args.push_back("--p12-file"); |
| 1217 | args.push_back(certificate_file); |
| 1218 | args.push_back("--p12-password"); |
| 1219 | args.push_back(certificate_pass); |
| 1220 | } |
| 1221 | args.push_back("--code-signature-flags"); |
| 1222 | args.push_back("runtime"); |
| 1223 | |
| 1224 | if (p_set_id) { |
| 1225 | String app_id = p_preset->get("application/bundle_identifier"); |
| 1226 | args.push_back("--binary-identifier"); |
| 1227 | args.push_back(app_id); |
| 1228 | } |
| 1229 | |
| 1230 | args.push_back("-v"); /* provide some more feedback */ |
| 1231 | |
| 1232 | args.push_back(p_path); |
| 1233 | |
| 1234 | String str; |
| 1235 | int exitcode = 0; |
| 1236 | |
| 1237 | Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true); |
| 1238 | if (err != OK) { |
| 1239 | add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start rcodesign executable.")); |
| 1240 | return; |
| 1241 | } |
| 1242 | |
| 1243 | if (exitcode != 0) { |
| 1244 | print_line("rcodesign (" + p_path + "):\n" + str); |
| 1245 | add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details.")); |
| 1246 | return; |
| 1247 | } else { |
| 1248 | print_verbose("rcodesign (" + p_path + "):\n" + str); |
| 1249 | } |
| 1250 | } break; |
| 1251 | #ifdef MACOS_ENABLED |
| 1252 | case 3: { // "codesign" |
| 1253 | print_verbose("using xcode codesign..."); |
| 1254 | |
| 1255 | if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) { |
| 1256 | add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xcode command line tools are not installed.")); |
| 1257 | return; |
| 1258 | } |
| 1259 | |
| 1260 | bool ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-"); |
| 1261 | |
| 1262 | List<String> args; |
| 1263 | if (!ad_hoc) { |
| 1264 | args.push_back("--timestamp"); |
| 1265 | args.push_back("--options"); |
| 1266 | args.push_back("runtime"); |
| 1267 | } |
| 1268 | |
| 1269 | if (!p_ent_path.is_empty()) { |
| 1270 | args.push_back("--entitlements"); |
| 1271 | args.push_back(p_ent_path); |
| 1272 | } |
| 1273 | |
| 1274 | PackedStringArray user_args = p_preset->get("codesign/custom_options"); |
| 1275 | for (int i = 0; i < user_args.size(); i++) { |
| 1276 | String user_arg = user_args[i].strip_edges(); |
| 1277 | if (!user_arg.is_empty()) { |
| 1278 | args.push_back(user_arg); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | args.push_back("-s"); |
| 1283 | if (ad_hoc) { |
| 1284 | args.push_back("-"); |
| 1285 | } else { |
| 1286 | args.push_back(p_preset->get("codesign/identity")); |
| 1287 | } |
| 1288 | |
| 1289 | if (p_set_id) { |
| 1290 | String app_id = p_preset->get("application/bundle_identifier"); |
| 1291 | args.push_back("-i"); |
| 1292 | args.push_back(app_id); |
| 1293 | } |
| 1294 | |
| 1295 | args.push_back("-v"); /* provide some more feedback */ |
| 1296 | args.push_back("-f"); |
| 1297 | |
| 1298 | args.push_back(p_path); |
| 1299 | |
| 1300 | String str; |
| 1301 | int exitcode = 0; |
| 1302 | |
| 1303 | Error err = OS::get_singleton()->execute("codesign", args, &str, &exitcode, true); |
| 1304 | if (err != OK) { |
| 1305 | add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start codesign executable, make sure Xcode command line tools are installed.")); |
| 1306 | return; |
| 1307 | } |
| 1308 | |
| 1309 | if (exitcode != 0) { |
| 1310 | print_line("codesign (" + p_path + "):\n" + str); |
| 1311 | add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details.")); |
| 1312 | return; |
| 1313 | } else { |
| 1314 | print_verbose("codesign (" + p_path + "):\n" + str); |
| 1315 | } |
| 1316 | } break; |
| 1317 | #endif |
| 1318 | default: { |
| 1319 | }; |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | void EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path, |
| 1324 | const String &p_ent_path, const String &p_helper_ent_path, bool p_should_error_on_non_code) { |
| 1325 | static Vector<String> extensions_to_sign; |
| 1326 | |
| 1327 | bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled"); |
| 1328 | if (extensions_to_sign.is_empty()) { |
| 1329 | extensions_to_sign.push_back("dylib"); |
| 1330 | extensions_to_sign.push_back("framework"); |
| 1331 | extensions_to_sign.push_back(""); |
| 1332 | } |
| 1333 | |
| 1334 | Error dir_access_error; |
| 1335 | Ref<DirAccess> dir_access{ DirAccess::open(p_path, &dir_access_error) }; |
| 1336 | |
| 1337 | if (dir_access_error != OK) { |
| 1338 | add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign directory %s."), p_path)); |
| 1339 | return; |
| 1340 | } |
| 1341 | |
| 1342 | dir_access->list_dir_begin(); |
| 1343 | String current_file{ dir_access->get_next() }; |
| 1344 | while (!current_file.is_empty()) { |
| 1345 | String current_file_path{ p_path.path_join(current_file) }; |
| 1346 | |
| 1347 | if (current_file == ".." || current_file == ".") { |
| 1348 | current_file = dir_access->get_next(); |
| 1349 | continue; |
| 1350 | } |
| 1351 | |
| 1352 | if (extensions_to_sign.has(current_file.get_extension())) { |
| 1353 | String ent_path; |
| 1354 | bool set_bundle_id = false; |
| 1355 | if (sandbox && FileAccess::exists(current_file_path)) { |
| 1356 | int ftype = MachO::get_filetype(current_file_path); |
| 1357 | if (ftype == 2 || ftype == 5) { |
| 1358 | ent_path = p_helper_ent_path; |
| 1359 | set_bundle_id = true; |
| 1360 | } |
| 1361 | } |
| 1362 | _code_sign(p_preset, current_file_path, ent_path, false, set_bundle_id); |
| 1363 | if (is_executable(current_file_path)) { |
| 1364 | // chmod with 0755 if the file is executable. |
| 1365 | FileAccess::set_unix_permissions(current_file_path, 0755); |
| 1366 | } |
| 1367 | } else if (dir_access->current_is_dir()) { |
| 1368 | _code_sign_directory(p_preset, current_file_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code); |
| 1369 | } else if (p_should_error_on_non_code) { |
| 1370 | add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign file %s."), current_file)); |
| 1371 | } |
| 1372 | |
| 1373 | current_file = dir_access->get_next(); |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | Error EditorExportPlatformMacOS::_copy_and_sign_files(Ref<DirAccess> &dir_access, const String &p_src_path, |
| 1378 | const String &p_in_app_path, bool p_sign_enabled, |
| 1379 | const Ref<EditorExportPreset> &p_preset, const String &p_ent_path, |
| 1380 | const String &p_helper_ent_path, |
| 1381 | bool p_should_error_on_non_code_sign, bool p_sandbox) { |
| 1382 | static Vector<String> extensions_to_sign; |
| 1383 | |
| 1384 | if (extensions_to_sign.is_empty()) { |
| 1385 | extensions_to_sign.push_back("dylib"); |
| 1386 | extensions_to_sign.push_back("framework"); |
| 1387 | extensions_to_sign.push_back(""); |
| 1388 | } |
| 1389 | |
| 1390 | Error err{ OK }; |
| 1391 | if (dir_access->dir_exists(p_src_path)) { |
| 1392 | #ifndef UNIX_ENABLED |
| 1393 | add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Relative symlinks are not supported, exported \"%s\" might be broken!"), p_src_path.get_file())); |
| 1394 | #endif |
| 1395 | print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path); |
| 1396 | |
| 1397 | bool plist_missing = false; |
| 1398 | Ref<PList> plist; |
| 1399 | plist.instantiate(); |
| 1400 | plist->load_file(p_src_path.path_join("Resources").path_join("Info.plist")); |
| 1401 | |
| 1402 | Ref<PListNode> root_node = plist->get_root(); |
| 1403 | if (root_node.is_null()) { |
| 1404 | plist_missing = true; |
| 1405 | } else { |
| 1406 | Dictionary root = root_node->get_value(); |
| 1407 | if (!root.has("CFBundleExecutable") || !root.has("CFBundleIdentifier") || !root.has("CFBundlePackageType") || !root.has("CFBundleInfoDictionaryVersion") || !root.has("CFBundleName") || !root.has("CFBundleSupportedPlatforms")) { |
| 1408 | plist_missing = true; |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | err = dir_access->make_dir_recursive(p_in_app_path); |
| 1413 | if (err == OK) { |
| 1414 | err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true); |
| 1415 | } |
| 1416 | if (err == OK && plist_missing) { |
| 1417 | add_message(EXPORT_MESSAGE_WARNING, TTR("Export"), vformat(TTR("\"%s\": Info.plist missing or invalid, new Info.plist generated."), p_src_path.get_file())); |
| 1418 | // Generate Info.plist |
| 1419 | String lib_name = p_src_path.get_basename().get_file(); |
| 1420 | String lib_id = p_preset->get("application/bundle_identifier"); |
| 1421 | String lib_clean_name = lib_name; |
| 1422 | for (int i = 0; i < lib_clean_name.length(); i++) { |
| 1423 | if (!is_ascii_alphanumeric_char(lib_clean_name[i]) && lib_clean_name[i] != '.' && lib_clean_name[i] != '-') { |
| 1424 | lib_clean_name[i] = '-'; |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 1429 | "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" |
| 1430 | "<plist version=\"1.0\">\n" |
| 1431 | " <dict>\n" |
| 1432 | " <key>CFBundleExecutable</key>\n" |
| 1433 | " <string>$name</string>\n" |
| 1434 | " <key>CFBundleIdentifier</key>\n" |
| 1435 | " <string>$id.framework.$cl_name</string>\n" |
| 1436 | " <key>CFBundleInfoDictionaryVersion</key>\n" |
| 1437 | " <string>6.0</string>\n" |
| 1438 | " <key>CFBundleName</key>\n" |
| 1439 | " <string>$name</string>\n" |
| 1440 | " <key>CFBundlePackageType</key>\n" |
| 1441 | " <string>FMWK</string>\n" |
| 1442 | " <key>CFBundleShortVersionString</key>\n" |
| 1443 | " <string>1.0.0</string>\n" |
| 1444 | " <key>CFBundleSupportedPlatforms</key>\n" |
| 1445 | " <array>\n" |
| 1446 | " <string>MacOSX</string>\n" |
| 1447 | " </array>\n" |
| 1448 | " <key>CFBundleVersion</key>\n" |
| 1449 | " <string>1.0.0</string>\n" |
| 1450 | " <key>LSMinimumSystemVersion</key>\n" |
| 1451 | " <string>10.12</string>\n" |
| 1452 | " </dict>\n" |
| 1453 | "</plist>"; |
| 1454 | |
| 1455 | String info_plist = info_plist_format.replace("$id", lib_id).replace("$name", lib_name).replace("$cl_name", lib_clean_name); |
| 1456 | |
| 1457 | err = dir_access->make_dir_recursive(p_in_app_path.path_join("Resources")); |
| 1458 | Ref<FileAccess> f = FileAccess::open(p_in_app_path.path_join("Resources").path_join("Info.plist"), FileAccess::WRITE); |
| 1459 | if (f.is_valid()) { |
| 1460 | f->store_string(info_plist); |
| 1461 | } |
| 1462 | } |
| 1463 | } else { |
| 1464 | print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path); |
| 1465 | err = dir_access->copy(p_src_path, p_in_app_path); |
| 1466 | } |
| 1467 | if (err == OK && p_sign_enabled) { |
| 1468 | if (dir_access->dir_exists(p_src_path) && p_src_path.get_extension().is_empty()) { |
| 1469 | // If it is a directory, find and sign all dynamic libraries. |
| 1470 | _code_sign_directory(p_preset, p_in_app_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code_sign); |
| 1471 | } else { |
| 1472 | if (extensions_to_sign.has(p_in_app_path.get_extension())) { |
| 1473 | String ent_path; |
| 1474 | bool set_bundle_id = false; |
| 1475 | if (p_sandbox && FileAccess::exists(p_in_app_path)) { |
| 1476 | int ftype = MachO::get_filetype(p_in_app_path); |
| 1477 | if (ftype == 2 || ftype == 5) { |
| 1478 | ent_path = p_helper_ent_path; |
| 1479 | set_bundle_id = true; |
| 1480 | } |
| 1481 | } |
| 1482 | _code_sign(p_preset, p_in_app_path, ent_path, false, set_bundle_id); |
| 1483 | } |
| 1484 | if (dir_access->file_exists(p_in_app_path) && is_executable(p_in_app_path)) { |
| 1485 | // chmod with 0755 if the file is executable. |
| 1486 | FileAccess::set_unix_permissions(p_in_app_path, 0755); |
| 1487 | } |
| 1488 | } |
| 1489 | } |
| 1490 | return err; |
| 1491 | } |
| 1492 | |
| 1493 | Error EditorExportPlatformMacOS::_export_macos_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin, |
| 1494 | const String &p_app_path_name, Ref<DirAccess> &dir_access, |
| 1495 | bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset, |
| 1496 | const String &p_ent_path, const String &p_helper_ent_path, bool p_sandbox) { |
| 1497 | Error error{ OK }; |
| 1498 | const Vector<String> &macos_plugins{ p_editor_export_plugin->get_macos_plugin_files() }; |
| 1499 | for (int i = 0; i < macos_plugins.size(); ++i) { |
| 1500 | String src_path{ ProjectSettings::get_singleton()->globalize_path(macos_plugins[i]) }; |
| 1501 | String path_in_app{ p_app_path_name + "/Contents/PlugIns/" + src_path.get_file() }; |
| 1502 | error = _copy_and_sign_files(dir_access, src_path, path_in_app, p_sign_enabled, p_preset, p_ent_path, p_helper_ent_path, false, p_sandbox); |
| 1503 | if (error != OK) { |
| 1504 | break; |
| 1505 | } |
| 1506 | } |
| 1507 | return error; |
| 1508 | } |
| 1509 | |
| 1510 | Error EditorExportPlatformMacOS::_create_pkg(const Ref<EditorExportPreset> &p_preset, const String &p_pkg_path, const String &p_app_path_name) { |
| 1511 | List<String> args; |
| 1512 | |
| 1513 | if (FileAccess::exists(p_pkg_path)) { |
| 1514 | OS::get_singleton()->move_to_trash(p_pkg_path); |
| 1515 | } |
| 1516 | |
| 1517 | args.push_back("productbuild"); |
| 1518 | args.push_back("--component"); |
| 1519 | args.push_back(p_app_path_name); |
| 1520 | args.push_back("/Applications"); |
| 1521 | String ident = p_preset->get("codesign/installer_identity"); |
| 1522 | if (!ident.is_empty()) { |
| 1523 | args.push_back("--timestamp"); |
| 1524 | args.push_back("--sign"); |
| 1525 | args.push_back(ident); |
| 1526 | } |
| 1527 | args.push_back("--quiet"); |
| 1528 | args.push_back(p_pkg_path); |
| 1529 | |
| 1530 | String str; |
| 1531 | Error err = OS::get_singleton()->execute("xcrun", args, &str, nullptr, true); |
| 1532 | if (err != OK) { |
| 1533 | add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("Could not start productbuild executable.")); |
| 1534 | return err; |
| 1535 | } |
| 1536 | |
| 1537 | print_verbose("productbuild returned: " + str); |
| 1538 | if (str.contains("productbuild: error:")) { |
| 1539 | add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("`productbuild` failed.")); |
| 1540 | return FAILED; |
| 1541 | } |
| 1542 | |
| 1543 | return OK; |
| 1544 | } |
| 1545 | |
| 1546 | Error EditorExportPlatformMacOS::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) { |
| 1547 | List<String> args; |
| 1548 | |
| 1549 | if (FileAccess::exists(p_dmg_path)) { |
| 1550 | OS::get_singleton()->move_to_trash(p_dmg_path); |
| 1551 | } |
| 1552 | |
| 1553 | args.push_back("create"); |
| 1554 | args.push_back(p_dmg_path); |
| 1555 | args.push_back("-volname"); |
| 1556 | args.push_back(p_pkg_name); |
| 1557 | args.push_back("-fs"); |
| 1558 | args.push_back("HFS+"); |
| 1559 | args.push_back("-srcfolder"); |
| 1560 | args.push_back(p_app_path_name); |
| 1561 | |
| 1562 | String str; |
| 1563 | Error err = OS::get_singleton()->execute("hdiutil", args, &str, nullptr, true); |
| 1564 | if (err != OK) { |
| 1565 | add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("Could not start hdiutil executable.")); |
| 1566 | return err; |
| 1567 | } |
| 1568 | |
| 1569 | print_verbose("hdiutil returned: " + str); |
| 1570 | if (str.contains("create failed")) { |
| 1571 | if (str.contains("File exists")) { |
| 1572 | add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed - file exists.")); |
| 1573 | } else { |
| 1574 | add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed.")); |
| 1575 | } |
| 1576 | return FAILED; |
| 1577 | } |
| 1578 | |
| 1579 | return OK; |
| 1580 | } |
| 1581 | |
| 1582 | bool EditorExportPlatformMacOS::is_shebang(const String &p_path) const { |
| 1583 | Ref<FileAccess> fb = FileAccess::open(p_path, FileAccess::READ); |
| 1584 | ERR_FAIL_COND_V_MSG(fb.is_null(), false, vformat("Can't open file: \"%s\".", p_path)); |
| 1585 | uint16_t magic = fb->get_16(); |
| 1586 | return (magic == 0x2123); |
| 1587 | } |
| 1588 | |
| 1589 | bool EditorExportPlatformMacOS::is_executable(const String &p_path) const { |
| 1590 | return MachO::is_macho(p_path) || LipO::is_lipo(p_path) || is_shebang(p_path); |
| 1591 | } |
| 1592 | |
| 1593 | Error EditorExportPlatformMacOS::_export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path) { |
| 1594 | Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE); |
| 1595 | if (f.is_null()) { |
| 1596 | add_message(EXPORT_MESSAGE_ERROR, TTR("Debug Script Export"), vformat(TTR("Could not open file \"%s\"."), p_path)); |
| 1597 | return ERR_CANT_CREATE; |
| 1598 | } |
| 1599 | |
| 1600 | f->store_line("#!/bin/sh"); |
| 1601 | f->store_line("printf '\\033c\\033]0;%s\\a' " + p_app_name); |
| 1602 | f->store_line(""); |
| 1603 | f->store_line("function app_realpath() {"); |
| 1604 | f->store_line(" SOURCE=$1"); |
| 1605 | f->store_line(" while [ -h \"$SOURCE\" ]; do"); |
| 1606 | f->store_line(" DIR=$(dirname \"$SOURCE\")"); |
| 1607 | f->store_line(" SOURCE=$(readlink \"$SOURCE\")"); |
| 1608 | f->store_line(" [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE"); |
| 1609 | f->store_line(" done"); |
| 1610 | f->store_line(" echo \"$( cd -P \"$( dirname \"$SOURCE\" )\" >/dev/null 2>&1 && pwd )\""); |
| 1611 | f->store_line("}"); |
| 1612 | f->store_line(""); |
| 1613 | f->store_line("BASE_PATH=\"$(app_realpath \"${BASH_SOURCE[0]}\")\""); |
| 1614 | f->store_line("\"$BASE_PATH/" + p_pkg_name + "\" \"$@\""); |
| 1615 | f->store_line(""); |
| 1616 | |
| 1617 | return OK; |
| 1618 | } |
| 1619 | |
| 1620 | Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) { |
| 1621 | ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags); |
| 1622 | |
| 1623 | const String base_dir = p_path.get_base_dir(); |
| 1624 | |
| 1625 | if (!DirAccess::exists(base_dir)) { |
| 1626 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Target folder does not exist or is inaccessible: \"%s\""), base_dir)); |
| 1627 | return ERR_FILE_BAD_PATH; |
| 1628 | } |
| 1629 | |
| 1630 | EditorProgress ep("export", TTR("Exporting for macOS"), 3, true); |
| 1631 | |
| 1632 | String src_pkg_name; |
| 1633 | if (p_debug) { |
| 1634 | src_pkg_name = p_preset->get("custom_template/debug"); |
| 1635 | } else { |
| 1636 | src_pkg_name = p_preset->get("custom_template/release"); |
| 1637 | } |
| 1638 | |
| 1639 | if (src_pkg_name.is_empty()) { |
| 1640 | String err; |
| 1641 | src_pkg_name = find_export_template("macos.zip", &err); |
| 1642 | if (src_pkg_name.is_empty()) { |
| 1643 | add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found.") + "\n" + err); |
| 1644 | return ERR_FILE_NOT_FOUND; |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | Ref<FileAccess> io_fa; |
| 1649 | zlib_filefunc_def io = zipio_create_io(&io_fa); |
| 1650 | |
| 1651 | if (ep.step(TTR("Creating app bundle"), 0)) { |
| 1652 | return ERR_SKIP; |
| 1653 | } |
| 1654 | |
| 1655 | unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io); |
| 1656 | if (!src_pkg_zip) { |
| 1657 | add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not find template app to export: \"%s\"."), src_pkg_name)); |
| 1658 | return ERR_FILE_NOT_FOUND; |
| 1659 | } |
| 1660 | |
| 1661 | int ret = unzGoToFirstFile(src_pkg_zip); |
| 1662 | |
| 1663 | String architecture = p_preset->get("binary_format/architecture"); |
| 1664 | String binary_to_use = "godot_macos_" + String(p_debug ? "debug" : "release") + "." + architecture; |
| 1665 | |
| 1666 | String pkg_name; |
| 1667 | if (String(get_project_setting(p_preset, "application/config/name")) != "") { |
| 1668 | pkg_name = String(get_project_setting(p_preset, "application/config/name")); |
| 1669 | } else { |
| 1670 | pkg_name = "Unnamed"; |
| 1671 | } |
| 1672 | pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name); |
| 1673 | |
| 1674 | String export_format; |
| 1675 | if (p_path.ends_with("zip")) { |
| 1676 | export_format = "zip"; |
| 1677 | } else if (p_path.ends_with("app")) { |
| 1678 | export_format = "app"; |
| 1679 | #ifdef MACOS_ENABLED |
| 1680 | } else if (p_path.ends_with("dmg")) { |
| 1681 | export_format = "dmg"; |
| 1682 | } else if (p_path.ends_with("pkg")) { |
| 1683 | export_format = "pkg"; |
| 1684 | #endif |
| 1685 | } else { |
| 1686 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Invalid export format.")); |
| 1687 | return ERR_CANT_CREATE; |
| 1688 | } |
| 1689 | |
| 1690 | // Create our application bundle. |
| 1691 | String tmp_app_dir_name = pkg_name + ".app"; |
| 1692 | String tmp_base_path_name; |
| 1693 | String tmp_app_path_name; |
| 1694 | String scr_path; |
| 1695 | if (export_format == "app") { |
| 1696 | tmp_base_path_name = p_path.get_base_dir(); |
| 1697 | tmp_app_path_name = p_path; |
| 1698 | scr_path = p_path.get_basename() + ".command"; |
| 1699 | } else { |
| 1700 | tmp_base_path_name = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name); |
| 1701 | tmp_app_path_name = tmp_base_path_name.path_join(tmp_app_dir_name); |
| 1702 | scr_path = tmp_base_path_name.path_join(pkg_name + ".command"); |
| 1703 | } |
| 1704 | |
| 1705 | print_verbose("Exporting to " + tmp_app_path_name); |
| 1706 | |
| 1707 | Error err = OK; |
| 1708 | |
| 1709 | Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_base_path_name); |
| 1710 | if (tmp_app_dir.is_null()) { |
| 1711 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory: \"%s\"."), tmp_base_path_name)); |
| 1712 | err = ERR_CANT_CREATE; |
| 1713 | } |
| 1714 | |
| 1715 | if (FileAccess::exists(scr_path)) { |
| 1716 | DirAccess::remove_file_or_error(scr_path); |
| 1717 | } |
| 1718 | if (DirAccess::exists(tmp_app_path_name)) { |
| 1719 | String old_dir = tmp_app_dir->get_current_dir(); |
| 1720 | if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) { |
| 1721 | tmp_app_dir->erase_contents_recursive(); |
| 1722 | tmp_app_dir->change_dir(old_dir); |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | Array helpers = p_preset->get("codesign/entitlements/app_sandbox/helper_executables"); |
| 1727 | |
| 1728 | // Create our folder structure. |
| 1729 | if (err == OK) { |
| 1730 | print_verbose("Creating " + tmp_app_path_name + "/Contents/MacOS"); |
| 1731 | err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS"); |
| 1732 | if (err != OK) { |
| 1733 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/MacOS")); |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | if (err == OK) { |
| 1738 | print_verbose("Creating " + tmp_app_path_name + "/Contents/Frameworks"); |
| 1739 | err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks"); |
| 1740 | if (err != OK) { |
| 1741 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Frameworks")); |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | if ((err == OK) && helpers.size() > 0) { |
| 1746 | print_line("Creating " + tmp_app_path_name + "/Contents/Helpers"); |
| 1747 | err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Helpers"); |
| 1748 | if (err != OK) { |
| 1749 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Helpers")); |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | if (err == OK) { |
| 1754 | print_verbose("Creating " + tmp_app_path_name + "/Contents/Resources"); |
| 1755 | err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources"); |
| 1756 | if (err != OK) { |
| 1757 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Resources")); |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized"); |
| 1762 | Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized"); |
| 1763 | Dictionary location_usage_descriptions = p_preset->get("privacy/location_usage_description_localized"); |
| 1764 | Dictionary address_book_usage_descriptions = p_preset->get("privacy/address_book_usage_description_localized"); |
| 1765 | Dictionary calendar_usage_descriptions = p_preset->get("privacy/calendar_usage_description_localized"); |
| 1766 | Dictionary photos_library_usage_descriptions = p_preset->get("privacy/photos_library_usage_description_localized"); |
| 1767 | Dictionary desktop_folder_usage_descriptions = p_preset->get("privacy/desktop_folder_usage_description_localized"); |
| 1768 | Dictionary documents_folder_usage_descriptions = p_preset->get("privacy/documents_folder_usage_description_localized"); |
| 1769 | Dictionary downloads_folder_usage_descriptions = p_preset->get("privacy/downloads_folder_usage_description_localized"); |
| 1770 | Dictionary network_volumes_usage_descriptions = p_preset->get("privacy/network_volumes_usage_description_localized"); |
| 1771 | Dictionary removable_volumes_usage_descriptions = p_preset->get("privacy/removable_volumes_usage_description_localized"); |
| 1772 | Dictionary copyrights = p_preset->get("application/copyright_localized"); |
| 1773 | |
| 1774 | const String project_name = get_project_setting(p_preset, "application/config/name"); |
| 1775 | const Dictionary appnames = get_project_setting(p_preset, "application/config/name_localized"); |
| 1776 | const StringName domain_name = "godot.project_name_localization"; |
| 1777 | Ref<TranslationDomain> domain = TranslationServer::get_singleton()->get_or_add_domain(domain_name); |
| 1778 | TranslationServer::get_singleton()->load_project_translations(domain); |
| 1779 | const Vector<String> locales = domain->get_loaded_locales(); |
| 1780 | |
| 1781 | if (!locales.is_empty()) { |
| 1782 | { |
| 1783 | String fname = tmp_app_path_name + "/Contents/Resources/en.lproj"; |
| 1784 | tmp_app_dir->make_dir_recursive(fname); |
| 1785 | Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE); |
| 1786 | f->store_line("/* Localized versions of Info.plist keys */"); |
| 1787 | f->store_line(""); |
| 1788 | f->store_line("CFBundleDisplayName = \"" + project_name.xml_escape(true) + "\";"); |
| 1789 | if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) { |
| 1790 | f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String().xml_escape(true) + "\";"); |
| 1791 | } |
| 1792 | if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) { |
| 1793 | f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String().xml_escape(true) + "\";"); |
| 1794 | } |
| 1795 | if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) { |
| 1796 | f->store_line("NSLocationUsageDescription = \"" + p_preset->get("privacy/location_usage_description").operator String().xml_escape(true) + "\";"); |
| 1797 | } |
| 1798 | if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) { |
| 1799 | f->store_line("NSContactsUsageDescription = \"" + p_preset->get("privacy/address_book_usage_description").operator String().xml_escape(true) + "\";"); |
| 1800 | } |
| 1801 | if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) { |
| 1802 | f->store_line("NSCalendarsUsageDescription = \"" + p_preset->get("privacy/calendar_usage_description").operator String().xml_escape(true) + "\";"); |
| 1803 | } |
| 1804 | if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) { |
| 1805 | f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photos_library_usage_description").operator String().xml_escape(true) + "\";"); |
| 1806 | } |
| 1807 | if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) { |
| 1808 | f->store_line("NSDesktopFolderUsageDescription = \"" + p_preset->get("privacy/desktop_folder_usage_description").operator String().xml_escape(true) + "\";"); |
| 1809 | } |
| 1810 | if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) { |
| 1811 | f->store_line("NSDocumentsFolderUsageDescription = \"" + p_preset->get("privacy/documents_folder_usage_description").operator String().xml_escape(true) + "\";"); |
| 1812 | } |
| 1813 | if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) { |
| 1814 | f->store_line("NSDownloadsFolderUsageDescription = \"" + p_preset->get("privacy/downloads_folder_usage_description").operator String().xml_escape(true) + "\";"); |
| 1815 | } |
| 1816 | if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) { |
| 1817 | f->store_line("NSNetworkVolumesUsageDescription = \"" + p_preset->get("privacy/network_volumes_usage_description").operator String().xml_escape(true) + "\";"); |
| 1818 | } |
| 1819 | if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) { |
| 1820 | f->store_line("NSRemovableVolumesUsageDescription = \"" + p_preset->get("privacy/removable_volumes_usage_description").operator String().xml_escape(true) + "\";"); |
| 1821 | } |
| 1822 | f->store_line("NSHumanReadableCopyright = \"" + p_preset->get("application/copyright").operator String().xml_escape(true) + "\";"); |
| 1823 | } |
| 1824 | |
| 1825 | for (const String &lang : locales) { |
| 1826 | if (lang == "en") { |
| 1827 | continue; |
| 1828 | } |
| 1829 | |
| 1830 | String fname = tmp_app_path_name + "/Contents/Resources/" + lang + ".lproj"; |
| 1831 | tmp_app_dir->make_dir_recursive(fname); |
| 1832 | Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE); |
| 1833 | f->store_line("/* Localized versions of Info.plist keys */"); |
| 1834 | f->store_line(""); |
| 1835 | |
| 1836 | if (appnames.is_empty()) { |
| 1837 | domain->set_locale_override(lang); |
| 1838 | const String &name = domain->translate(project_name, String()); |
| 1839 | if (name != project_name) { |
| 1840 | f->store_line("CFBundleDisplayName = \"" + name.xml_escape(true) + "\";"); |
| 1841 | } |
| 1842 | } else if (appnames.has(lang)) { |
| 1843 | f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String().xml_escape(true) + "\";"); |
| 1844 | } |
| 1845 | |
| 1846 | if (microphone_usage_descriptions.has(lang)) { |
| 1847 | f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1848 | } |
| 1849 | if (camera_usage_descriptions.has(lang)) { |
| 1850 | f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1851 | } |
| 1852 | if (location_usage_descriptions.has(lang)) { |
| 1853 | f->store_line("NSLocationUsageDescription = \"" + location_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1854 | } |
| 1855 | if (address_book_usage_descriptions.has(lang)) { |
| 1856 | f->store_line("NSContactsUsageDescription = \"" + address_book_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1857 | } |
| 1858 | if (calendar_usage_descriptions.has(lang)) { |
| 1859 | f->store_line("NSCalendarsUsageDescription = \"" + calendar_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1860 | } |
| 1861 | if (photos_library_usage_descriptions.has(lang)) { |
| 1862 | f->store_line("NSPhotoLibraryUsageDescription = \"" + photos_library_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1863 | } |
| 1864 | if (desktop_folder_usage_descriptions.has(lang)) { |
| 1865 | f->store_line("NSDesktopFolderUsageDescription = \"" + desktop_folder_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1866 | } |
| 1867 | if (documents_folder_usage_descriptions.has(lang)) { |
| 1868 | f->store_line("NSDocumentsFolderUsageDescription = \"" + documents_folder_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1869 | } |
| 1870 | if (downloads_folder_usage_descriptions.has(lang)) { |
| 1871 | f->store_line("NSDownloadsFolderUsageDescription = \"" + downloads_folder_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1872 | } |
| 1873 | if (network_volumes_usage_descriptions.has(lang)) { |
| 1874 | f->store_line("NSNetworkVolumesUsageDescription = \"" + network_volumes_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1875 | } |
| 1876 | if (removable_volumes_usage_descriptions.has(lang)) { |
| 1877 | f->store_line("NSRemovableVolumesUsageDescription = \"" + removable_volumes_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1878 | } |
| 1879 | if (copyrights.has(lang)) { |
| 1880 | f->store_line("NSHumanReadableCopyright = \"" + copyrights[lang].operator String().xml_escape(true) + "\";"); |
| 1881 | } |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | TranslationServer::get_singleton()->remove_domain(domain_name); |
| 1886 | |
| 1887 | // Now process our template. |
| 1888 | bool found_binary = false; |
| 1889 | |
| 1890 | int export_angle = p_preset->get("application/export_angle"); |
| 1891 | bool include_angle_libs = false; |
| 1892 | if (export_angle == 0) { |
| 1893 | include_angle_libs = String(get_project_setting(p_preset, "rendering/gl_compatibility/driver.macos")) == "opengl3_angle"; |
| 1894 | } else if (export_angle == 1) { |
| 1895 | include_angle_libs = true; |
| 1896 | } |
| 1897 | |
| 1898 | while (ret == UNZ_OK && err == OK) { |
| 1899 | // Get filename. |
| 1900 | unz_file_info info; |
| 1901 | char fname[16384]; |
| 1902 | ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0); |
| 1903 | if (ret != UNZ_OK) { |
| 1904 | break; |
| 1905 | } |
| 1906 | |
| 1907 | String file = String::utf8(fname); |
| 1908 | |
| 1909 | Vector<uint8_t> data; |
| 1910 | data.resize(info.uncompressed_size); |
| 1911 | |
| 1912 | // Read. |
| 1913 | unzOpenCurrentFile(src_pkg_zip); |
| 1914 | unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size()); |
| 1915 | unzCloseCurrentFile(src_pkg_zip); |
| 1916 | |
| 1917 | // Write. |
| 1918 | file = file.replace_first("macos_template.app/", ""); |
| 1919 | |
| 1920 | if (((info.external_fa >> 16L) & 0120000) == 0120000) { |
| 1921 | #ifndef UNIX_ENABLED |
| 1922 | add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Relative symlinks are not supported on this OS, the exported project might be broken!")); |
| 1923 | #endif |
| 1924 | // Handle symlinks in the archive. |
| 1925 | file = tmp_app_path_name.path_join(file); |
| 1926 | if (err == OK) { |
| 1927 | err = tmp_app_dir->make_dir_recursive(file.get_base_dir()); |
| 1928 | if (err != OK) { |
| 1929 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir())); |
| 1930 | } |
| 1931 | } |
| 1932 | if (err == OK) { |
| 1933 | String lnk_data = String::utf8((const char *)data.ptr(), data.size()); |
| 1934 | err = tmp_app_dir->create_link(lnk_data, file); |
| 1935 | if (err != OK) { |
| 1936 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not created symlink \"%s\" -> \"%s\"."), lnk_data, file)); |
| 1937 | } |
| 1938 | print_verbose(vformat("ADDING SYMLINK %s => %s\n", file, lnk_data)); |
| 1939 | } |
| 1940 | |
| 1941 | ret = unzGoToNextFile(src_pkg_zip); |
| 1942 | continue; // next |
| 1943 | } |
| 1944 | |
| 1945 | if (file == "Contents/Frameworks/libEGL.dylib") { |
| 1946 | if (!include_angle_libs) { |
| 1947 | ret = unzGoToNextFile(src_pkg_zip); |
| 1948 | continue; // skip |
| 1949 | } |
| 1950 | } |
| 1951 | |
| 1952 | if (file == "Contents/Frameworks/libGLESv2.dylib") { |
| 1953 | if (!include_angle_libs) { |
| 1954 | ret = unzGoToNextFile(src_pkg_zip); |
| 1955 | continue; // skip |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | if (file == "Contents/Info.plist") { |
| 1960 | bool lg_icon_expored = false; |
| 1961 | String lg_icon = p_preset->get("application/liquid_glass_icon"); |
| 1962 | #ifdef MACOS_ENABLED |
| 1963 | // Export liquid glass. |
| 1964 | if (!lg_icon.is_empty()) { |
| 1965 | lg_icon_expored = (_export_liquid_glass_icon(p_preset, tmp_app_path_name, lg_icon) == OK); |
| 1966 | } |
| 1967 | #endif |
| 1968 | // Modify plist. |
| 1969 | _fix_plist(p_preset, data, pkg_name, lg_icon_expored, lg_icon.get_file().get_basename()); |
| 1970 | } |
| 1971 | |
| 1972 | if (file == "Contents/Resources/PrivacyInfo.xcprivacy") { |
| 1973 | _fix_privacy_manifest(p_preset, data); |
| 1974 | } |
| 1975 | |
| 1976 | if (file.begins_with("Contents/MacOS/godot_")) { |
| 1977 | if (file != "Contents/MacOS/" + binary_to_use) { |
| 1978 | ret = unzGoToNextFile(src_pkg_zip); |
| 1979 | continue; // skip |
| 1980 | } |
| 1981 | found_binary = true; |
| 1982 | file = "Contents/MacOS/" + pkg_name; |
| 1983 | } |
| 1984 | |
| 1985 | if (file == "Contents/Resources/icon.icns") { |
| 1986 | // See if there is an icon. |
| 1987 | String icon_path; |
| 1988 | if (p_preset->get("application/icon") != "") { |
| 1989 | icon_path = p_preset->get("application/icon"); |
| 1990 | } else if (get_project_setting(p_preset, "application/config/macos_native_icon") != "") { |
| 1991 | icon_path = get_project_setting(p_preset, "application/config/macos_native_icon"); |
| 1992 | } else { |
| 1993 | icon_path = get_project_setting(p_preset, "application/config/icon"); |
| 1994 | } |
| 1995 | |
| 1996 | if (!icon_path.is_empty()) { |
| 1997 | if (icon_path.get_extension() == "icns") { |
| 1998 | Ref<FileAccess> icon = FileAccess::open(icon_path, FileAccess::READ); |
| 1999 | if (icon.is_valid()) { |
| 2000 | data.resize(icon->get_length()); |
| 2001 | icon->get_buffer(&data.write[0], icon->get_length()); |
| 2002 | } |
| 2003 | } else { |
| 2004 | Ref<Image> icon = _load_icon_or_splash_image(icon_path, &err); |
| 2005 | if (err == OK && icon.is_valid() && !icon->is_empty()) { |
| 2006 | _make_icon(p_preset, icon, data); |
| 2007 | } |
| 2008 | } |
| 2009 | } |
| 2010 | } |
| 2011 | |
| 2012 | if (data.size() > 0) { |
| 2013 | print_verbose("ADDING: " + file + " size: " + itos(data.size())); |
| 2014 | |
| 2015 | // Write it into our application bundle. |
| 2016 | file = tmp_app_path_name.path_join(file); |
| 2017 | if (err == OK) { |
| 2018 | err = tmp_app_dir->make_dir_recursive(file.get_base_dir()); |
| 2019 | if (err != OK) { |
| 2020 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir())); |
| 2021 | } |
| 2022 | } |
| 2023 | if (err == OK) { |
| 2024 | Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE); |
| 2025 | if (f.is_valid()) { |
| 2026 | f->store_buffer(data.ptr(), data.size()); |
| 2027 | f.unref(); |
| 2028 | if (is_executable(file)) { |
| 2029 | // chmod with 0755 if the file is executable. |
| 2030 | FileAccess::set_unix_permissions(file, 0755); |
| 2031 | #ifndef UNIX_ENABLED |
| 2032 | if (export_format == "app") { |
| 2033 | add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Unable to set Unix permissions for executable \"%s\". Use \"chmod +x\" to set it after transferring the exported .app to macOS or Linux."), "Contents/MacOS/" + file.get_file())); |
| 2034 | } |
| 2035 | #endif |
| 2036 | } |
| 2037 | } else { |
| 2038 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not open \"%s\"."), file)); |
| 2039 | err = ERR_CANT_CREATE; |
| 2040 | } |
| 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | ret = unzGoToNextFile(src_pkg_zip); |
| 2045 | } |
| 2046 | |
| 2047 | // We're done with our source zip. |
| 2048 | unzClose(src_pkg_zip); |
| 2049 | |
| 2050 | if (!found_binary) { |
| 2051 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Requested template binary \"%s\" not found. It might be missing from your template archive."), binary_to_use)); |
| 2052 | err = ERR_FILE_NOT_FOUND; |
| 2053 | } |
| 2054 | |
| 2055 | // Save console wrapper. |
| 2056 | if (err == OK) { |
| 2057 | int con_scr = p_preset->get("debug/export_console_wrapper"); |
| 2058 | if ((con_scr == 1 && p_debug) || (con_scr == 2)) { |
| 2059 | err = _export_debug_script(p_preset, pkg_name, tmp_app_path_name.get_file() + "/Contents/MacOS/" + pkg_name, scr_path); |
| 2060 | FileAccess::set_unix_permissions(scr_path, 0755); |
| 2061 | #ifndef UNIX_ENABLED |
| 2062 | if (export_format == "app") { |
| 2063 | add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Unable to set Unix permissions for executable \"%s\". Use \"chmod +x\" to set it after transferring the exported .app to macOS or Linux."), scr_path.get_file())); |
| 2064 | } |
| 2065 | #endif |
| 2066 | if (err != OK) { |
| 2067 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not create console wrapper.")); |
| 2068 | } |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | if (err == OK) { |
| 2073 | if (ep.step(TTR("Making PKG"), 1)) { |
| 2074 | return ERR_SKIP; |
| 2075 | } |
| 2076 | |
| 2077 | // See if we can code sign our new package. |
| 2078 | bool sign_enabled = (p_preset->get("codesign/codesign").operator int() > 0); |
| 2079 | bool ad_hoc = false; |
| 2080 | int codesign_tool = p_preset->get("codesign/codesign"); |
| 2081 | switch (codesign_tool) { |
| 2082 | case 1: { // built-in ad-hoc |
| 2083 | ad_hoc = true; |
| 2084 | } break; |
| 2085 | case 2: { // "rcodesign" |
| 2086 | ad_hoc = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty() || p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS).operator String().is_empty(); |
| 2087 | } break; |
| 2088 | #ifdef MACOS_ENABLED |
| 2089 | case 3: { // "codesign" |
| 2090 | ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-"); |
| 2091 | } break; |
| 2092 | #endif |
| 2093 | default: { |
| 2094 | }; |
| 2095 | } |
| 2096 | |
| 2097 | String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck"; |
| 2098 | Vector<SharedObject> shared_objects; |
| 2099 | err = save_pack(p_preset, p_debug, pack_path, &shared_objects); |
| 2100 | |
| 2101 | bool lib_validation = p_preset->get("codesign/entitlements/disable_library_validation"); |
| 2102 | if (!shared_objects.is_empty() && sign_enabled && ad_hoc && !lib_validation) { |
| 2103 | add_message(EXPORT_MESSAGE_INFO, TTR("Entitlements Modified"), TTR("Ad-hoc signed applications require the 'Disable Library Validation' entitlement to load dynamic libraries.")); |
| 2104 | lib_validation = true; |
| 2105 | } |
| 2106 | |
| 2107 | if (!shared_objects.is_empty() && sign_enabled && codesign_tool == 2) { |
| 2108 | add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("'rcodesign' doesn't support signing applications with embedded dynamic libraries.")); |
| 2109 | } |
| 2110 | |
| 2111 | bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled"); |
| 2112 | String ent_path = p_preset->get("codesign/entitlements/custom_file"); |
| 2113 | String hlp_ent_path = sandbox ? EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + "_helper.entitlements") : ent_path; |
| 2114 | if (sign_enabled && (ent_path.is_empty())) { |
| 2115 | ent_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".entitlements"); |
| 2116 | |
| 2117 | Ref<FileAccess> ent_f = FileAccess::open(ent_path, FileAccess::WRITE); |
| 2118 | if (ent_f.is_valid()) { |
| 2119 | ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
| 2120 | ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"); |
| 2121 | ent_f->store_line("<plist version=\"1.0\">"); |
| 2122 | ent_f->store_line("<dict>"); |
| 2123 | if (ClassDB::class_exists("CSharpScript")) { |
| 2124 | // These entitlements are required to run managed code, and are always enabled in Mono builds. |
| 2125 | ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>"); |
| 2126 | ent_f->store_line("<true/>"); |
| 2127 | ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>"); |
| 2128 | ent_f->store_line("<true/>"); |
| 2129 | ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>"); |
| 2130 | ent_f->store_line("<true/>"); |
| 2131 | } else { |
| 2132 | if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) { |
| 2133 | ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>"); |
| 2134 | ent_f->store_line("<true/>"); |
| 2135 | } |
| 2136 | if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) { |
| 2137 | ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>"); |
| 2138 | ent_f->store_line("<true/>"); |
| 2139 | } |
| 2140 | if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) { |
| 2141 | ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>"); |
| 2142 | ent_f->store_line("<true/>"); |
| 2143 | } |
| 2144 | } |
| 2145 | |
| 2146 | if (lib_validation) { |
| 2147 | ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>"); |
| 2148 | ent_f->store_line("<true/>"); |
| 2149 | } |
| 2150 | if ((bool)p_preset->get("codesign/entitlements/audio_input")) { |
| 2151 | ent_f->store_line("<key>com.apple.security.device.audio-input</key>"); |
| 2152 | ent_f->store_line("<true/>"); |
| 2153 | } |
| 2154 | if ((bool)p_preset->get("codesign/entitlements/camera")) { |
| 2155 | ent_f->store_line("<key>com.apple.security.device.camera</key>"); |
| 2156 | ent_f->store_line("<true/>"); |
| 2157 | } |
| 2158 | if ((bool)p_preset->get("codesign/entitlements/location")) { |
| 2159 | ent_f->store_line("<key>com.apple.security.personal-information.location</key>"); |
| 2160 | ent_f->store_line("<true/>"); |
| 2161 | } |
| 2162 | if ((bool)p_preset->get("codesign/entitlements/address_book")) { |
| 2163 | ent_f->store_line("<key>com.apple.security.personal-information.addressbook</key>"); |
| 2164 | ent_f->store_line("<true/>"); |
| 2165 | } |
| 2166 | if ((bool)p_preset->get("codesign/entitlements/calendars")) { |
| 2167 | ent_f->store_line("<key>com.apple.security.personal-information.calendars</key>"); |
| 2168 | ent_f->store_line("<true/>"); |
| 2169 | } |
| 2170 | if ((bool)p_preset->get("codesign/entitlements/photos_library")) { |
| 2171 | ent_f->store_line("<key>com.apple.security.personal-information.photos-library</key>"); |
| 2172 | ent_f->store_line("<true/>"); |
| 2173 | } |
| 2174 | if ((bool)p_preset->get("codesign/entitlements/apple_events")) { |
| 2175 | ent_f->store_line("<key>com.apple.security.automation.apple-events</key>"); |
| 2176 | ent_f->store_line("<true/>"); |
| 2177 | } |
| 2178 | if ((bool)p_preset->get("codesign/entitlements/debugging")) { |
| 2179 | ent_f->store_line("<key>com.apple.security.get-task-allow</key>"); |
| 2180 | ent_f->store_line("<true/>"); |
| 2181 | } |
| 2182 | |
| 2183 | int dist_type = p_preset->get("export/distribution_type"); |
| 2184 | if (dist_type == 2) { |
| 2185 | String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE); |
| 2186 | String teamid = p_preset->get("codesign/apple_team_id"); |
| 2187 | String bid = p_preset->get("application/bundle_identifier"); |
| 2188 | if (!pprof.is_empty() && !teamid.is_empty()) { |
| 2189 | ent_f->store_line("<key>com.apple.developer.team-identifier</key>"); |
| 2190 | ent_f->store_line("<string>" + teamid + "</string>"); |
| 2191 | ent_f->store_line("<key>com.apple.application-identifier</key>"); |
| 2192 | ent_f->store_line("<string>" + teamid + "." + bid + "</string>"); |
| 2193 | } |
| 2194 | } |
| 2195 | |
| 2196 | if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) { |
| 2197 | ent_f->store_line("<key>com.apple.security.app-sandbox</key>"); |
| 2198 | ent_f->store_line("<true/>"); |
| 2199 | |
| 2200 | if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) { |
| 2201 | ent_f->store_line("<key>com.apple.security.network.server</key>"); |
| 2202 | ent_f->store_line("<true/>"); |
| 2203 | } |
| 2204 | if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) { |
| 2205 | ent_f->store_line("<key>com.apple.security.network.client</key>"); |
| 2206 | ent_f->store_line("<true/>"); |
| 2207 | } |
| 2208 | if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) { |
| 2209 | ent_f->store_line("<key>com.apple.security.device.usb</key>"); |
| 2210 | ent_f->store_line("<true/>"); |
| 2211 | } |
| 2212 | if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) { |
| 2213 | ent_f->store_line("<key>com.apple.security.device.bluetooth</key>"); |
| 2214 | ent_f->store_line("<true/>"); |
| 2215 | } |
| 2216 | if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) { |
| 2217 | ent_f->store_line("<key>com.apple.security.files.downloads.read-only</key>"); |
| 2218 | ent_f->store_line("<true/>"); |
| 2219 | } |
| 2220 | if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) { |
| 2221 | ent_f->store_line("<key>com.apple.security.files.downloads.read-write</key>"); |
| 2222 | ent_f->store_line("<true/>"); |
| 2223 | } |
| 2224 | if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) { |
| 2225 | ent_f->store_line("<key>com.apple.security.files.pictures.read-only</key>"); |
| 2226 | ent_f->store_line("<true/>"); |
| 2227 | } |
| 2228 | if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) { |
| 2229 | ent_f->store_line("<key>com.apple.security.files.pictures.read-write</key>"); |
| 2230 | ent_f->store_line("<true/>"); |
| 2231 | } |
| 2232 | if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) { |
| 2233 | ent_f->store_line("<key>com.apple.security.files.music.read-only</key>"); |
| 2234 | ent_f->store_line("<true/>"); |
| 2235 | } |
| 2236 | if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) { |
| 2237 | ent_f->store_line("<key>com.apple.security.files.music.read-write</key>"); |
| 2238 | ent_f->store_line("<true/>"); |
| 2239 | } |
| 2240 | if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) { |
| 2241 | ent_f->store_line("<key>com.apple.security.files.movies.read-only</key>"); |
| 2242 | ent_f->store_line("<true/>"); |
| 2243 | } |
| 2244 | if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) { |
| 2245 | ent_f->store_line("<key>com.apple.security.files.movies.read-write</key>"); |
| 2246 | ent_f->store_line("<true/>"); |
| 2247 | } |
| 2248 | if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 1) { |
| 2249 | ent_f->store_line("<key>com.apple.security.files.user-selected.read-only</key>"); |
| 2250 | ent_f->store_line("<true/>"); |
| 2251 | } |
| 2252 | if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 2) { |
| 2253 | ent_f->store_line("<key>com.apple.security.files.user-selected.read-write</key>"); |
| 2254 | ent_f->store_line("<true/>"); |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | const String &additional_entitlements = p_preset->get("codesign/entitlements/additional"); |
| 2259 | if (!additional_entitlements.is_empty()) { |
| 2260 | ent_f->store_line(additional_entitlements); |
| 2261 | } |
| 2262 | |
| 2263 | ent_f->store_line("</dict>"); |
| 2264 | ent_f->store_line("</plist>"); |
| 2265 | } else { |
| 2266 | add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create entitlements file.")); |
| 2267 | err = ERR_CANT_CREATE; |
| 2268 | } |
| 2269 | |
| 2270 | if ((err == OK) && sandbox && (helpers.size() > 0 || shared_objects.size() > 0)) { |
| 2271 | ent_f = FileAccess::open(hlp_ent_path, FileAccess::WRITE); |
| 2272 | if (ent_f.is_valid()) { |
| 2273 | ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
| 2274 | ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"); |
| 2275 | ent_f->store_line("<plist version=\"1.0\">"); |
| 2276 | ent_f->store_line("<dict>"); |
| 2277 | ent_f->store_line("<key>com.apple.security.app-sandbox</key>"); |
| 2278 | ent_f->store_line("<true/>"); |
| 2279 | ent_f->store_line("<key>com.apple.security.inherit</key>"); |
| 2280 | ent_f->store_line("<true/>"); |
| 2281 | ent_f->store_line("</dict>"); |
| 2282 | ent_f->store_line("</plist>"); |
| 2283 | } else { |
| 2284 | add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create helper entitlements file.")); |
| 2285 | err = ERR_CANT_CREATE; |
| 2286 | } |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | if ((err == OK) && helpers.size() > 0) { |
| 2291 | Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 2292 | for (int i = 0; i < helpers.size(); i++) { |
| 2293 | String hlp_path = helpers[i]; |
| 2294 | err = da->copy(hlp_path, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file()); |
| 2295 | if (err == OK && sign_enabled) { |
| 2296 | _code_sign(p_preset, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), hlp_ent_path, false, true); |
| 2297 | } |
| 2298 | FileAccess::set_unix_permissions(tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), 0755); |
| 2299 | #ifndef UNIX_ENABLED |
| 2300 | if (export_format == "app") { |
| 2301 | add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Unable to set Unix permissions for executable \"%s\". Use \"chmod +x\" to set it after transferring the exported .app to macOS or Linux."), "Contents/Helpers/" + hlp_path.get_file())); |
| 2302 | } |
| 2303 | #endif |
| 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | if (err == OK) { |
| 2308 | Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 2309 | for (int i = 0; i < shared_objects.size(); i++) { |
| 2310 | String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path); |
| 2311 | if (shared_objects[i].target.is_empty()) { |
| 2312 | String path_in_app = tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file(); |
| 2313 | err = _copy_and_sign_files(da, src_path, path_in_app, sign_enabled, p_preset, ent_path, hlp_ent_path, true, sandbox); |
| 2314 | } else { |
| 2315 | String path_in_app = tmp_app_path_name.path_join(shared_objects[i].target); |
| 2316 | tmp_app_dir->make_dir_recursive(path_in_app); |
| 2317 | err = _copy_and_sign_files(da, src_path, path_in_app.path_join(src_path.get_file()), sign_enabled, p_preset, ent_path, hlp_ent_path, false, sandbox); |
| 2318 | } |
| 2319 | if (err != OK) { |
| 2320 | break; |
| 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | Vector<Ref<EditorExportPlugin>> export_plugins{ EditorExport::get_singleton()->get_export_plugins() }; |
| 2325 | for (int i = 0; i < export_plugins.size(); ++i) { |
| 2326 | err = _export_macos_plugins_for(export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path, hlp_ent_path, sandbox); |
| 2327 | if (err != OK) { |
| 2328 | break; |
| 2329 | } |
| 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | if (err == OK && sign_enabled) { |
| 2334 | int dist_type = p_preset->get("export/distribution_type"); |
| 2335 | if (dist_type == 2) { |
| 2336 | String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE).operator String(); |
| 2337 | if (!pprof.is_empty()) { |
| 2338 | Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 2339 | err = da->copy(pprof, tmp_app_path_name + "/Contents/embedded.provisionprofile"); |
| 2340 | } |
| 2341 | } |
| 2342 | |
| 2343 | if (ep.step(TTR("Code signing bundle"), 2)) { |
| 2344 | return ERR_SKIP; |
| 2345 | } |
| 2346 | _code_sign(p_preset, tmp_app_path_name, ent_path, true, false); |
| 2347 | } |
| 2348 | |
| 2349 | String noto_path = p_path; |
| 2350 | bool noto_enabled = (p_preset->get("notarization/notarization").operator int() > 0); |
| 2351 | if (export_format == "dmg") { |
| 2352 | // Create a DMG. |
| 2353 | if (err == OK) { |
| 2354 | if (ep.step(TTR("Making DMG"), 3)) { |
| 2355 | return ERR_SKIP; |
| 2356 | } |
| 2357 | err = _create_dmg(p_path, pkg_name, tmp_base_path_name); |
| 2358 | } |
| 2359 | // Sign DMG. |
| 2360 | if (err == OK && sign_enabled && !ad_hoc) { |
| 2361 | if (ep.step(TTR("Code signing DMG"), 3)) { |
| 2362 | return ERR_SKIP; |
| 2363 | } |
| 2364 | _code_sign(p_preset, p_path, ent_path, false, false); |
| 2365 | } |
| 2366 | } else if (export_format == "pkg") { |
| 2367 | // Create a Installer. |
| 2368 | if (err == OK) { |
| 2369 | if (ep.step(TTR("Making PKG installer"), 3)) { |
| 2370 | return ERR_SKIP; |
| 2371 | } |
| 2372 | err = _create_pkg(p_preset, p_path, tmp_app_path_name); |
| 2373 | } |
| 2374 | } else if (export_format == "zip") { |
| 2375 | // Create ZIP. |
| 2376 | if (err == OK) { |
| 2377 | if (ep.step(TTR("Making ZIP"), 3)) { |
| 2378 | return ERR_SKIP; |
| 2379 | } |
| 2380 | if (FileAccess::exists(p_path)) { |
| 2381 | OS::get_singleton()->move_to_trash(p_path); |
| 2382 | } |
| 2383 | |
| 2384 | Ref<FileAccess> io_fa_dst; |
| 2385 | zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst); |
| 2386 | zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst); |
| 2387 | |
| 2388 | zip_folder_recursive(zip, tmp_base_path_name, "", pkg_name); |
| 2389 | |
| 2390 | zipClose(zip, nullptr); |
| 2391 | } |
| 2392 | } else if (export_format == "app" && noto_enabled) { |
| 2393 | // Create temporary ZIP. |
| 2394 | if (err == OK) { |
| 2395 | noto_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".zip"); |
| 2396 | |
| 2397 | if (ep.step(TTR("Making ZIP"), 3)) { |
| 2398 | return ERR_SKIP; |
| 2399 | } |
| 2400 | if (FileAccess::exists(noto_path)) { |
| 2401 | OS::get_singleton()->move_to_trash(noto_path); |
| 2402 | } |
| 2403 | |
| 2404 | Ref<FileAccess> io_fa_dst; |
| 2405 | zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst); |
| 2406 | zipFile zip = zipOpen2(noto_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst); |
| 2407 | |
| 2408 | zip_folder_recursive(zip, tmp_base_path_name, tmp_app_dir_name, pkg_name); |
| 2409 | |
| 2410 | zipClose(zip, nullptr); |
| 2411 | } |
| 2412 | } |
| 2413 | |
| 2414 | if (err == OK && noto_enabled) { |
| 2415 | if (export_format == "pkg") { |
| 2416 | add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("Notarization requires the app to be archived first, select the DMG or ZIP export format instead.")); |
| 2417 | } else { |
| 2418 | if (ep.step(TTR("Sending archive for notarization"), 4)) { |
| 2419 | return ERR_SKIP; |
| 2420 | } |
| 2421 | err = _notarize(p_preset, noto_path); |
| 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | if (FileAccess::exists(ent_path)) { |
| 2426 | print_verbose("entitlements:\n" + FileAccess::get_file_as_string(ent_path)); |
| 2427 | } |
| 2428 | |
| 2429 | if (FileAccess::exists(hlp_ent_path)) { |
| 2430 | print_verbose("helper entitlements:\n" + FileAccess::get_file_as_string(hlp_ent_path)); |
| 2431 | } |
| 2432 | |
| 2433 | // Clean up temporary entitlements files. |
| 2434 | if (FileAccess::exists(hlp_ent_path)) { |
| 2435 | DirAccess::remove_file_or_error(hlp_ent_path); |
| 2436 | } |
| 2437 | |
| 2438 | // Clean up temporary .app dir and generated entitlements. |
| 2439 | if ((String)(p_preset->get("codesign/entitlements/custom_file")) == "") { |
| 2440 | tmp_app_dir->remove(ent_path); |
| 2441 | } |
| 2442 | if (export_format != "app") { |
| 2443 | if (tmp_app_dir->change_dir(tmp_base_path_name) == OK) { |
| 2444 | tmp_app_dir->erase_contents_recursive(); |
| 2445 | tmp_app_dir->change_dir(".."); |
| 2446 | tmp_app_dir->remove(pkg_name); |
| 2447 | } |
| 2448 | } else if (noto_path != p_path) { |
| 2449 | if (FileAccess::exists(noto_path)) { |
| 2450 | DirAccess::remove_file_or_error(noto_path); |
| 2451 | } |
| 2452 | } |
| 2453 | } |
| 2454 | |
| 2455 | return err; |
| 2456 | } |
| 2457 | |
| 2458 | bool EditorExportPlatformMacOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const { |
| 2459 | String err; |
| 2460 | // Look for export templates (official templates first, then custom). |
| 2461 | bool dvalid = exists_export_template("macos.zip", &err); |
| 2462 | bool rvalid = dvalid; // Both in the same ZIP. |
| 2463 | |
| 2464 | if (p_preset->get("custom_template/debug") != "") { |
| 2465 | dvalid = FileAccess::exists(p_preset->get("custom_template/debug")); |
| 2466 | if (!dvalid) { |
| 2467 | err += TTR("Custom debug template not found.") + "\n"; |
| 2468 | } |
| 2469 | } |
| 2470 | if (p_preset->get("custom_template/release") != "") { |
| 2471 | rvalid = FileAccess::exists(p_preset->get("custom_template/release")); |
| 2472 | if (!rvalid) { |
| 2473 | err += TTR("Custom release template not found.") + "\n"; |
| 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | bool valid = dvalid || rvalid; |
| 2478 | r_missing_templates = !valid; |
| 2479 | |
| 2480 | // Check the texture formats, which vary depending on the target architecture. |
| 2481 | String architecture = p_preset->get("binary_format/architecture"); |
| 2482 | if (architecture == "universal" || architecture == "x86_64") { |
| 2483 | if (!ResourceImporterTextureSettings::should_import_s3tc_bptc()) { |
| 2484 | err += TTR("Cannot export for universal or x86_64 if S3TC BPTC texture format is disabled. Enable it in the Project Settings (Rendering > Textures > VRAM Compression > Import S3TC BPTC).") + "\n"; |
| 2485 | valid = false; |
| 2486 | } |
| 2487 | } |
| 2488 | if (architecture == "universal" || architecture == "arm64") { |
| 2489 | if (!ResourceImporterTextureSettings::should_import_etc2_astc()) { |
| 2490 | err += TTR("Cannot export for universal or arm64 if ETC2 ASTC texture format is disabled. Enable it in the Project Settings (Rendering > Textures > VRAM Compression > Import ETC2 ASTC).") + "\n"; |
| 2491 | valid = false; |
| 2492 | } |
| 2493 | } |
| 2494 | if (architecture != "universal" && architecture != "x86_64" && architecture != "arm64") { |
| 2495 | ERR_PRINT("Invalid architecture"); |
| 2496 | } |
| 2497 | |
| 2498 | if (!err.is_empty()) { |
| 2499 | r_error = err; |
| 2500 | } |
| 2501 | return valid; |
| 2502 | } |
| 2503 | |
| 2504 | bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const { |
| 2505 | String err; |
| 2506 | bool valid = true; |
| 2507 | |
| 2508 | int dist_type = p_preset->get("export/distribution_type"); |
| 2509 | bool ad_hoc = false; |
| 2510 | int codesign_tool = p_preset->get("codesign/codesign"); |
| 2511 | int notary_tool = p_preset->get("notarization/notarization"); |
| 2512 | switch (codesign_tool) { |
| 2513 | case 1: { // built-in ad-hoc |
| 2514 | ad_hoc = true; |
| 2515 | } break; |
| 2516 | case 2: { // "rcodesign" |
| 2517 | ad_hoc = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty() || p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS).operator String().is_empty(); |
| 2518 | } break; |
| 2519 | #ifdef MACOS_ENABLED |
| 2520 | case 3: { // "codesign" |
| 2521 | ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-"); |
| 2522 | } break; |
| 2523 | #endif |
| 2524 | default: { |
| 2525 | }; |
| 2526 | } |
| 2527 | |
| 2528 | const String &additional_plist_content = p_preset->get("application/additional_plist_content"); |
| 2529 | if (!additional_plist_content.is_empty()) { |
| 2530 | const String &plist = vformat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 2531 | "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" |
| 2532 | "<plist version=\"1.0\">" |
| 2533 | "<dict>\n" |
| 2534 | "%s\n" |
| 2535 | "</dict>\n" |
| 2536 | "</plist>\n", |
| 2537 | additional_plist_content); |
| 2538 | |
| 2539 | String plist_err; |
| 2540 | Ref<PList> plist_parser; |
| 2541 | plist_parser.instantiate(); |
| 2542 | if (!plist_parser->load_string(plist, plist_err)) { |
| 2543 | err += TTR("Invalid additional PList content: ") + plist_err + "\n"; |
| 2544 | valid = false; |
| 2545 | } |
| 2546 | } |
| 2547 | |
| 2548 | List<ExportOption> options; |
| 2549 | get_export_options(&options); |
| 2550 | for (const EditorExportPlatform::ExportOption &E : options) { |
| 2551 | if (get_export_option_visibility(p_preset.ptr(), E.option.name)) { |
| 2552 | String warn = get_export_option_warning(p_preset.ptr(), E.option.name); |
| 2553 | if (!warn.is_empty()) { |
| 2554 | err += warn + "\n"; |
| 2555 | if (E.required) { |
| 2556 | valid = false; |
| 2557 | } |
| 2558 | } |
| 2559 | } |
| 2560 | } |
| 2561 | |
| 2562 | if (dist_type != 2) { |
| 2563 | if (notary_tool > 0) { |
| 2564 | if (notary_tool == 2 || notary_tool == 3) { |
| 2565 | if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) { |
| 2566 | err += TTR("Notarization: Xcode command line tools are not installed.") + "\n"; |
| 2567 | valid = false; |
| 2568 | } |
| 2569 | } else if (notary_tool == 1) { |
| 2570 | String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String(); |
| 2571 | if (rcodesign.is_empty()) { |
| 2572 | err += TTR("Notarization: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n"; |
| 2573 | valid = false; |
| 2574 | } |
| 2575 | } |
| 2576 | } else { |
| 2577 | err += TTR("Warning: Notarization is disabled. The exported project will be blocked by Gatekeeper if it's downloaded from an unknown source.") + "\n"; |
| 2578 | if (codesign_tool == 0) { |
| 2579 | err += TTR("Code signing is disabled. The exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n"; |
| 2580 | } |
| 2581 | } |
| 2582 | } |
| 2583 | |
| 2584 | if (codesign_tool > 0) { |
| 2585 | if (ad_hoc) { |
| 2586 | err += TTR("Code signing: Using ad-hoc signature. The exported project will be blocked by Gatekeeper") + "\n"; |
| 2587 | } |
| 2588 | if (codesign_tool == 3) { |
| 2589 | if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) { |
| 2590 | err += TTR("Code signing: Xcode command line tools are not installed.") + "\n"; |
| 2591 | valid = false; |
| 2592 | } |
| 2593 | } else if (codesign_tool == 2) { |
| 2594 | String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String(); |
| 2595 | if (rcodesign.is_empty()) { |
| 2596 | err += TTR("Code signing: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n"; |
| 2597 | valid = false; |
| 2598 | } |
| 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | if (!err.is_empty()) { |
| 2603 | r_error = err; |
| 2604 | } |
| 2605 | return valid; |
| 2606 | } |
| 2607 | |
| 2608 | Ref<Texture2D> EditorExportPlatformMacOS::get_run_icon() const { |
| 2609 | return run_icon; |
| 2610 | } |
| 2611 | |
| 2612 | bool EditorExportPlatformMacOS::poll_export() { |
| 2613 | Ref<EditorExportPreset> preset; |
| 2614 | |
| 2615 | for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { |
| 2616 | Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i); |
| 2617 | if (ep->is_runnable() && ep->get_platform() == this) { |
| 2618 | preset = ep; |
| 2619 | break; |
| 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | int prev = menu_options; |
| 2624 | menu_options = (preset.is_valid() && preset->get("ssh_remote_deploy/enabled").operator bool()); |
| 2625 | if (ssh_pid != 0 || !cleanup_commands.is_empty()) { |
| 2626 | if (menu_options == 0) { |
| 2627 | cleanup(); |
| 2628 | } else { |
| 2629 | menu_options += 1; |
| 2630 | } |
| 2631 | } |
| 2632 | return menu_options != prev; |
| 2633 | } |
| 2634 | |
| 2635 | Ref<Texture2D> EditorExportPlatformMacOS::get_option_icon(int p_index) const { |
| 2636 | if (p_index == 1) { |
| 2637 | return stop_icon; |
| 2638 | } else { |
| 2639 | return EditorExportPlatform::get_option_icon(p_index); |
| 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | int EditorExportPlatformMacOS::get_options_count() const { |
| 2644 | return menu_options; |
| 2645 | } |
| 2646 | |
| 2647 | String EditorExportPlatformMacOS::get_option_label(int p_index) const { |
| 2648 | return (p_index) ? TTR("Stop and uninstall") : TTR("Run on remote macOS system"); |
| 2649 | } |
| 2650 | |
| 2651 | String EditorExportPlatformMacOS::get_option_tooltip(int p_index) const { |
| 2652 | return (p_index) ? TTR("Stop and uninstall running project from the remote system") : TTR("Run exported project on remote macOS system"); |
| 2653 | } |
| 2654 | |
| 2655 | void EditorExportPlatformMacOS::cleanup() { |
| 2656 | if (ssh_pid != 0 && OS::get_singleton()->is_process_running(ssh_pid)) { |
| 2657 | print_line("Terminating connection..."); |
| 2658 | OS::get_singleton()->kill(ssh_pid); |
| 2659 | OS::get_singleton()->delay_usec(1000); |
| 2660 | } |
| 2661 | |
| 2662 | if (!cleanup_commands.is_empty()) { |
| 2663 | print_line("Stopping and deleting previous version..."); |
| 2664 | for (const SSHCleanupCommand &cmd : cleanup_commands) { |
| 2665 | if (cmd.wait) { |
| 2666 | ssh_run_on_remote(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args); |
| 2667 | } else { |
| 2668 | ssh_run_on_remote_no_wait(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args); |
| 2669 | } |
| 2670 | } |
| 2671 | } |
| 2672 | ssh_pid = 0; |
| 2673 | cleanup_commands.clear(); |
| 2674 | } |
| 2675 | |
| 2676 | Error EditorExportPlatformMacOS::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) { |
| 2677 | cleanup(); |
| 2678 | if (p_device) { // Stop command, cleanup only. |
| 2679 | return OK; |
| 2680 | } |
| 2681 | |
| 2682 | EditorProgress ep("run", TTR("Running..."), 5); |
| 2683 | |
| 2684 | const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("macos"); |
| 2685 | Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 2686 | if (!da->dir_exists(dest)) { |
| 2687 | Error err = da->make_dir_recursive(dest); |
| 2688 | if (err != OK) { |
| 2689 | EditorNode::get_singleton()->show_warning(TTR("Could not create temp directory:") + "\n" + dest); |
| 2690 | return err; |
| 2691 | } |
| 2692 | } |
| 2693 | |
| 2694 | String pkg_name; |
| 2695 | if (String(get_project_setting(p_preset, "application/config/name")) != "") { |
| 2696 | pkg_name = String(get_project_setting(p_preset, "application/config/name")); |
| 2697 | } else { |
| 2698 | pkg_name = "Unnamed"; |
| 2699 | } |
| 2700 | pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name); |
| 2701 | |
| 2702 | String host = p_preset->get("ssh_remote_deploy/host").operator String(); |
| 2703 | String port = p_preset->get("ssh_remote_deploy/port").operator String(); |
| 2704 | if (port.is_empty()) { |
| 2705 | port = "22"; |
| 2706 | } |
| 2707 | Vector<String> extra_args_ssh = p_preset->get("ssh_remote_deploy/extra_args_ssh").operator String().split(" ", false); |
| 2708 | Vector<String> extra_args_scp = p_preset->get("ssh_remote_deploy/extra_args_scp").operator String().split(" ", false); |
| 2709 | |
| 2710 | const String basepath = dest.path_join("tmp_macos_export"); |
| 2711 | |
| 2712 | #define CLEANUP_AND_RETURN(m_err) \ |
| 2713 | { \ |
| 2714 | if (da->file_exists(basepath + ".zip")) { \ |
| 2715 | da->remove(basepath + ".zip"); \ |
| 2716 | } \ |
| 2717 | if (da->file_exists(basepath + "_start.sh")) { \ |
| 2718 | da->remove(basepath + "_start.sh"); \ |
| 2719 | } \ |
| 2720 | if (da->file_exists(basepath + "_clean.sh")) { \ |
| 2721 | da->remove(basepath + "_clean.sh"); \ |
| 2722 | } \ |
| 2723 | return m_err; \ |
| 2724 | } \ |
| 2725 | ((void)0) |
| 2726 | |
| 2727 | if (ep.step(TTR("Exporting project..."), 1)) { |
| 2728 | return ERR_SKIP; |
| 2729 | } |
| 2730 | Error err = export_project(p_preset, true, basepath + ".zip", p_debug_flags); |
| 2731 | if (err != OK) { |
| 2732 | DirAccess::remove_file_or_error(basepath + ".zip"); |
| 2733 | return err; |
| 2734 | } |
| 2735 | |
| 2736 | String cmd_args; |
| 2737 | { |
| 2738 | Vector<String> cmd_args_list = gen_export_flags(p_debug_flags); |
| 2739 | for (int i = 0; i < cmd_args_list.size(); i++) { |
| 2740 | if (i != 0) { |
| 2741 | cmd_args += " "; |
| 2742 | } |
| 2743 | cmd_args += cmd_args_list[i]; |
| 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | const bool use_remote = p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG) || p_debug_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT); |
| 2748 | int dbg_port = EDITOR_GET("network/debug/remote_port"); |
| 2749 | |
| 2750 | print_line("Creating temporary directory..."); |
| 2751 | ep.step(TTR("Creating temporary directory..."), 2); |
| 2752 | String temp_dir; |
| 2753 | err = ssh_run_on_remote(host, port, extra_args_ssh, "mktemp -d", &temp_dir); |
| 2754 | if (err != OK || temp_dir.is_empty()) { |
| 2755 | CLEANUP_AND_RETURN(err); |
| 2756 | } |
| 2757 | |
| 2758 | print_line("Uploading archive..."); |
| 2759 | ep.step(TTR("Uploading archive..."), 3); |
| 2760 | err = ssh_push_to_remote(host, port, extra_args_scp, basepath + ".zip", temp_dir); |
| 2761 | if (err != OK) { |
| 2762 | CLEANUP_AND_RETURN(err); |
| 2763 | } |
| 2764 | |
| 2765 | { |
| 2766 | String run_script = p_preset->get("ssh_remote_deploy/run_script"); |
| 2767 | run_script = run_script.replace("{temp_dir}", temp_dir); |
| 2768 | run_script = run_script.replace("{archive_name}", basepath.get_file() + ".zip"); |
| 2769 | run_script = run_script.replace("{exe_name}", pkg_name); |
| 2770 | run_script = run_script.replace("{cmd_args}", cmd_args); |
| 2771 | |
| 2772 | Ref<FileAccess> f = FileAccess::open(basepath + "_start.sh", FileAccess::WRITE); |
| 2773 | if (f.is_null()) { |
| 2774 | CLEANUP_AND_RETURN(err); |
| 2775 | } |
| 2776 | |
| 2777 | f->store_string(run_script); |
| 2778 | } |
| 2779 | |
| 2780 | { |
| 2781 | String clean_script = p_preset->get("ssh_remote_deploy/cleanup_script"); |
| 2782 | clean_script = clean_script.replace("{temp_dir}", temp_dir); |
| 2783 | clean_script = clean_script.replace("{archive_name}", basepath.get_file() + ".zip"); |
| 2784 | clean_script = clean_script.replace("{exe_name}", pkg_name); |
| 2785 | clean_script = clean_script.replace("{cmd_args}", cmd_args); |
| 2786 | |
| 2787 | Ref<FileAccess> f = FileAccess::open(basepath + "_clean.sh", FileAccess::WRITE); |
| 2788 | if (f.is_null()) { |
| 2789 | CLEANUP_AND_RETURN(err); |
| 2790 | } |
| 2791 | |
| 2792 | f->store_string(clean_script); |
| 2793 | } |
| 2794 | |
| 2795 | print_line("Uploading scripts..."); |
| 2796 | ep.step(TTR("Uploading scripts..."), 4); |
| 2797 | err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_start.sh", temp_dir); |
| 2798 | if (err != OK) { |
| 2799 | CLEANUP_AND_RETURN(err); |
| 2800 | } |
| 2801 | err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_start.sh")); |
| 2802 | if (err != OK || temp_dir.is_empty()) { |
| 2803 | CLEANUP_AND_RETURN(err); |
| 2804 | } |
| 2805 | err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_clean.sh", temp_dir); |
| 2806 | if (err != OK) { |
| 2807 | CLEANUP_AND_RETURN(err); |
| 2808 | } |
| 2809 | err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh")); |
| 2810 | if (err != OK || temp_dir.is_empty()) { |
| 2811 | CLEANUP_AND_RETURN(err); |
| 2812 | } |
| 2813 | |
| 2814 | print_line("Starting project..."); |
| 2815 | ep.step(TTR("Starting project..."), 5); |
| 2816 | err = ssh_run_on_remote_no_wait(host, port, extra_args_ssh, vformat("\"%s/%s\"", temp_dir, basepath.get_file() + "_start.sh"), &ssh_pid, (use_remote) ? dbg_port : -1); |
| 2817 | if (err != OK) { |
| 2818 | CLEANUP_AND_RETURN(err); |
| 2819 | } |
| 2820 | |
| 2821 | cleanup_commands.clear(); |
| 2822 | cleanup_commands.push_back(SSHCleanupCommand(host, port, extra_args_ssh, vformat("\"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh"))); |
| 2823 | |
| 2824 | print_line("Project started."); |
| 2825 | |
| 2826 | CLEANUP_AND_RETURN(OK); |
| 2827 | #undef CLEANUP_AND_RETURN |
| 2828 | } |
| 2829 | |
| 2830 | void EditorExportPlatformMacOS::initialize() { |
| 2831 | if (EditorNode::get_singleton()) { |
| 2832 | Ref<Image> img = memnew(Image); |
| 2833 | const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE); |
| 2834 | |
| 2835 | ImageLoaderSVG::create_image_from_string(img, _macos_logo_svg, EDSCALE, upsample, false); |
| 2836 | logo = ImageTexture::create_from_image(img); |
| 2837 | |
| 2838 | ImageLoaderSVG::create_image_from_string(img, _macos_run_icon_svg, EDSCALE, upsample, false); |
| 2839 | run_icon = ImageTexture::create_from_image(img); |
| 2840 | |
| 2841 | Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme(); |
| 2842 | if (theme.is_valid()) { |
| 2843 | stop_icon = theme->get_icon(SNAME("Stop"), EditorStringName(EditorIcons)); |
| 2844 | } else { |
| 2845 | stop_icon.instantiate(); |
| 2846 | } |
| 2847 | } |
| 2848 | } |