Path: blob/master/platform/macos/export/export_plugin.cpp
10278 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.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->get("shader_baker/enabled")) {66r_features->push_back("shader_baker");67}6869if (architecture == "universal") {70r_features->push_back("x86_64");71r_features->push_back("arm64");72}73}7475String EditorExportPlatformMacOS::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const {76if (p_preset) {77int dist_type = p_preset->get("export/distribution_type");78bool ad_hoc = false;79int codesign_tool = p_preset->get("codesign/codesign");80int notary_tool = p_preset->get("notarization/notarization");81switch (codesign_tool) {82case 1: { // built-in ad-hoc83ad_hoc = true;84} break;85case 2: { // "rcodesign"86ad_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();87} break;88#ifdef MACOS_ENABLED89case 3: { // "codesign"90ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");91} break;92#endif93default: {94};95}9697if (p_name == "application/bundle_identifier") {98String identifier = p_preset->get("application/bundle_identifier");99String pn_err;100if (!is_package_name_valid(identifier, &pn_err)) {101return TTR("Invalid bundle identifier:") + " " + pn_err;102}103}104105if (p_name == "shader_baker/enabled" && bool(p_preset->get("shader_baker/enabled"))) {106String export_renderer = GLOBAL_GET("rendering/renderer/rendering_method");107if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {108return TTR("\"Shader Baker\" is not supported when using the Compatibility renderer.");109} else if (OS::get_singleton()->get_current_rendering_method() != export_renderer) {110return 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);111}112}113114if (p_name == "codesign/certificate_file" || p_name == "codesign/certificate_password" || p_name == "codesign/identity") {115if (dist_type == 2) {116if (ad_hoc) {117return TTR("App Store distribution with ad-hoc code signing is not supported.");118}119} else if (notary_tool > 0 && ad_hoc) {120return TTR("Notarization with an ad-hoc signature is not supported.");121}122}123124if (p_name == "codesign/apple_team_id") {125String team_id = p_preset->get("codesign/apple_team_id");126if (team_id.is_empty()) {127if (dist_type == 2) {128return TTR("Apple Team ID is required for App Store distribution.");129} else if (notary_tool > 0) {130return TTR("Apple Team ID is required for notarization.");131}132}133}134135if (p_name == "codesign/provisioning_profile" && dist_type == 2) {136String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE);137if (pprof.is_empty()) {138return TTR("Provisioning profile is required for App Store distribution.");139}140}141142if (p_name == "codesign/installer_identity" && dist_type == 2) {143String ident = p_preset->get("codesign/installer_identity");144if (ident.is_empty()) {145return TTR("Installer signing identity is required for App Store distribution.");146}147}148149if (p_name == "codesign/entitlements/app_sandbox/enabled" && dist_type == 2) {150bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");151if (!sandbox) {152return TTR("App sandbox is required for App Store distribution.");153}154}155156if (p_name == "codesign/codesign") {157if (dist_type == 2) {158if (codesign_tool == 2 && ClassDB::class_exists("CSharpScript")) {159return TTR("'rcodesign' doesn't support signing applications with embedded dynamic libraries (GDExtension or .NET).");160}161if (codesign_tool == 0) {162return TTR("Code signing is required for App Store distribution.");163}164if (codesign_tool == 1) {165return TTR("App Store distribution with ad-hoc code signing is not supported.");166}167} else if (notary_tool > 0) {168if (codesign_tool == 0) {169return TTR("Code signing is required for notarization.");170}171if (codesign_tool == 1) {172return TTR("Notarization with an ad-hoc signature is not supported.");173}174}175}176177if (notary_tool == 2 || notary_tool == 3) {178if (p_name == "notarization/apple_id_name" || p_name == "notarization/api_uuid") {179String apple_id = p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID);180String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);181if (apple_id.is_empty() && api_uuid.is_empty()) {182return TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified.");183}184if (!apple_id.is_empty() && !api_uuid.is_empty()) {185return TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.");186}187}188if (p_name == "notarization/apple_id_password") {189String apple_id = p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID);190String apple_pass = p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS);191if (!apple_id.is_empty() && apple_pass.is_empty()) {192return TTR("Apple ID password not specified.");193}194}195if (p_name == "notarization/api_key_id") {196String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);197String api_key = p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID);198if (!api_uuid.is_empty() && api_key.is_empty()) {199return TTR("App Store Connect API key ID not specified.");200}201}202} else if (notary_tool == 1) {203if (p_name == "notarization/api_uuid") {204String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);205if (api_uuid.is_empty()) {206return TTR("App Store Connect issuer ID name not specified.");207}208}209if (p_name == "notarization/api_key_id") {210String api_key = p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID);211if (api_key.is_empty()) {212return TTR("App Store Connect API key ID not specified.");213}214}215}216217if (codesign_tool > 0) {218if (p_name == "privacy/microphone_usage_description") {219String discr = p_preset->get("privacy/microphone_usage_description");220bool enabled = p_preset->get("codesign/entitlements/audio_input");221if (enabled && discr.is_empty()) {222return TTR("Microphone access is enabled, but usage description is not specified.");223}224}225if (p_name == "privacy/camera_usage_description") {226String discr = p_preset->get("privacy/camera_usage_description");227bool enabled = p_preset->get("codesign/entitlements/camera");228if (enabled && discr.is_empty()) {229return TTR("Camera access is enabled, but usage description is not specified.");230}231}232if (p_name == "privacy/location_usage_description") {233String discr = p_preset->get("privacy/location_usage_description");234bool enabled = p_preset->get("codesign/entitlements/location");235if (enabled && discr.is_empty()) {236return TTR("Location information access is enabled, but usage description is not specified.");237}238}239if (p_name == "privacy/address_book_usage_description") {240String discr = p_preset->get("privacy/address_book_usage_description");241bool enabled = p_preset->get("codesign/entitlements/address_book");242if (enabled && discr.is_empty()) {243return TTR("Address book access is enabled, but usage description is not specified.");244}245}246if (p_name == "privacy/calendar_usage_description") {247String discr = p_preset->get("privacy/calendar_usage_description");248bool enabled = p_preset->get("codesign/entitlements/calendars");249if (enabled && discr.is_empty()) {250return TTR("Calendar access is enabled, but usage description is not specified.");251}252}253if (p_name == "privacy/photos_library_usage_description") {254String discr = p_preset->get("privacy/photos_library_usage_description");255bool enabled = p_preset->get("codesign/entitlements/photos_library");256if (enabled && discr.is_empty()) {257return TTR("Photo library access is enabled, but usage description is not specified.");258}259}260}261}262return String();263}264265bool EditorExportPlatformMacOS::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {266// Hide irrelevant code signing options.267if (p_preset) {268int codesign_tool = p_preset->get("codesign/codesign");269switch (codesign_tool) {270case 1: { // built-in ad-hoc271if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options" || p_option == "codesign/team_id") {272return false;273}274} break;275case 2: { // "rcodesign"276if (p_option == "codesign/identity") {277return false;278}279} break;280#ifdef MACOS_ENABLED281case 3: { // "codesign"282if (p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password") {283return false;284}285} break;286#endif287default: { // disabled288if (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") {289return false;290}291} break;292}293294// Distribution type.295int dist_type = p_preset->get("export/distribution_type");296if (dist_type != 2 && p_option == "codesign/installer_identity") {297return false;298}299300if (dist_type == 2 && p_option.begins_with("notarization/")) {301return false;302}303304if (dist_type != 2 && p_option == "codesign/provisioning_profile") {305return false;306}307308String custom_prof = p_preset->get("codesign/entitlements/custom_file");309if (!custom_prof.is_empty() && p_option != "codesign/entitlements/custom_file" && p_option.begins_with("codesign/entitlements/")) {310return false;311}312313// Hide sandbox entitlements.314bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");315if (!sandbox && p_option != "codesign/entitlements/app_sandbox/enabled" && p_option.begins_with("codesign/entitlements/app_sandbox/")) {316return false;317}318319// Hide SSH options.320bool ssh = p_preset->get("ssh_remote_deploy/enabled");321if (!ssh && p_option != "ssh_remote_deploy/enabled" && p_option.begins_with("ssh_remote_deploy/")) {322return false;323}324325// Hide irrelevant notarization options.326int notary_tool = p_preset->get("notarization/notarization");327switch (notary_tool) {328case 1: { // "rcodesign"329if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password") {330return false;331}332} break;333case 2: { // "notarytool"334// All options are visible.335} break;336default: { // disabled337if (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") {338return false;339}340} break;341}342343bool advanced_options_enabled = p_preset->are_advanced_options_enabled();344if (p_option.begins_with("privacy") ||345p_option == "codesign/entitlements/additional" ||346p_option == "custom_template/debug" ||347p_option == "custom_template/release" ||348p_option == "application/additional_plist_content" ||349p_option == "application/export_angle" ||350p_option == "application/icon_interpolation" ||351p_option == "application/signature" ||352p_option == "display/high_res" ||353p_option == "xcode/platform_build" ||354p_option == "xcode/sdk_build" ||355p_option == "xcode/sdk_name" ||356p_option == "xcode/sdk_version" ||357p_option == "xcode/xcode_build" ||358p_option == "xcode/xcode_version") {359return advanced_options_enabled;360}361}362363// These entitlements are required to run managed code, and are always enabled in Mono builds.364if (ClassDB::class_exists("CSharpScript")) {365if (p_option == "codesign/entitlements/allow_jit_code_execution" || p_option == "codesign/entitlements/allow_unsigned_executable_memory" || p_option == "codesign/entitlements/allow_dyld_environment_variables") {366return false;367}368}369370// Hide unsupported .NET embedding option.371if (p_option == "dotnet/embed_build_outputs") {372return false;373}374375return true;376}377378List<String> EditorExportPlatformMacOS::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {379List<String> list;380381if (p_preset.is_valid()) {382int dist_type = p_preset->get("export/distribution_type");383if (dist_type == 0) {384#ifdef MACOS_ENABLED385list.push_back("dmg");386#endif387list.push_back("zip");388list.push_back("app");389} else if (dist_type == 1) {390#ifdef MACOS_ENABLED391list.push_back("dmg");392#endif393list.push_back("zip");394list.push_back("app");395} else if (dist_type == 2) {396#ifdef MACOS_ENABLED397list.push_back("pkg");398#endif399}400}401402return list;403}404405struct DataCollectionInfo {406String prop_name;407String type_name;408};409410static const DataCollectionInfo data_collect_type_info[] = {411{ "name", "NSPrivacyCollectedDataTypeName" },412{ "email_address", "NSPrivacyCollectedDataTypeEmailAddress" },413{ "phone_number", "NSPrivacyCollectedDataTypePhoneNumber" },414{ "physical_address", "NSPrivacyCollectedDataTypePhysicalAddress" },415{ "other_contact_info", "NSPrivacyCollectedDataTypeOtherUserContactInfo" },416{ "health", "NSPrivacyCollectedDataTypeHealth" },417{ "fitness", "NSPrivacyCollectedDataTypeFitness" },418{ "payment_info", "NSPrivacyCollectedDataTypePaymentInfo" },419{ "credit_info", "NSPrivacyCollectedDataTypeCreditInfo" },420{ "other_financial_info", "NSPrivacyCollectedDataTypeOtherFinancialInfo" },421{ "precise_location", "NSPrivacyCollectedDataTypePreciseLocation" },422{ "coarse_location", "NSPrivacyCollectedDataTypeCoarseLocation" },423{ "sensitive_info", "NSPrivacyCollectedDataTypeSensitiveInfo" },424{ "contacts", "NSPrivacyCollectedDataTypeContacts" },425{ "emails_or_text_messages", "NSPrivacyCollectedDataTypeEmailsOrTextMessages" },426{ "photos_or_videos", "NSPrivacyCollectedDataTypePhotosorVideos" },427{ "audio_data", "NSPrivacyCollectedDataTypeAudioData" },428{ "gameplay_content", "NSPrivacyCollectedDataTypeGameplayContent" },429{ "customer_support", "NSPrivacyCollectedDataTypeCustomerSupport" },430{ "other_user_content", "NSPrivacyCollectedDataTypeOtherUserContent" },431{ "browsing_history", "NSPrivacyCollectedDataTypeBrowsingHistory" },432{ "search_hhistory", "NSPrivacyCollectedDataTypeSearchHistory" },433{ "user_id", "NSPrivacyCollectedDataTypeUserID" },434{ "device_id", "NSPrivacyCollectedDataTypeDeviceID" },435{ "purchase_history", "NSPrivacyCollectedDataTypePurchaseHistory" },436{ "product_interaction", "NSPrivacyCollectedDataTypeProductInteraction" },437{ "advertising_data", "NSPrivacyCollectedDataTypeAdvertisingData" },438{ "other_usage_data", "NSPrivacyCollectedDataTypeOtherUsageData" },439{ "crash_data", "NSPrivacyCollectedDataTypeCrashData" },440{ "performance_data", "NSPrivacyCollectedDataTypePerformanceData" },441{ "other_diagnostic_data", "NSPrivacyCollectedDataTypeOtherDiagnosticData" },442{ "environment_scanning", "NSPrivacyCollectedDataTypeEnvironmentScanning" },443{ "hands", "NSPrivacyCollectedDataTypeHands" },444{ "head", "NSPrivacyCollectedDataTypeHead" },445{ "other_data_types", "NSPrivacyCollectedDataTypeOtherDataTypes" },446};447448static const DataCollectionInfo data_collect_purpose_info[] = {449{ "Analytics", "NSPrivacyCollectedDataTypePurposeAnalytics" },450{ "App Functionality", "NSPrivacyCollectedDataTypePurposeAppFunctionality" },451{ "Developer Advertising", "NSPrivacyCollectedDataTypePurposeDeveloperAdvertising" },452{ "Third-party Advertising", "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising" },453{ "Product Personalization", "NSPrivacyCollectedDataTypePurposeProductPersonalization" },454{ "Other", "NSPrivacyCollectedDataTypePurposeOther" },455};456457void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options) const {458#ifdef MACOS_ENABLED459r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution,App Store"), 1, true));460#else461r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution"), 1, true));462#endif463464r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "binary_format/architecture", PROPERTY_HINT_ENUM, "universal,x86_64,arm64", PROPERTY_USAGE_STORAGE), "universal"));465r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));466r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));467468r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "debug/export_console_wrapper", PROPERTY_HINT_ENUM, "No,Debug Only,Debug and Release"), 1));469r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.icns,*.png,*.webp,*.svg"), ""));470r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));471r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "", false, true));472r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));473r_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"));474r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));475r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));476r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));477r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "application/copyright_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));478r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version_x86_64"), "10.12"));479r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version_arm64"), "11.00"));480r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_angle", PROPERTY_HINT_ENUM, "Auto,Yes,No"), 0, true));481r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), true));482483r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "shader_baker/enabled"), false));484485r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/additional_plist_content", PROPERTY_HINT_MULTILINE_TEXT), ""));486487r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/platform_build"), "14C18"));488// TODO(sgc): Need to set appropriate version when using Metal489r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_version"), "13.1"));490r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_build"), "22C55"));491r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_name"), "macosx13.1"));492r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_version"), "1420"));493r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_build"), "14C18"));494495#ifdef MACOS_ENABLED496r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign,Xcode codesign"), 3, true));497#else498r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign"), 1, true, true));499#endif500r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/installer_identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "3rd Party Mac Developer Installer: (ID)"), "", false, true));501r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/apple_team_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "ID"), "", false, true));502// "codesign" only options:503r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), ""));504// "rcodesign" only options:505r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_file", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));506r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_password", PROPERTY_HINT_PASSWORD, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));507// "codesign" and "rcodesign" only options:508r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/provisioning_profile", PROPERTY_HINT_GLOBAL_FILE, "*.provisionprofile", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));509510r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), "", true));511r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false));512r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false));513r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false));514r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false));515r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false));516r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false));517r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/location"), false));518r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/address_book"), false));519r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/calendars"), false));520r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/photos_library"), false));521r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/apple_events"), false));522r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/debugging"), false));523r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/enabled"), false, true, true));524r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_server"), false));525r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_client"), false));526r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_usb"), false));527r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_bluetooth"), false));528r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_downloads", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));529r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_pictures", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));530r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_music", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));531r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_movies", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));532r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_user_selected", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));533r_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()));534r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/additional", PROPERTY_HINT_MULTILINE_TEXT), ""));535r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));536537#ifdef MACOS_ENABLED538r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign,Xcode notarytool"), 0, true));539#else540r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign"), 0, true));541#endif542// "notarytool" only options:543r_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));544r_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));545// "notarytool" and "rcodesign" only options:546r_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));547r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_GLOBAL_FILE, "*.p8", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));548r_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));549550r_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));551r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));552r_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));553r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));554r_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));555r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/location_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));556r_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));557r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/address_book_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));558r_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));559r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/calendar_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));560r_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));561r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photos_library_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));562r_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));563r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/desktop_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));564r_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));565r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/documents_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));566r_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));567r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/downloads_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));568r_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));569r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/network_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));570r_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));571r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/removable_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));572573r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "privacy/tracking_enabled"), false));574r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "privacy/tracking_domains"), Vector<String>()));575576{577String hint;578for (uint64_t i = 0; i < std::size(data_collect_purpose_info); ++i) {579if (i != 0) {580hint += ",";581}582hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i));583}584for (uint64_t i = 0; i < std::size(data_collect_type_info); ++i) {585r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false));586r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false));587r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false));588r_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));589}590}591592String run_script = "#!/usr/bin/env bash\n"593"unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"\n"594"open \"{temp_dir}/{exe_name}.app\" --args {cmd_args}";595596String cleanup_script = "#!/usr/bin/env bash\n"597"kill $(pgrep -x -f \"{temp_dir}/{exe_name}.app/Contents/MacOS/{exe_name} {cmd_args}\")\n"598"rm -rf \"{temp_dir}\"";599600r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true));601r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/host"), "user@host_ip"));602r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/port"), "22"));603604r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_ssh", PROPERTY_HINT_MULTILINE_TEXT), ""));605r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_scp", PROPERTY_HINT_MULTILINE_TEXT), ""));606r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/run_script", PROPERTY_HINT_MULTILINE_TEXT), run_script));607r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/cleanup_script", PROPERTY_HINT_MULTILINE_TEXT), cleanup_script));608}609610void _rgba8_to_packbits_encode(int p_ch, int p_size, Vector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {611int src_len = p_size * p_size;612613Vector<uint8_t> result;614615int i = 0;616const uint8_t *src = p_source.ptr();617while (i < src_len) {618Vector<uint8_t> seq;619620uint8_t count = 0;621while (count <= 0x7f && i < src_len) {622if (i + 2 < src_len && src[i * 4 + p_ch] == src[(i + 1) * 4 + p_ch] && src[i] == src[(i + 2) * 4 + p_ch]) {623break;624}625seq.push_back(src[i * 4 + p_ch]);626i++;627count++;628}629if (!seq.is_empty()) {630result.push_back(count - 1);631result.append_array(seq);632}633if (i >= src_len) {634break;635}636637uint8_t rep = src[i * 4 + p_ch];638count = 0;639while (count <= 0x7f && i < src_len && src[i * 4 + p_ch] == rep) {640i++;641count++;642}643if (count >= 3) {644result.push_back(0x80 + count - 3);645result.push_back(rep);646} else {647result.push_back(count - 1);648for (int j = 0; j < count; j++) {649result.push_back(rep);650}651}652}653654int ofs = p_dest.size();655p_dest.resize(p_dest.size() + result.size());656memcpy(&p_dest.write[ofs], result.ptr(), result.size());657}658659void EditorExportPlatformMacOS::_make_icon(const Ref<EditorExportPreset> &p_preset, const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {660Vector<uint8_t> data;661662data.resize(8);663data.write[0] = 'i';664data.write[1] = 'c';665data.write[2] = 'n';666data.write[3] = 's';667668struct MacOSIconInfo {669const char *name;670const char *mask_name;671bool is_png;672int size;673};674675static const MacOSIconInfo icon_infos[] = {676{ "ic10", "", true, 1024 }, //1024×1024 32-bit PNG and 512×512@2x 32-bit "retina" PNG677{ "ic09", "", true, 512 }, //512×512 32-bit PNG678{ "ic14", "", true, 512 }, //256×256@2x 32-bit "retina" PNG679{ "ic08", "", true, 256 }, //256×256 32-bit PNG680{ "ic13", "", true, 256 }, //128×128@2x 32-bit "retina" PNG681{ "ic07", "", true, 128 }, //128×128 32-bit PNG682{ "ic12", "", true, 64 }, //32×32@2× 32-bit "retina" PNG683{ "ic11", "", true, 32 }, //16×16@2× 32-bit "retina" PNG684{ "il32", "l8mk", false, 32 }, //32×32 24-bit RLE + 8-bit uncompressed mask685{ "is32", "s8mk", false, 16 } //16×16 24-bit RLE + 8-bit uncompressed mask686};687688for (uint64_t i = 0; i < std::size(icon_infos); ++i) {689Ref<Image> copy = p_icon->duplicate();690copy->convert(Image::FORMAT_RGBA8);691copy->resize(icon_infos[i].size, icon_infos[i].size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));692693if (icon_infos[i].is_png) {694// Encode PNG icon.695Vector<uint8_t> png_buffer;696Error err = PNGDriverCommon::image_to_png(copy, png_buffer);697if (err == OK) {698int ofs = data.size();699uint64_t len = png_buffer.size();700data.resize(data.size() + len + 8);701memcpy(&data.write[ofs + 8], png_buffer.ptr(), len);702len += 8;703len = BSWAP32(len);704memcpy(&data.write[ofs], icon_infos[i].name, 4);705encode_uint32(len, &data.write[ofs + 4]);706}707} else {708Vector<uint8_t> src_data = copy->get_data();709710// Encode 24-bit RGB RLE icon.711{712int ofs = data.size();713data.resize(data.size() + 8);714715_rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // Encode R.716_rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // Encode G.717_rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // Encode B.718719// Note: workaround for macOS icon decoder bug corrupting last RLE encoded value.720data.push_back(0x00);721722int len = data.size() - ofs;723len = BSWAP32(len);724memcpy(&data.write[ofs], icon_infos[i].name, 4);725encode_uint32(len, &data.write[ofs + 4]);726}727728// Encode 8-bit mask uncompressed icon.729{730int ofs = data.size();731int len = copy->get_width() * copy->get_height();732data.resize(data.size() + len + 8);733734for (int j = 0; j < len; j++) {735data.write[ofs + 8 + j] = src_data.ptr()[j * 4 + 3];736}737len += 8;738len = BSWAP32(len);739memcpy(&data.write[ofs], icon_infos[i].mask_name, 4);740encode_uint32(len, &data.write[ofs + 4]);741}742}743}744745uint32_t total_len = data.size();746total_len = BSWAP32(total_len);747encode_uint32(total_len, &data.write[4]);748749p_data = data;750}751752void EditorExportPlatformMacOS::_fix_privacy_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist) {753String str = String::utf8((const char *)plist.ptr(), plist.size());754String strnew;755Vector<String> lines = str.split("\n");756for (int i = 0; i < lines.size(); i++) {757if (lines[i].find("$priv_collection") != -1) {758bool section_opened = false;759for (uint64_t j = 0; j < std::size(data_collect_type_info); ++j) {760bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name));761bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name));762bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name));763int purposes = p_preset->get(vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[j].prop_name));764if (data_collected) {765if (!section_opened) {766section_opened = true;767strnew += "\t<key>NSPrivacyCollectedDataTypes</key>\n";768strnew += "\t<array>\n";769}770strnew += "\t\t<dict>\n";771strnew += "\t\t\t<key>NSPrivacyCollectedDataType</key>\n";772strnew += vformat("\t\t\t<string>%s</string>\n", data_collect_type_info[j].type_name);773strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeLinked</key>\n";774if (linked) {775strnew += "\t\t\t\t<true/>\n";776} else {777strnew += "\t\t\t\t<false/>\n";778}779strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeTracking</key>\n";780if (tracking) {781strnew += "\t\t\t\t<true/>\n";782} else {783strnew += "\t\t\t\t<false/>\n";784}785if (purposes != 0) {786strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n";787strnew += "\t\t\t\t<array>\n";788for (uint64_t k = 0; k < std::size(data_collect_purpose_info); ++k) {789if (purposes & (1 << k)) {790strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name);791}792}793strnew += "\t\t\t\t</array>\n";794}795strnew += "\t\t\t</dict>\n";796}797}798if (section_opened) {799strnew += "\t</array>\n";800}801} else if (lines[i].find("$priv_tracking") != -1) {802bool tracking = p_preset->get("privacy/tracking_enabled");803strnew += "\t<key>NSPrivacyTracking</key>\n";804if (tracking) {805strnew += "\t<true/>\n";806} else {807strnew += "\t<false/>\n";808}809Vector<String> tracking_domains = p_preset->get("privacy/tracking_domains");810if (!tracking_domains.is_empty()) {811strnew += "\t<key>NSPrivacyTrackingDomains</key>\n";812strnew += "\t<array>\n";813for (const String &E : tracking_domains) {814strnew += "\t\t<string>" + E + "</string>\n";815}816strnew += "\t</array>\n";817}818} else {819strnew += lines[i] + "\n";820}821}822823CharString cs = strnew.utf8();824plist.resize(cs.size() - 1);825for (int i = 0; i < cs.size() - 1; i++) {826plist.write[i] = cs[i];827}828}829830void EditorExportPlatformMacOS::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) {831String str = String::utf8((const char *)plist.ptr(), plist.size());832String strnew;833Vector<String> lines = str.split("\n");834for (int i = 0; i < lines.size(); i++) {835if (lines[i].contains("$binary")) {836strnew += lines[i].replace("$binary", p_binary) + "\n";837} else if (lines[i].contains("$name")) {838strnew += lines[i].replace("$name", get_project_setting(p_preset, "application/config/name")) + "\n";839} else if (lines[i].contains("$bundle_identifier")) {840strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";841} else if (lines[i].contains("$short_version")) {842strnew += lines[i].replace("$short_version", p_preset->get_version("application/short_version")) + "\n";843} else if (lines[i].contains("$version")) {844strnew += lines[i].replace("$version", p_preset->get_version("application/version")) + "\n";845} else if (lines[i].contains("$signature")) {846strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";847} else if (lines[i].contains("$app_category")) {848String cat = p_preset->get("application/app_category");849strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n";850} else if (lines[i].contains("$copyright")) {851strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";852} else if (lines[i].contains("$min_version_arm64")) {853strnew += lines[i].replace("$min_version_arm64", p_preset->get("application/min_macos_version_arm64")) + "\n";854} else if (lines[i].contains("$min_version_x86_64")) {855strnew += lines[i].replace("$min_version_x86_64", p_preset->get("application/min_macos_version_x86_64")) + "\n";856} else if (lines[i].contains("$min_version")) {857strnew += lines[i].replace("$min_version", p_preset->get("application/min_macos_version_x86_64")) + "\n"; // Old template, use x86-64 version for both.858} else if (lines[i].contains("$highres")) {859strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "\t<true/>" : "\t<false/>") + "\n";860} else if (lines[i].contains("$additional_plist_content")) {861strnew += lines[i].replace("$additional_plist_content", p_preset->get("application/additional_plist_content")) + "\n";862} else if (lines[i].contains("$platfbuild")) {863strnew += lines[i].replace("$platfbuild", p_preset->get("xcode/platform_build")) + "\n";864} else if (lines[i].contains("$sdkver")) {865strnew += lines[i].replace("$sdkver", p_preset->get("xcode/sdk_version")) + "\n";866} else if (lines[i].contains("$sdkname")) {867strnew += lines[i].replace("$sdkname", p_preset->get("xcode/sdk_name")) + "\n";868} else if (lines[i].contains("$sdkbuild")) {869strnew += lines[i].replace("$sdkbuild", p_preset->get("xcode/sdk_build")) + "\n";870} else if (lines[i].contains("$xcodever")) {871strnew += lines[i].replace("$xcodever", p_preset->get("xcode/xcode_version")) + "\n";872} else if (lines[i].contains("$xcodebuild")) {873strnew += lines[i].replace("$xcodebuild", p_preset->get("xcode/xcode_build")) + "\n";874} else if (lines[i].contains("$usage_descriptions")) {875String descriptions;876if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {877descriptions += "\t<key>NSMicrophoneUsageDescription</key>\n";878descriptions += "\t<string>" + (String)p_preset->get("privacy/microphone_usage_description") + "</string>\n";879}880if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {881descriptions += "\t<key>NSCameraUsageDescription</key>\n";882descriptions += "\t<string>" + (String)p_preset->get("privacy/camera_usage_description") + "</string>\n";883}884if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {885descriptions += "\t<key>NSLocationUsageDescription</key>\n";886descriptions += "\t<string>" + (String)p_preset->get("privacy/location_usage_description") + "</string>\n";887}888if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {889descriptions += "\t<key>NSContactsUsageDescription</key>\n";890descriptions += "\t<string>" + (String)p_preset->get("privacy/address_book_usage_description") + "</string>\n";891}892if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {893descriptions += "\t<key>NSCalendarsUsageDescription</key>\n";894descriptions += "\t<string>" + (String)p_preset->get("privacy/calendar_usage_description") + "</string>\n";895}896if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {897descriptions += "\t<key>NSPhotoLibraryUsageDescription</key>\n";898descriptions += "\t<string>" + (String)p_preset->get("privacy/photos_library_usage_description") + "</string>\n";899}900if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {901descriptions += "\t<key>NSDesktopFolderUsageDescription</key>\n";902descriptions += "\t<string>" + (String)p_preset->get("privacy/desktop_folder_usage_description") + "</string>\n";903}904if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {905descriptions += "\t<key>NSDocumentsFolderUsageDescription</key>\n";906descriptions += "\t<string>" + (String)p_preset->get("privacy/documents_folder_usage_description") + "</string>\n";907}908if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {909descriptions += "\t<key>NSDownloadsFolderUsageDescription</key>\n";910descriptions += "\t<string>" + (String)p_preset->get("privacy/downloads_folder_usage_description") + "</string>\n";911}912if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {913descriptions += "\t<key>NSNetworkVolumesUsageDescription</key>\n";914descriptions += "\t<string>" + (String)p_preset->get("privacy/network_volumes_usage_description") + "</string>\n";915}916if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {917descriptions += "\t<key>NSRemovableVolumesUsageDescription</key>\n";918descriptions += "\t<string>" + (String)p_preset->get("privacy/removable_volumes_usage_description") + "</string>\n";919}920if (!descriptions.is_empty()) {921strnew += lines[i].replace("$usage_descriptions", descriptions);922}923} else {924strnew += lines[i] + "\n";925}926}927928CharString cs = strnew.utf8();929plist.resize(cs.size() - 1);930for (int i = 0; i < cs.size() - 1; i++) {931plist.write[i] = cs[i];932}933}934935/**936* If we're running the macOS version of the Godot editor we'll:937* - export our application bundle to a temporary folder938* - attempt to code sign it939* - and then wrap it up in a DMG940*/941942Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path) {943int notary_tool = p_preset->get("notarization/notarization");944switch (notary_tool) {945case 1: { // "rcodesign"946print_verbose("using rcodesign notarization...");947948String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();949if (rcodesign.is_empty()) {950add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));951return Error::FAILED;952}953954List<String> args;955956args.push_back("notary-submit");957958if (p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) == "") {959add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect issuer ID name not specified."));960return Error::FAILED;961}962if (p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY) == "") {963add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));964return Error::FAILED;965}966967args.push_back("--api-issuer");968args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID));969970args.push_back("--api-key");971args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID));972973if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) {974args.push_back("--api-key-path");975args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY));976}977978args.push_back(p_path);979980String str;981int exitcode = 0;982983Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);984if (err != OK) {985add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start rcodesign executable."));986return err;987}988989int rq_offset = str.find("created submission ID:");990if (exitcode != 0 || rq_offset == -1) {991print_line("rcodesign (" + p_path + "):\n" + str);992add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));993return Error::FAILED;994} else {995print_verbose("rcodesign (" + p_path + "):\n" + str);996int next_nl = str.find_char('\n', rq_offset);997String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 23) : str.substr(rq_offset + 23, next_nl - rq_offset - 23);998add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));999add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour."));1000add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:"));1001add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign notary-log --api-issuer <api uuid> --api-key <api key> <request uuid>\"");1002add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));1003add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign staple <app path>\"");1004}1005} break;1006#ifdef MACOS_ENABLED1007case 2: { // "notarytool"1008print_verbose("using notarytool notarization...");10091010if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {1011add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed."));1012return Error::FAILED;1013}10141015List<String> args;10161017args.push_back("notarytool");1018args.push_back("submit");10191020args.push_back(p_path);10211022if (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) == "") {1023add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified."));1024return Error::FAILED;1025}1026if (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) != "") {1027add_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."));1028return Error::FAILED;1029}10301031if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) != "") {1032if (p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS) == "") {1033add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified."));1034return Error::FAILED;1035}1036args.push_back("--apple-id");1037args.push_back(p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID));10381039args.push_back("--password");1040args.push_back(p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS));1041} else {1042if (p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID) == "") {1043add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));1044return Error::FAILED;1045}1046args.push_back("--issuer");1047args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID));10481049if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) {1050args.push_back("--key");1051args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY));1052}10531054args.push_back("--key-id");1055args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID));1056}10571058args.push_back("--no-progress");10591060if (p_preset->get("codesign/apple_team_id")) {1061args.push_back("--team-id");1062args.push_back(p_preset->get("codesign/apple_team_id"));1063}10641065String str;1066int exitcode = 0;1067Error err = OS::get_singleton()->execute("xcrun", args, &str, &exitcode, true);1068if (err != OK) {1069add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable."));1070return err;1071}10721073int rq_offset = str.find("id:");1074if (exitcode != 0 || rq_offset == -1) {1075print_line("notarytool (" + 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("notarytool (" + p_path + "):\n" + str);1080int next_nl = str.find_char('\n', rq_offset);1081String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 4) : str.substr(rq_offset + 4, next_nl - rq_offset - 4);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 progress manually by opening a Terminal and running the following command:"));1085add_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");1086add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request uuid> --apple-id <your email> --password <app-specific pwd>>\"");1087add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));1088add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple <app path>\"");1089}1090} break;1091#endif1092default: {1093};1094}1095return OK;1096}10971098void EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_warn, bool p_set_id) {1099int codesign_tool = p_preset->get("codesign/codesign");1100switch (codesign_tool) {1101case 1: { // built-in ad-hoc1102print_verbose("using built-in codesign...");1103String error_msg;1104Error err = CodeSign::codesign(false, true, p_path, p_ent_path, error_msg);1105if (err != OK) {1106add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Built-in CodeSign failed with error \"%s\"."), error_msg));1107return;1108}1109} break;1110case 2: { // "rcodesign"1111print_verbose("using rcodesign codesign...");11121113String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();1114if (rcodesign.is_empty()) {1115add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xrcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));1116return;1117}11181119List<String> args;1120args.push_back("sign");11211122if (!p_ent_path.is_empty()) {1123args.push_back("--entitlements-xml-path");1124args.push_back(p_ent_path);1125}11261127String certificate_file = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE);1128String certificate_pass = p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS);1129if (!certificate_file.is_empty() && !certificate_pass.is_empty()) {1130args.push_back("--p12-file");1131args.push_back(certificate_file);1132args.push_back("--p12-password");1133args.push_back(certificate_pass);1134}1135args.push_back("--code-signature-flags");1136args.push_back("runtime");11371138if (p_set_id) {1139String app_id = p_preset->get("application/bundle_identifier");1140args.push_back("--binary-identifier");1141args.push_back(app_id);1142}11431144args.push_back("-v"); /* provide some more feedback */11451146args.push_back(p_path);11471148String str;1149int exitcode = 0;11501151Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);1152if (err != OK) {1153add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start rcodesign executable."));1154return;1155}11561157if (exitcode != 0) {1158print_line("rcodesign (" + p_path + "):\n" + str);1159add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));1160return;1161} else {1162print_verbose("rcodesign (" + p_path + "):\n" + str);1163}1164} break;1165#ifdef MACOS_ENABLED1166case 3: { // "codesign"1167print_verbose("using xcode codesign...");11681169if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {1170add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xcode command line tools are not installed."));1171return;1172}11731174bool ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");11751176List<String> args;1177if (!ad_hoc) {1178args.push_back("--timestamp");1179args.push_back("--options");1180args.push_back("runtime");1181}11821183if (!p_ent_path.is_empty()) {1184args.push_back("--entitlements");1185args.push_back(p_ent_path);1186}11871188PackedStringArray user_args = p_preset->get("codesign/custom_options");1189for (int i = 0; i < user_args.size(); i++) {1190String user_arg = user_args[i].strip_edges();1191if (!user_arg.is_empty()) {1192args.push_back(user_arg);1193}1194}11951196args.push_back("-s");1197if (ad_hoc) {1198args.push_back("-");1199} else {1200args.push_back(p_preset->get("codesign/identity"));1201}12021203if (p_set_id) {1204String app_id = p_preset->get("application/bundle_identifier");1205args.push_back("-i");1206args.push_back(app_id);1207}12081209args.push_back("-v"); /* provide some more feedback */1210args.push_back("-f");12111212args.push_back(p_path);12131214String str;1215int exitcode = 0;12161217Error err = OS::get_singleton()->execute("codesign", args, &str, &exitcode, true);1218if (err != OK) {1219add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start codesign executable, make sure Xcode command line tools are installed."));1220return;1221}12221223if (exitcode != 0) {1224print_line("codesign (" + p_path + "):\n" + str);1225add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));1226return;1227} else {1228print_verbose("codesign (" + p_path + "):\n" + str);1229}1230} break;1231#endif1232default: {1233};1234}1235}12361237void EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path,1238const String &p_ent_path, const String &p_helper_ent_path, bool p_should_error_on_non_code) {1239static Vector<String> extensions_to_sign;12401241bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");1242if (extensions_to_sign.is_empty()) {1243extensions_to_sign.push_back("dylib");1244extensions_to_sign.push_back("framework");1245extensions_to_sign.push_back("");1246}12471248Error dir_access_error;1249Ref<DirAccess> dir_access{ DirAccess::open(p_path, &dir_access_error) };12501251if (dir_access_error != OK) {1252add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign directory %s."), p_path));1253return;1254}12551256dir_access->list_dir_begin();1257String current_file{ dir_access->get_next() };1258while (!current_file.is_empty()) {1259String current_file_path{ p_path.path_join(current_file) };12601261if (current_file == ".." || current_file == ".") {1262current_file = dir_access->get_next();1263continue;1264}12651266if (extensions_to_sign.has(current_file.get_extension())) {1267String ent_path;1268bool set_bundle_id = false;1269if (sandbox && FileAccess::exists(current_file_path)) {1270int ftype = MachO::get_filetype(current_file_path);1271if (ftype == 2 || ftype == 5) {1272ent_path = p_helper_ent_path;1273set_bundle_id = true;1274}1275}1276_code_sign(p_preset, current_file_path, ent_path, false, set_bundle_id);1277if (is_executable(current_file_path)) {1278// chmod with 0755 if the file is executable.1279FileAccess::set_unix_permissions(current_file_path, 0755);1280}1281} else if (dir_access->current_is_dir()) {1282_code_sign_directory(p_preset, current_file_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code);1283} else if (p_should_error_on_non_code) {1284add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign file %s."), current_file));1285}12861287current_file = dir_access->get_next();1288}1289}12901291Error EditorExportPlatformMacOS::_copy_and_sign_files(Ref<DirAccess> &dir_access, const String &p_src_path,1292const String &p_in_app_path, bool p_sign_enabled,1293const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,1294const String &p_helper_ent_path,1295bool p_should_error_on_non_code_sign, bool p_sandbox) {1296static Vector<String> extensions_to_sign;12971298if (extensions_to_sign.is_empty()) {1299extensions_to_sign.push_back("dylib");1300extensions_to_sign.push_back("framework");1301extensions_to_sign.push_back("");1302}13031304Error err{ OK };1305if (dir_access->dir_exists(p_src_path)) {1306#ifndef UNIX_ENABLED1307add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Relative symlinks are not supported, exported \"%s\" might be broken!"), p_src_path.get_file()));1308#endif1309print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path);13101311bool plist_missing = false;1312Ref<PList> plist;1313plist.instantiate();1314plist->load_file(p_src_path.path_join("Resources").path_join("Info.plist"));13151316Ref<PListNode> root_node = plist->get_root();1317if (root_node.is_null()) {1318plist_missing = true;1319} else {1320Dictionary root = root_node->get_value();1321if (!root.has("CFBundleExecutable") || !root.has("CFBundleIdentifier") || !root.has("CFBundlePackageType") || !root.has("CFBundleInfoDictionaryVersion") || !root.has("CFBundleName") || !root.has("CFBundleSupportedPlatforms")) {1322plist_missing = true;1323}1324}13251326err = dir_access->make_dir_recursive(p_in_app_path);1327if (err == OK) {1328err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true);1329}1330if (err == OK && plist_missing) {1331add_message(EXPORT_MESSAGE_WARNING, TTR("Export"), vformat(TTR("\"%s\": Info.plist missing or invalid, new Info.plist generated."), p_src_path.get_file()));1332// Generate Info.plist1333String lib_name = p_src_path.get_basename().get_file();1334String lib_id = p_preset->get("application/bundle_identifier");1335String lib_clean_name = lib_name;1336for (int i = 0; i < lib_clean_name.length(); i++) {1337if (!is_ascii_alphanumeric_char(lib_clean_name[i]) && lib_clean_name[i] != '.' && lib_clean_name[i] != '-') {1338lib_clean_name[i] = '-';1339}1340}13411342String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"1343"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"1344"<plist version=\"1.0\">\n"1345" <dict>\n"1346" <key>CFBundleExecutable</key>\n"1347" <string>$name</string>\n"1348" <key>CFBundleIdentifier</key>\n"1349" <string>$id.framework.$cl_name</string>\n"1350" <key>CFBundleInfoDictionaryVersion</key>\n"1351" <string>6.0</string>\n"1352" <key>CFBundleName</key>\n"1353" <string>$name</string>\n"1354" <key>CFBundlePackageType</key>\n"1355" <string>FMWK</string>\n"1356" <key>CFBundleShortVersionString</key>\n"1357" <string>1.0.0</string>\n"1358" <key>CFBundleSupportedPlatforms</key>\n"1359" <array>\n"1360" <string>MacOSX</string>\n"1361" </array>\n"1362" <key>CFBundleVersion</key>\n"1363" <string>1.0.0</string>\n"1364" <key>LSMinimumSystemVersion</key>\n"1365" <string>10.12</string>\n"1366" </dict>\n"1367"</plist>";13681369String info_plist = info_plist_format.replace("$id", lib_id).replace("$name", lib_name).replace("$cl_name", lib_clean_name);13701371err = dir_access->make_dir_recursive(p_in_app_path.path_join("Resources"));1372Ref<FileAccess> f = FileAccess::open(p_in_app_path.path_join("Resources").path_join("Info.plist"), FileAccess::WRITE);1373if (f.is_valid()) {1374f->store_string(info_plist);1375}1376}1377} else {1378print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path);1379err = dir_access->copy(p_src_path, p_in_app_path);1380}1381if (err == OK && p_sign_enabled) {1382if (dir_access->dir_exists(p_src_path) && p_src_path.get_extension().is_empty()) {1383// If it is a directory, find and sign all dynamic libraries.1384_code_sign_directory(p_preset, p_in_app_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code_sign);1385} else {1386if (extensions_to_sign.has(p_in_app_path.get_extension())) {1387String ent_path;1388bool set_bundle_id = false;1389if (p_sandbox && FileAccess::exists(p_in_app_path)) {1390int ftype = MachO::get_filetype(p_in_app_path);1391if (ftype == 2 || ftype == 5) {1392ent_path = p_helper_ent_path;1393set_bundle_id = true;1394}1395}1396_code_sign(p_preset, p_in_app_path, ent_path, false, set_bundle_id);1397}1398if (dir_access->file_exists(p_in_app_path) && is_executable(p_in_app_path)) {1399// chmod with 0755 if the file is executable.1400FileAccess::set_unix_permissions(p_in_app_path, 0755);1401}1402}1403}1404return err;1405}14061407Error EditorExportPlatformMacOS::_export_macos_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin,1408const String &p_app_path_name, Ref<DirAccess> &dir_access,1409bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,1410const String &p_ent_path, const String &p_helper_ent_path, bool p_sandbox) {1411Error error{ OK };1412const Vector<String> &macos_plugins{ p_editor_export_plugin->get_macos_plugin_files() };1413for (int i = 0; i < macos_plugins.size(); ++i) {1414String src_path{ ProjectSettings::get_singleton()->globalize_path(macos_plugins[i]) };1415String path_in_app{ p_app_path_name + "/Contents/PlugIns/" + src_path.get_file() };1416error = _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);1417if (error != OK) {1418break;1419}1420}1421return error;1422}14231424Error EditorExportPlatformMacOS::_create_pkg(const Ref<EditorExportPreset> &p_preset, const String &p_pkg_path, const String &p_app_path_name) {1425List<String> args;14261427if (FileAccess::exists(p_pkg_path)) {1428OS::get_singleton()->move_to_trash(p_pkg_path);1429}14301431args.push_back("productbuild");1432args.push_back("--component");1433args.push_back(p_app_path_name);1434args.push_back("/Applications");1435String ident = p_preset->get("codesign/installer_identity");1436if (!ident.is_empty()) {1437args.push_back("--timestamp");1438args.push_back("--sign");1439args.push_back(ident);1440}1441args.push_back("--quiet");1442args.push_back(p_pkg_path);14431444String str;1445Error err = OS::get_singleton()->execute("xcrun", args, &str, nullptr, true);1446if (err != OK) {1447add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("Could not start productbuild executable."));1448return err;1449}14501451print_verbose("productbuild returned: " + str);1452if (str.contains("productbuild: error:")) {1453add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("`productbuild` failed."));1454return FAILED;1455}14561457return OK;1458}14591460Error EditorExportPlatformMacOS::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {1461List<String> args;14621463if (FileAccess::exists(p_dmg_path)) {1464OS::get_singleton()->move_to_trash(p_dmg_path);1465}14661467args.push_back("create");1468args.push_back(p_dmg_path);1469args.push_back("-volname");1470args.push_back(p_pkg_name);1471args.push_back("-fs");1472args.push_back("HFS+");1473args.push_back("-srcfolder");1474args.push_back(p_app_path_name);14751476String str;1477Error err = OS::get_singleton()->execute("hdiutil", args, &str, nullptr, true);1478if (err != OK) {1479add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("Could not start hdiutil executable."));1480return err;1481}14821483print_verbose("hdiutil returned: " + str);1484if (str.contains("create failed")) {1485if (str.contains("File exists")) {1486add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed - file exists."));1487} else {1488add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed."));1489}1490return FAILED;1491}14921493return OK;1494}14951496bool EditorExportPlatformMacOS::is_shebang(const String &p_path) const {1497Ref<FileAccess> fb = FileAccess::open(p_path, FileAccess::READ);1498ERR_FAIL_COND_V_MSG(fb.is_null(), false, vformat("Can't open file: \"%s\".", p_path));1499uint16_t magic = fb->get_16();1500return (magic == 0x2123);1501}15021503bool EditorExportPlatformMacOS::is_executable(const String &p_path) const {1504return MachO::is_macho(p_path) || LipO::is_lipo(p_path) || is_shebang(p_path);1505}15061507Error EditorExportPlatformMacOS::_export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path) {1508Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE);1509if (f.is_null()) {1510add_message(EXPORT_MESSAGE_ERROR, TTR("Debug Script Export"), vformat(TTR("Could not open file \"%s\"."), p_path));1511return ERR_CANT_CREATE;1512}15131514f->store_line("#!/bin/sh");1515f->store_line("printf '\\033c\\033]0;%s\\a' " + p_app_name);1516f->store_line("");1517f->store_line("function app_realpath() {");1518f->store_line(" SOURCE=$1");1519f->store_line(" while [ -h \"$SOURCE\" ]; do");1520f->store_line(" DIR=$(dirname \"$SOURCE\")");1521f->store_line(" SOURCE=$(readlink \"$SOURCE\")");1522f->store_line(" [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE");1523f->store_line(" done");1524f->store_line(" echo \"$( cd -P \"$( dirname \"$SOURCE\" )\" >/dev/null 2>&1 && pwd )\"");1525f->store_line("}");1526f->store_line("");1527f->store_line("BASE_PATH=\"$(app_realpath \"${BASH_SOURCE[0]}\")\"");1528f->store_line("\"$BASE_PATH/" + p_pkg_name + "\" \"$@\"");1529f->store_line("");15301531return OK;1532}15331534Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) {1535ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);15361537const String base_dir = p_path.get_base_dir();15381539if (!DirAccess::exists(base_dir)) {1540add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Target folder does not exist or is inaccessible: \"%s\""), base_dir));1541return ERR_FILE_BAD_PATH;1542}15431544EditorProgress ep("export", TTR("Exporting for macOS"), 3, true);15451546String src_pkg_name;1547if (p_debug) {1548src_pkg_name = p_preset->get("custom_template/debug");1549} else {1550src_pkg_name = p_preset->get("custom_template/release");1551}15521553if (src_pkg_name.is_empty()) {1554String err;1555src_pkg_name = find_export_template("macos.zip", &err);1556if (src_pkg_name.is_empty()) {1557add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found.") + "\n" + err);1558return ERR_FILE_NOT_FOUND;1559}1560}15611562Ref<FileAccess> io_fa;1563zlib_filefunc_def io = zipio_create_io(&io_fa);15641565if (ep.step(TTR("Creating app bundle"), 0)) {1566return ERR_SKIP;1567}15681569unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);1570if (!src_pkg_zip) {1571add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not find template app to export: \"%s\"."), src_pkg_name));1572return ERR_FILE_NOT_FOUND;1573}15741575int ret = unzGoToFirstFile(src_pkg_zip);15761577String architecture = p_preset->get("binary_format/architecture");1578String binary_to_use = "godot_macos_" + String(p_debug ? "debug" : "release") + "." + architecture;15791580String pkg_name;1581if (String(get_project_setting(p_preset, "application/config/name")) != "") {1582pkg_name = String(get_project_setting(p_preset, "application/config/name"));1583} else {1584pkg_name = "Unnamed";1585}1586pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);15871588String export_format;1589if (p_path.ends_with("zip")) {1590export_format = "zip";1591} else if (p_path.ends_with("app")) {1592export_format = "app";1593#ifdef MACOS_ENABLED1594} else if (p_path.ends_with("dmg")) {1595export_format = "dmg";1596} else if (p_path.ends_with("pkg")) {1597export_format = "pkg";1598#endif1599} else {1600add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Invalid export format."));1601return ERR_CANT_CREATE;1602}16031604// Create our application bundle.1605String tmp_app_dir_name = pkg_name + ".app";1606String tmp_base_path_name;1607String tmp_app_path_name;1608String scr_path;1609if (export_format == "app") {1610tmp_base_path_name = p_path.get_base_dir();1611tmp_app_path_name = p_path;1612scr_path = p_path.get_basename() + ".command";1613} else {1614tmp_base_path_name = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name);1615tmp_app_path_name = tmp_base_path_name.path_join(tmp_app_dir_name);1616scr_path = tmp_base_path_name.path_join(pkg_name + ".command");1617}16181619print_verbose("Exporting to " + tmp_app_path_name);16201621Error err = OK;16221623Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_base_path_name);1624if (tmp_app_dir.is_null()) {1625add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory: \"%s\"."), tmp_base_path_name));1626err = ERR_CANT_CREATE;1627}16281629if (FileAccess::exists(scr_path)) {1630DirAccess::remove_file_or_error(scr_path);1631}1632if (DirAccess::exists(tmp_app_path_name)) {1633String old_dir = tmp_app_dir->get_current_dir();1634if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {1635tmp_app_dir->erase_contents_recursive();1636tmp_app_dir->change_dir(old_dir);1637}1638}16391640Array helpers = p_preset->get("codesign/entitlements/app_sandbox/helper_executables");16411642// Create our folder structure.1643if (err == OK) {1644print_verbose("Creating " + tmp_app_path_name + "/Contents/MacOS");1645err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");1646if (err != OK) {1647add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/MacOS"));1648}1649}16501651if (err == OK) {1652print_verbose("Creating " + tmp_app_path_name + "/Contents/Frameworks");1653err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");1654if (err != OK) {1655add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Frameworks"));1656}1657}16581659if ((err == OK) && helpers.size() > 0) {1660print_line("Creating " + tmp_app_path_name + "/Contents/Helpers");1661err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Helpers");1662if (err != OK) {1663add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Helpers"));1664}1665}16661667if (err == OK) {1668print_verbose("Creating " + tmp_app_path_name + "/Contents/Resources");1669err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");1670if (err != OK) {1671add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Resources"));1672}1673}16741675Dictionary appnames = get_project_setting(p_preset, "application/config/name_localized");1676Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");1677Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");1678Dictionary location_usage_descriptions = p_preset->get("privacy/location_usage_description_localized");1679Dictionary address_book_usage_descriptions = p_preset->get("privacy/address_book_usage_description_localized");1680Dictionary calendar_usage_descriptions = p_preset->get("privacy/calendar_usage_description_localized");1681Dictionary photos_library_usage_descriptions = p_preset->get("privacy/photos_library_usage_description_localized");1682Dictionary desktop_folder_usage_descriptions = p_preset->get("privacy/desktop_folder_usage_description_localized");1683Dictionary documents_folder_usage_descriptions = p_preset->get("privacy/documents_folder_usage_description_localized");1684Dictionary downloads_folder_usage_descriptions = p_preset->get("privacy/downloads_folder_usage_description_localized");1685Dictionary network_volumes_usage_descriptions = p_preset->get("privacy/network_volumes_usage_description_localized");1686Dictionary removable_volumes_usage_descriptions = p_preset->get("privacy/removable_volumes_usage_description_localized");1687Dictionary copyrights = p_preset->get("application/copyright_localized");16881689Vector<String> translations = get_project_setting(p_preset, "internationalization/locale/translations");1690if (translations.size() > 0) {1691{1692String fname = tmp_app_path_name + "/Contents/Resources/en.lproj";1693tmp_app_dir->make_dir_recursive(fname);1694Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);1695f->store_line("/* Localized versions of Info.plist keys */");1696f->store_line("");1697f->store_line("CFBundleDisplayName = \"" + get_project_setting(p_preset, "application/config/name").operator String() + "\";");1698if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {1699f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String() + "\";");1700}1701if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {1702f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String() + "\";");1703}1704if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {1705f->store_line("NSLocationUsageDescription = \"" + p_preset->get("privacy/location_usage_description").operator String() + "\";");1706}1707if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {1708f->store_line("NSContactsUsageDescription = \"" + p_preset->get("privacy/address_book_usage_description").operator String() + "\";");1709}1710if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {1711f->store_line("NSCalendarsUsageDescription = \"" + p_preset->get("privacy/calendar_usage_description").operator String() + "\";");1712}1713if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {1714f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photos_library_usage_description").operator String() + "\";");1715}1716if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {1717f->store_line("NSDesktopFolderUsageDescription = \"" + p_preset->get("privacy/desktop_folder_usage_description").operator String() + "\";");1718}1719if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {1720f->store_line("NSDocumentsFolderUsageDescription = \"" + p_preset->get("privacy/documents_folder_usage_description").operator String() + "\";");1721}1722if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {1723f->store_line("NSDownloadsFolderUsageDescription = \"" + p_preset->get("privacy/downloads_folder_usage_description").operator String() + "\";");1724}1725if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {1726f->store_line("NSNetworkVolumesUsageDescription = \"" + p_preset->get("privacy/network_volumes_usage_description").operator String() + "\";");1727}1728if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {1729f->store_line("NSRemovableVolumesUsageDescription = \"" + p_preset->get("privacy/removable_volumes_usage_description").operator String() + "\";");1730}1731f->store_line("NSHumanReadableCopyright = \"" + p_preset->get("application/copyright").operator String() + "\";");1732}17331734HashSet<String> languages;1735for (const String &E : translations) {1736Ref<Translation> tr = ResourceLoader::load(E);1737if (tr.is_valid() && tr->get_locale() != "en") {1738languages.insert(tr->get_locale());1739}1740}17411742for (const String &lang : languages) {1743String fname = tmp_app_path_name + "/Contents/Resources/" + lang + ".lproj";1744tmp_app_dir->make_dir_recursive(fname);1745Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);1746f->store_line("/* Localized versions of Info.plist keys */");1747f->store_line("");1748if (appnames.has(lang)) {1749f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String() + "\";");1750}1751if (microphone_usage_descriptions.has(lang)) {1752f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String() + "\";");1753}1754if (camera_usage_descriptions.has(lang)) {1755f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String() + "\";");1756}1757if (location_usage_descriptions.has(lang)) {1758f->store_line("NSLocationUsageDescription = \"" + location_usage_descriptions[lang].operator String() + "\";");1759}1760if (address_book_usage_descriptions.has(lang)) {1761f->store_line("NSContactsUsageDescription = \"" + address_book_usage_descriptions[lang].operator String() + "\";");1762}1763if (calendar_usage_descriptions.has(lang)) {1764f->store_line("NSCalendarsUsageDescription = \"" + calendar_usage_descriptions[lang].operator String() + "\";");1765}1766if (photos_library_usage_descriptions.has(lang)) {1767f->store_line("NSPhotoLibraryUsageDescription = \"" + photos_library_usage_descriptions[lang].operator String() + "\";");1768}1769if (desktop_folder_usage_descriptions.has(lang)) {1770f->store_line("NSDesktopFolderUsageDescription = \"" + desktop_folder_usage_descriptions[lang].operator String() + "\";");1771}1772if (documents_folder_usage_descriptions.has(lang)) {1773f->store_line("NSDocumentsFolderUsageDescription = \"" + documents_folder_usage_descriptions[lang].operator String() + "\";");1774}1775if (downloads_folder_usage_descriptions.has(lang)) {1776f->store_line("NSDownloadsFolderUsageDescription = \"" + downloads_folder_usage_descriptions[lang].operator String() + "\";");1777}1778if (network_volumes_usage_descriptions.has(lang)) {1779f->store_line("NSNetworkVolumesUsageDescription = \"" + network_volumes_usage_descriptions[lang].operator String() + "\";");1780}1781if (removable_volumes_usage_descriptions.has(lang)) {1782f->store_line("NSRemovableVolumesUsageDescription = \"" + removable_volumes_usage_descriptions[lang].operator String() + "\";");1783}1784if (copyrights.has(lang)) {1785f->store_line("NSHumanReadableCopyright = \"" + copyrights[lang].operator String() + "\";");1786}1787}1788}17891790// Now process our template.1791bool found_binary = false;17921793int export_angle = p_preset->get("application/export_angle");1794bool include_angle_libs = false;1795if (export_angle == 0) {1796include_angle_libs = String(get_project_setting(p_preset, "rendering/gl_compatibility/driver.macos")) == "opengl3_angle";1797} else if (export_angle == 1) {1798include_angle_libs = true;1799}18001801while (ret == UNZ_OK && err == OK) {1802// Get filename.1803unz_file_info info;1804char fname[16384];1805ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);1806if (ret != UNZ_OK) {1807break;1808}18091810String file = String::utf8(fname);18111812Vector<uint8_t> data;1813data.resize(info.uncompressed_size);18141815// Read.1816unzOpenCurrentFile(src_pkg_zip);1817unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());1818unzCloseCurrentFile(src_pkg_zip);18191820// Write.1821file = file.replace_first("macos_template.app/", "");18221823if (((info.external_fa >> 16L) & 0120000) == 0120000) {1824#ifndef UNIX_ENABLED1825add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Relative symlinks are not supported on this OS, the exported project might be broken!"));1826#endif1827// Handle symlinks in the archive.1828file = tmp_app_path_name.path_join(file);1829if (err == OK) {1830err = tmp_app_dir->make_dir_recursive(file.get_base_dir());1831if (err != OK) {1832add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));1833}1834}1835if (err == OK) {1836String lnk_data = String::utf8((const char *)data.ptr(), data.size());1837err = tmp_app_dir->create_link(lnk_data, file);1838if (err != OK) {1839add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not created symlink \"%s\" -> \"%s\"."), lnk_data, file));1840}1841print_verbose(vformat("ADDING SYMLINK %s => %s\n", file, lnk_data));1842}18431844ret = unzGoToNextFile(src_pkg_zip);1845continue; // next1846}18471848if (file == "Contents/Frameworks/libEGL.dylib") {1849if (!include_angle_libs) {1850ret = unzGoToNextFile(src_pkg_zip);1851continue; // skip1852}1853}18541855if (file == "Contents/Frameworks/libGLESv2.dylib") {1856if (!include_angle_libs) {1857ret = unzGoToNextFile(src_pkg_zip);1858continue; // skip1859}1860}18611862if (file == "Contents/Info.plist") {1863_fix_plist(p_preset, data, pkg_name);1864}18651866if (file == "Contents/Resources/PrivacyInfo.xcprivacy") {1867_fix_privacy_manifest(p_preset, data);1868}18691870if (file.begins_with("Contents/MacOS/godot_")) {1871if (file != "Contents/MacOS/" + binary_to_use) {1872ret = unzGoToNextFile(src_pkg_zip);1873continue; // skip1874}1875found_binary = true;1876file = "Contents/MacOS/" + pkg_name;1877}18781879if (file == "Contents/Resources/icon.icns") {1880// See if there is an icon.1881String icon_path;1882if (p_preset->get("application/icon") != "") {1883icon_path = p_preset->get("application/icon");1884} else if (get_project_setting(p_preset, "application/config/macos_native_icon") != "") {1885icon_path = get_project_setting(p_preset, "application/config/macos_native_icon");1886} else {1887icon_path = get_project_setting(p_preset, "application/config/icon");1888}18891890if (!icon_path.is_empty()) {1891if (icon_path.get_extension() == "icns") {1892Ref<FileAccess> icon = FileAccess::open(icon_path, FileAccess::READ);1893if (icon.is_valid()) {1894data.resize(icon->get_length());1895icon->get_buffer(&data.write[0], icon->get_length());1896}1897} else {1898Ref<Image> icon = _load_icon_or_splash_image(icon_path, &err);1899if (err == OK && icon.is_valid() && !icon->is_empty()) {1900_make_icon(p_preset, icon, data);1901}1902}1903}1904}19051906if (data.size() > 0) {1907print_verbose("ADDING: " + file + " size: " + itos(data.size()));19081909// Write it into our application bundle.1910file = tmp_app_path_name.path_join(file);1911if (err == OK) {1912err = tmp_app_dir->make_dir_recursive(file.get_base_dir());1913if (err != OK) {1914add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));1915}1916}1917if (err == OK) {1918Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);1919if (f.is_valid()) {1920f->store_buffer(data.ptr(), data.size());1921f.unref();1922if (is_executable(file)) {1923// chmod with 0755 if the file is executable.1924FileAccess::set_unix_permissions(file, 0755);1925#ifndef UNIX_ENABLED1926if (export_format == "app") {1927add_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()));1928}1929#endif1930}1931} else {1932add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not open \"%s\"."), file));1933err = ERR_CANT_CREATE;1934}1935}1936}19371938ret = unzGoToNextFile(src_pkg_zip);1939}19401941// We're done with our source zip.1942unzClose(src_pkg_zip);19431944if (!found_binary) {1945add_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));1946err = ERR_FILE_NOT_FOUND;1947}19481949// Save console wrapper.1950if (err == OK) {1951int con_scr = p_preset->get("debug/export_console_wrapper");1952if ((con_scr == 1 && p_debug) || (con_scr == 2)) {1953err = _export_debug_script(p_preset, pkg_name, tmp_app_path_name.get_file() + "/Contents/MacOS/" + pkg_name, scr_path);1954FileAccess::set_unix_permissions(scr_path, 0755);1955#ifndef UNIX_ENABLED1956if (export_format == "app") {1957add_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()));1958}1959#endif1960if (err != OK) {1961add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not create console wrapper."));1962}1963}1964}19651966if (err == OK) {1967if (ep.step(TTR("Making PKG"), 1)) {1968return ERR_SKIP;1969}19701971// See if we can code sign our new package.1972bool sign_enabled = (p_preset->get("codesign/codesign").operator int() > 0);1973bool ad_hoc = false;1974int codesign_tool = p_preset->get("codesign/codesign");1975switch (codesign_tool) {1976case 1: { // built-in ad-hoc1977ad_hoc = true;1978} break;1979case 2: { // "rcodesign"1980ad_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();1981} break;1982#ifdef MACOS_ENABLED1983case 3: { // "codesign"1984ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");1985} break;1986#endif1987default: {1988};1989}19901991String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";1992Vector<SharedObject> shared_objects;1993err = save_pack(p_preset, p_debug, pack_path, &shared_objects);19941995bool lib_validation = p_preset->get("codesign/entitlements/disable_library_validation");1996if (!shared_objects.is_empty() && sign_enabled && ad_hoc && !lib_validation) {1997add_message(EXPORT_MESSAGE_INFO, TTR("Entitlements Modified"), TTR("Ad-hoc signed applications require the 'Disable Library Validation' entitlement to load dynamic libraries."));1998lib_validation = true;1999}20002001if (!shared_objects.is_empty() && sign_enabled && codesign_tool == 2) {2002add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("'rcodesign' doesn't support signing applications with embedded dynamic libraries."));2003}20042005bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");2006String ent_path = p_preset->get("codesign/entitlements/custom_file");2007String hlp_ent_path = sandbox ? EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + "_helper.entitlements") : ent_path;2008if (sign_enabled && (ent_path.is_empty())) {2009ent_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".entitlements");20102011Ref<FileAccess> ent_f = FileAccess::open(ent_path, FileAccess::WRITE);2012if (ent_f.is_valid()) {2013ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");2014ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");2015ent_f->store_line("<plist version=\"1.0\">");2016ent_f->store_line("<dict>");2017if (ClassDB::class_exists("CSharpScript")) {2018// These entitlements are required to run managed code, and are always enabled in Mono builds.2019ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");2020ent_f->store_line("<true/>");2021ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");2022ent_f->store_line("<true/>");2023ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");2024ent_f->store_line("<true/>");2025} else {2026if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) {2027ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");2028ent_f->store_line("<true/>");2029}2030if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) {2031ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");2032ent_f->store_line("<true/>");2033}2034if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) {2035ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");2036ent_f->store_line("<true/>");2037}2038}20392040if (lib_validation) {2041ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>");2042ent_f->store_line("<true/>");2043}2044if ((bool)p_preset->get("codesign/entitlements/audio_input")) {2045ent_f->store_line("<key>com.apple.security.device.audio-input</key>");2046ent_f->store_line("<true/>");2047}2048if ((bool)p_preset->get("codesign/entitlements/camera")) {2049ent_f->store_line("<key>com.apple.security.device.camera</key>");2050ent_f->store_line("<true/>");2051}2052if ((bool)p_preset->get("codesign/entitlements/location")) {2053ent_f->store_line("<key>com.apple.security.personal-information.location</key>");2054ent_f->store_line("<true/>");2055}2056if ((bool)p_preset->get("codesign/entitlements/address_book")) {2057ent_f->store_line("<key>com.apple.security.personal-information.addressbook</key>");2058ent_f->store_line("<true/>");2059}2060if ((bool)p_preset->get("codesign/entitlements/calendars")) {2061ent_f->store_line("<key>com.apple.security.personal-information.calendars</key>");2062ent_f->store_line("<true/>");2063}2064if ((bool)p_preset->get("codesign/entitlements/photos_library")) {2065ent_f->store_line("<key>com.apple.security.personal-information.photos-library</key>");2066ent_f->store_line("<true/>");2067}2068if ((bool)p_preset->get("codesign/entitlements/apple_events")) {2069ent_f->store_line("<key>com.apple.security.automation.apple-events</key>");2070ent_f->store_line("<true/>");2071}2072if ((bool)p_preset->get("codesign/entitlements/debugging")) {2073ent_f->store_line("<key>com.apple.security.get-task-allow</key>");2074ent_f->store_line("<true/>");2075}20762077int dist_type = p_preset->get("export/distribution_type");2078if (dist_type == 2) {2079String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE);2080String teamid = p_preset->get("codesign/apple_team_id");2081String bid = p_preset->get("application/bundle_identifier");2082if (!pprof.is_empty() && !teamid.is_empty()) {2083ent_f->store_line("<key>com.apple.developer.team-identifier</key>");2084ent_f->store_line("<string>" + teamid + "</string>");2085ent_f->store_line("<key>com.apple.application-identifier</key>");2086ent_f->store_line("<string>" + teamid + "." + bid + "</string>");2087}2088}20892090if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) {2091ent_f->store_line("<key>com.apple.security.app-sandbox</key>");2092ent_f->store_line("<true/>");20932094if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) {2095ent_f->store_line("<key>com.apple.security.network.server</key>");2096ent_f->store_line("<true/>");2097}2098if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) {2099ent_f->store_line("<key>com.apple.security.network.client</key>");2100ent_f->store_line("<true/>");2101}2102if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) {2103ent_f->store_line("<key>com.apple.security.device.usb</key>");2104ent_f->store_line("<true/>");2105}2106if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) {2107ent_f->store_line("<key>com.apple.security.device.bluetooth</key>");2108ent_f->store_line("<true/>");2109}2110if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) {2111ent_f->store_line("<key>com.apple.security.files.downloads.read-only</key>");2112ent_f->store_line("<true/>");2113}2114if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) {2115ent_f->store_line("<key>com.apple.security.files.downloads.read-write</key>");2116ent_f->store_line("<true/>");2117}2118if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) {2119ent_f->store_line("<key>com.apple.security.files.pictures.read-only</key>");2120ent_f->store_line("<true/>");2121}2122if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) {2123ent_f->store_line("<key>com.apple.security.files.pictures.read-write</key>");2124ent_f->store_line("<true/>");2125}2126if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) {2127ent_f->store_line("<key>com.apple.security.files.music.read-only</key>");2128ent_f->store_line("<true/>");2129}2130if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) {2131ent_f->store_line("<key>com.apple.security.files.music.read-write</key>");2132ent_f->store_line("<true/>");2133}2134if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) {2135ent_f->store_line("<key>com.apple.security.files.movies.read-only</key>");2136ent_f->store_line("<true/>");2137}2138if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) {2139ent_f->store_line("<key>com.apple.security.files.movies.read-write</key>");2140ent_f->store_line("<true/>");2141}2142if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 1) {2143ent_f->store_line("<key>com.apple.security.files.user-selected.read-only</key>");2144ent_f->store_line("<true/>");2145}2146if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 2) {2147ent_f->store_line("<key>com.apple.security.files.user-selected.read-write</key>");2148ent_f->store_line("<true/>");2149}2150}21512152const String &additional_entitlements = p_preset->get("codesign/entitlements/additional");2153if (!additional_entitlements.is_empty()) {2154ent_f->store_line(additional_entitlements);2155}21562157ent_f->store_line("</dict>");2158ent_f->store_line("</plist>");2159} else {2160add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create entitlements file."));2161err = ERR_CANT_CREATE;2162}21632164if ((err == OK) && sandbox && (helpers.size() > 0 || shared_objects.size() > 0)) {2165ent_f = FileAccess::open(hlp_ent_path, FileAccess::WRITE);2166if (ent_f.is_valid()) {2167ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");2168ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");2169ent_f->store_line("<plist version=\"1.0\">");2170ent_f->store_line("<dict>");2171ent_f->store_line("<key>com.apple.security.app-sandbox</key>");2172ent_f->store_line("<true/>");2173ent_f->store_line("<key>com.apple.security.inherit</key>");2174ent_f->store_line("<true/>");2175ent_f->store_line("</dict>");2176ent_f->store_line("</plist>");2177} else {2178add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create helper entitlements file."));2179err = ERR_CANT_CREATE;2180}2181}2182}21832184if ((err == OK) && helpers.size() > 0) {2185Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);2186for (int i = 0; i < helpers.size(); i++) {2187String hlp_path = helpers[i];2188err = da->copy(hlp_path, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file());2189if (err == OK && sign_enabled) {2190_code_sign(p_preset, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), hlp_ent_path, false, true);2191}2192FileAccess::set_unix_permissions(tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), 0755);2193#ifndef UNIX_ENABLED2194if (export_format == "app") {2195add_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()));2196}2197#endif2198}2199}22002201if (err == OK) {2202Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);2203for (int i = 0; i < shared_objects.size(); i++) {2204String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path);2205if (shared_objects[i].target.is_empty()) {2206String path_in_app = tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file();2207err = _copy_and_sign_files(da, src_path, path_in_app, sign_enabled, p_preset, ent_path, hlp_ent_path, true, sandbox);2208} else {2209String path_in_app = tmp_app_path_name.path_join(shared_objects[i].target);2210tmp_app_dir->make_dir_recursive(path_in_app);2211err = _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);2212}2213if (err != OK) {2214break;2215}2216}22172218Vector<Ref<EditorExportPlugin>> export_plugins{ EditorExport::get_singleton()->get_export_plugins() };2219for (int i = 0; i < export_plugins.size(); ++i) {2220err = _export_macos_plugins_for(export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path, hlp_ent_path, sandbox);2221if (err != OK) {2222break;2223}2224}2225}22262227if (err == OK && sign_enabled) {2228int dist_type = p_preset->get("export/distribution_type");2229if (dist_type == 2) {2230String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE).operator String();2231if (!pprof.is_empty()) {2232Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);2233err = da->copy(pprof, tmp_app_path_name + "/Contents/embedded.provisionprofile");2234}2235}22362237if (ep.step(TTR("Code signing bundle"), 2)) {2238return ERR_SKIP;2239}2240_code_sign(p_preset, tmp_app_path_name, ent_path, true, false);2241}22422243String noto_path = p_path;2244bool noto_enabled = (p_preset->get("notarization/notarization").operator int() > 0);2245if (export_format == "dmg") {2246// Create a DMG.2247if (err == OK) {2248if (ep.step(TTR("Making DMG"), 3)) {2249return ERR_SKIP;2250}2251err = _create_dmg(p_path, pkg_name, tmp_base_path_name);2252}2253// Sign DMG.2254if (err == OK && sign_enabled && !ad_hoc) {2255if (ep.step(TTR("Code signing DMG"), 3)) {2256return ERR_SKIP;2257}2258_code_sign(p_preset, p_path, ent_path, false, false);2259}2260} else if (export_format == "pkg") {2261// Create a Installer.2262if (err == OK) {2263if (ep.step(TTR("Making PKG installer"), 3)) {2264return ERR_SKIP;2265}2266err = _create_pkg(p_preset, p_path, tmp_app_path_name);2267}2268} else if (export_format == "zip") {2269// Create ZIP.2270if (err == OK) {2271if (ep.step(TTR("Making ZIP"), 3)) {2272return ERR_SKIP;2273}2274if (FileAccess::exists(p_path)) {2275OS::get_singleton()->move_to_trash(p_path);2276}22772278Ref<FileAccess> io_fa_dst;2279zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);2280zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);22812282zip_folder_recursive(zip, tmp_base_path_name, "", pkg_name);22832284zipClose(zip, nullptr);2285}2286} else if (export_format == "app" && noto_enabled) {2287// Create temporary ZIP.2288if (err == OK) {2289noto_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".zip");22902291if (ep.step(TTR("Making ZIP"), 3)) {2292return ERR_SKIP;2293}2294if (FileAccess::exists(noto_path)) {2295OS::get_singleton()->move_to_trash(noto_path);2296}22972298Ref<FileAccess> io_fa_dst;2299zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);2300zipFile zip = zipOpen2(noto_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);23012302zip_folder_recursive(zip, tmp_base_path_name, tmp_app_dir_name, pkg_name);23032304zipClose(zip, nullptr);2305}2306}23072308if (err == OK && noto_enabled) {2309if (export_format == "pkg") {2310add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("Notarization requires the app to be archived first, select the DMG or ZIP export format instead."));2311} else {2312if (ep.step(TTR("Sending archive for notarization"), 4)) {2313return ERR_SKIP;2314}2315err = _notarize(p_preset, noto_path);2316}2317}23182319if (FileAccess::exists(ent_path)) {2320print_verbose("entitlements:\n" + FileAccess::get_file_as_string(ent_path));2321}23222323if (FileAccess::exists(hlp_ent_path)) {2324print_verbose("helper entitlements:\n" + FileAccess::get_file_as_string(hlp_ent_path));2325}23262327// Clean up temporary entitlements files.2328if (FileAccess::exists(hlp_ent_path)) {2329DirAccess::remove_file_or_error(hlp_ent_path);2330}23312332// Clean up temporary .app dir and generated entitlements.2333if ((String)(p_preset->get("codesign/entitlements/custom_file")) == "") {2334tmp_app_dir->remove(ent_path);2335}2336if (export_format != "app") {2337if (tmp_app_dir->change_dir(tmp_base_path_name) == OK) {2338tmp_app_dir->erase_contents_recursive();2339tmp_app_dir->change_dir("..");2340tmp_app_dir->remove(pkg_name);2341}2342} else if (noto_path != p_path) {2343if (FileAccess::exists(noto_path)) {2344DirAccess::remove_file_or_error(noto_path);2345}2346}2347}23482349return err;2350}23512352bool EditorExportPlatformMacOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {2353String err;2354// Look for export templates (official templates first, then custom).2355bool dvalid = exists_export_template("macos.zip", &err);2356bool rvalid = dvalid; // Both in the same ZIP.23572358if (p_preset->get("custom_template/debug") != "") {2359dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));2360if (!dvalid) {2361err += TTR("Custom debug template not found.") + "\n";2362}2363}2364if (p_preset->get("custom_template/release") != "") {2365rvalid = FileAccess::exists(p_preset->get("custom_template/release"));2366if (!rvalid) {2367err += TTR("Custom release template not found.") + "\n";2368}2369}23702371bool valid = dvalid || rvalid;2372r_missing_templates = !valid;23732374// Check the texture formats, which vary depending on the target architecture.2375String architecture = p_preset->get("binary_format/architecture");2376if (architecture == "universal" || architecture == "x86_64") {2377if (!ResourceImporterTextureSettings::should_import_s3tc_bptc()) {2378err += 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";2379valid = false;2380}2381}2382if (architecture == "universal" || architecture == "arm64") {2383if (!ResourceImporterTextureSettings::should_import_etc2_astc()) {2384err += 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";2385valid = false;2386}2387}2388if (architecture != "universal" && architecture != "x86_64" && architecture != "arm64") {2389ERR_PRINT("Invalid architecture");2390}23912392if (!err.is_empty()) {2393r_error = err;2394}2395return valid;2396}23972398bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {2399String err;2400bool valid = true;24012402int dist_type = p_preset->get("export/distribution_type");2403bool ad_hoc = false;2404int codesign_tool = p_preset->get("codesign/codesign");2405int notary_tool = p_preset->get("notarization/notarization");2406switch (codesign_tool) {2407case 1: { // built-in ad-hoc2408ad_hoc = true;2409} break;2410case 2: { // "rcodesign"2411ad_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();2412} break;2413#ifdef MACOS_ENABLED2414case 3: { // "codesign"2415ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");2416} break;2417#endif2418default: {2419};2420}24212422const String &additional_plist_content = p_preset->get("application/additional_plist_content");2423if (!additional_plist_content.is_empty()) {2424const String &plist = vformat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"2425"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"2426"<plist version=\"1.0\">"2427"<dict>\n"2428"%s\n"2429"</dict>\n"2430"</plist>\n",2431additional_plist_content);24322433String plist_err;2434Ref<PList> plist_parser;2435plist_parser.instantiate();2436if (!plist_parser->load_string(plist, plist_err)) {2437err += TTR("Invalid additional PList content: ") + plist_err + "\n";2438valid = false;2439}2440}24412442List<ExportOption> options;2443get_export_options(&options);2444for (const EditorExportPlatform::ExportOption &E : options) {2445if (get_export_option_visibility(p_preset.ptr(), E.option.name)) {2446String warn = get_export_option_warning(p_preset.ptr(), E.option.name);2447if (!warn.is_empty()) {2448err += warn + "\n";2449if (E.required) {2450valid = false;2451}2452}2453}2454}24552456if (dist_type != 2) {2457if (notary_tool > 0) {2458if (notary_tool == 2 || notary_tool == 3) {2459if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {2460err += TTR("Notarization: Xcode command line tools are not installed.") + "\n";2461valid = false;2462}2463} else if (notary_tool == 1) {2464String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();2465if (rcodesign.is_empty()) {2466err += TTR("Notarization: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";2467valid = false;2468}2469}2470} else {2471err += TTR("Warning: Notarization is disabled. The exported project will be blocked by Gatekeeper if it's downloaded from an unknown source.") + "\n";2472if (codesign_tool == 0) {2473err += TTR("Code signing is disabled. The exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n";2474}2475}2476}24772478if (codesign_tool > 0) {2479if (ad_hoc) {2480err += TTR("Code signing: Using ad-hoc signature. The exported project will be blocked by Gatekeeper") + "\n";2481}2482if (codesign_tool == 3) {2483if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {2484err += TTR("Code signing: Xcode command line tools are not installed.") + "\n";2485valid = false;2486}2487} else if (codesign_tool == 2) {2488String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();2489if (rcodesign.is_empty()) {2490err += TTR("Code signing: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";2491valid = false;2492}2493}2494}24952496if (!err.is_empty()) {2497r_error = err;2498}2499return valid;2500}25012502Ref<Texture2D> EditorExportPlatformMacOS::get_run_icon() const {2503return run_icon;2504}25052506bool EditorExportPlatformMacOS::poll_export() {2507Ref<EditorExportPreset> preset;25082509for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {2510Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);2511if (ep->is_runnable() && ep->get_platform() == this) {2512preset = ep;2513break;2514}2515}25162517int prev = menu_options;2518menu_options = (preset.is_valid() && preset->get("ssh_remote_deploy/enabled").operator bool());2519if (ssh_pid != 0 || !cleanup_commands.is_empty()) {2520if (menu_options == 0) {2521cleanup();2522} else {2523menu_options += 1;2524}2525}2526return menu_options != prev;2527}25282529Ref<Texture2D> EditorExportPlatformMacOS::get_option_icon(int p_index) const {2530if (p_index == 1) {2531return stop_icon;2532} else {2533return EditorExportPlatform::get_option_icon(p_index);2534}2535}25362537int EditorExportPlatformMacOS::get_options_count() const {2538return menu_options;2539}25402541String EditorExportPlatformMacOS::get_option_label(int p_index) const {2542return (p_index) ? TTR("Stop and uninstall") : TTR("Run on remote macOS system");2543}25442545String EditorExportPlatformMacOS::get_option_tooltip(int p_index) const {2546return (p_index) ? TTR("Stop and uninstall running project from the remote system") : TTR("Run exported project on remote macOS system");2547}25482549void EditorExportPlatformMacOS::cleanup() {2550if (ssh_pid != 0 && OS::get_singleton()->is_process_running(ssh_pid)) {2551print_line("Terminating connection...");2552OS::get_singleton()->kill(ssh_pid);2553OS::get_singleton()->delay_usec(1000);2554}25552556if (!cleanup_commands.is_empty()) {2557print_line("Stopping and deleting previous version...");2558for (const SSHCleanupCommand &cmd : cleanup_commands) {2559if (cmd.wait) {2560ssh_run_on_remote(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);2561} else {2562ssh_run_on_remote_no_wait(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);2563}2564}2565}2566ssh_pid = 0;2567cleanup_commands.clear();2568}25692570Error EditorExportPlatformMacOS::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) {2571cleanup();2572if (p_device) { // Stop command, cleanup only.2573return OK;2574}25752576EditorProgress ep("run", TTR("Running..."), 5);25772578const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("macos");2579Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);2580if (!da->dir_exists(dest)) {2581Error err = da->make_dir_recursive(dest);2582if (err != OK) {2583EditorNode::get_singleton()->show_warning(TTR("Could not create temp directory:") + "\n" + dest);2584return err;2585}2586}25872588String pkg_name;2589if (String(get_project_setting(p_preset, "application/config/name")) != "") {2590pkg_name = String(get_project_setting(p_preset, "application/config/name"));2591} else {2592pkg_name = "Unnamed";2593}2594pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);25952596String host = p_preset->get("ssh_remote_deploy/host").operator String();2597String port = p_preset->get("ssh_remote_deploy/port").operator String();2598if (port.is_empty()) {2599port = "22";2600}2601Vector<String> extra_args_ssh = p_preset->get("ssh_remote_deploy/extra_args_ssh").operator String().split(" ", false);2602Vector<String> extra_args_scp = p_preset->get("ssh_remote_deploy/extra_args_scp").operator String().split(" ", false);26032604const String basepath = dest.path_join("tmp_macos_export");26052606#define CLEANUP_AND_RETURN(m_err) \2607{ \2608if (da->file_exists(basepath + ".zip")) { \2609da->remove(basepath + ".zip"); \2610} \2611if (da->file_exists(basepath + "_start.sh")) { \2612da->remove(basepath + "_start.sh"); \2613} \2614if (da->file_exists(basepath + "_clean.sh")) { \2615da->remove(basepath + "_clean.sh"); \2616} \2617return m_err; \2618} \2619((void)0)26202621if (ep.step(TTR("Exporting project..."), 1)) {2622return ERR_SKIP;2623}2624Error err = export_project(p_preset, true, basepath + ".zip", p_debug_flags);2625if (err != OK) {2626DirAccess::remove_file_or_error(basepath + ".zip");2627return err;2628}26292630String cmd_args;2631{2632Vector<String> cmd_args_list = gen_export_flags(p_debug_flags);2633for (int i = 0; i < cmd_args_list.size(); i++) {2634if (i != 0) {2635cmd_args += " ";2636}2637cmd_args += cmd_args_list[i];2638}2639}26402641const bool use_remote = p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG) || p_debug_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT);2642int dbg_port = EDITOR_GET("network/debug/remote_port");26432644print_line("Creating temporary directory...");2645ep.step(TTR("Creating temporary directory..."), 2);2646String temp_dir;2647err = ssh_run_on_remote(host, port, extra_args_ssh, "mktemp -d", &temp_dir);2648if (err != OK || temp_dir.is_empty()) {2649CLEANUP_AND_RETURN(err);2650}26512652print_line("Uploading archive...");2653ep.step(TTR("Uploading archive..."), 3);2654err = ssh_push_to_remote(host, port, extra_args_scp, basepath + ".zip", temp_dir);2655if (err != OK) {2656CLEANUP_AND_RETURN(err);2657}26582659{2660String run_script = p_preset->get("ssh_remote_deploy/run_script");2661run_script = run_script.replace("{temp_dir}", temp_dir);2662run_script = run_script.replace("{archive_name}", basepath.get_file() + ".zip");2663run_script = run_script.replace("{exe_name}", pkg_name);2664run_script = run_script.replace("{cmd_args}", cmd_args);26652666Ref<FileAccess> f = FileAccess::open(basepath + "_start.sh", FileAccess::WRITE);2667if (f.is_null()) {2668CLEANUP_AND_RETURN(err);2669}26702671f->store_string(run_script);2672}26732674{2675String clean_script = p_preset->get("ssh_remote_deploy/cleanup_script");2676clean_script = clean_script.replace("{temp_dir}", temp_dir);2677clean_script = clean_script.replace("{archive_name}", basepath.get_file() + ".zip");2678clean_script = clean_script.replace("{exe_name}", pkg_name);2679clean_script = clean_script.replace("{cmd_args}", cmd_args);26802681Ref<FileAccess> f = FileAccess::open(basepath + "_clean.sh", FileAccess::WRITE);2682if (f.is_null()) {2683CLEANUP_AND_RETURN(err);2684}26852686f->store_string(clean_script);2687}26882689print_line("Uploading scripts...");2690ep.step(TTR("Uploading scripts..."), 4);2691err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_start.sh", temp_dir);2692if (err != OK) {2693CLEANUP_AND_RETURN(err);2694}2695err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_start.sh"));2696if (err != OK || temp_dir.is_empty()) {2697CLEANUP_AND_RETURN(err);2698}2699err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_clean.sh", temp_dir);2700if (err != OK) {2701CLEANUP_AND_RETURN(err);2702}2703err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh"));2704if (err != OK || temp_dir.is_empty()) {2705CLEANUP_AND_RETURN(err);2706}27072708print_line("Starting project...");2709ep.step(TTR("Starting project..."), 5);2710err = 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);2711if (err != OK) {2712CLEANUP_AND_RETURN(err);2713}27142715cleanup_commands.clear();2716cleanup_commands.push_back(SSHCleanupCommand(host, port, extra_args_ssh, vformat("\"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh")));27172718print_line("Project started.");27192720CLEANUP_AND_RETURN(OK);2721#undef CLEANUP_AND_RETURN2722}27232724EditorExportPlatformMacOS::EditorExportPlatformMacOS() {2725if (EditorNode::get_singleton()) {2726Ref<Image> img = memnew(Image);2727const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);27282729ImageLoaderSVG::create_image_from_string(img, _macos_logo_svg, EDSCALE, upsample, false);2730logo = ImageTexture::create_from_image(img);27312732ImageLoaderSVG::create_image_from_string(img, _macos_run_icon_svg, EDSCALE, upsample, false);2733run_icon = ImageTexture::create_from_image(img);27342735Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();2736if (theme.is_valid()) {2737stop_icon = theme->get_icon(SNAME("Stop"), EditorStringName(EditorIcons));2738} else {2739stop_icon.instantiate();2740}2741}2742}274327442745