Path: blob/master/platform/macos/export/export_plugin.cpp
20952 views
/**************************************************************************/1/* export_plugin.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "export_plugin.h"3132#include "logo_svg.gen.h"33#include "run_icon_svg.gen.h"3435#include "core/io/image_loader.h"36#include "core/io/plist.h"37#include "core/string/translation_server.h"38#include "drivers/png/png_driver_common.h"39#include "editor/editor_node.h"40#include "editor/editor_string_names.h"41#include "editor/export/codesign.h"42#include "editor/export/lipo.h"43#include "editor/export/macho.h"44#include "editor/file_system/editor_paths.h"45#include "editor/import/resource_importer_texture_settings.h"46#include "editor/themes/editor_scale.h"47#include "scene/resources/image_texture.h"4849#include "modules/svg/image_loader_svg.h"5051void EditorExportPlatformMacOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {52r_features->push_back(p_preset->get("binary_format/architecture"));53String architecture = p_preset->get("binary_format/architecture");5455if (architecture == "universal" || architecture == "x86_64") {56r_features->push_back("s3tc");57r_features->push_back("bptc");58} else if (architecture == "arm64") {59r_features->push_back("etc2");60r_features->push_back("astc");61} else {62ERR_PRINT("Invalid architecture");63}6465if (!p_preset->is_dedicated_server() && p_preset->get("shader_baker/enabled")) {66// Don't use the shader baker if exporting as a dedicated server, as no rendering is performed.67r_features->push_back("shader_baker");68}6970if (architecture == "universal") {71r_features->push_back("x86_64");72r_features->push_back("arm64");73}74}7576String EditorExportPlatformMacOS::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const {77if (p_preset) {78int dist_type = p_preset->get("export/distribution_type");79bool ad_hoc = false;80int codesign_tool = p_preset->get("codesign/codesign");81int notary_tool = p_preset->get("notarization/notarization");82switch (codesign_tool) {83case 1: { // built-in ad-hoc84ad_hoc = true;85} break;86case 2: { // "rcodesign"87ad_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();88} break;89#ifdef MACOS_ENABLED90case 3: { // "codesign"91ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");92} break;93#endif94default: {95};96}9798if (p_name == "application/bundle_identifier") {99String identifier = p_preset->get("application/bundle_identifier");100String pn_err;101if (!is_package_name_valid(identifier, &pn_err)) {102return TTR("Invalid bundle identifier:") + " " + pn_err;103}104}105106if (p_name == "shader_baker/enabled" && bool(p_preset->get("shader_baker/enabled"))) {107String export_renderer = GLOBAL_GET("rendering/renderer/rendering_method");108if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {109return TTR("\"Shader Baker\" is not supported when using the Compatibility renderer.");110} else if (OS::get_singleton()->get_current_rendering_method() != export_renderer) {111return 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);112}113}114115if (p_name == "codesign/certificate_file" || p_name == "codesign/certificate_password" || p_name == "codesign/identity") {116if (dist_type == 2) {117if (ad_hoc) {118return TTR("App Store distribution with ad-hoc code signing is not supported.");119}120} else if (notary_tool > 0 && ad_hoc) {121return TTR("Notarization with an ad-hoc signature is not supported.");122}123}124125if (p_name == "codesign/apple_team_id") {126String team_id = p_preset->get("codesign/apple_team_id");127if (team_id.is_empty()) {128if (dist_type == 2) {129return TTR("Apple Team ID is required for App Store distribution.");130} else if (notary_tool > 0) {131return TTR("Apple Team ID is required for notarization.");132}133}134}135136if (p_name == "codesign/provisioning_profile" && dist_type == 2) {137String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE);138if (pprof.is_empty()) {139return TTR("Provisioning profile is required for App Store distribution.");140}141}142143if (p_name == "codesign/installer_identity" && dist_type == 2) {144String ident = p_preset->get("codesign/installer_identity");145if (ident.is_empty()) {146return TTR("Installer signing identity is required for App Store distribution.");147}148}149150if (p_name == "codesign/entitlements/app_sandbox/enabled" && dist_type == 2) {151bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");152if (!sandbox) {153return TTR("App sandbox is required for App Store distribution.");154}155}156157if (p_name == "codesign/codesign") {158if (dist_type == 2) {159if (codesign_tool == 2 && ClassDB::class_exists("CSharpScript")) {160return TTR("'rcodesign' doesn't support signing applications with embedded dynamic libraries (GDExtension or .NET).");161}162if (codesign_tool == 0) {163return TTR("Code signing is required for App Store distribution.");164}165if (codesign_tool == 1) {166return TTR("App Store distribution with ad-hoc code signing is not supported.");167}168} else if (notary_tool > 0) {169if (codesign_tool == 0) {170return TTR("Code signing is required for notarization.");171}172if (codesign_tool == 1) {173return TTR("Notarization with an ad-hoc signature is not supported.");174}175}176}177178if (notary_tool == 2 || notary_tool == 3) {179if (p_name == "notarization/apple_id_name" || p_name == "notarization/api_uuid") {180String apple_id = p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID);181String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);182if (apple_id.is_empty() && api_uuid.is_empty()) {183return TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified.");184}185if (!apple_id.is_empty() && !api_uuid.is_empty()) {186return TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.");187}188}189if (p_name == "notarization/apple_id_password") {190String apple_id = p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID);191String apple_pass = p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS);192if (!apple_id.is_empty() && apple_pass.is_empty()) {193return TTR("Apple ID password not specified.");194}195}196if (p_name == "notarization/api_key_id") {197String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);198String api_key = p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID);199if (!api_uuid.is_empty() && api_key.is_empty()) {200return TTR("App Store Connect API key ID not specified.");201}202}203} else if (notary_tool == 1) {204if (p_name == "notarization/api_uuid") {205String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);206if (api_uuid.is_empty()) {207return TTR("App Store Connect issuer ID name not specified.");208}209}210if (p_name == "notarization/api_key_id") {211String api_key = p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID);212if (api_key.is_empty()) {213return TTR("App Store Connect API key ID not specified.");214}215}216}217218if (codesign_tool > 0) {219if (p_name == "privacy/microphone_usage_description") {220String discr = p_preset->get("privacy/microphone_usage_description");221bool enabled = p_preset->get("codesign/entitlements/audio_input");222if (enabled && discr.is_empty()) {223return TTR("Microphone access is enabled, but usage description is not specified.");224}225}226if (p_name == "privacy/camera_usage_description") {227String discr = p_preset->get("privacy/camera_usage_description");228bool enabled = p_preset->get("codesign/entitlements/camera");229if (enabled && discr.is_empty()) {230return TTR("Camera access is enabled, but usage description is not specified.");231}232}233if (p_name == "privacy/location_usage_description") {234String discr = p_preset->get("privacy/location_usage_description");235bool enabled = p_preset->get("codesign/entitlements/location");236if (enabled && discr.is_empty()) {237return TTR("Location information access is enabled, but usage description is not specified.");238}239}240if (p_name == "privacy/address_book_usage_description") {241String discr = p_preset->get("privacy/address_book_usage_description");242bool enabled = p_preset->get("codesign/entitlements/address_book");243if (enabled && discr.is_empty()) {244return TTR("Address book access is enabled, but usage description is not specified.");245}246}247if (p_name == "privacy/calendar_usage_description") {248String discr = p_preset->get("privacy/calendar_usage_description");249bool enabled = p_preset->get("codesign/entitlements/calendars");250if (enabled && discr.is_empty()) {251return TTR("Calendar access is enabled, but usage description is not specified.");252}253}254if (p_name == "privacy/photos_library_usage_description") {255String discr = p_preset->get("privacy/photos_library_usage_description");256bool enabled = p_preset->get("codesign/entitlements/photos_library");257if (enabled && discr.is_empty()) {258return TTR("Photo library access is enabled, but usage description is not specified.");259}260}261}262}263return String();264}265266bool EditorExportPlatformMacOS::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {267// Hide irrelevant code signing options.268if (p_preset) {269int codesign_tool = p_preset->get("codesign/codesign");270switch (codesign_tool) {271case 1: { // built-in ad-hoc272if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options" || p_option == "codesign/team_id") {273return false;274}275} break;276case 2: { // "rcodesign"277if (p_option == "codesign/identity") {278return false;279}280} break;281#ifdef MACOS_ENABLED282case 3: { // "codesign"283if (p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password") {284return false;285}286} break;287#endif288default: { // disabled289if (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") {290return false;291}292} break;293}294295// Distribution type.296int dist_type = p_preset->get("export/distribution_type");297if (dist_type != 2 && p_option == "codesign/installer_identity") {298return false;299}300301if (dist_type == 2 && p_option.begins_with("notarization/")) {302return false;303}304305if (dist_type != 2 && p_option == "codesign/provisioning_profile") {306return false;307}308309#ifndef MACOS_ENABLED310if (p_option == "application/liquid_glass_icon") {311return false;312}313#endif314315String custom_prof = p_preset->get("codesign/entitlements/custom_file");316if (!custom_prof.is_empty() && p_option != "codesign/entitlements/custom_file" && p_option.begins_with("codesign/entitlements/")) {317return false;318}319320// Hide sandbox entitlements.321bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");322if (!sandbox && p_option != "codesign/entitlements/app_sandbox/enabled" && p_option.begins_with("codesign/entitlements/app_sandbox/")) {323return false;324}325326// Hide SSH options.327bool ssh = p_preset->get("ssh_remote_deploy/enabled");328if (!ssh && p_option != "ssh_remote_deploy/enabled" && p_option.begins_with("ssh_remote_deploy/")) {329return false;330}331332// Hide irrelevant notarization options.333int notary_tool = p_preset->get("notarization/notarization");334switch (notary_tool) {335case 1: { // "rcodesign"336if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password") {337return false;338}339} break;340case 2: { // "notarytool"341// All options are visible.342} break;343default: { // disabled344if (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") {345return false;346}347} break;348}349350bool advanced_options_enabled = p_preset->are_advanced_options_enabled();351if (p_option.begins_with("privacy") ||352p_option == "codesign/entitlements/additional" ||353p_option == "custom_template/debug" ||354p_option == "custom_template/release" ||355p_option == "application/additional_plist_content" ||356p_option == "application/export_angle" ||357p_option == "application/icon_interpolation" ||358p_option == "application/signature" ||359p_option == "display/high_res" ||360p_option == "xcode/platform_build" ||361p_option == "xcode/sdk_build" ||362p_option == "xcode/sdk_name" ||363p_option == "xcode/sdk_version" ||364p_option == "xcode/xcode_build" ||365p_option == "xcode/xcode_version") {366return advanced_options_enabled;367}368}369370// These entitlements are required to run managed code, and are always enabled in Mono builds.371if (ClassDB::class_exists("CSharpScript")) {372if (p_option == "codesign/entitlements/allow_jit_code_execution" || p_option == "codesign/entitlements/allow_unsigned_executable_memory" || p_option == "codesign/entitlements/allow_dyld_environment_variables") {373return false;374}375}376377// Hide unsupported .NET embedding option.378if (p_option == "dotnet/embed_build_outputs") {379return false;380}381382return true;383}384385List<String> EditorExportPlatformMacOS::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {386List<String> list;387388if (p_preset.is_valid()) {389int dist_type = p_preset->get("export/distribution_type");390if (dist_type == 0) {391#ifdef MACOS_ENABLED392list.push_back("dmg");393#endif394list.push_back("zip");395list.push_back("app");396} else if (dist_type == 1) {397#ifdef MACOS_ENABLED398list.push_back("dmg");399#endif400list.push_back("zip");401list.push_back("app");402} else if (dist_type == 2) {403#ifdef MACOS_ENABLED404list.push_back("pkg");405#endif406}407}408409return list;410}411412struct DataCollectionInfo {413String prop_name;414String type_name;415};416417static const DataCollectionInfo data_collect_type_info[] = {418{ "name", "NSPrivacyCollectedDataTypeName" },419{ "email_address", "NSPrivacyCollectedDataTypeEmailAddress" },420{ "phone_number", "NSPrivacyCollectedDataTypePhoneNumber" },421{ "physical_address", "NSPrivacyCollectedDataTypePhysicalAddress" },422{ "other_contact_info", "NSPrivacyCollectedDataTypeOtherUserContactInfo" },423{ "health", "NSPrivacyCollectedDataTypeHealth" },424{ "fitness", "NSPrivacyCollectedDataTypeFitness" },425{ "payment_info", "NSPrivacyCollectedDataTypePaymentInfo" },426{ "credit_info", "NSPrivacyCollectedDataTypeCreditInfo" },427{ "other_financial_info", "NSPrivacyCollectedDataTypeOtherFinancialInfo" },428{ "precise_location", "NSPrivacyCollectedDataTypePreciseLocation" },429{ "coarse_location", "NSPrivacyCollectedDataTypeCoarseLocation" },430{ "sensitive_info", "NSPrivacyCollectedDataTypeSensitiveInfo" },431{ "contacts", "NSPrivacyCollectedDataTypeContacts" },432{ "emails_or_text_messages", "NSPrivacyCollectedDataTypeEmailsOrTextMessages" },433{ "photos_or_videos", "NSPrivacyCollectedDataTypePhotosorVideos" },434{ "audio_data", "NSPrivacyCollectedDataTypeAudioData" },435{ "gameplay_content", "NSPrivacyCollectedDataTypeGameplayContent" },436{ "customer_support", "NSPrivacyCollectedDataTypeCustomerSupport" },437{ "other_user_content", "NSPrivacyCollectedDataTypeOtherUserContent" },438{ "browsing_history", "NSPrivacyCollectedDataTypeBrowsingHistory" },439{ "search_history", "NSPrivacyCollectedDataTypeSearchHistory" },440{ "user_id", "NSPrivacyCollectedDataTypeUserID" },441{ "device_id", "NSPrivacyCollectedDataTypeDeviceID" },442{ "purchase_history", "NSPrivacyCollectedDataTypePurchaseHistory" },443{ "product_interaction", "NSPrivacyCollectedDataTypeProductInteraction" },444{ "advertising_data", "NSPrivacyCollectedDataTypeAdvertisingData" },445{ "other_usage_data", "NSPrivacyCollectedDataTypeOtherUsageData" },446{ "crash_data", "NSPrivacyCollectedDataTypeCrashData" },447{ "performance_data", "NSPrivacyCollectedDataTypePerformanceData" },448{ "other_diagnostic_data", "NSPrivacyCollectedDataTypeOtherDiagnosticData" },449{ "environment_scanning", "NSPrivacyCollectedDataTypeEnvironmentScanning" },450{ "hands", "NSPrivacyCollectedDataTypeHands" },451{ "head", "NSPrivacyCollectedDataTypeHead" },452{ "other_data_types", "NSPrivacyCollectedDataTypeOtherDataTypes" },453};454455static const DataCollectionInfo data_collect_purpose_info[] = {456{ "Analytics", "NSPrivacyCollectedDataTypePurposeAnalytics" },457{ "App Functionality", "NSPrivacyCollectedDataTypePurposeAppFunctionality" },458{ "Developer Advertising", "NSPrivacyCollectedDataTypePurposeDeveloperAdvertising" },459{ "Third-party Advertising", "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising" },460{ "Product Personalization", "NSPrivacyCollectedDataTypePurposeProductPersonalization" },461{ "Other", "NSPrivacyCollectedDataTypePurposeOther" },462};463464void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options) const {465#ifdef MACOS_ENABLED466r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution,App Store"), 1, true));467#else468r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution"), 1, true));469#endif470471r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "binary_format/architecture", PROPERTY_HINT_ENUM, "universal,x86_64,arm64", PROPERTY_USAGE_STORAGE), "universal"));472r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));473r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));474475r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "debug/export_console_wrapper", PROPERTY_HINT_ENUM, "No,Debug Only,Debug and Release"), 1));476r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/liquid_glass_icon", PROPERTY_HINT_FILE, "*.icon"), ""));477r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.icns,*.png,*.webp,*.svg"), ""));478r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));479r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "", false, true));480r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));481r_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"));482r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));483r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));484r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));485r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "application/copyright_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));486r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version_x86_64"), "10.12"));487r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version_arm64"), "11.00"));488r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_angle", PROPERTY_HINT_ENUM, "Auto,Yes,No"), 0, true));489r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), true));490491r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "shader_baker/enabled"), false));492493r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/additional_plist_content", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), ""));494495r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/platform_build"), "14C18"));496// TODO(sgc): Need to set appropriate version when using Metal497r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_version"), "13.1"));498r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_build"), "22C55"));499r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_name"), "macosx13.1"));500r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_version"), "1420"));501r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_build"), "14C18"));502503#ifdef MACOS_ENABLED504r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign,Xcode codesign"), 3, true));505#else506r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign"), 1, true, true));507#endif508r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/installer_identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "3rd Party Mac Developer Installer: (ID)"), "", false, true));509r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/apple_team_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "ID"), "", false, true));510// "codesign" only options:511r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), ""));512// "rcodesign" only options:513r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_file", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));514r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_password", PROPERTY_HINT_PASSWORD, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));515// "codesign" and "rcodesign" only options:516r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/provisioning_profile", PROPERTY_HINT_GLOBAL_FILE, "*.provisionprofile", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));517518r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), "", true));519r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false));520r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false));521r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false));522r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false));523r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false));524r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false));525r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/location"), false));526r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/address_book"), false));527r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/calendars"), false));528r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/photos_library"), false));529r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/apple_events"), false));530r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/debugging"), false));531r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/enabled"), false, true, true));532r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_server"), false));533r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_client"), false));534r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_usb"), false));535r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_bluetooth"), false));536r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_downloads", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));537r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_pictures", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));538r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_music", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));539r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_movies", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));540r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_user_selected", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));541r_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()));542r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/additional", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), ""));543r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));544545#ifdef MACOS_ENABLED546r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign,Xcode notarytool"), 0, true));547#else548r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign"), 0, true));549#endif550// "notarytool" only options:551r_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));552r_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));553// "notarytool" and "rcodesign" only options:554r_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));555r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_GLOBAL_FILE, "*.p8", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));556r_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));557558r_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));559r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));560r_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));561r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));562r_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));563r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/location_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));564r_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));565r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/address_book_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));566r_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));567r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/calendar_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));568r_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));569r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photos_library_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));570r_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));571r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/desktop_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));572r_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));573r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/documents_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));574r_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));575r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/downloads_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));576r_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));577r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/network_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));578r_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));579r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/removable_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));580581r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "privacy/tracking_enabled"), false));582r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "privacy/tracking_domains"), Vector<String>()));583584{585String hint;586for (uint64_t i = 0; i < std_size(data_collect_purpose_info); ++i) {587if (i != 0) {588hint += ",";589}590hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i));591}592for (uint64_t i = 0; i < std_size(data_collect_type_info); ++i) {593r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false));594r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false));595r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false));596r_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));597}598}599600String run_script = "#!/usr/bin/env bash\n"601"unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"\n"602"open \"{temp_dir}/{exe_name}.app\" --args {cmd_args}";603604String cleanup_script = "#!/usr/bin/env bash\n"605"pkill -x -f \"{temp_dir}/{exe_name}.app/Contents/MacOS/{exe_name} {cmd_args}\"\n"606"rm -rf \"{temp_dir}\"";607608r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true));609r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/host"), "user@host_ip"));610r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/port"), "22"));611612r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_ssh", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), ""));613r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_scp", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), ""));614r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/run_script", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), run_script));615r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/cleanup_script", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), cleanup_script));616}617618void _rgba8_to_packbits_encode(int p_ch, int p_size, Vector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {619int src_len = p_size * p_size;620621Vector<uint8_t> result;622623int i = 0;624const uint8_t *src = p_source.ptr();625while (i < src_len) {626Vector<uint8_t> seq;627628uint8_t count = 0;629while (count <= 0x7f && i < src_len) {630if (i + 2 < src_len && src[i * 4 + p_ch] == src[(i + 1) * 4 + p_ch] && src[i] == src[(i + 2) * 4 + p_ch]) {631break;632}633seq.push_back(src[i * 4 + p_ch]);634i++;635count++;636}637if (!seq.is_empty()) {638result.push_back(count - 1);639result.append_array(seq);640}641if (i >= src_len) {642break;643}644645uint8_t rep = src[i * 4 + p_ch];646count = 0;647while (count <= 0x7f && i < src_len && src[i * 4 + p_ch] == rep) {648i++;649count++;650}651if (count >= 3) {652result.push_back(0x80 + count - 3);653result.push_back(rep);654} else {655result.push_back(count - 1);656for (int j = 0; j < count; j++) {657result.push_back(rep);658}659}660}661662int ofs = p_dest.size();663p_dest.resize(p_dest.size() + result.size());664memcpy(&p_dest.write[ofs], result.ptr(), result.size());665}666667void EditorExportPlatformMacOS::_make_icon(const Ref<EditorExportPreset> &p_preset, const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {668Vector<uint8_t> data;669670data.resize(8);671data.write[0] = 'i';672data.write[1] = 'c';673data.write[2] = 'n';674data.write[3] = 's';675676struct MacOSIconInfo {677const char *name;678const char *mask_name;679bool is_png;680int size;681};682683static const MacOSIconInfo icon_infos[] = {684{ "ic10", "", true, 1024 }, //1024×1024 32-bit PNG and 512×512@2x 32-bit "retina" PNG685{ "ic09", "", true, 512 }, //512×512 32-bit PNG686{ "ic14", "", true, 512 }, //256×256@2x 32-bit "retina" PNG687{ "ic08", "", true, 256 }, //256×256 32-bit PNG688{ "ic13", "", true, 256 }, //128×128@2x 32-bit "retina" PNG689{ "ic07", "", true, 128 }, //128×128 32-bit PNG690{ "ic12", "", true, 64 }, //32×32@2× 32-bit "retina" PNG691{ "ic11", "", true, 32 }, //16×16@2× 32-bit "retina" PNG692{ "il32", "l8mk", false, 32 }, //32×32 24-bit RLE + 8-bit uncompressed mask693{ "is32", "s8mk", false, 16 } //16×16 24-bit RLE + 8-bit uncompressed mask694};695696for (uint64_t i = 0; i < std_size(icon_infos); ++i) {697Ref<Image> copy = p_icon->duplicate();698copy->convert(Image::FORMAT_RGBA8);699copy->resize(icon_infos[i].size, icon_infos[i].size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));700701if (icon_infos[i].is_png) {702// Encode PNG icon.703Vector<uint8_t> png_buffer;704Error err = PNGDriverCommon::image_to_png(copy, png_buffer);705if (err == OK) {706int ofs = data.size();707uint64_t len = png_buffer.size();708data.resize(data.size() + len + 8);709memcpy(&data.write[ofs + 8], png_buffer.ptr(), len);710len += 8;711len = BSWAP32(len);712memcpy(&data.write[ofs], icon_infos[i].name, 4);713encode_uint32(len, &data.write[ofs + 4]);714}715} else {716Vector<uint8_t> src_data = copy->get_data();717718// Encode 24-bit RGB RLE icon.719{720int ofs = data.size();721data.resize(data.size() + 8);722723_rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // Encode R.724_rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // Encode G.725_rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // Encode B.726727// Note: workaround for macOS icon decoder bug corrupting last RLE encoded value.728data.push_back(0x00);729730int len = data.size() - ofs;731len = BSWAP32(len);732memcpy(&data.write[ofs], icon_infos[i].name, 4);733encode_uint32(len, &data.write[ofs + 4]);734}735736// Encode 8-bit mask uncompressed icon.737{738int ofs = data.size();739int len = copy->get_width() * copy->get_height();740data.resize(data.size() + len + 8);741742for (int j = 0; j < len; j++) {743data.write[ofs + 8 + j] = src_data.ptr()[j * 4 + 3];744}745len += 8;746len = BSWAP32(len);747memcpy(&data.write[ofs], icon_infos[i].mask_name, 4);748encode_uint32(len, &data.write[ofs + 4]);749}750}751}752753uint32_t total_len = data.size();754total_len = BSWAP32(total_len);755encode_uint32(total_len, &data.write[4]);756757p_data = data;758}759760void EditorExportPlatformMacOS::_fix_privacy_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist) {761String str = String::utf8((const char *)plist.ptr(), plist.size());762String strnew;763Vector<String> lines = str.split("\n");764for (int i = 0; i < lines.size(); i++) {765if (lines[i].find("$priv_collection") != -1) {766bool section_opened = false;767for (uint64_t j = 0; j < std_size(data_collect_type_info); ++j) {768bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name));769bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name));770bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name));771int purposes = p_preset->get(vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[j].prop_name));772if (data_collected) {773if (!section_opened) {774section_opened = true;775strnew += "\t<key>NSPrivacyCollectedDataTypes</key>\n";776strnew += "\t<array>\n";777}778strnew += "\t\t<dict>\n";779strnew += "\t\t\t<key>NSPrivacyCollectedDataType</key>\n";780strnew += vformat("\t\t\t<string>%s</string>\n", data_collect_type_info[j].type_name);781strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeLinked</key>\n";782if (linked) {783strnew += "\t\t\t\t<true/>\n";784} else {785strnew += "\t\t\t\t<false/>\n";786}787strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeTracking</key>\n";788if (tracking) {789strnew += "\t\t\t\t<true/>\n";790} else {791strnew += "\t\t\t\t<false/>\n";792}793if (purposes != 0) {794strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n";795strnew += "\t\t\t\t<array>\n";796for (uint64_t k = 0; k < std_size(data_collect_purpose_info); ++k) {797if (purposes & (1 << k)) {798strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name);799}800}801strnew += "\t\t\t\t</array>\n";802}803strnew += "\t\t\t</dict>\n";804}805}806if (section_opened) {807strnew += "\t</array>\n";808}809} else if (lines[i].find("$priv_tracking") != -1) {810bool tracking = p_preset->get("privacy/tracking_enabled");811strnew += "\t<key>NSPrivacyTracking</key>\n";812if (tracking) {813strnew += "\t<true/>\n";814} else {815strnew += "\t<false/>\n";816}817Vector<String> tracking_domains = p_preset->get("privacy/tracking_domains");818if (!tracking_domains.is_empty()) {819strnew += "\t<key>NSPrivacyTrackingDomains</key>\n";820strnew += "\t<array>\n";821for (const String &E : tracking_domains) {822strnew += "\t\t<string>" + E + "</string>\n";823}824strnew += "\t</array>\n";825}826} else {827strnew += lines[i] + "\n";828}829}830831CharString cs = strnew.utf8();832plist.resize(cs.size() - 1);833for (int i = 0; i < cs.size() - 1; i++) {834plist.write[i] = cs[i];835}836}837838void 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) {839String str = String::utf8((const char *)plist.ptr(), plist.size());840String strnew;841Vector<String> lines = str.split("\n");842for (int i = 0; i < lines.size(); i++) {843if (lines[i].contains("$binary")) {844strnew += lines[i].replace("$binary", p_binary) + "\n";845} else if (lines[i].contains("$name")) {846strnew += lines[i].replace("$name", get_project_setting(p_preset, "application/config/name").operator String().xml_escape(true)) + "\n";847} else if (lines[i].contains("$bundle_identifier")) {848strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";849} else if (lines[i].contains("$short_version")) {850strnew += lines[i].replace("$short_version", p_preset->get_version("application/short_version")) + "\n";851} else if (lines[i].contains("$version")) {852strnew += lines[i].replace("$version", p_preset->get_version("application/version")) + "\n";853} else if (lines[i].contains("$signature")) {854strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";855} else if (lines[i].contains("$app_category")) {856String cat = p_preset->get("application/app_category");857strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n";858} else if (lines[i].contains("$copyright")) {859strnew += lines[i].replace("$copyright", p_preset->get("application/copyright").operator String().xml_escape(true)) + "\n";860} else if (lines[i].contains("$min_version_arm64")) {861strnew += lines[i].replace("$min_version_arm64", p_preset->get("application/min_macos_version_arm64")) + "\n";862} else if (lines[i].contains("$min_version_x86_64")) {863strnew += lines[i].replace("$min_version_x86_64", p_preset->get("application/min_macos_version_x86_64")) + "\n";864} else if (lines[i].contains("$min_version")) {865strnew += lines[i].replace("$min_version", p_preset->get("application/min_macos_version_x86_64")) + "\n"; // Old template, use x86-64 version for both.866} else if (lines[i].contains("$highres")) {867strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "\t<true/>" : "\t<false/>") + "\n";868} else if (lines[i].contains("$additional_plist_content")) {869strnew += lines[i].replace("$additional_plist_content", p_preset->get("application/additional_plist_content")) + "\n";870} else if (lines[i].contains("$platfbuild")) {871strnew += lines[i].replace("$platfbuild", p_preset->get("xcode/platform_build")) + "\n";872} else if (lines[i].contains("$sdkver")) {873strnew += lines[i].replace("$sdkver", p_preset->get("xcode/sdk_version")) + "\n";874} else if (lines[i].contains("$sdkname")) {875strnew += lines[i].replace("$sdkname", p_preset->get("xcode/sdk_name")) + "\n";876} else if (lines[i].contains("$sdkbuild")) {877strnew += lines[i].replace("$sdkbuild", p_preset->get("xcode/sdk_build")) + "\n";878} else if (lines[i].contains("$xcodever")) {879strnew += lines[i].replace("$xcodever", p_preset->get("xcode/xcode_version")) + "\n";880} else if (lines[i].contains("$xcodebuild")) {881strnew += lines[i].replace("$xcodebuild", p_preset->get("xcode/xcode_build")) + "\n";882} else if (lines[i].contains("$liquid_glass_icon")) {883if (p_lg_icon_exported) {884strnew += lines[i].replace("$liquid_glass_icon", "\t<key>CFBundleIconName</key>\n\t<string>" + p_lg_icon + "</string>\n");885} else {886strnew += lines[i].replace("$liquid_glass_icon", "");887}888} else if (lines[i].contains("$usage_descriptions")) {889String descriptions;890if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {891descriptions += "\t<key>NSMicrophoneUsageDescription</key>\n";892descriptions += "\t<string>" + p_preset->get("privacy/microphone_usage_description").operator String().xml_escape(true) + "</string>\n";893}894if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {895descriptions += "\t<key>NSCameraUsageDescription</key>\n";896descriptions += "\t<string>" + p_preset->get("privacy/camera_usage_description").operator String().xml_escape(true) + "</string>\n";897}898if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {899descriptions += "\t<key>NSLocationUsageDescription</key>\n";900descriptions += "\t<string>" + p_preset->get("privacy/location_usage_description").operator String().xml_escape(true) + "</string>\n";901}902if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {903descriptions += "\t<key>NSContactsUsageDescription</key>\n";904descriptions += "\t<string>" + p_preset->get("privacy/address_book_usage_description").operator String().xml_escape(true) + "</string>\n";905}906if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {907descriptions += "\t<key>NSCalendarsUsageDescription</key>\n";908descriptions += "\t<string>" + p_preset->get("privacy/calendar_usage_description").operator String().xml_escape(true) + "</string>\n";909}910if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {911descriptions += "\t<key>NSPhotoLibraryUsageDescription</key>\n";912descriptions += "\t<string>" + p_preset->get("privacy/photos_library_usage_description").operator String().xml_escape(true) + "</string>\n";913}914if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {915descriptions += "\t<key>NSDesktopFolderUsageDescription</key>\n";916descriptions += "\t<string>" + p_preset->get("privacy/desktop_folder_usage_description").operator String().xml_escape(true) + "</string>\n";917}918if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {919descriptions += "\t<key>NSDocumentsFolderUsageDescription</key>\n";920descriptions += "\t<string>" + p_preset->get("privacy/documents_folder_usage_description").operator String().xml_escape(true) + "</string>\n";921}922if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {923descriptions += "\t<key>NSDownloadsFolderUsageDescription</key>\n";924descriptions += "\t<string>" + p_preset->get("privacy/downloads_folder_usage_description").operator String().xml_escape(true) + "</string>\n";925}926if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {927descriptions += "\t<key>NSNetworkVolumesUsageDescription</key>\n";928descriptions += "\t<string>" + p_preset->get("privacy/network_volumes_usage_description").operator String().xml_escape(true) + "</string>\n";929}930if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {931descriptions += "\t<key>NSRemovableVolumesUsageDescription</key>\n";932descriptions += "\t<string>" + p_preset->get("privacy/removable_volumes_usage_description").operator String().xml_escape(true) + "</string>\n";933}934if (!descriptions.is_empty()) {935strnew += lines[i].replace("$usage_descriptions", descriptions);936}937} else {938strnew += lines[i] + "\n";939}940}941942CharString cs = strnew.utf8();943plist.resize(cs.size() - 1);944for (int i = 0; i < cs.size() - 1; i++) {945plist.write[i] = cs[i];946}947}948949Error EditorExportPlatformMacOS::_export_liquid_glass_icon(const Ref<EditorExportPreset> &p_preset, const String &p_app_path, const String &p_icon_path) {950String actool = EDITOR_GET("export/macos/actool").operator String();951if (actool.is_empty()) {952actool = "actool";953}954955List<String> args;956args.push_back("--version");957String str;958String err_str;959int exitcode = 0;960961Error err = OS::get_singleton()->execute(actool, args, &str, &exitcode, true);962if (err != OK) {963add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not start 'actool' executable."));964return err;965}966PList info_plist;967if (!info_plist.load_string(str, err_str)) {968print_verbose(str);969add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not read 'actool' version."));970return err;971}972if (info_plist.get_root()->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && info_plist.get_root()->data_dict.has("com.apple.actool.version")) {973Ref<PListNode> dict = info_plist.get_root()->data_dict["com.apple.actool.version"];974if (dict->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && dict->data_dict.has("short-bundle-version")) {975float version = String::utf8(dict->data_dict["short-bundle-version"]->data_string.get_data()).to_float();976if (version < 26.0) {977add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), vformat(TTR("At least version 26.0 of 'actool' is required (version %f found)."), version));978return ERR_UNAVAILABLE;979}980}981}982str.clear();983984String plist = EditorPaths::get_singleton()->get_temp_dir().path_join("assetcatalog.plist");985args.clear();986args.push_back(ProjectSettings::get_singleton()->globalize_path(p_icon_path));987args.push_back("--compile");988args.push_back(p_app_path + "/Contents/Resources/");989args.push_back("--output-format");990args.push_back("human-readable-text");991args.push_back("--lightweight-asset-runtime-mode");992args.push_back("enabled");993args.push_back("--app-icon");994args.push_back(p_icon_path.get_file().get_basename());995args.push_back("--include-all-app-icons");996args.push_back("--enable-on-demand-resources");997args.push_back("NO");998args.push_back("--development-region");999args.push_back("en");1000args.push_back("--target-device");1001args.push_back("mac");1002args.push_back("--minimum-deployment-target");1003args.push_back("26");1004args.push_back("--platform");1005args.push_back("macosx");1006args.push_back("--output-partial-info-plist");1007args.push_back(plist);10081009err = OS::get_singleton()->execute(actool, args, &str, &exitcode, true);1010if (err != OK || str.contains("error:") || !FileAccess::exists(p_app_path + "/Contents/Resources/Assets.car") || !FileAccess::exists(plist)) {1011print_verbose(str);1012add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not export liquid glass icon:") + "\n" + str);1013return err;1014}10151016return OK;1017}10181019/**1020* If we're running the macOS version of the Godot editor we'll:1021* - export our application bundle to a temporary folder1022* - attempt to code sign it1023* - and then wrap it up in a DMG1024*/10251026Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path) {1027int notary_tool = p_preset->get("notarization/notarization");1028switch (notary_tool) {1029case 1: { // "rcodesign"1030print_verbose("using rcodesign notarization...");10311032String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();1033if (rcodesign.is_empty()) {1034add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));1035return Error::FAILED;1036}10371038List<String> args;10391040args.push_back("notary-submit");10411042if (p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) == "") {1043add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect issuer ID name not specified."));1044return Error::FAILED;1045}1046if (p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY) == "") {1047add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));1048return Error::FAILED;1049}10501051args.push_back("--api-issuer");1052args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID));10531054args.push_back("--api-key");1055args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID));10561057if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) {1058args.push_back("--api-key-path");1059args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY));1060}10611062args.push_back(p_path);10631064String str;1065int exitcode = 0;10661067Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);1068if (err != OK) {1069add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start rcodesign executable."));1070return err;1071}10721073int rq_offset = str.find("created submission ID:");1074if (exitcode != 0 || rq_offset == -1) {1075print_line("rcodesign (" + p_path + "):\n" + str);1076add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));1077return Error::FAILED;1078} else {1079print_verbose("rcodesign (" + p_path + "):\n" + str);1080int next_nl = str.find_char('\n', rq_offset);1081String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 23) : str.substr(rq_offset + 23, next_nl - rq_offset - 23);1082add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));1083add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour."));1084add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check the progress manually by opening a Terminal and running the following command:"));1085add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign notary-log --api-issuer <API UUID> --api-key <API key> <request UUID>\"");1086add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));1087add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign staple <app path>\"");1088}1089} break;1090#ifdef MACOS_ENABLED1091case 2: { // "notarytool"1092print_verbose("using notarytool notarization...");10931094if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {1095add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed."));1096return Error::FAILED;1097}10981099List<String> args;11001101args.push_back("notarytool");1102args.push_back("submit");11031104args.push_back(p_path);11051106if (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) == "") {1107add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified."));1108return Error::FAILED;1109}1110if (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) != "") {1111add_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."));1112return Error::FAILED;1113}11141115if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) != "") {1116if (p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS) == "") {1117add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified."));1118return Error::FAILED;1119}1120args.push_back("--apple-id");1121args.push_back(p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID));11221123args.push_back("--password");1124args.push_back(p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS));1125} else {1126if (p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID) == "") {1127add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));1128return Error::FAILED;1129}1130args.push_back("--issuer");1131args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID));11321133if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) {1134args.push_back("--key");1135args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY));1136}11371138args.push_back("--key-id");1139args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID));1140}11411142args.push_back("--no-progress");11431144if (p_preset->get("codesign/apple_team_id")) {1145args.push_back("--team-id");1146args.push_back(p_preset->get("codesign/apple_team_id"));1147}11481149String str;1150int exitcode = 0;1151Error err = OS::get_singleton()->execute("xcrun", args, &str, &exitcode, true);1152if (err != OK) {1153add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable."));1154return err;1155}11561157int rq_offset = str.find("id:");1158if (exitcode != 0 || rq_offset == -1) {1159print_line("notarytool (" + p_path + "):\n" + str);1160add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));1161return Error::FAILED;1162} else {1163print_verbose("notarytool (" + p_path + "):\n" + str);1164int next_nl = str.find_char('\n', rq_offset);1165String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 4) : str.substr(rq_offset + 4, next_nl - rq_offset - 4);1166add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));1167add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour."));1168add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("See instructions on finding your team ID: https://developer.apple.com/help/glossary/team-id"));1169add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check the progress manually by opening a Terminal and running the following command:"));1170add_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");1171add_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>\"");1172add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));1173add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple <app path>\"");1174}1175} break;1176#endif1177default: {1178};1179}1180return OK;1181}11821183void EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_warn, bool p_set_id) {1184int codesign_tool = p_preset->get("codesign/codesign");1185switch (codesign_tool) {1186case 1: { // built-in ad-hoc1187print_verbose("using built-in codesign...");1188String error_msg;1189Error err = CodeSign::codesign(false, true, p_path, p_ent_path, error_msg);1190if (err != OK) {1191add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Built-in CodeSign failed with error \"%s\"."), error_msg));1192return;1193}1194} break;1195case 2: { // "rcodesign"1196print_verbose("using rcodesign codesign...");11971198String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();1199if (rcodesign.is_empty()) {1200add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xrcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));1201return;1202}12031204List<String> args;1205args.push_back("sign");12061207if (!p_ent_path.is_empty()) {1208args.push_back("--entitlements-xml-path");1209args.push_back(p_ent_path);1210}12111212String certificate_file = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE);1213String certificate_pass = p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS);1214if (!certificate_file.is_empty() && !certificate_pass.is_empty()) {1215args.push_back("--p12-file");1216args.push_back(certificate_file);1217args.push_back("--p12-password");1218args.push_back(certificate_pass);1219}1220args.push_back("--code-signature-flags");1221args.push_back("runtime");12221223if (p_set_id) {1224String app_id = p_preset->get("application/bundle_identifier");1225args.push_back("--binary-identifier");1226args.push_back(app_id);1227}12281229args.push_back("-v"); /* provide some more feedback */12301231args.push_back(p_path);12321233String str;1234int exitcode = 0;12351236Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);1237if (err != OK) {1238add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start rcodesign executable."));1239return;1240}12411242if (exitcode != 0) {1243print_line("rcodesign (" + p_path + "):\n" + str);1244add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));1245return;1246} else {1247print_verbose("rcodesign (" + p_path + "):\n" + str);1248}1249} break;1250#ifdef MACOS_ENABLED1251case 3: { // "codesign"1252print_verbose("using xcode codesign...");12531254if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {1255add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xcode command line tools are not installed."));1256return;1257}12581259bool ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");12601261List<String> args;1262if (!ad_hoc) {1263args.push_back("--timestamp");1264args.push_back("--options");1265args.push_back("runtime");1266}12671268if (!p_ent_path.is_empty()) {1269args.push_back("--entitlements");1270args.push_back(p_ent_path);1271}12721273PackedStringArray user_args = p_preset->get("codesign/custom_options");1274for (int i = 0; i < user_args.size(); i++) {1275String user_arg = user_args[i].strip_edges();1276if (!user_arg.is_empty()) {1277args.push_back(user_arg);1278}1279}12801281args.push_back("-s");1282if (ad_hoc) {1283args.push_back("-");1284} else {1285args.push_back(p_preset->get("codesign/identity"));1286}12871288if (p_set_id) {1289String app_id = p_preset->get("application/bundle_identifier");1290args.push_back("-i");1291args.push_back(app_id);1292}12931294args.push_back("-v"); /* provide some more feedback */1295args.push_back("-f");12961297args.push_back(p_path);12981299String str;1300int exitcode = 0;13011302Error err = OS::get_singleton()->execute("codesign", args, &str, &exitcode, true);1303if (err != OK) {1304add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start codesign executable, make sure Xcode command line tools are installed."));1305return;1306}13071308if (exitcode != 0) {1309print_line("codesign (" + p_path + "):\n" + str);1310add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));1311return;1312} else {1313print_verbose("codesign (" + p_path + "):\n" + str);1314}1315} break;1316#endif1317default: {1318};1319}1320}13211322void EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path,1323const String &p_ent_path, const String &p_helper_ent_path, bool p_should_error_on_non_code) {1324static Vector<String> extensions_to_sign;13251326bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");1327if (extensions_to_sign.is_empty()) {1328extensions_to_sign.push_back("dylib");1329extensions_to_sign.push_back("framework");1330extensions_to_sign.push_back("");1331}13321333Error dir_access_error;1334Ref<DirAccess> dir_access{ DirAccess::open(p_path, &dir_access_error) };13351336if (dir_access_error != OK) {1337add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign directory %s."), p_path));1338return;1339}13401341dir_access->list_dir_begin();1342String current_file{ dir_access->get_next() };1343while (!current_file.is_empty()) {1344String current_file_path{ p_path.path_join(current_file) };13451346if (current_file == ".." || current_file == ".") {1347current_file = dir_access->get_next();1348continue;1349}13501351if (extensions_to_sign.has(current_file.get_extension())) {1352String ent_path;1353bool set_bundle_id = false;1354if (sandbox && FileAccess::exists(current_file_path)) {1355int ftype = MachO::get_filetype(current_file_path);1356if (ftype == 2 || ftype == 5) {1357ent_path = p_helper_ent_path;1358set_bundle_id = true;1359}1360}1361_code_sign(p_preset, current_file_path, ent_path, false, set_bundle_id);1362if (is_executable(current_file_path)) {1363// chmod with 0755 if the file is executable.1364FileAccess::set_unix_permissions(current_file_path, 0755);1365}1366} else if (dir_access->current_is_dir()) {1367_code_sign_directory(p_preset, current_file_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code);1368} else if (p_should_error_on_non_code) {1369add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign file %s."), current_file));1370}13711372current_file = dir_access->get_next();1373}1374}13751376Error EditorExportPlatformMacOS::_copy_and_sign_files(Ref<DirAccess> &dir_access, const String &p_src_path,1377const String &p_in_app_path, bool p_sign_enabled,1378const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,1379const String &p_helper_ent_path,1380bool p_should_error_on_non_code_sign, bool p_sandbox) {1381static Vector<String> extensions_to_sign;13821383if (extensions_to_sign.is_empty()) {1384extensions_to_sign.push_back("dylib");1385extensions_to_sign.push_back("framework");1386extensions_to_sign.push_back("");1387}13881389Error err{ OK };1390if (dir_access->dir_exists(p_src_path)) {1391#ifndef UNIX_ENABLED1392add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Relative symlinks are not supported, exported \"%s\" might be broken!"), p_src_path.get_file()));1393#endif1394print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path);13951396bool plist_missing = false;1397Ref<PList> plist;1398plist.instantiate();1399plist->load_file(p_src_path.path_join("Resources").path_join("Info.plist"));14001401Ref<PListNode> root_node = plist->get_root();1402if (root_node.is_null()) {1403plist_missing = true;1404} else {1405Dictionary root = root_node->get_value();1406if (!root.has("CFBundleExecutable") || !root.has("CFBundleIdentifier") || !root.has("CFBundlePackageType") || !root.has("CFBundleInfoDictionaryVersion") || !root.has("CFBundleName") || !root.has("CFBundleSupportedPlatforms")) {1407plist_missing = true;1408}1409}14101411err = dir_access->make_dir_recursive(p_in_app_path);1412if (err == OK) {1413err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true);1414}1415if (err == OK && plist_missing) {1416add_message(EXPORT_MESSAGE_WARNING, TTR("Export"), vformat(TTR("\"%s\": Info.plist missing or invalid, new Info.plist generated."), p_src_path.get_file()));1417// Generate Info.plist1418String lib_name = p_src_path.get_basename().get_file();1419String lib_id = p_preset->get("application/bundle_identifier");1420String lib_clean_name = lib_name;1421for (int i = 0; i < lib_clean_name.length(); i++) {1422if (!is_ascii_alphanumeric_char(lib_clean_name[i]) && lib_clean_name[i] != '.' && lib_clean_name[i] != '-') {1423lib_clean_name[i] = '-';1424}1425}14261427String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"1428"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"1429"<plist version=\"1.0\">\n"1430" <dict>\n"1431" <key>CFBundleExecutable</key>\n"1432" <string>$name</string>\n"1433" <key>CFBundleIdentifier</key>\n"1434" <string>$id.framework.$cl_name</string>\n"1435" <key>CFBundleInfoDictionaryVersion</key>\n"1436" <string>6.0</string>\n"1437" <key>CFBundleName</key>\n"1438" <string>$name</string>\n"1439" <key>CFBundlePackageType</key>\n"1440" <string>FMWK</string>\n"1441" <key>CFBundleShortVersionString</key>\n"1442" <string>1.0.0</string>\n"1443" <key>CFBundleSupportedPlatforms</key>\n"1444" <array>\n"1445" <string>MacOSX</string>\n"1446" </array>\n"1447" <key>CFBundleVersion</key>\n"1448" <string>1.0.0</string>\n"1449" <key>LSMinimumSystemVersion</key>\n"1450" <string>10.12</string>\n"1451" </dict>\n"1452"</plist>";14531454String info_plist = info_plist_format.replace("$id", lib_id).replace("$name", lib_name).replace("$cl_name", lib_clean_name);14551456err = dir_access->make_dir_recursive(p_in_app_path.path_join("Resources"));1457Ref<FileAccess> f = FileAccess::open(p_in_app_path.path_join("Resources").path_join("Info.plist"), FileAccess::WRITE);1458if (f.is_valid()) {1459f->store_string(info_plist);1460}1461}1462} else {1463print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path);1464err = dir_access->copy(p_src_path, p_in_app_path);1465}1466if (err == OK && p_sign_enabled) {1467if (dir_access->dir_exists(p_src_path) && p_src_path.get_extension().is_empty()) {1468// If it is a directory, find and sign all dynamic libraries.1469_code_sign_directory(p_preset, p_in_app_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code_sign);1470} else {1471if (extensions_to_sign.has(p_in_app_path.get_extension())) {1472String ent_path;1473bool set_bundle_id = false;1474if (p_sandbox && FileAccess::exists(p_in_app_path)) {1475int ftype = MachO::get_filetype(p_in_app_path);1476if (ftype == 2 || ftype == 5) {1477ent_path = p_helper_ent_path;1478set_bundle_id = true;1479}1480}1481_code_sign(p_preset, p_in_app_path, ent_path, false, set_bundle_id);1482}1483if (dir_access->file_exists(p_in_app_path) && is_executable(p_in_app_path)) {1484// chmod with 0755 if the file is executable.1485FileAccess::set_unix_permissions(p_in_app_path, 0755);1486}1487}1488}1489return err;1490}14911492Error EditorExportPlatformMacOS::_export_macos_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin,1493const String &p_app_path_name, Ref<DirAccess> &dir_access,1494bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,1495const String &p_ent_path, const String &p_helper_ent_path, bool p_sandbox) {1496Error error{ OK };1497const Vector<String> &macos_plugins{ p_editor_export_plugin->get_macos_plugin_files() };1498for (int i = 0; i < macos_plugins.size(); ++i) {1499String src_path{ ProjectSettings::get_singleton()->globalize_path(macos_plugins[i]) };1500String path_in_app{ p_app_path_name + "/Contents/PlugIns/" + src_path.get_file() };1501error = _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);1502if (error != OK) {1503break;1504}1505}1506return error;1507}15081509Error EditorExportPlatformMacOS::_create_pkg(const Ref<EditorExportPreset> &p_preset, const String &p_pkg_path, const String &p_app_path_name) {1510List<String> args;15111512if (FileAccess::exists(p_pkg_path)) {1513OS::get_singleton()->move_to_trash(p_pkg_path);1514}15151516args.push_back("productbuild");1517args.push_back("--component");1518args.push_back(p_app_path_name);1519args.push_back("/Applications");1520String ident = p_preset->get("codesign/installer_identity");1521if (!ident.is_empty()) {1522args.push_back("--timestamp");1523args.push_back("--sign");1524args.push_back(ident);1525}1526args.push_back("--quiet");1527args.push_back(p_pkg_path);15281529String str;1530Error err = OS::get_singleton()->execute("xcrun", args, &str, nullptr, true);1531if (err != OK) {1532add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("Could not start productbuild executable."));1533return err;1534}15351536print_verbose("productbuild returned: " + str);1537if (str.contains("productbuild: error:")) {1538add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("`productbuild` failed."));1539return FAILED;1540}15411542return OK;1543}15441545Error EditorExportPlatformMacOS::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {1546List<String> args;15471548if (FileAccess::exists(p_dmg_path)) {1549OS::get_singleton()->move_to_trash(p_dmg_path);1550}15511552args.push_back("create");1553args.push_back(p_dmg_path);1554args.push_back("-volname");1555args.push_back(p_pkg_name);1556args.push_back("-fs");1557args.push_back("HFS+");1558args.push_back("-srcfolder");1559args.push_back(p_app_path_name);15601561String str;1562Error err = OS::get_singleton()->execute("hdiutil", args, &str, nullptr, true);1563if (err != OK) {1564add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("Could not start hdiutil executable."));1565return err;1566}15671568print_verbose("hdiutil returned: " + str);1569if (str.contains("create failed")) {1570if (str.contains("File exists")) {1571add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed - file exists."));1572} else {1573add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed."));1574}1575return FAILED;1576}15771578return OK;1579}15801581bool EditorExportPlatformMacOS::is_shebang(const String &p_path) const {1582Ref<FileAccess> fb = FileAccess::open(p_path, FileAccess::READ);1583ERR_FAIL_COND_V_MSG(fb.is_null(), false, vformat("Can't open file: \"%s\".", p_path));1584uint16_t magic = fb->get_16();1585return (magic == 0x2123);1586}15871588bool EditorExportPlatformMacOS::is_executable(const String &p_path) const {1589return MachO::is_macho(p_path) || LipO::is_lipo(p_path) || is_shebang(p_path);1590}15911592Error EditorExportPlatformMacOS::_export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path) {1593Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE);1594if (f.is_null()) {1595add_message(EXPORT_MESSAGE_ERROR, TTR("Debug Script Export"), vformat(TTR("Could not open file \"%s\"."), p_path));1596return ERR_CANT_CREATE;1597}15981599f->store_line("#!/bin/sh");1600f->store_line("printf '\\033c\\033]0;%s\\a' " + p_app_name);1601f->store_line("");1602f->store_line("function app_realpath() {");1603f->store_line(" SOURCE=$1");1604f->store_line(" while [ -h \"$SOURCE\" ]; do");1605f->store_line(" DIR=$(dirname \"$SOURCE\")");1606f->store_line(" SOURCE=$(readlink \"$SOURCE\")");1607f->store_line(" [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE");1608f->store_line(" done");1609f->store_line(" echo \"$( cd -P \"$( dirname \"$SOURCE\" )\" >/dev/null 2>&1 && pwd )\"");1610f->store_line("}");1611f->store_line("");1612f->store_line("BASE_PATH=\"$(app_realpath \"${BASH_SOURCE[0]}\")\"");1613f->store_line("\"$BASE_PATH/" + p_pkg_name + "\" \"$@\"");1614f->store_line("");16151616return OK;1617}16181619Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) {1620ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);16211622const String base_dir = p_path.get_base_dir();16231624if (!DirAccess::exists(base_dir)) {1625add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Target folder does not exist or is inaccessible: \"%s\""), base_dir));1626return ERR_FILE_BAD_PATH;1627}16281629EditorProgress ep("export", TTR("Exporting for macOS"), 3, true);16301631String src_pkg_name;1632if (p_debug) {1633src_pkg_name = p_preset->get("custom_template/debug");1634} else {1635src_pkg_name = p_preset->get("custom_template/release");1636}16371638if (src_pkg_name.is_empty()) {1639String err;1640src_pkg_name = find_export_template("macos.zip", &err);1641if (src_pkg_name.is_empty()) {1642add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found.") + "\n" + err);1643return ERR_FILE_NOT_FOUND;1644}1645}16461647Ref<FileAccess> io_fa;1648zlib_filefunc_def io = zipio_create_io(&io_fa);16491650if (ep.step(TTR("Creating app bundle"), 0)) {1651return ERR_SKIP;1652}16531654unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);1655if (!src_pkg_zip) {1656add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not find template app to export: \"%s\"."), src_pkg_name));1657return ERR_FILE_NOT_FOUND;1658}16591660int ret = unzGoToFirstFile(src_pkg_zip);16611662String architecture = p_preset->get("binary_format/architecture");1663String binary_to_use = "godot_macos_" + String(p_debug ? "debug" : "release") + "." + architecture;16641665String pkg_name;1666if (String(get_project_setting(p_preset, "application/config/name")) != "") {1667pkg_name = String(get_project_setting(p_preset, "application/config/name"));1668} else {1669pkg_name = "Unnamed";1670}1671pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);16721673String export_format;1674if (p_path.ends_with("zip")) {1675export_format = "zip";1676} else if (p_path.ends_with("app")) {1677export_format = "app";1678#ifdef MACOS_ENABLED1679} else if (p_path.ends_with("dmg")) {1680export_format = "dmg";1681} else if (p_path.ends_with("pkg")) {1682export_format = "pkg";1683#endif1684} else {1685add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Invalid export format."));1686return ERR_CANT_CREATE;1687}16881689// Create our application bundle.1690String tmp_app_dir_name = pkg_name + ".app";1691String tmp_base_path_name;1692String tmp_app_path_name;1693String scr_path;1694if (export_format == "app") {1695tmp_base_path_name = p_path.get_base_dir();1696tmp_app_path_name = p_path;1697scr_path = p_path.get_basename() + ".command";1698} else {1699tmp_base_path_name = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name);1700tmp_app_path_name = tmp_base_path_name.path_join(tmp_app_dir_name);1701scr_path = tmp_base_path_name.path_join(pkg_name + ".command");1702}17031704print_verbose("Exporting to " + tmp_app_path_name);17051706Error err = OK;17071708Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_base_path_name);1709if (tmp_app_dir.is_null()) {1710add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory: \"%s\"."), tmp_base_path_name));1711err = ERR_CANT_CREATE;1712}17131714if (FileAccess::exists(scr_path)) {1715DirAccess::remove_file_or_error(scr_path);1716}1717if (DirAccess::exists(tmp_app_path_name)) {1718String old_dir = tmp_app_dir->get_current_dir();1719if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {1720tmp_app_dir->erase_contents_recursive();1721tmp_app_dir->change_dir(old_dir);1722}1723}17241725Array helpers = p_preset->get("codesign/entitlements/app_sandbox/helper_executables");17261727// Create our folder structure.1728if (err == OK) {1729print_verbose("Creating " + tmp_app_path_name + "/Contents/MacOS");1730err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");1731if (err != OK) {1732add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/MacOS"));1733}1734}17351736if (err == OK) {1737print_verbose("Creating " + tmp_app_path_name + "/Contents/Frameworks");1738err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");1739if (err != OK) {1740add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Frameworks"));1741}1742}17431744if ((err == OK) && helpers.size() > 0) {1745print_line("Creating " + tmp_app_path_name + "/Contents/Helpers");1746err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Helpers");1747if (err != OK) {1748add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Helpers"));1749}1750}17511752if (err == OK) {1753print_verbose("Creating " + tmp_app_path_name + "/Contents/Resources");1754err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");1755if (err != OK) {1756add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Resources"));1757}1758}17591760Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");1761Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");1762Dictionary location_usage_descriptions = p_preset->get("privacy/location_usage_description_localized");1763Dictionary address_book_usage_descriptions = p_preset->get("privacy/address_book_usage_description_localized");1764Dictionary calendar_usage_descriptions = p_preset->get("privacy/calendar_usage_description_localized");1765Dictionary photos_library_usage_descriptions = p_preset->get("privacy/photos_library_usage_description_localized");1766Dictionary desktop_folder_usage_descriptions = p_preset->get("privacy/desktop_folder_usage_description_localized");1767Dictionary documents_folder_usage_descriptions = p_preset->get("privacy/documents_folder_usage_description_localized");1768Dictionary downloads_folder_usage_descriptions = p_preset->get("privacy/downloads_folder_usage_description_localized");1769Dictionary network_volumes_usage_descriptions = p_preset->get("privacy/network_volumes_usage_description_localized");1770Dictionary removable_volumes_usage_descriptions = p_preset->get("privacy/removable_volumes_usage_description_localized");1771Dictionary copyrights = p_preset->get("application/copyright_localized");17721773const String project_name = get_project_setting(p_preset, "application/config/name");1774const Dictionary appnames = get_project_setting(p_preset, "application/config/name_localized");1775const StringName domain_name = "godot.project_name_localization";1776Ref<TranslationDomain> domain = TranslationServer::get_singleton()->get_or_add_domain(domain_name);1777TranslationServer::get_singleton()->load_project_translations(domain);1778const Vector<String> locales = domain->get_loaded_locales();17791780if (!locales.is_empty()) {1781{1782String fname = tmp_app_path_name + "/Contents/Resources/en.lproj";1783tmp_app_dir->make_dir_recursive(fname);1784Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);1785f->store_line("/* Localized versions of Info.plist keys */");1786f->store_line("");1787f->store_line("CFBundleDisplayName = \"" + project_name.xml_escape(true) + "\";");1788if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {1789f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String().xml_escape(true) + "\";");1790}1791if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {1792f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String().xml_escape(true) + "\";");1793}1794if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {1795f->store_line("NSLocationUsageDescription = \"" + p_preset->get("privacy/location_usage_description").operator String().xml_escape(true) + "\";");1796}1797if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {1798f->store_line("NSContactsUsageDescription = \"" + p_preset->get("privacy/address_book_usage_description").operator String().xml_escape(true) + "\";");1799}1800if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {1801f->store_line("NSCalendarsUsageDescription = \"" + p_preset->get("privacy/calendar_usage_description").operator String().xml_escape(true) + "\";");1802}1803if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {1804f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photos_library_usage_description").operator String().xml_escape(true) + "\";");1805}1806if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {1807f->store_line("NSDesktopFolderUsageDescription = \"" + p_preset->get("privacy/desktop_folder_usage_description").operator String().xml_escape(true) + "\";");1808}1809if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {1810f->store_line("NSDocumentsFolderUsageDescription = \"" + p_preset->get("privacy/documents_folder_usage_description").operator String().xml_escape(true) + "\";");1811}1812if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {1813f->store_line("NSDownloadsFolderUsageDescription = \"" + p_preset->get("privacy/downloads_folder_usage_description").operator String().xml_escape(true) + "\";");1814}1815if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {1816f->store_line("NSNetworkVolumesUsageDescription = \"" + p_preset->get("privacy/network_volumes_usage_description").operator String().xml_escape(true) + "\";");1817}1818if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {1819f->store_line("NSRemovableVolumesUsageDescription = \"" + p_preset->get("privacy/removable_volumes_usage_description").operator String().xml_escape(true) + "\";");1820}1821f->store_line("NSHumanReadableCopyright = \"" + p_preset->get("application/copyright").operator String().xml_escape(true) + "\";");1822}18231824for (const String &lang : locales) {1825if (lang == "en") {1826continue;1827}18281829String fname = tmp_app_path_name + "/Contents/Resources/" + lang + ".lproj";1830tmp_app_dir->make_dir_recursive(fname);1831Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);1832f->store_line("/* Localized versions of Info.plist keys */");1833f->store_line("");18341835if (appnames.is_empty()) {1836domain->set_locale_override(lang);1837const String &name = domain->translate(project_name, String());1838if (name != project_name) {1839f->store_line("CFBundleDisplayName = \"" + name.xml_escape(true) + "\";");1840}1841} else if (appnames.has(lang)) {1842f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String().xml_escape(true) + "\";");1843}18441845if (microphone_usage_descriptions.has(lang)) {1846f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String().xml_escape(true) + "\";");1847}1848if (camera_usage_descriptions.has(lang)) {1849f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String().xml_escape(true) + "\";");1850}1851if (location_usage_descriptions.has(lang)) {1852f->store_line("NSLocationUsageDescription = \"" + location_usage_descriptions[lang].operator String().xml_escape(true) + "\";");1853}1854if (address_book_usage_descriptions.has(lang)) {1855f->store_line("NSContactsUsageDescription = \"" + address_book_usage_descriptions[lang].operator String().xml_escape(true) + "\";");1856}1857if (calendar_usage_descriptions.has(lang)) {1858f->store_line("NSCalendarsUsageDescription = \"" + calendar_usage_descriptions[lang].operator String().xml_escape(true) + "\";");1859}1860if (photos_library_usage_descriptions.has(lang)) {1861f->store_line("NSPhotoLibraryUsageDescription = \"" + photos_library_usage_descriptions[lang].operator String().xml_escape(true) + "\";");1862}1863if (desktop_folder_usage_descriptions.has(lang)) {1864f->store_line("NSDesktopFolderUsageDescription = \"" + desktop_folder_usage_descriptions[lang].operator String().xml_escape(true) + "\";");1865}1866if (documents_folder_usage_descriptions.has(lang)) {1867f->store_line("NSDocumentsFolderUsageDescription = \"" + documents_folder_usage_descriptions[lang].operator String().xml_escape(true) + "\";");1868}1869if (downloads_folder_usage_descriptions.has(lang)) {1870f->store_line("NSDownloadsFolderUsageDescription = \"" + downloads_folder_usage_descriptions[lang].operator String().xml_escape(true) + "\";");1871}1872if (network_volumes_usage_descriptions.has(lang)) {1873f->store_line("NSNetworkVolumesUsageDescription = \"" + network_volumes_usage_descriptions[lang].operator String().xml_escape(true) + "\";");1874}1875if (removable_volumes_usage_descriptions.has(lang)) {1876f->store_line("NSRemovableVolumesUsageDescription = \"" + removable_volumes_usage_descriptions[lang].operator String().xml_escape(true) + "\";");1877}1878if (copyrights.has(lang)) {1879f->store_line("NSHumanReadableCopyright = \"" + copyrights[lang].operator String().xml_escape(true) + "\";");1880}1881}1882}18831884TranslationServer::get_singleton()->remove_domain(domain_name);18851886// Now process our template.1887bool found_binary = false;18881889int export_angle = p_preset->get("application/export_angle");1890bool include_angle_libs = false;1891if (export_angle == 0) {1892include_angle_libs = String(get_project_setting(p_preset, "rendering/gl_compatibility/driver.macos")) == "opengl3_angle";1893} else if (export_angle == 1) {1894include_angle_libs = true;1895}18961897while (ret == UNZ_OK && err == OK) {1898// Get filename.1899unz_file_info info;1900char fname[16384];1901ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);1902if (ret != UNZ_OK) {1903break;1904}19051906String file = String::utf8(fname);19071908Vector<uint8_t> data;1909data.resize(info.uncompressed_size);19101911// Read.1912unzOpenCurrentFile(src_pkg_zip);1913unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());1914unzCloseCurrentFile(src_pkg_zip);19151916// Write.1917file = file.replace_first("macos_template.app/", "");19181919if (((info.external_fa >> 16L) & 0120000) == 0120000) {1920#ifndef UNIX_ENABLED1921add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Relative symlinks are not supported on this OS, the exported project might be broken!"));1922#endif1923// Handle symlinks in the archive.1924file = tmp_app_path_name.path_join(file);1925if (err == OK) {1926err = tmp_app_dir->make_dir_recursive(file.get_base_dir());1927if (err != OK) {1928add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));1929}1930}1931if (err == OK) {1932String lnk_data = String::utf8((const char *)data.ptr(), data.size());1933err = tmp_app_dir->create_link(lnk_data, file);1934if (err != OK) {1935add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not created symlink \"%s\" -> \"%s\"."), lnk_data, file));1936}1937print_verbose(vformat("ADDING SYMLINK %s => %s\n", file, lnk_data));1938}19391940ret = unzGoToNextFile(src_pkg_zip);1941continue; // next1942}19431944if (file == "Contents/Frameworks/libEGL.dylib") {1945if (!include_angle_libs) {1946ret = unzGoToNextFile(src_pkg_zip);1947continue; // skip1948}1949}19501951if (file == "Contents/Frameworks/libGLESv2.dylib") {1952if (!include_angle_libs) {1953ret = unzGoToNextFile(src_pkg_zip);1954continue; // skip1955}1956}19571958if (file == "Contents/Info.plist") {1959bool lg_icon_expored = false;1960String lg_icon = p_preset->get("application/liquid_glass_icon");1961#ifdef MACOS_ENABLED1962// Export liquid glass.1963if (!lg_icon.is_empty()) {1964lg_icon_expored = (_export_liquid_glass_icon(p_preset, tmp_app_path_name, lg_icon) == OK);1965}1966#endif1967// Modify plist.1968_fix_plist(p_preset, data, pkg_name, lg_icon_expored, lg_icon.get_file().get_basename());1969}19701971if (file == "Contents/Resources/PrivacyInfo.xcprivacy") {1972_fix_privacy_manifest(p_preset, data);1973}19741975if (file.begins_with("Contents/MacOS/godot_")) {1976if (file != "Contents/MacOS/" + binary_to_use) {1977ret = unzGoToNextFile(src_pkg_zip);1978continue; // skip1979}1980found_binary = true;1981file = "Contents/MacOS/" + pkg_name;1982}19831984if (file == "Contents/Resources/icon.icns") {1985// See if there is an icon.1986String icon_path;1987if (p_preset->get("application/icon") != "") {1988icon_path = p_preset->get("application/icon");1989} else if (get_project_setting(p_preset, "application/config/macos_native_icon") != "") {1990icon_path = get_project_setting(p_preset, "application/config/macos_native_icon");1991} else {1992icon_path = get_project_setting(p_preset, "application/config/icon");1993}19941995if (!icon_path.is_empty()) {1996if (icon_path.get_extension() == "icns") {1997Ref<FileAccess> icon = FileAccess::open(icon_path, FileAccess::READ);1998if (icon.is_valid()) {1999data.resize(icon->get_length());2000icon->get_buffer(&data.write[0], icon->get_length());2001}2002} else {2003Ref<Image> icon = _load_icon_or_splash_image(icon_path, &err);2004if (err == OK && icon.is_valid() && !icon->is_empty()) {2005_make_icon(p_preset, icon, data);2006}2007}2008}2009}20102011if (data.size() > 0) {2012print_verbose("ADDING: " + file + " size: " + itos(data.size()));20132014// Write it into our application bundle.2015file = tmp_app_path_name.path_join(file);2016if (err == OK) {2017err = tmp_app_dir->make_dir_recursive(file.get_base_dir());2018if (err != OK) {2019add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));2020}2021}2022if (err == OK) {2023Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);2024if (f.is_valid()) {2025f->store_buffer(data.ptr(), data.size());2026f.unref();2027if (is_executable(file)) {2028// chmod with 0755 if the file is executable.2029FileAccess::set_unix_permissions(file, 0755);2030#ifndef UNIX_ENABLED2031if (export_format == "app") {2032add_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()));2033}2034#endif2035}2036} else {2037add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not open \"%s\"."), file));2038err = ERR_CANT_CREATE;2039}2040}2041}20422043ret = unzGoToNextFile(src_pkg_zip);2044}20452046// We're done with our source zip.2047unzClose(src_pkg_zip);20482049if (!found_binary) {2050add_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));2051err = ERR_FILE_NOT_FOUND;2052}20532054// Save console wrapper.2055if (err == OK) {2056int con_scr = p_preset->get("debug/export_console_wrapper");2057if ((con_scr == 1 && p_debug) || (con_scr == 2)) {2058err = _export_debug_script(p_preset, pkg_name, tmp_app_path_name.get_file() + "/Contents/MacOS/" + pkg_name, scr_path);2059FileAccess::set_unix_permissions(scr_path, 0755);2060#ifndef UNIX_ENABLED2061if (export_format == "app") {2062add_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()));2063}2064#endif2065if (err != OK) {2066add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not create console wrapper."));2067}2068}2069}20702071if (err == OK) {2072if (ep.step(TTR("Making PKG"), 1)) {2073return ERR_SKIP;2074}20752076// See if we can code sign our new package.2077bool sign_enabled = (p_preset->get("codesign/codesign").operator int() > 0);2078bool ad_hoc = false;2079int codesign_tool = p_preset->get("codesign/codesign");2080switch (codesign_tool) {2081case 1: { // built-in ad-hoc2082ad_hoc = true;2083} break;2084case 2: { // "rcodesign"2085ad_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();2086} break;2087#ifdef MACOS_ENABLED2088case 3: { // "codesign"2089ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");2090} break;2091#endif2092default: {2093};2094}20952096String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";2097Vector<SharedObject> shared_objects;2098err = save_pack(p_preset, p_debug, pack_path, &shared_objects);20992100bool lib_validation = p_preset->get("codesign/entitlements/disable_library_validation");2101if (!shared_objects.is_empty() && sign_enabled && ad_hoc && !lib_validation) {2102add_message(EXPORT_MESSAGE_INFO, TTR("Entitlements Modified"), TTR("Ad-hoc signed applications require the 'Disable Library Validation' entitlement to load dynamic libraries."));2103lib_validation = true;2104}21052106if (!shared_objects.is_empty() && sign_enabled && codesign_tool == 2) {2107add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("'rcodesign' doesn't support signing applications with embedded dynamic libraries."));2108}21092110bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");2111String ent_path = p_preset->get("codesign/entitlements/custom_file");2112String hlp_ent_path = sandbox ? EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + "_helper.entitlements") : ent_path;2113if (sign_enabled && (ent_path.is_empty())) {2114ent_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".entitlements");21152116Ref<FileAccess> ent_f = FileAccess::open(ent_path, FileAccess::WRITE);2117if (ent_f.is_valid()) {2118ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");2119ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");2120ent_f->store_line("<plist version=\"1.0\">");2121ent_f->store_line("<dict>");2122if (ClassDB::class_exists("CSharpScript")) {2123// These entitlements are required to run managed code, and are always enabled in Mono builds.2124ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");2125ent_f->store_line("<true/>");2126ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");2127ent_f->store_line("<true/>");2128ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");2129ent_f->store_line("<true/>");2130} else {2131if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) {2132ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");2133ent_f->store_line("<true/>");2134}2135if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) {2136ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");2137ent_f->store_line("<true/>");2138}2139if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) {2140ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");2141ent_f->store_line("<true/>");2142}2143}21442145if (lib_validation) {2146ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>");2147ent_f->store_line("<true/>");2148}2149if ((bool)p_preset->get("codesign/entitlements/audio_input")) {2150ent_f->store_line("<key>com.apple.security.device.audio-input</key>");2151ent_f->store_line("<true/>");2152}2153if ((bool)p_preset->get("codesign/entitlements/camera")) {2154ent_f->store_line("<key>com.apple.security.device.camera</key>");2155ent_f->store_line("<true/>");2156}2157if ((bool)p_preset->get("codesign/entitlements/location")) {2158ent_f->store_line("<key>com.apple.security.personal-information.location</key>");2159ent_f->store_line("<true/>");2160}2161if ((bool)p_preset->get("codesign/entitlements/address_book")) {2162ent_f->store_line("<key>com.apple.security.personal-information.addressbook</key>");2163ent_f->store_line("<true/>");2164}2165if ((bool)p_preset->get("codesign/entitlements/calendars")) {2166ent_f->store_line("<key>com.apple.security.personal-information.calendars</key>");2167ent_f->store_line("<true/>");2168}2169if ((bool)p_preset->get("codesign/entitlements/photos_library")) {2170ent_f->store_line("<key>com.apple.security.personal-information.photos-library</key>");2171ent_f->store_line("<true/>");2172}2173if ((bool)p_preset->get("codesign/entitlements/apple_events")) {2174ent_f->store_line("<key>com.apple.security.automation.apple-events</key>");2175ent_f->store_line("<true/>");2176}2177if ((bool)p_preset->get("codesign/entitlements/debugging")) {2178ent_f->store_line("<key>com.apple.security.get-task-allow</key>");2179ent_f->store_line("<true/>");2180}21812182int dist_type = p_preset->get("export/distribution_type");2183if (dist_type == 2) {2184String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE);2185String teamid = p_preset->get("codesign/apple_team_id");2186String bid = p_preset->get("application/bundle_identifier");2187if (!pprof.is_empty() && !teamid.is_empty()) {2188ent_f->store_line("<key>com.apple.developer.team-identifier</key>");2189ent_f->store_line("<string>" + teamid + "</string>");2190ent_f->store_line("<key>com.apple.application-identifier</key>");2191ent_f->store_line("<string>" + teamid + "." + bid + "</string>");2192}2193}21942195if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) {2196ent_f->store_line("<key>com.apple.security.app-sandbox</key>");2197ent_f->store_line("<true/>");21982199if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) {2200ent_f->store_line("<key>com.apple.security.network.server</key>");2201ent_f->store_line("<true/>");2202}2203if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) {2204ent_f->store_line("<key>com.apple.security.network.client</key>");2205ent_f->store_line("<true/>");2206}2207if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) {2208ent_f->store_line("<key>com.apple.security.device.usb</key>");2209ent_f->store_line("<true/>");2210}2211if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) {2212ent_f->store_line("<key>com.apple.security.device.bluetooth</key>");2213ent_f->store_line("<true/>");2214}2215if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) {2216ent_f->store_line("<key>com.apple.security.files.downloads.read-only</key>");2217ent_f->store_line("<true/>");2218}2219if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) {2220ent_f->store_line("<key>com.apple.security.files.downloads.read-write</key>");2221ent_f->store_line("<true/>");2222}2223if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) {2224ent_f->store_line("<key>com.apple.security.files.pictures.read-only</key>");2225ent_f->store_line("<true/>");2226}2227if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) {2228ent_f->store_line("<key>com.apple.security.files.pictures.read-write</key>");2229ent_f->store_line("<true/>");2230}2231if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) {2232ent_f->store_line("<key>com.apple.security.files.music.read-only</key>");2233ent_f->store_line("<true/>");2234}2235if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) {2236ent_f->store_line("<key>com.apple.security.files.music.read-write</key>");2237ent_f->store_line("<true/>");2238}2239if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) {2240ent_f->store_line("<key>com.apple.security.files.movies.read-only</key>");2241ent_f->store_line("<true/>");2242}2243if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) {2244ent_f->store_line("<key>com.apple.security.files.movies.read-write</key>");2245ent_f->store_line("<true/>");2246}2247if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 1) {2248ent_f->store_line("<key>com.apple.security.files.user-selected.read-only</key>");2249ent_f->store_line("<true/>");2250}2251if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 2) {2252ent_f->store_line("<key>com.apple.security.files.user-selected.read-write</key>");2253ent_f->store_line("<true/>");2254}2255}22562257const String &additional_entitlements = p_preset->get("codesign/entitlements/additional");2258if (!additional_entitlements.is_empty()) {2259ent_f->store_line(additional_entitlements);2260}22612262ent_f->store_line("</dict>");2263ent_f->store_line("</plist>");2264} else {2265add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create entitlements file."));2266err = ERR_CANT_CREATE;2267}22682269if ((err == OK) && sandbox && (helpers.size() > 0 || shared_objects.size() > 0)) {2270ent_f = FileAccess::open(hlp_ent_path, FileAccess::WRITE);2271if (ent_f.is_valid()) {2272ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");2273ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");2274ent_f->store_line("<plist version=\"1.0\">");2275ent_f->store_line("<dict>");2276ent_f->store_line("<key>com.apple.security.app-sandbox</key>");2277ent_f->store_line("<true/>");2278ent_f->store_line("<key>com.apple.security.inherit</key>");2279ent_f->store_line("<true/>");2280ent_f->store_line("</dict>");2281ent_f->store_line("</plist>");2282} else {2283add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create helper entitlements file."));2284err = ERR_CANT_CREATE;2285}2286}2287}22882289if ((err == OK) && helpers.size() > 0) {2290Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);2291for (int i = 0; i < helpers.size(); i++) {2292String hlp_path = helpers[i];2293err = da->copy(hlp_path, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file());2294if (err == OK && sign_enabled) {2295_code_sign(p_preset, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), hlp_ent_path, false, true);2296}2297FileAccess::set_unix_permissions(tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), 0755);2298#ifndef UNIX_ENABLED2299if (export_format == "app") {2300add_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()));2301}2302#endif2303}2304}23052306if (err == OK) {2307Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);2308for (int i = 0; i < shared_objects.size(); i++) {2309String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path);2310if (shared_objects[i].target.is_empty()) {2311String path_in_app = tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file();2312err = _copy_and_sign_files(da, src_path, path_in_app, sign_enabled, p_preset, ent_path, hlp_ent_path, true, sandbox);2313} else {2314String path_in_app = tmp_app_path_name.path_join(shared_objects[i].target);2315tmp_app_dir->make_dir_recursive(path_in_app);2316err = _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);2317}2318if (err != OK) {2319break;2320}2321}23222323Vector<Ref<EditorExportPlugin>> export_plugins{ EditorExport::get_singleton()->get_export_plugins() };2324for (int i = 0; i < export_plugins.size(); ++i) {2325err = _export_macos_plugins_for(export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path, hlp_ent_path, sandbox);2326if (err != OK) {2327break;2328}2329}2330}23312332if (err == OK && sign_enabled) {2333int dist_type = p_preset->get("export/distribution_type");2334if (dist_type == 2) {2335String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE).operator String();2336if (!pprof.is_empty()) {2337Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);2338err = da->copy(pprof, tmp_app_path_name + "/Contents/embedded.provisionprofile");2339}2340}23412342if (ep.step(TTR("Code signing bundle"), 2)) {2343return ERR_SKIP;2344}2345_code_sign(p_preset, tmp_app_path_name, ent_path, true, false);2346}23472348String noto_path = p_path;2349bool noto_enabled = (p_preset->get("notarization/notarization").operator int() > 0);2350if (export_format == "dmg") {2351// Create a DMG.2352if (err == OK) {2353if (ep.step(TTR("Making DMG"), 3)) {2354return ERR_SKIP;2355}2356err = _create_dmg(p_path, pkg_name, tmp_base_path_name);2357}2358// Sign DMG.2359if (err == OK && sign_enabled && !ad_hoc) {2360if (ep.step(TTR("Code signing DMG"), 3)) {2361return ERR_SKIP;2362}2363_code_sign(p_preset, p_path, ent_path, false, false);2364}2365} else if (export_format == "pkg") {2366// Create a Installer.2367if (err == OK) {2368if (ep.step(TTR("Making PKG installer"), 3)) {2369return ERR_SKIP;2370}2371err = _create_pkg(p_preset, p_path, tmp_app_path_name);2372}2373} else if (export_format == "zip") {2374// Create ZIP.2375if (err == OK) {2376if (ep.step(TTR("Making ZIP"), 3)) {2377return ERR_SKIP;2378}2379if (FileAccess::exists(p_path)) {2380OS::get_singleton()->move_to_trash(p_path);2381}23822383Ref<FileAccess> io_fa_dst;2384zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);2385zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);23862387zip_folder_recursive(zip, tmp_base_path_name, "", pkg_name);23882389zipClose(zip, nullptr);2390}2391} else if (export_format == "app" && noto_enabled) {2392// Create temporary ZIP.2393if (err == OK) {2394noto_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".zip");23952396if (ep.step(TTR("Making ZIP"), 3)) {2397return ERR_SKIP;2398}2399if (FileAccess::exists(noto_path)) {2400OS::get_singleton()->move_to_trash(noto_path);2401}24022403Ref<FileAccess> io_fa_dst;2404zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);2405zipFile zip = zipOpen2(noto_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);24062407zip_folder_recursive(zip, tmp_base_path_name, tmp_app_dir_name, pkg_name);24082409zipClose(zip, nullptr);2410}2411}24122413if (err == OK && noto_enabled) {2414if (export_format == "pkg") {2415add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("Notarization requires the app to be archived first, select the DMG or ZIP export format instead."));2416} else {2417if (ep.step(TTR("Sending archive for notarization"), 4)) {2418return ERR_SKIP;2419}2420err = _notarize(p_preset, noto_path);2421}2422}24232424if (FileAccess::exists(ent_path)) {2425print_verbose("entitlements:\n" + FileAccess::get_file_as_string(ent_path));2426}24272428if (FileAccess::exists(hlp_ent_path)) {2429print_verbose("helper entitlements:\n" + FileAccess::get_file_as_string(hlp_ent_path));2430}24312432// Clean up temporary entitlements files.2433if (FileAccess::exists(hlp_ent_path)) {2434DirAccess::remove_file_or_error(hlp_ent_path);2435}24362437// Clean up temporary .app dir and generated entitlements.2438if ((String)(p_preset->get("codesign/entitlements/custom_file")) == "") {2439tmp_app_dir->remove(ent_path);2440}2441if (export_format != "app") {2442if (tmp_app_dir->change_dir(tmp_base_path_name) == OK) {2443tmp_app_dir->erase_contents_recursive();2444tmp_app_dir->change_dir("..");2445tmp_app_dir->remove(pkg_name);2446}2447} else if (noto_path != p_path) {2448if (FileAccess::exists(noto_path)) {2449DirAccess::remove_file_or_error(noto_path);2450}2451}2452}24532454return err;2455}24562457bool EditorExportPlatformMacOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {2458String err;2459// Look for export templates (official templates first, then custom).2460bool dvalid = exists_export_template("macos.zip", &err);2461bool rvalid = dvalid; // Both in the same ZIP.24622463if (p_preset->get("custom_template/debug") != "") {2464dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));2465if (!dvalid) {2466err += TTR("Custom debug template not found.") + "\n";2467}2468}2469if (p_preset->get("custom_template/release") != "") {2470rvalid = FileAccess::exists(p_preset->get("custom_template/release"));2471if (!rvalid) {2472err += TTR("Custom release template not found.") + "\n";2473}2474}24752476bool valid = dvalid || rvalid;2477r_missing_templates = !valid;24782479// Check the texture formats, which vary depending on the target architecture.2480String architecture = p_preset->get("binary_format/architecture");2481if (architecture == "universal" || architecture == "x86_64") {2482if (!ResourceImporterTextureSettings::should_import_s3tc_bptc()) {2483err += 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";2484valid = false;2485}2486}2487if (architecture == "universal" || architecture == "arm64") {2488if (!ResourceImporterTextureSettings::should_import_etc2_astc()) {2489err += 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";2490valid = false;2491}2492}2493if (architecture != "universal" && architecture != "x86_64" && architecture != "arm64") {2494ERR_PRINT("Invalid architecture");2495}24962497if (!err.is_empty()) {2498r_error = err;2499}2500return valid;2501}25022503bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {2504String err;2505bool valid = true;25062507int dist_type = p_preset->get("export/distribution_type");2508bool ad_hoc = false;2509int codesign_tool = p_preset->get("codesign/codesign");2510int notary_tool = p_preset->get("notarization/notarization");2511switch (codesign_tool) {2512case 1: { // built-in ad-hoc2513ad_hoc = true;2514} break;2515case 2: { // "rcodesign"2516ad_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();2517} break;2518#ifdef MACOS_ENABLED2519case 3: { // "codesign"2520ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");2521} break;2522#endif2523default: {2524};2525}25262527const String &additional_plist_content = p_preset->get("application/additional_plist_content");2528if (!additional_plist_content.is_empty()) {2529const String &plist = vformat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"2530"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"2531"<plist version=\"1.0\">"2532"<dict>\n"2533"%s\n"2534"</dict>\n"2535"</plist>\n",2536additional_plist_content);25372538String plist_err;2539Ref<PList> plist_parser;2540plist_parser.instantiate();2541if (!plist_parser->load_string(plist, plist_err)) {2542err += TTR("Invalid additional PList content: ") + plist_err + "\n";2543valid = false;2544}2545}25462547List<ExportOption> options;2548get_export_options(&options);2549for (const EditorExportPlatform::ExportOption &E : options) {2550if (get_export_option_visibility(p_preset.ptr(), E.option.name)) {2551String warn = get_export_option_warning(p_preset.ptr(), E.option.name);2552if (!warn.is_empty()) {2553err += warn + "\n";2554if (E.required) {2555valid = false;2556}2557}2558}2559}25602561if (dist_type != 2) {2562if (notary_tool > 0) {2563if (notary_tool == 2 || notary_tool == 3) {2564if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {2565err += TTR("Notarization: Xcode command line tools are not installed.") + "\n";2566valid = false;2567}2568} else if (notary_tool == 1) {2569String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();2570if (rcodesign.is_empty()) {2571err += TTR("Notarization: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";2572valid = false;2573}2574}2575} else {2576err += TTR("Warning: Notarization is disabled. The exported project will be blocked by Gatekeeper if it's downloaded from an unknown source.") + "\n";2577if (codesign_tool == 0) {2578err += TTR("Code signing is disabled. The exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n";2579}2580}2581}25822583if (codesign_tool > 0) {2584if (ad_hoc) {2585err += TTR("Code signing: Using ad-hoc signature. The exported project will be blocked by Gatekeeper") + "\n";2586}2587if (codesign_tool == 3) {2588if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {2589err += TTR("Code signing: Xcode command line tools are not installed.") + "\n";2590valid = false;2591}2592} else if (codesign_tool == 2) {2593String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();2594if (rcodesign.is_empty()) {2595err += TTR("Code signing: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";2596valid = false;2597}2598}2599}26002601if (!err.is_empty()) {2602r_error = err;2603}2604return valid;2605}26062607Ref<Texture2D> EditorExportPlatformMacOS::get_run_icon() const {2608return run_icon;2609}26102611bool EditorExportPlatformMacOS::poll_export() {2612Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_runnable_preset_for_platform(this);26132614int prev = menu_options;2615menu_options = (preset.is_valid() && preset->get("ssh_remote_deploy/enabled").operator bool());2616if (ssh_pid != 0 || !cleanup_commands.is_empty()) {2617if (menu_options == 0) {2618cleanup();2619} else {2620menu_options += 1;2621}2622}2623return menu_options != prev;2624}26252626Ref<Texture2D> EditorExportPlatformMacOS::get_option_icon(int p_index) const {2627if (p_index == 1) {2628return stop_icon;2629} else {2630return EditorExportPlatform::get_option_icon(p_index);2631}2632}26332634int EditorExportPlatformMacOS::get_options_count() const {2635return menu_options;2636}26372638String EditorExportPlatformMacOS::get_option_label(int p_index) const {2639return (p_index) ? TTR("Stop and uninstall") : TTR("Run on remote macOS system");2640}26412642String EditorExportPlatformMacOS::get_option_tooltip(int p_index) const {2643return (p_index) ? TTR("Stop and uninstall running project from the remote system") : TTR("Run exported project on remote macOS system");2644}26452646void EditorExportPlatformMacOS::cleanup() {2647if (ssh_pid != 0 && OS::get_singleton()->is_process_running(ssh_pid)) {2648print_line("Terminating connection...");2649OS::get_singleton()->kill(ssh_pid);2650OS::get_singleton()->delay_usec(1000);2651}26522653if (!cleanup_commands.is_empty()) {2654print_line("Stopping and deleting previous version...");2655for (const SSHCleanupCommand &cmd : cleanup_commands) {2656if (cmd.wait) {2657ssh_run_on_remote(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);2658} else {2659ssh_run_on_remote_no_wait(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);2660}2661}2662}2663ssh_pid = 0;2664cleanup_commands.clear();2665}26662667Error EditorExportPlatformMacOS::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) {2668cleanup();2669if (p_device) { // Stop command, cleanup only.2670return OK;2671}26722673EditorProgress ep("run", TTR("Running..."), 5);26742675const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("macos");2676Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);2677if (!da->dir_exists(dest)) {2678Error err = da->make_dir_recursive(dest);2679if (err != OK) {2680EditorNode::get_singleton()->show_warning(TTR("Could not create temp directory:") + "\n" + dest);2681return err;2682}2683}26842685String pkg_name;2686if (String(get_project_setting(p_preset, "application/config/name")) != "") {2687pkg_name = String(get_project_setting(p_preset, "application/config/name"));2688} else {2689pkg_name = "Unnamed";2690}2691pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);26922693String host = p_preset->get("ssh_remote_deploy/host").operator String();2694String port = p_preset->get("ssh_remote_deploy/port").operator String();2695if (port.is_empty()) {2696port = "22";2697}2698Vector<String> extra_args_ssh = p_preset->get("ssh_remote_deploy/extra_args_ssh").operator String().split(" ", false);2699Vector<String> extra_args_scp = p_preset->get("ssh_remote_deploy/extra_args_scp").operator String().split(" ", false);27002701const String basepath = dest.path_join("tmp_macos_export");27022703#define CLEANUP_AND_RETURN(m_err) \2704{ \2705if (da->file_exists(basepath + ".zip")) { \2706da->remove(basepath + ".zip"); \2707} \2708if (da->file_exists(basepath + "_start.sh")) { \2709da->remove(basepath + "_start.sh"); \2710} \2711if (da->file_exists(basepath + "_clean.sh")) { \2712da->remove(basepath + "_clean.sh"); \2713} \2714return m_err; \2715} \2716((void)0)27172718if (ep.step(TTR("Exporting project..."), 1)) {2719return ERR_SKIP;2720}2721Error err = export_project(p_preset, true, basepath + ".zip", p_debug_flags);2722if (err != OK) {2723DirAccess::remove_file_or_error(basepath + ".zip");2724return err;2725}27262727String cmd_args;2728{2729Vector<String> cmd_args_list = gen_export_flags(p_debug_flags);2730for (int i = 0; i < cmd_args_list.size(); i++) {2731if (i != 0) {2732cmd_args += " ";2733}2734cmd_args += cmd_args_list[i];2735}2736}27372738const bool use_remote = p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG) || p_debug_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT);2739int dbg_port = EDITOR_GET("network/debug/remote_port");27402741print_line("Creating temporary directory...");2742ep.step(TTR("Creating temporary directory..."), 2);2743String temp_dir;2744err = ssh_run_on_remote(host, port, extra_args_ssh, "mktemp -d", &temp_dir);2745if (err != OK || temp_dir.is_empty()) {2746CLEANUP_AND_RETURN(err);2747}27482749print_line("Uploading archive...");2750ep.step(TTR("Uploading archive..."), 3);2751err = ssh_push_to_remote(host, port, extra_args_scp, basepath + ".zip", temp_dir);2752if (err != OK) {2753CLEANUP_AND_RETURN(err);2754}27552756{2757String run_script = p_preset->get("ssh_remote_deploy/run_script");2758run_script = run_script.replace("{temp_dir}", temp_dir);2759run_script = run_script.replace("{archive_name}", basepath.get_file() + ".zip");2760run_script = run_script.replace("{exe_name}", pkg_name);2761run_script = run_script.replace("{cmd_args}", cmd_args);27622763Ref<FileAccess> f = FileAccess::open(basepath + "_start.sh", FileAccess::WRITE);2764if (f.is_null()) {2765CLEANUP_AND_RETURN(err);2766}27672768f->store_string(run_script);2769}27702771{2772String clean_script = p_preset->get("ssh_remote_deploy/cleanup_script");2773clean_script = clean_script.replace("{temp_dir}", temp_dir);2774clean_script = clean_script.replace("{archive_name}", basepath.get_file() + ".zip");2775clean_script = clean_script.replace("{exe_name}", pkg_name);2776clean_script = clean_script.replace("{cmd_args}", cmd_args);27772778Ref<FileAccess> f = FileAccess::open(basepath + "_clean.sh", FileAccess::WRITE);2779if (f.is_null()) {2780CLEANUP_AND_RETURN(err);2781}27822783f->store_string(clean_script);2784}27852786print_line("Uploading scripts...");2787ep.step(TTR("Uploading scripts..."), 4);2788err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_start.sh", temp_dir);2789if (err != OK) {2790CLEANUP_AND_RETURN(err);2791}2792err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_start.sh"));2793if (err != OK || temp_dir.is_empty()) {2794CLEANUP_AND_RETURN(err);2795}2796err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_clean.sh", temp_dir);2797if (err != OK) {2798CLEANUP_AND_RETURN(err);2799}2800err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh"));2801if (err != OK || temp_dir.is_empty()) {2802CLEANUP_AND_RETURN(err);2803}28042805print_line("Starting project...");2806ep.step(TTR("Starting project..."), 5);2807err = 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);2808if (err != OK) {2809CLEANUP_AND_RETURN(err);2810}28112812cleanup_commands.clear();2813cleanup_commands.push_back(SSHCleanupCommand(host, port, extra_args_ssh, vformat("\"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh")));28142815print_line("Project started.");28162817CLEANUP_AND_RETURN(OK);2818#undef CLEANUP_AND_RETURN2819}28202821void EditorExportPlatformMacOS::initialize() {2822if (EditorNode::get_singleton()) {2823Ref<Image> img = memnew(Image);2824const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);28252826ImageLoaderSVG::create_image_from_string(img, _macos_logo_svg, EDSCALE, upsample, false);2827logo = ImageTexture::create_from_image(img);28282829ImageLoaderSVG::create_image_from_string(img, _macos_run_icon_svg, EDSCALE, upsample, false);2830run_icon = ImageTexture::create_from_image(img);28312832Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();2833if (theme.is_valid()) {2834stop_icon = theme->get_icon(SNAME("Stop"), EditorStringName(EditorIcons));2835} else {2836stop_icon.instantiate();2837}2838}2839}284028412842