| 1 | /**************************************************************************/ |
| 2 | /* editor_export_platform_apple_embedded.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "editor_export_platform_apple_embedded.h" |
| 32 | |
| 33 | #include "core/io/json.h" |
| 34 | #include "core/io/plist.h" |
| 35 | #include "core/string/translation_server.h" |
| 36 | #include "editor/editor_node.h" |
| 37 | #include "editor/editor_string_names.h" |
| 38 | #include "editor/export/editor_export.h" |
| 39 | #include "editor/export/lipo.h" |
| 40 | #include "editor/export/macho.h" |
| 41 | #include "editor/file_system/editor_paths.h" |
| 42 | #include "editor/import/resource_importer_texture_settings.h" |
| 43 | #include "editor/script/script_editor_plugin.h" |
| 44 | #include "editor/themes/editor_scale.h" |
| 45 | #include "main/main.h" |
| 46 | |
| 47 | #include "modules/modules_enabled.gen.h" // For mono. |
| 48 | #include "modules/svg/image_loader_svg.h" |
| 49 | |
| 50 | void EditorExportPlatformAppleEmbedded::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const { |
| 51 | // Vulkan and OpenGL ES 3.0 both mandate ETC2 support. |
| 52 | r_features->push_back("etc2"); |
| 53 | r_features->push_back("astc"); |
| 54 | |
| 55 | if (!p_preset->is_dedicated_server() && p_preset->get("shader_baker/enabled")) { |
| 56 | // Don't use the shader baker if exporting as a dedicated server, as no rendering is performed. |
| 57 | r_features->push_back("shader_baker"); |
| 58 | } |
| 59 | |
| 60 | Vector<String> architectures = _get_preset_architectures(p_preset); |
| 61 | for (int i = 0; i < architectures.size(); ++i) { |
| 62 | r_features->push_back(architectures[i]); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | Vector<EditorExportPlatformAppleEmbedded::ExportArchitecture> EditorExportPlatformAppleEmbedded::_get_supported_architectures() const { |
| 67 | Vector<ExportArchitecture> archs; |
| 68 | archs.push_back(ExportArchitecture("arm64", true)); |
| 69 | return archs; |
| 70 | } |
| 71 | |
| 72 | struct APIAccessInfo { |
| 73 | String prop_name; |
| 74 | String type_name; |
| 75 | Vector<String> prop_flag_value; |
| 76 | Vector<String> prop_flag_name; |
| 77 | int default_value; |
| 78 | }; |
| 79 | |
| 80 | static const APIAccessInfo api_info[] = { |
| 81 | { "file_timestamp", |
| 82 | "NSPrivacyAccessedAPICategoryFileTimestamp", |
| 83 | { "DDA9.1", "C617.1", "3B52.1" }, |
| 84 | { "Display to user on-device:", "Inside app or group container", "Files provided to app by user" }, |
| 85 | 3 }, |
| 86 | { "system_boot_time", |
| 87 | "NSPrivacyAccessedAPICategorySystemBootTime", |
| 88 | { "35F9.1", "8FFB.1", "3D61.1" }, |
| 89 | { "Measure time on-device", "Calculate absolute event timestamps", "User-initiated bug report" }, |
| 90 | 1 }, |
| 91 | { "disk_space", |
| 92 | "NSPrivacyAccessedAPICategoryDiskSpace", |
| 93 | { "E174.1", "85F4.1", "7D9E.1", "B728.1" }, |
| 94 | { "Write or delete file on-device", "Display to user on-device", "User-initiated bug report", "Health research app" }, |
| 95 | 3 }, |
| 96 | { "active_keyboard", |
| 97 | "NSPrivacyAccessedAPICategoryActiveKeyboards", |
| 98 | { "3EC4.1", "54BD.1" }, |
| 99 | { "Custom keyboard app on-device", "Customize UI on-device:2" }, |
| 100 | 0 }, |
| 101 | { "user_defaults", |
| 102 | "NSPrivacyAccessedAPICategoryUserDefaults", |
| 103 | { "1C8F.1", "AC6B.1", "CA92.1" }, |
| 104 | { "Access info from same App Group", "Access managed app configuration", "Access info from same app" }, |
| 105 | 0 }, |
| 106 | }; |
| 107 | |
| 108 | struct DataCollectionInfo { |
| 109 | String prop_name; |
| 110 | String type_name; |
| 111 | }; |
| 112 | |
| 113 | static const DataCollectionInfo data_collect_type_info[] = { |
| 114 | { "name", "NSPrivacyCollectedDataTypeName" }, |
| 115 | { "email_address", "NSPrivacyCollectedDataTypeEmailAddress" }, |
| 116 | { "phone_number", "NSPrivacyCollectedDataTypePhoneNumber" }, |
| 117 | { "physical_address", "NSPrivacyCollectedDataTypePhysicalAddress" }, |
| 118 | { "other_contact_info", "NSPrivacyCollectedDataTypeOtherUserContactInfo" }, |
| 119 | { "health", "NSPrivacyCollectedDataTypeHealth" }, |
| 120 | { "fitness", "NSPrivacyCollectedDataTypeFitness" }, |
| 121 | { "payment_info", "NSPrivacyCollectedDataTypePaymentInfo" }, |
| 122 | { "credit_info", "NSPrivacyCollectedDataTypeCreditInfo" }, |
| 123 | { "other_financial_info", "NSPrivacyCollectedDataTypeOtherFinancialInfo" }, |
| 124 | { "precise_location", "NSPrivacyCollectedDataTypePreciseLocation" }, |
| 125 | { "coarse_location", "NSPrivacyCollectedDataTypeCoarseLocation" }, |
| 126 | { "sensitive_info", "NSPrivacyCollectedDataTypeSensitiveInfo" }, |
| 127 | { "contacts", "NSPrivacyCollectedDataTypeContacts" }, |
| 128 | { "emails_or_text_messages", "NSPrivacyCollectedDataTypeEmailsOrTextMessages" }, |
| 129 | { "photos_or_videos", "NSPrivacyCollectedDataTypePhotosorVideos" }, |
| 130 | { "audio_data", "NSPrivacyCollectedDataTypeAudioData" }, |
| 131 | { "gameplay_content", "NSPrivacyCollectedDataTypeGameplayContent" }, |
| 132 | { "customer_support", "NSPrivacyCollectedDataTypeCustomerSupport" }, |
| 133 | { "other_user_content", "NSPrivacyCollectedDataTypeOtherUserContent" }, |
| 134 | { "browsing_history", "NSPrivacyCollectedDataTypeBrowsingHistory" }, |
| 135 | { "search_history", "NSPrivacyCollectedDataTypeSearchHistory" }, |
| 136 | { "user_id", "NSPrivacyCollectedDataTypeUserID" }, |
| 137 | { "device_id", "NSPrivacyCollectedDataTypeDeviceID" }, |
| 138 | { "purchase_history", "NSPrivacyCollectedDataTypePurchaseHistory" }, |
| 139 | { "product_interaction", "NSPrivacyCollectedDataTypeProductInteraction" }, |
| 140 | { "advertising_data", "NSPrivacyCollectedDataTypeAdvertisingData" }, |
| 141 | { "other_usage_data", "NSPrivacyCollectedDataTypeOtherUsageData" }, |
| 142 | { "crash_data", "NSPrivacyCollectedDataTypeCrashData" }, |
| 143 | { "performance_data", "NSPrivacyCollectedDataTypePerformanceData" }, |
| 144 | { "other_diagnostic_data", "NSPrivacyCollectedDataTypeOtherDiagnosticData" }, |
| 145 | { "environment_scanning", "NSPrivacyCollectedDataTypeEnvironmentScanning" }, |
| 146 | { "hands", "NSPrivacyCollectedDataTypeHands" }, |
| 147 | { "head", "NSPrivacyCollectedDataTypeHead" }, |
| 148 | { "other_data_types", "NSPrivacyCollectedDataTypeOtherDataTypes" }, |
| 149 | }; |
| 150 | |
| 151 | static const DataCollectionInfo data_collect_purpose_info[] = { |
| 152 | { "Analytics", "NSPrivacyCollectedDataTypePurposeAnalytics" }, |
| 153 | { "App Functionality", "NSPrivacyCollectedDataTypePurposeAppFunctionality" }, |
| 154 | { "Developer Advertising", "NSPrivacyCollectedDataTypePurposeDeveloperAdvertising" }, |
| 155 | { "Third-party Advertising", "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising" }, |
| 156 | { "Product Personalization", "NSPrivacyCollectedDataTypePurposeProductPersonalization" }, |
| 157 | { "Other", "NSPrivacyCollectedDataTypePurposeOther" }, |
| 158 | }; |
| 159 | |
| 160 | static const String export_method_string[] = { |
| 161 | "app-store", |
| 162 | "development", |
| 163 | "ad-hoc", |
| 164 | "enterprise", |
| 165 | }; |
| 166 | |
| 167 | String EditorExportPlatformAppleEmbedded::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const { |
| 168 | if (p_preset) { |
| 169 | if (p_name == "application/app_store_team_id") { |
| 170 | String team_id = p_preset->get("application/app_store_team_id"); |
| 171 | if (team_id.is_empty()) { |
| 172 | return TTR("App Store Team ID not specified.") + "\n"; |
| 173 | } |
| 174 | } else if (p_name == "application/bundle_identifier") { |
| 175 | String identifier = p_preset->get("application/bundle_identifier"); |
| 176 | String pn_err; |
| 177 | if (!is_package_name_valid(identifier, &pn_err)) { |
| 178 | return TTR("Invalid Identifier:") + " " + pn_err; |
| 179 | } |
| 180 | } else if (p_name == "privacy/file_timestamp_access_reasons") { |
| 181 | int access = p_preset->get("privacy/file_timestamp_access_reasons"); |
| 182 | if (access == 0) { |
| 183 | return TTR("At least one file timestamp access reason should be selected."); |
| 184 | } |
| 185 | } else if (p_name == "privacy/disk_space_access_reasons") { |
| 186 | int access = p_preset->get("privacy/disk_space_access_reasons"); |
| 187 | if (access == 0) { |
| 188 | return TTR("At least one disk space access reason should be selected."); |
| 189 | } |
| 190 | } else if (p_name == "privacy/system_boot_time_access_reasons") { |
| 191 | int access = p_preset->get("privacy/system_boot_time_access_reasons"); |
| 192 | if (access == 0) { |
| 193 | return TTR("At least one system boot time access reason should be selected."); |
| 194 | } |
| 195 | } else if (p_name == "shader_baker/enabled" && bool(p_preset->get("shader_baker/enabled"))) { |
| 196 | String export_renderer = GLOBAL_GET("rendering/renderer/rendering_method.mobile"); |
| 197 | if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") { |
| 198 | return TTR("\"Shader Baker\" doesn't work with the Compatibility renderer."); |
| 199 | } else if (OS::get_singleton()->get_current_rendering_method() != export_renderer) { |
| 200 | return vformat(TTR("The editor is currently using a different renderer than what the target platform will use. \"Shader Baker\" won't be able to include core shaders. Switch to \"%s\" renderer temporarily to fix this."), export_renderer); |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | return String(); |
| 205 | } |
| 206 | |
| 207 | void EditorExportPlatformAppleEmbedded::_notification(int p_what) { |
| 208 | #ifdef MACOS_ENABLED |
| 209 | if (p_what == NOTIFICATION_POSTINITIALIZE) { |
| 210 | if (EditorExport::get_singleton()) { |
| 211 | EditorExport::get_singleton()->connect_presets_runnable_updated(callable_mp(this, &EditorExportPlatformAppleEmbedded::_update_preset_status)); |
| 212 | } |
| 213 | } |
| 214 | #endif |
| 215 | } |
| 216 | |
| 217 | bool EditorExportPlatformAppleEmbedded::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const { |
| 218 | // Hide unsupported .NET embedding option. |
| 219 | if (p_option == "dotnet/embed_build_outputs") { |
| 220 | return false; |
| 221 | } |
| 222 | |
| 223 | if (p_preset == nullptr) { |
| 224 | return true; |
| 225 | } |
| 226 | |
| 227 | bool advanced_options_enabled = p_preset->are_advanced_options_enabled(); |
| 228 | if (p_option.begins_with("privacy") || |
| 229 | (p_option.begins_with("icons/") && !p_option.begins_with("icons/icon") && !p_option.begins_with("icons/app_store")) || |
| 230 | p_option == "custom_template/debug" || |
| 231 | p_option == "custom_template/release" || |
| 232 | p_option == "application/additional_plist_content" || |
| 233 | p_option == "application/delete_old_export_files_unconditionally" || |
| 234 | p_option == "application/icon_interpolation" || |
| 235 | p_option == "application/signature") { |
| 236 | return advanced_options_enabled; |
| 237 | } |
| 238 | if (p_option == "capabilities/performance_a12") { |
| 239 | String rendering_method = get_project_setting(Ref<EditorExportPreset>(p_preset), "rendering/renderer/rendering_method.mobile"); |
| 240 | return !(rendering_method == "forward_plus" || rendering_method == "mobile"); |
| 241 | } |
| 242 | |
| 243 | return true; |
| 244 | } |
| 245 | |
| 246 | void EditorExportPlatformAppleEmbedded::get_export_options(List<ExportOption> *r_options) const { |
| 247 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), "")); |
| 248 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), "")); |
| 249 | |
| 250 | Vector<ExportArchitecture> architectures = _get_supported_architectures(); |
| 251 | for (int i = 0; i < architectures.size(); ++i) { |
| 252 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("architectures"), architectures[i].name)), architectures[i].is_default)); |
| 253 | } |
| 254 | |
| 255 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_store_team_id"), "", false, true)); |
| 256 | |
| 257 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_debug", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 1)); |
| 258 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple Development"), "")); |
| 259 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple Distribution"), "")); |
| 260 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_debug", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "")); |
| 261 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_release", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "")); |
| 262 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_specifier_debug", PROPERTY_HINT_PLACEHOLDER_TEXT, ""), "")); |
| 263 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_specifier_release", PROPERTY_HINT_PLACEHOLDER_TEXT, ""), "")); |
| 264 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_release", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 0)); |
| 265 | |
| 266 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "", false, true)); |
| 267 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "")); |
| 268 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), "")); |
| 269 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), "")); |
| 270 | |
| 271 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/additional_plist_content", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), "")); |
| 272 | |
| 273 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4)); |
| 274 | |
| 275 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/export_project_only"), false)); |
| 276 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/delete_old_export_files_unconditionally"), false)); |
| 277 | |
| 278 | Vector<PluginConfigAppleEmbedded> found_plugins = get_plugins(get_platform_name()); |
| 279 | for (int i = 0; i < found_plugins.size(); i++) { |
| 280 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("plugins"), found_plugins[i].name)), false)); |
| 281 | } |
| 282 | |
| 283 | HashSet<String> plist_keys; |
| 284 | |
| 285 | for (int i = 0; i < found_plugins.size(); i++) { |
| 286 | // Editable plugin plist values |
| 287 | PluginConfigAppleEmbedded plugin = found_plugins[i]; |
| 288 | |
| 289 | for (const KeyValue<String, PluginConfigAppleEmbedded::PlistItem> &E : plugin.plist) { |
| 290 | switch (E.value.type) { |
| 291 | case PluginConfigAppleEmbedded::PlistItemType::STRING_INPUT: { |
| 292 | String preset_name = "plugins_plist/" + E.key; |
| 293 | if (!plist_keys.has(preset_name)) { |
| 294 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, preset_name), E.value.value)); |
| 295 | plist_keys.insert(preset_name); |
| 296 | } |
| 297 | } break; |
| 298 | default: |
| 299 | continue; |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | plugins_changed.clear(); |
| 305 | plugins = found_plugins; |
| 306 | |
| 307 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "entitlements/increased_memory_limit"), false)); |
| 308 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "entitlements/game_center"), false)); |
| 309 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "entitlements/push_notifications", PROPERTY_HINT_ENUM, "Disabled,Production,Development"), "Disabled")); |
| 310 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "entitlements/additional", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), "")); |
| 311 | |
| 312 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/access_wifi"), false)); |
| 313 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/performance_gaming_tier"), false)); |
| 314 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/performance_a12"), false)); |
| 315 | r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "capabilities/additional"), PackedStringArray())); |
| 316 | |
| 317 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "shader_baker/enabled"), false)); |
| 318 | |
| 319 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_files_app"), false)); |
| 320 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_itunes_sharing"), false)); |
| 321 | |
| 322 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/camera_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the camera"), "")); |
| 323 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 324 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/microphone_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the microphone"), "")); |
| 325 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 326 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/photolibrary_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need access to the photo library"), "")); |
| 327 | r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photolibrary_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); |
| 328 | |
| 329 | for (uint64_t i = 0; i < std_size(api_info); ++i) { |
| 330 | String prop_name = vformat("privacy/%s_access_reasons", api_info[i].prop_name); |
| 331 | String hint; |
| 332 | for (int j = 0; j < api_info[i].prop_flag_value.size(); j++) { |
| 333 | if (j != 0) { |
| 334 | hint += ","; |
| 335 | } |
| 336 | hint += vformat("%s - %s:%d", api_info[i].prop_flag_value[j], api_info[i].prop_flag_name[j], (1 << j)); |
| 337 | } |
| 338 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, prop_name, PROPERTY_HINT_FLAGS, hint), api_info[i].default_value)); |
| 339 | } |
| 340 | |
| 341 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "privacy/tracking_enabled"), false)); |
| 342 | r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "privacy/tracking_domains"), Vector<String>())); |
| 343 | |
| 344 | { |
| 345 | String hint; |
| 346 | for (uint64_t i = 0; i < std_size(data_collect_purpose_info); ++i) { |
| 347 | if (i != 0) { |
| 348 | hint += ","; |
| 349 | } |
| 350 | hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i)); |
| 351 | } |
| 352 | for (uint64_t i = 0; i < std_size(data_collect_type_info); ++i) { |
| 353 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false)); |
| 354 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false)); |
| 355 | r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false)); |
| 356 | r_options->push_back(ExportOption(PropertyInfo(Variant::INT, vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[i].prop_name), PROPERTY_HINT_FLAGS, hint), 0)); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), "")); |
| 361 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_dark", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), "")); |
| 362 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "icons/icon_1024x1024_tinted", PROPERTY_HINT_FILE_PATH, "*.svg,*.png,*.webp,*.jpg,*.jpeg"), "")); |
| 363 | |
| 364 | HashSet<String> used_names; |
| 365 | |
| 366 | Vector<IconInfo> icon_infos = get_icon_infos(); |
| 367 | for (int i = 0; i < icon_infos.size(); ++i) { |
| 368 | if (!used_names.has(icon_infos[i].preset_key)) { |
| 369 | used_names.insert(icon_infos[i].preset_key); |
| 370 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key), PROPERTY_HINT_FILE_PATH, "*.png,*.jpg,*.jpeg"), "")); |
| 371 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_dark", PROPERTY_HINT_FILE_PATH, "*.png,*.jpg,*.jpeg"), "")); |
| 372 | r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, String(icon_infos[i].preset_key) + "_tinted", PROPERTY_HINT_FILE_PATH, "*.png,*.jpg,*.jpeg"), "")); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | void EditorExportPlatformAppleEmbedded::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_file, const AppleEmbeddedConfigData &p_config, bool p_debug) { |
| 378 | CodeSigningDetails code_signing(p_preset); |
| 379 | |
| 380 | String str = String::utf8((const char *)p_file.ptr(), p_file.size()); |
| 381 | String strnew; |
| 382 | Vector<String> lines = str.split("\n"); |
| 383 | for (const String &line : lines) { |
| 384 | strnew += _process_config_file_line(p_preset, line, p_config, p_debug, code_signing); |
| 385 | } |
| 386 | |
| 387 | // Write (size - 1) to avoid outputting the null terminator. |
| 388 | CharString cs = strnew.utf8(); |
| 389 | p_file.resize(cs.size() - 1); |
| 390 | uint8_t *p_file_ptrw = p_file.ptrw(); |
| 391 | for (int i = 0; i < cs.size() - 1; i++) { |
| 392 | p_file_ptrw[i] = cs[i]; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | String EditorExportPlatformAppleEmbedded::_process_config_file_line(const Ref<EditorExportPreset> &p_preset, const String &p_line, const AppleEmbeddedConfigData &p_config, bool p_debug, const CodeSigningDetails &p_code_signing) { |
| 397 | String strnew; |
| 398 | if (p_line.contains("$binary")) { |
| 399 | strnew += p_line.replace("$binary", p_config.binary_name) + "\n"; |
| 400 | } else if (p_line.contains("$modules_buildfile")) { |
| 401 | strnew += p_line.replace("$modules_buildfile", p_config.modules_buildfile) + "\n"; |
| 402 | } else if (p_line.contains("$modules_fileref")) { |
| 403 | strnew += p_line.replace("$modules_fileref", p_config.modules_fileref) + "\n"; |
| 404 | } else if (p_line.contains("$modules_buildphase")) { |
| 405 | strnew += p_line.replace("$modules_buildphase", p_config.modules_buildphase) + "\n"; |
| 406 | } else if (p_line.contains("$modules_buildgrp")) { |
| 407 | strnew += p_line.replace("$modules_buildgrp", p_config.modules_buildgrp) + "\n"; |
| 408 | } else if (p_line.contains("$name")) { |
| 409 | strnew += p_line.replace("$name", p_config.pkg_name) + "\n"; |
| 410 | } else if (p_line.contains("$bundle_identifier")) { |
| 411 | strnew += p_line.replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n"; |
| 412 | } else if (p_line.contains("$short_version")) { |
| 413 | strnew += p_line.replace("$short_version", p_preset->get_version("application/short_version")) + "\n"; |
| 414 | } else if (p_line.contains("$version")) { |
| 415 | strnew += p_line.replace("$version", p_preset->get_version("application/version")) + "\n"; |
| 416 | } else if (p_line.contains("$signature")) { |
| 417 | strnew += p_line.replace("$signature", p_preset->get("application/signature")) + "\n"; |
| 418 | } else if (p_line.contains("$team_id")) { |
| 419 | strnew += p_line.replace("$team_id", p_preset->get("application/app_store_team_id")) + "\n"; |
| 420 | } else if (p_line.contains("$default_build_config")) { |
| 421 | strnew += p_line.replace("$default_build_config", p_debug ? "Debug" : "Release") + "\n"; |
| 422 | } else if (p_line.contains("$export_method")) { |
| 423 | int export_method = p_preset->get(p_debug ? "application/export_method_debug" : "application/export_method_release"); |
| 424 | strnew += p_line.replace("$export_method", export_method_string[export_method]) + "\n"; |
| 425 | } else if (p_line.contains("$provisioning_profile_specifier_debug")) { |
| 426 | strnew += p_line.replace("$provisioning_profile_specifier_debug", p_code_signing.debug_provisioning_profile_specifier) + "\n"; |
| 427 | } else if (p_line.contains("$provisioning_profile_specifier_release")) { |
| 428 | strnew += p_line.replace("$provisioning_profile_specifier_release", p_code_signing.release_provisioning_profile_specifier) + "\n"; |
| 429 | } else if (p_line.contains("$provisioning_profile_specifier")) { |
| 430 | String specifier = p_debug ? p_code_signing.debug_provisioning_profile_specifier : p_code_signing.release_provisioning_profile_specifier; |
| 431 | strnew += p_line.replace("$provisioning_profile_specifier", specifier) + "\n"; |
| 432 | } else if (p_line.contains("$provisioning_profile_uuid_release")) { |
| 433 | strnew += p_line.replace("$provisioning_profile_uuid_release", p_code_signing.release_provisioning_profile_uuid) + "\n"; |
| 434 | } else if (p_line.contains("$provisioning_profile_uuid_debug")) { |
| 435 | strnew += p_line.replace("$provisioning_profile_uuid_debug", p_code_signing.debug_provisioning_profile_uuid) + "\n"; |
| 436 | } else if (p_line.contains("$code_sign_style_debug")) { |
| 437 | if (p_code_signing.debug_manual_signing) { |
| 438 | strnew += p_line.replace("$code_sign_style_debug", "Manual") + "\n"; |
| 439 | } else { |
| 440 | strnew += p_line.replace("$code_sign_style_debug", "Automatic") + "\n"; |
| 441 | } |
| 442 | } else if (p_line.contains("$code_sign_style_release")) { |
| 443 | if (p_code_signing.release_manual_signing) { |
| 444 | strnew += p_line.replace("$code_sign_style_release", "Manual") + "\n"; |
| 445 | } else { |
| 446 | strnew += p_line.replace("$code_sign_style_release", "Automatic") + "\n"; |
| 447 | } |
| 448 | } else if (p_line.contains("$provisioning_profile_uuid")) { |
| 449 | String uuid = p_debug ? p_code_signing.debug_provisioning_profile_uuid : p_code_signing.release_provisioning_profile_uuid; |
| 450 | if (uuid.is_empty()) { |
| 451 | uuid = p_debug ? p_code_signing.debug_provisioning_profile_specifier : p_code_signing.release_provisioning_profile_specifier; |
| 452 | } |
| 453 | strnew += p_line.replace("$provisioning_profile_uuid", uuid) + "\n"; |
| 454 | } else if (p_line.contains("$code_sign_identity_debug")) { |
| 455 | strnew += p_line.replace("$code_sign_identity_debug", p_code_signing.debug_signing_identity) + "\n"; |
| 456 | } else if (p_line.contains("$code_sign_identity_release")) { |
| 457 | strnew += p_line.replace("$code_sign_identity_release", p_code_signing.release_signing_identity) + "\n"; |
| 458 | } else if (p_line.contains("$additional_plist_content")) { |
| 459 | strnew += p_line.replace("$additional_plist_content", p_config.plist_content) + "\n"; |
| 460 | } else if (p_line.contains("$godot_archs")) { |
| 461 | strnew += p_line.replace("$godot_archs", p_config.architectures) + "\n"; |
| 462 | } else if (p_line.contains("$linker_flags")) { |
| 463 | strnew += p_line.replace("$linker_flags", p_config.linker_flags) + "\n"; |
| 464 | } else if (p_line.contains("$targeted_device_family")) { |
| 465 | String xcode_value; |
| 466 | switch ((int)p_preset->get("application/targeted_device_family")) { |
| 467 | case 0: // iPhone |
| 468 | xcode_value = "1"; |
| 469 | break; |
| 470 | case 1: // iPad |
| 471 | xcode_value = "2"; |
| 472 | break; |
| 473 | case 2: // iPhone & iPad |
| 474 | xcode_value = "1,2"; |
| 475 | break; |
| 476 | } |
| 477 | strnew += p_line.replace("$targeted_device_family", xcode_value) + "\n"; |
| 478 | } else if (p_line.contains("$cpp_code")) { |
| 479 | strnew += p_line.replace("$cpp_code", p_config.cpp_code) + "\n"; |
| 480 | } else if (p_line.contains("$docs_in_place")) { |
| 481 | strnew += p_line.replace("$docs_in_place", ((bool)p_preset->get("user_data/accessible_from_files_app")) ? "<true/>" : "<false/>") + "\n"; |
| 482 | } else if (p_line.contains("$docs_sharing")) { |
| 483 | strnew += p_line.replace("$docs_sharing", ((bool)p_preset->get("user_data/accessible_from_itunes_sharing")) ? "<true/>" : "<false/>") + "\n"; |
| 484 | } else if (p_line.contains("$entitlements_full")) { |
| 485 | String entitlements; |
| 486 | if ((String)p_preset->get("entitlements/push_notifications") != "Disabled") { |
| 487 | entitlements += "<key>aps-environment</key>\n<string>" + p_preset->get("entitlements/push_notifications").operator String().to_lower() + "</string>" + "\n"; |
| 488 | } |
| 489 | if ((bool)p_preset->get("entitlements/game_center")) { |
| 490 | entitlements += "<key>com.apple.developer.game-center</key>\n<true/>\n"; |
| 491 | } |
| 492 | if ((bool)p_preset->get("entitlements/increased_memory_limit")) { |
| 493 | entitlements += "<key>com.apple.developer.kernel.increased-memory-limit</key>\n<true/>\n"; |
| 494 | } |
| 495 | entitlements += p_preset->get("entitlements/additional").operator String() + "\n"; |
| 496 | |
| 497 | strnew += p_line.replace("$entitlements_full", entitlements); |
| 498 | } else if (p_line.contains("$required_device_capabilities")) { |
| 499 | String capabilities; |
| 500 | |
| 501 | // I've removed armv7 as we can run on 64bit only devices |
| 502 | // Note that capabilities listed here are requirements for the app to be installed. |
| 503 | // They don't enable anything. |
| 504 | Vector<String> capabilities_list = p_config.capabilities; |
| 505 | String rendering_method = get_project_setting(p_preset, "rendering/renderer/rendering_method.mobile"); |
| 506 | |
| 507 | if ((bool)p_preset->get("capabilities/access_wifi") && !capabilities_list.has("wifi")) { |
| 508 | capabilities_list.push_back("wifi"); |
| 509 | } |
| 510 | if ((bool)p_preset->get("capabilities/performance_gaming_tier") && !capabilities_list.has("iphone-performance-gaming-tier")) { |
| 511 | capabilities_list.push_back("iphone-performance-gaming-tier"); |
| 512 | } |
| 513 | if (((bool)p_preset->get("capabilities/performance_a12") || rendering_method == "forward_plus" || rendering_method == "mobile") && !capabilities_list.has("iphone-ipad-minimum-performance-a12")) { |
| 514 | capabilities_list.push_back("iphone-ipad-minimum-performance-a12"); |
| 515 | } |
| 516 | for (const String &capability : capabilities_list) { |
| 517 | capabilities += "<string>" + capability + "</string>\n"; |
| 518 | } |
| 519 | for (const String &cap : p_preset->get("capabilities/additional").operator PackedStringArray()) { |
| 520 | capabilities += "<string>" + cap + "</string>\n"; |
| 521 | } |
| 522 | |
| 523 | strnew += p_line.replace("$required_device_capabilities", capabilities); |
| 524 | } else if (p_line.contains("$interface_orientations")) { |
| 525 | String orientations; |
| 526 | const DisplayServer::ScreenOrientation screen_orientation = |
| 527 | DisplayServer::ScreenOrientation(int(get_project_setting(p_preset, "display/window/handheld/orientation"))); |
| 528 | |
| 529 | switch (screen_orientation) { |
| 530 | case DisplayServer::SCREEN_LANDSCAPE: |
| 531 | orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n"; |
| 532 | break; |
| 533 | case DisplayServer::SCREEN_PORTRAIT: |
| 534 | orientations += "<string>UIInterfaceOrientationPortrait</string>\n"; |
| 535 | break; |
| 536 | case DisplayServer::SCREEN_REVERSE_LANDSCAPE: |
| 537 | orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n"; |
| 538 | break; |
| 539 | case DisplayServer::SCREEN_REVERSE_PORTRAIT: |
| 540 | orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n"; |
| 541 | break; |
| 542 | case DisplayServer::SCREEN_SENSOR_LANDSCAPE: |
| 543 | // Allow both landscape orientations depending on sensor direction. |
| 544 | orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n"; |
| 545 | orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n"; |
| 546 | break; |
| 547 | case DisplayServer::SCREEN_SENSOR_PORTRAIT: |
| 548 | // Allow both portrait orientations depending on sensor direction. |
| 549 | orientations += "<string>UIInterfaceOrientationPortrait</string>\n"; |
| 550 | orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n"; |
| 551 | break; |
| 552 | case DisplayServer::SCREEN_SENSOR: |
| 553 | // Allow all screen orientations depending on sensor direction. |
| 554 | orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n"; |
| 555 | orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n"; |
| 556 | orientations += "<string>UIInterfaceOrientationPortrait</string>\n"; |
| 557 | orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n"; |
| 558 | break; |
| 559 | } |
| 560 | |
| 561 | strnew += p_line.replace("$interface_orientations", orientations); |
| 562 | } else if (p_line.contains("$ipad_interface_orientations")) { |
| 563 | String orientations; |
| 564 | const DisplayServer::ScreenOrientation screen_orientation = |
| 565 | DisplayServer::ScreenOrientation(int(get_project_setting(p_preset, "display/window/handheld/orientation"))); |
| 566 | |
| 567 | switch (screen_orientation) { |
| 568 | case DisplayServer::SCREEN_LANDSCAPE: |
| 569 | orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n"; |
| 570 | break; |
| 571 | case DisplayServer::SCREEN_PORTRAIT: |
| 572 | orientations += "<string>UIInterfaceOrientationPortrait</string>\n"; |
| 573 | break; |
| 574 | case DisplayServer::SCREEN_REVERSE_LANDSCAPE: |
| 575 | orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n"; |
| 576 | break; |
| 577 | case DisplayServer::SCREEN_REVERSE_PORTRAIT: |
| 578 | orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n"; |
| 579 | break; |
| 580 | case DisplayServer::SCREEN_SENSOR_LANDSCAPE: |
| 581 | // Allow both landscape orientations depending on sensor direction. |
| 582 | orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n"; |
| 583 | orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n"; |
| 584 | break; |
| 585 | case DisplayServer::SCREEN_SENSOR_PORTRAIT: |
| 586 | // Allow both portrait orientations depending on sensor direction. |
| 587 | orientations += "<string>UIInterfaceOrientationPortrait</string>\n"; |
| 588 | orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n"; |
| 589 | break; |
| 590 | case DisplayServer::SCREEN_SENSOR: |
| 591 | // Allow all screen orientations depending on sensor direction. |
| 592 | orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n"; |
| 593 | orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n"; |
| 594 | orientations += "<string>UIInterfaceOrientationPortrait</string>\n"; |
| 595 | orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n"; |
| 596 | break; |
| 597 | } |
| 598 | |
| 599 | strnew += p_line.replace("$ipad_interface_orientations", orientations); |
| 600 | } else if (p_line.contains("$camera_usage_description")) { |
| 601 | String description = p_preset->get("privacy/camera_usage_description"); |
| 602 | strnew += p_line.replace("$camera_usage_description", description.xml_escape(true)) + "\n"; |
| 603 | } else if (p_line.contains("$microphone_usage_description")) { |
| 604 | String description = p_preset->get("privacy/microphone_usage_description"); |
| 605 | strnew += p_line.replace("$microphone_usage_description", description.xml_escape(true)) + "\n"; |
| 606 | } else if (p_line.contains("$photolibrary_usage_description")) { |
| 607 | String description = p_preset->get("privacy/photolibrary_usage_description"); |
| 608 | strnew += p_line.replace("$photolibrary_usage_description", description.xml_escape(true)) + "\n"; |
| 609 | } else if (p_line.contains("$pbx_locale_file_reference")) { |
| 610 | String locale_files; |
| 611 | Vector<String> translations = get_project_setting(p_preset, "internationalization/locale/translations"); |
| 612 | if (translations.size() > 0) { |
| 613 | HashSet<String> languages; |
| 614 | for (const String &E : translations) { |
| 615 | Ref<Translation> tr = ResourceLoader::load(E); |
| 616 | if (tr.is_valid() && tr->get_locale() != "en") { |
| 617 | languages.insert(tr->get_locale()); |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | int index = 0; |
| 622 | for (const String &lang : languages) { |
| 623 | locale_files += "D0BCFE4518AEBDA2004A" + itos(index).pad_zeros(4) + " /* " + lang + " */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = " + lang + "; path = " + lang + ".lproj/InfoPlist.strings; sourceTree = \"<group>\"; };\n"; |
| 624 | index++; |
| 625 | } |
| 626 | } |
| 627 | strnew += p_line.replace("$pbx_locale_file_reference", locale_files); |
| 628 | } else if (p_line.contains("$pbx_locale_build_reference")) { |
| 629 | String locale_files; |
| 630 | Vector<String> translations = get_project_setting(p_preset, "internationalization/locale/translations"); |
| 631 | if (translations.size() > 0) { |
| 632 | HashSet<String> languages; |
| 633 | for (const String &E : translations) { |
| 634 | Ref<Translation> tr = ResourceLoader::load(E); |
| 635 | if (tr.is_valid() && tr->get_locale() != "en") { |
| 636 | languages.insert(tr->get_locale()); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | int index = 0; |
| 641 | for (const String &lang : languages) { |
| 642 | locale_files += "D0BCFE4518AEBDA2004A" + itos(index).pad_zeros(4) + " /* " + lang + " */,\n"; |
| 643 | index++; |
| 644 | } |
| 645 | } |
| 646 | strnew += p_line.replace("$pbx_locale_build_reference", locale_files); |
| 647 | } else if (p_line.contains("$priv_collection")) { |
| 648 | bool section_opened = false; |
| 649 | for (uint64_t j = 0; j < std_size(data_collect_type_info); ++j) { |
| 650 | bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name)); |
| 651 | bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name)); |
| 652 | bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name)); |
| 653 | int purposes = p_preset->get(vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[j].prop_name)); |
| 654 | if (data_collected) { |
| 655 | if (!section_opened) { |
| 656 | section_opened = true; |
| 657 | strnew += "\t<key>NSPrivacyCollectedDataTypes</key>\n"; |
| 658 | strnew += "\t<array>\n"; |
| 659 | } |
| 660 | strnew += "\t\t<dict>\n"; |
| 661 | strnew += "\t\t\t<key>NSPrivacyCollectedDataType</key>\n"; |
| 662 | strnew += vformat("\t\t\t<string>%s</string>\n", data_collect_type_info[j].type_name); |
| 663 | strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeLinked</key>\n"; |
| 664 | if (linked) { |
| 665 | strnew += "\t\t\t\t<true/>\n"; |
| 666 | } else { |
| 667 | strnew += "\t\t\t\t<false/>\n"; |
| 668 | } |
| 669 | strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeTracking</key>\n"; |
| 670 | if (tracking) { |
| 671 | strnew += "\t\t\t\t<true/>\n"; |
| 672 | } else { |
| 673 | strnew += "\t\t\t\t<false/>\n"; |
| 674 | } |
| 675 | if (purposes != 0) { |
| 676 | strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n"; |
| 677 | strnew += "\t\t\t\t<array>\n"; |
| 678 | for (uint64_t k = 0; k < std_size(data_collect_purpose_info); ++k) { |
| 679 | if (purposes & (1 << k)) { |
| 680 | strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name); |
| 681 | } |
| 682 | } |
| 683 | strnew += "\t\t\t\t</array>\n"; |
| 684 | } |
| 685 | strnew += "\t\t\t</dict>\n"; |
| 686 | } |
| 687 | } |
| 688 | if (section_opened) { |
| 689 | strnew += "\t</array>\n"; |
| 690 | } |
| 691 | } else if (p_line.contains("$priv_tracking")) { |
| 692 | bool tracking = p_preset->get("privacy/tracking_enabled"); |
| 693 | strnew += "\t<key>NSPrivacyTracking</key>\n"; |
| 694 | if (tracking) { |
| 695 | strnew += "\t<true/>\n"; |
| 696 | } else { |
| 697 | strnew += "\t<false/>\n"; |
| 698 | } |
| 699 | Vector<String> tracking_domains = p_preset->get("privacy/tracking_domains"); |
| 700 | if (!tracking_domains.is_empty()) { |
| 701 | strnew += "\t<key>NSPrivacyTrackingDomains</key>\n"; |
| 702 | strnew += "\t<array>\n"; |
| 703 | for (const String &E : tracking_domains) { |
| 704 | strnew += "\t\t<string>" + E + "</string>\n"; |
| 705 | } |
| 706 | strnew += "\t</array>\n"; |
| 707 | } |
| 708 | } else if (p_line.contains("$priv_api_types")) { |
| 709 | strnew += "\t<array>\n"; |
| 710 | for (uint64_t j = 0; j < std_size(api_info); ++j) { |
| 711 | int api_access = p_preset->get(vformat("privacy/%s_access_reasons", api_info[j].prop_name)); |
| 712 | if (api_access != 0) { |
| 713 | strnew += "\t\t<dict>\n"; |
| 714 | strnew += "\t\t\t<key>NSPrivacyAccessedAPITypeReasons</key>\n"; |
| 715 | strnew += "\t\t\t<array>\n"; |
| 716 | for (int k = 0; k < api_info[j].prop_flag_value.size(); k++) { |
| 717 | if (api_access & (1 << k)) { |
| 718 | strnew += vformat("\t\t\t\t<string>%s</string>\n", api_info[j].prop_flag_value[k]); |
| 719 | } |
| 720 | } |
| 721 | strnew += "\t\t\t</array>\n"; |
| 722 | strnew += "\t\t\t<key>NSPrivacyAccessedAPIType</key>\n"; |
| 723 | strnew += vformat("\t\t\t<string>%s</string>\n", api_info[j].type_name); |
| 724 | strnew += "\t\t</dict>\n"; |
| 725 | } |
| 726 | } |
| 727 | strnew += "\t</array>\n"; |
| 728 | } else if (p_line.contains("$sdkroot")) { |
| 729 | strnew += p_line.replace("$sdkroot", get_sdk_name()) + "\n"; |
| 730 | |
| 731 | } else { |
| 732 | strnew += p_line + "\n"; |
| 733 | } |
| 734 | return strnew; |
| 735 | } |
| 736 | |
| 737 | String EditorExportPlatformAppleEmbedded::_get_additional_plist_content() { |
| 738 | Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins(); |
| 739 | String result; |
| 740 | for (int i = 0; i < export_plugins.size(); ++i) { |
| 741 | result += export_plugins[i]->get_apple_embedded_platform_plist_content(); |
| 742 | } |
| 743 | return result; |
| 744 | } |
| 745 | |
| 746 | String EditorExportPlatformAppleEmbedded::_get_linker_flags() { |
| 747 | Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins(); |
| 748 | String result; |
| 749 | for (int i = 0; i < export_plugins.size(); ++i) { |
| 750 | String flags = export_plugins[i]->get_apple_embedded_platform_linker_flags(); |
| 751 | if (flags.length() == 0) { |
| 752 | continue; |
| 753 | } |
| 754 | if (result.length() > 0) { |
| 755 | result += ' '; |
| 756 | } |
| 757 | result += flags; |
| 758 | } |
| 759 | // the flags will be enclosed in quotes, so need to escape them |
| 760 | return result.replace("\"", "\\\""); |
| 761 | } |
| 762 | |
| 763 | String EditorExportPlatformAppleEmbedded::_get_cpp_code() { |
| 764 | Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins(); |
| 765 | String result; |
| 766 | for (int i = 0; i < export_plugins.size(); ++i) { |
| 767 | result += export_plugins[i]->get_apple_embedded_platform_cpp_code(); |
| 768 | } |
| 769 | return result; |
| 770 | } |
| 771 | |
| 772 | void EditorExportPlatformAppleEmbedded::_blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot) { |
| 773 | ERR_FAIL_COND(p_dst.is_null()); |
| 774 | ERR_FAIL_COND(p_src.is_null()); |
| 775 | |
| 776 | int sw = p_rot ? p_src->get_height() : p_src->get_width(); |
| 777 | int sh = p_rot ? p_src->get_width() : p_src->get_height(); |
| 778 | |
| 779 | int x_pos = (p_dst->get_width() - sw) / 2; |
| 780 | int y_pos = (p_dst->get_height() - sh) / 2; |
| 781 | |
| 782 | int xs = (x_pos >= 0) ? 0 : -x_pos; |
| 783 | int ys = (y_pos >= 0) ? 0 : -y_pos; |
| 784 | |
| 785 | if (sw + x_pos > p_dst->get_width()) { |
| 786 | sw = p_dst->get_width() - x_pos; |
| 787 | } |
| 788 | if (sh + y_pos > p_dst->get_height()) { |
| 789 | sh = p_dst->get_height() - y_pos; |
| 790 | } |
| 791 | |
| 792 | for (int y = ys; y < sh; y++) { |
| 793 | for (int x = xs; x < sw; x++) { |
| 794 | Color sc = p_rot ? p_src->get_pixel(p_src->get_width() - y - 1, x) : p_src->get_pixel(x, y); |
| 795 | Color dc = p_dst->get_pixel(x_pos + x, y_pos + y); |
| 796 | dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r); |
| 797 | dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g); |
| 798 | dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b); |
| 799 | dc.a = (double)(sc.a + dc.a * (1.0 - sc.a)); |
| 800 | p_dst->set_pixel(x_pos + x, y_pos + y, dc); |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | Error EditorExportPlatformAppleEmbedded::_walk_dir_recursive(Ref<DirAccess> &p_da, FileHandler p_handler, void *p_userdata) { |
| 806 | Vector<String> dirs; |
| 807 | String current_dir = p_da->get_current_dir(); |
| 808 | p_da->list_dir_begin(); |
| 809 | String path = p_da->get_next(); |
| 810 | while (!path.is_empty()) { |
| 811 | if (p_da->current_is_dir()) { |
| 812 | if (path != "." && path != "..") { |
| 813 | dirs.push_back(path); |
| 814 | } |
| 815 | } else { |
| 816 | Error err = p_handler(current_dir.path_join(path), p_userdata); |
| 817 | if (err) { |
| 818 | p_da->list_dir_end(); |
| 819 | return err; |
| 820 | } |
| 821 | } |
| 822 | path = p_da->get_next(); |
| 823 | } |
| 824 | p_da->list_dir_end(); |
| 825 | |
| 826 | for (int i = 0; i < dirs.size(); ++i) { |
| 827 | p_da->change_dir(dirs[i]); |
| 828 | Error err = _walk_dir_recursive(p_da, p_handler, p_userdata); |
| 829 | p_da->change_dir(".."); |
| 830 | if (err) { |
| 831 | return err; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | return OK; |
| 836 | } |
| 837 | |
| 838 | struct CodesignData { |
| 839 | const Ref<EditorExportPreset> &preset; |
| 840 | bool debug = false; |
| 841 | |
| 842 | CodesignData(const Ref<EditorExportPreset> &p_preset, bool p_debug) : |
| 843 | preset(p_preset), |
| 844 | debug(p_debug) { |
| 845 | } |
| 846 | }; |
| 847 | |
| 848 | Error EditorExportPlatformAppleEmbedded::_codesign(String p_file, void *p_userdata) { |
| 849 | if (p_file.ends_with(".dylib")) { |
| 850 | CodesignData *data = static_cast<CodesignData *>(p_userdata); |
| 851 | print_line(String("Signing ") + p_file); |
| 852 | |
| 853 | String sign_id; |
| 854 | if (data->debug) { |
| 855 | sign_id = data->preset->get("application/code_sign_identity_debug").operator String().is_empty() ? "Apple Development" : data->preset->get("application/code_sign_identity_debug"); |
| 856 | } else { |
| 857 | sign_id = data->preset->get("application/code_sign_identity_release").operator String().is_empty() ? "Apple Distribution" : data->preset->get("application/code_sign_identity_release"); |
| 858 | } |
| 859 | |
| 860 | List<String> codesign_args; |
| 861 | codesign_args.push_back("-f"); |
| 862 | codesign_args.push_back("-s"); |
| 863 | codesign_args.push_back(sign_id); |
| 864 | codesign_args.push_back(p_file); |
| 865 | String str; |
| 866 | Error err = OS::get_singleton()->execute("codesign", codesign_args, &str, nullptr, true); |
| 867 | print_verbose("codesign (" + p_file + "):\n" + str); |
| 868 | |
| 869 | return err; |
| 870 | } |
| 871 | return OK; |
| 872 | } |
| 873 | |
| 874 | struct PbxId { |
| 875 | private: |
| 876 | static char _hex_char(uint8_t p_four_bits) { |
| 877 | if (p_four_bits < 10) { |
| 878 | return ('0' + p_four_bits); |
| 879 | } |
| 880 | return 'A' + (p_four_bits - 10); |
| 881 | } |
| 882 | |
| 883 | static String _hex_pad(uint32_t p_num) { |
| 884 | Vector<char> ret; |
| 885 | ret.resize(sizeof(p_num) * 2); |
| 886 | for (uint64_t i = 0; i < sizeof(p_num) * 2; ++i) { |
| 887 | uint8_t four_bits = (p_num >> (sizeof(p_num) * 8 - (i + 1) * 4)) & 0xF; |
| 888 | ret.write[i] = _hex_char(four_bits); |
| 889 | } |
| 890 | return String::utf8(ret.ptr(), ret.size()); |
| 891 | } |
| 892 | |
| 893 | public: |
| 894 | uint32_t high_bits; |
| 895 | uint32_t mid_bits; |
| 896 | uint32_t low_bits; |
| 897 | |
| 898 | String str() const { |
| 899 | return _hex_pad(high_bits) + _hex_pad(mid_bits) + _hex_pad(low_bits); |
| 900 | } |
| 901 | |
| 902 | PbxId &operator++() { |
| 903 | low_bits++; |
| 904 | if (!low_bits) { |
| 905 | mid_bits++; |
| 906 | if (!mid_bits) { |
| 907 | high_bits++; |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | return *this; |
| 912 | } |
| 913 | }; |
| 914 | |
| 915 | struct ExportLibsData { |
| 916 | Vector<String> lib_paths; |
| 917 | String dest_dir; |
| 918 | }; |
| 919 | |
| 920 | void EditorExportPlatformAppleEmbedded::_check_xcframework_content(const String &p_path, int &r_total_libs, int &r_static_libs, int &r_dylibs, int &r_frameworks) const { |
| 921 | Ref<PList> plist; |
| 922 | plist.instantiate(); |
| 923 | plist->load_file(p_path.path_join("Info.plist")); |
| 924 | Ref<PListNode> root_node = plist->get_root(); |
| 925 | if (root_node.is_null()) { |
| 926 | return; |
| 927 | } |
| 928 | Dictionary root = root_node->get_value(); |
| 929 | if (!root.has("AvailableLibraries")) { |
| 930 | return; |
| 931 | } |
| 932 | Ref<PListNode> libs_node = root["AvailableLibraries"]; |
| 933 | if (libs_node.is_null()) { |
| 934 | return; |
| 935 | } |
| 936 | Array libs = libs_node->get_value(); |
| 937 | r_total_libs = libs.size(); |
| 938 | for (int j = 0; j < libs.size(); j++) { |
| 939 | Ref<PListNode> lib_node = libs[j]; |
| 940 | if (lib_node.is_null()) { |
| 941 | return; |
| 942 | } |
| 943 | Dictionary lib = lib_node->get_value(); |
| 944 | if (lib.has("BinaryPath")) { |
| 945 | Ref<PListNode> path_node = lib["BinaryPath"]; |
| 946 | if (path_node.is_valid()) { |
| 947 | String path = path_node->get_value(); |
| 948 | if (path.ends_with(".a")) { |
| 949 | r_static_libs++; |
| 950 | } |
| 951 | if (path.ends_with(".dylib")) { |
| 952 | r_dylibs++; |
| 953 | } |
| 954 | if (path.ends_with(".framework")) { |
| 955 | r_frameworks++; |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | Error EditorExportPlatformAppleEmbedded::_convert_to_framework(const String &p_source, const String &p_destination, const String &p_id) const { |
| 963 | print_line("Converting to .framework", p_source, " -> ", p_destination); |
| 964 | |
| 965 | Ref<DirAccess> da = DirAccess::create_for_path(p_source); |
| 966 | if (da.is_null()) { |
| 967 | return ERR_CANT_OPEN; |
| 968 | } |
| 969 | |
| 970 | Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 971 | if (filesystem_da.is_null()) { |
| 972 | return ERR_CANT_OPEN; |
| 973 | } |
| 974 | |
| 975 | if (!filesystem_da->dir_exists(p_destination)) { |
| 976 | Error make_dir_err = filesystem_da->make_dir_recursive(p_destination); |
| 977 | if (make_dir_err) { |
| 978 | return make_dir_err; |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | String asset = p_source.ends_with("/") ? p_source.left(-1) : p_source; |
| 983 | if (asset.ends_with(".xcframework")) { |
| 984 | Ref<PList> plist; |
| 985 | plist.instantiate(); |
| 986 | plist->load_file(p_source.path_join("Info.plist")); |
| 987 | Ref<PListNode> root_node = plist->get_root(); |
| 988 | if (root_node.is_null()) { |
| 989 | return ERR_CANT_OPEN; |
| 990 | } |
| 991 | Dictionary root = root_node->get_value(); |
| 992 | if (!root.has("AvailableLibraries")) { |
| 993 | return ERR_CANT_OPEN; |
| 994 | } |
| 995 | Ref<PListNode> libs_node = root["AvailableLibraries"]; |
| 996 | if (libs_node.is_null()) { |
| 997 | return ERR_CANT_OPEN; |
| 998 | } |
| 999 | Array libs = libs_node->get_value(); |
| 1000 | for (int j = 0; j < libs.size(); j++) { |
| 1001 | Ref<PListNode> lib_node = libs[j]; |
| 1002 | if (lib_node.is_null()) { |
| 1003 | return ERR_CANT_OPEN; |
| 1004 | } |
| 1005 | Dictionary lib = lib_node->get_value(); |
| 1006 | if (lib.has("BinaryPath") && lib.has("LibraryPath") && lib.has("LibraryIdentifier")) { |
| 1007 | Ref<PListNode> bpath_node = lib["BinaryPath"]; |
| 1008 | Ref<PListNode> lpath_node = lib["LibraryPath"]; |
| 1009 | Ref<PListNode> lid_node = lib["LibraryIdentifier"]; |
| 1010 | if (bpath_node.is_valid() && lpath_node.is_valid() && lid_node.is_valid()) { |
| 1011 | String binary_path = bpath_node->get_value(); |
| 1012 | String library_identifier = lid_node->get_value(); |
| 1013 | |
| 1014 | String file_name = binary_path.get_basename().get_file(); |
| 1015 | String framework_name = file_name + ".framework"; |
| 1016 | |
| 1017 | bpath_node->data_string = framework_name.utf8(); |
| 1018 | lpath_node->data_string = framework_name.utf8(); |
| 1019 | if (!filesystem_da->dir_exists(p_destination.path_join(library_identifier))) { |
| 1020 | filesystem_da->make_dir_recursive(p_destination.path_join(library_identifier)); |
| 1021 | } |
| 1022 | _convert_to_framework(p_source.path_join(library_identifier).path_join(binary_path), p_destination.path_join(library_identifier).path_join(framework_name), p_id); |
| 1023 | if (lib.has("DebugSymbolsPath")) { |
| 1024 | Ref<PListNode> dpath_node = lib["DebugSymbolsPath"]; |
| 1025 | if (dpath_node.is_valid()) { |
| 1026 | String dpath = dpath_node->get_value(); |
| 1027 | if (da->dir_exists(p_source.path_join(library_identifier).path_join(dpath))) { |
| 1028 | da->copy_dir(p_source.path_join(library_identifier).path_join(dpath), p_destination.path_join(library_identifier).path_join("dSYMs")); |
| 1029 | } |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | String info_plist = plist->save_text(); |
| 1036 | |
| 1037 | Ref<FileAccess> f = FileAccess::open(p_destination.path_join("Info.plist"), FileAccess::WRITE); |
| 1038 | if (f.is_valid()) { |
| 1039 | f->store_string(info_plist); |
| 1040 | } |
| 1041 | } else { |
| 1042 | String file_name = p_destination.get_basename().get_file(); |
| 1043 | String framework_name = file_name + ".framework"; |
| 1044 | |
| 1045 | da->copy(p_source, p_destination.path_join(file_name)); |
| 1046 | |
| 1047 | // Performing `install_name_tool -id @rpath/{name}.framework/{name} ./{name}` on dylib |
| 1048 | { |
| 1049 | List<String> install_name_args; |
| 1050 | install_name_args.push_back("-id"); |
| 1051 | install_name_args.push_back(String("@rpath").path_join(framework_name).path_join(file_name)); |
| 1052 | install_name_args.push_back(p_destination.path_join(file_name)); |
| 1053 | |
| 1054 | OS::get_singleton()->execute("install_name_tool", install_name_args); |
| 1055 | } |
| 1056 | |
| 1057 | // Creating Info.plist |
| 1058 | { |
| 1059 | String lib_clean_name = file_name; |
| 1060 | for (int i = 0; i < lib_clean_name.length(); i++) { |
| 1061 | if (!is_ascii_alphanumeric_char(lib_clean_name[i]) && lib_clean_name[i] != '.' && lib_clean_name[i] != '-') { |
| 1062 | lib_clean_name[i] = '-'; |
| 1063 | } |
| 1064 | } |
| 1065 | String info_plist_format = |
| 1066 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 1067 | "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" |
| 1068 | "<plist version=\"1.0\">\n" |
| 1069 | " <dict>\n" |
| 1070 | " <key>CFBundleShortVersionString</key>\n" |
| 1071 | " <string>1.0</string>\n" |
| 1072 | " <key>CFBundleIdentifier</key>\n" |
| 1073 | " <string>$id.framework.$cl_name</string>\n" |
| 1074 | " <key>CFBundleName</key>\n" |
| 1075 | " <string>$name</string>\n" |
| 1076 | " <key>CFBundleExecutable</key>\n" |
| 1077 | " <string>$name</string>\n" |
| 1078 | " <key>DTPlatformName</key>\n" |
| 1079 | " <string>" + |
| 1080 | get_sdk_name() + |
| 1081 | "</string>\n" |
| 1082 | " <key>CFBundleInfoDictionaryVersion</key>\n" |
| 1083 | " <string>6.0</string>\n" |
| 1084 | " <key>CFBundleVersion</key>\n" |
| 1085 | " <string>1</string>\n" |
| 1086 | " <key>CFBundlePackageType</key>\n" |
| 1087 | " <string>FMWK</string>\n" |
| 1088 | " <key>MinimumOSVersion</key>\n" |
| 1089 | " <string>" + |
| 1090 | get_minimum_deployment_target() + |
| 1091 | "</string>\n" |
| 1092 | " </dict>\n" |
| 1093 | "</plist>"; |
| 1094 | |
| 1095 | String info_plist = info_plist_format.replace("$id", p_id).replace("$name", file_name).replace("$cl_name", lib_clean_name); |
| 1096 | |
| 1097 | Ref<FileAccess> f = FileAccess::open(p_destination.path_join("Info.plist"), FileAccess::WRITE); |
| 1098 | if (f.is_valid()) { |
| 1099 | f->store_string(info_plist); |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | return OK; |
| 1105 | } |
| 1106 | |
| 1107 | void EditorExportPlatformAppleEmbedded::_add_assets_to_project(const String &p_out_dir, const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<AppleEmbeddedExportAsset> &p_additional_assets) { |
| 1108 | // that is just a random number, we just need Godot IDs not to clash with |
| 1109 | // existing IDs in the project. |
| 1110 | PbxId current_id = { 0x58938401, 0, 0 }; |
| 1111 | String pbx_files; |
| 1112 | String pbx_frameworks_build; |
| 1113 | String pbx_frameworks_refs; |
| 1114 | String pbx_resources_build; |
| 1115 | String pbx_resources_refs; |
| 1116 | String pbx_embeded_frameworks; |
| 1117 | |
| 1118 | const String file_info_format = String("$build_id = {isa = PBXBuildFile; fileRef = $ref_id; };\n") + |
| 1119 | "$ref_id = {isa = PBXFileReference; lastKnownFileType = $file_type; name = \"$name\"; path = \"$file_path\"; sourceTree = \"<group>\"; };\n"; |
| 1120 | |
| 1121 | for (int i = 0; i < p_additional_assets.size(); ++i) { |
| 1122 | String additional_asset_info_format = file_info_format; |
| 1123 | |
| 1124 | String build_id = (++current_id).str(); |
| 1125 | String ref_id = (++current_id).str(); |
| 1126 | String framework_id = ""; |
| 1127 | |
| 1128 | const AppleEmbeddedExportAsset &asset = p_additional_assets[i]; |
| 1129 | |
| 1130 | String type; |
| 1131 | if (asset.exported_path.ends_with(".framework")) { |
| 1132 | if (asset.should_embed) { |
| 1133 | additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n"; |
| 1134 | framework_id = (++current_id).str(); |
| 1135 | pbx_embeded_frameworks += framework_id + ",\n"; |
| 1136 | } |
| 1137 | |
| 1138 | type = "wrapper.framework"; |
| 1139 | } else if (asset.exported_path.ends_with(".xcframework")) { |
| 1140 | int total_libs = 0; |
| 1141 | int static_libs = 0; |
| 1142 | int dylibs = 0; |
| 1143 | int frameworks = 0; |
| 1144 | _check_xcframework_content(p_out_dir.path_join(asset.exported_path), total_libs, static_libs, dylibs, frameworks); |
| 1145 | if (asset.should_embed && static_libs != total_libs) { |
| 1146 | additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n"; |
| 1147 | framework_id = (++current_id).str(); |
| 1148 | pbx_embeded_frameworks += framework_id + ",\n"; |
| 1149 | } |
| 1150 | |
| 1151 | type = "wrapper.xcframework"; |
| 1152 | } else if (asset.exported_path.ends_with(".dylib")) { |
| 1153 | type = "compiled.mach-o.dylib"; |
| 1154 | } else if (asset.exported_path.ends_with(".a")) { |
| 1155 | type = "archive.ar"; |
| 1156 | } else { |
| 1157 | type = "file"; |
| 1158 | } |
| 1159 | |
| 1160 | String &pbx_build = asset.is_framework ? pbx_frameworks_build : pbx_resources_build; |
| 1161 | String &pbx_refs = asset.is_framework ? pbx_frameworks_refs : pbx_resources_refs; |
| 1162 | |
| 1163 | if (pbx_build.length() > 0) { |
| 1164 | pbx_build += ",\n"; |
| 1165 | pbx_refs += ",\n"; |
| 1166 | } |
| 1167 | pbx_build += build_id; |
| 1168 | pbx_refs += ref_id; |
| 1169 | |
| 1170 | Dictionary format_dict; |
| 1171 | format_dict["build_id"] = build_id; |
| 1172 | format_dict["ref_id"] = ref_id; |
| 1173 | format_dict["name"] = asset.exported_path.get_file(); |
| 1174 | format_dict["file_path"] = asset.exported_path; |
| 1175 | format_dict["file_type"] = type; |
| 1176 | if (framework_id.length() > 0) { |
| 1177 | format_dict["framework_id"] = framework_id; |
| 1178 | } |
| 1179 | pbx_files += additional_asset_info_format.format(format_dict, "$_"); |
| 1180 | } |
| 1181 | |
| 1182 | // Note, frameworks like gamekit are always included in our project.pbxprof file |
| 1183 | // even if turned off in capabilities. |
| 1184 | |
| 1185 | String str = String::utf8((const char *)p_project_data.ptr(), p_project_data.size()); |
| 1186 | str = str.replace("$additional_pbx_files", pbx_files); |
| 1187 | str = str.replace("$additional_pbx_frameworks_build", pbx_frameworks_build); |
| 1188 | str = str.replace("$additional_pbx_frameworks_refs", pbx_frameworks_refs); |
| 1189 | str = str.replace("$additional_pbx_resources_build", pbx_resources_build); |
| 1190 | str = str.replace("$additional_pbx_resources_refs", pbx_resources_refs); |
| 1191 | str = str.replace("$pbx_embeded_frameworks", pbx_embeded_frameworks); |
| 1192 | |
| 1193 | CharString cs = str.utf8(); |
| 1194 | p_project_data.resize(cs.size() - 1); |
| 1195 | for (int i = 0; i < cs.size() - 1; i++) { |
| 1196 | p_project_data.write[i] = cs[i]; |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | Error EditorExportPlatformAppleEmbedded::_copy_asset(const Ref<EditorExportPreset> &p_preset, const String &p_out_dir, const String &p_asset, const String *p_custom_file_name, bool p_is_framework, bool p_should_embed, Vector<AppleEmbeddedExportAsset> &r_exported_assets) { |
| 1201 | String binary_name = p_out_dir.get_file().get_basename(); |
| 1202 | |
| 1203 | Ref<DirAccess> da = DirAccess::create_for_path(p_asset); |
| 1204 | if (da.is_null()) { |
| 1205 | ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't open directory: " + p_asset + "."); |
| 1206 | } |
| 1207 | bool file_exists = da->file_exists(p_asset); |
| 1208 | bool dir_exists = da->dir_exists(p_asset); |
| 1209 | if (!file_exists && !dir_exists) { |
| 1210 | return ERR_FILE_NOT_FOUND; |
| 1211 | } |
| 1212 | |
| 1213 | String base_dir = p_asset.get_base_dir().replace("res://", "").replace(".godot/mono/temp/bin/", ""); |
| 1214 | String asset = p_asset.ends_with("/") ? p_asset.left(-1) : p_asset; |
| 1215 | String destination_dir; |
| 1216 | String destination; |
| 1217 | String asset_path; |
| 1218 | |
| 1219 | Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 1220 | ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_out_dir + "'."); |
| 1221 | |
| 1222 | if (p_is_framework && asset.ends_with(".dylib")) { |
| 1223 | // For Apple Embedded platforms we need to turn .dylib into .framework |
| 1224 | // to be able to send application to AppStore |
| 1225 | asset_path = String("dylibs").path_join(base_dir); |
| 1226 | |
| 1227 | String file_name; |
| 1228 | |
| 1229 | if (!p_custom_file_name) { |
| 1230 | file_name = p_asset.get_basename().get_file(); |
| 1231 | } else { |
| 1232 | file_name = *p_custom_file_name; |
| 1233 | } |
| 1234 | |
| 1235 | String framework_name = file_name + ".framework"; |
| 1236 | |
| 1237 | asset_path = asset_path.path_join(framework_name); |
| 1238 | destination_dir = p_out_dir.path_join(asset_path); |
| 1239 | destination = destination_dir; |
| 1240 | |
| 1241 | // Convert to framework and copy. |
| 1242 | Error err = _convert_to_framework(p_asset, destination, p_preset->get("application/bundle_identifier")); |
| 1243 | if (err) { |
| 1244 | return err; |
| 1245 | } |
| 1246 | } else if (p_is_framework && asset.ends_with(".xcframework")) { |
| 1247 | // For Apple Embedded platforms we need to turn .dylib inside .xcframework |
| 1248 | // into .framework to be able to send application to AppStore |
| 1249 | |
| 1250 | int total_libs = 0; |
| 1251 | int static_libs = 0; |
| 1252 | int dylibs = 0; |
| 1253 | int frameworks = 0; |
| 1254 | _check_xcframework_content(p_asset, total_libs, static_libs, dylibs, frameworks); |
| 1255 | |
| 1256 | asset_path = String("dylibs").path_join(base_dir); |
| 1257 | String file_name; |
| 1258 | |
| 1259 | if (!p_custom_file_name) { |
| 1260 | file_name = p_asset.get_file(); |
| 1261 | } else { |
| 1262 | file_name = *p_custom_file_name; |
| 1263 | } |
| 1264 | |
| 1265 | asset_path = asset_path.path_join(file_name); |
| 1266 | destination_dir = p_out_dir.path_join(asset_path); |
| 1267 | destination = destination_dir; |
| 1268 | |
| 1269 | if (dylibs > 0) { |
| 1270 | // Convert to framework and copy. |
| 1271 | Error err = _convert_to_framework(p_asset, destination, p_preset->get("application/bundle_identifier")); |
| 1272 | if (err) { |
| 1273 | return err; |
| 1274 | } |
| 1275 | } else { |
| 1276 | // Copy as is. |
| 1277 | if (!filesystem_da->dir_exists(destination_dir)) { |
| 1278 | Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir); |
| 1279 | if (make_dir_err) { |
| 1280 | return make_dir_err; |
| 1281 | } |
| 1282 | } |
| 1283 | Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination); |
| 1284 | if (err) { |
| 1285 | return err; |
| 1286 | } |
| 1287 | } |
| 1288 | } else if (p_is_framework && asset.ends_with(".framework")) { |
| 1289 | // Framework. |
| 1290 | asset_path = String("dylibs").path_join(base_dir); |
| 1291 | |
| 1292 | String file_name; |
| 1293 | |
| 1294 | if (!p_custom_file_name) { |
| 1295 | file_name = p_asset.get_file(); |
| 1296 | } else { |
| 1297 | file_name = *p_custom_file_name; |
| 1298 | } |
| 1299 | |
| 1300 | asset_path = asset_path.path_join(file_name); |
| 1301 | destination_dir = p_out_dir.path_join(asset_path); |
| 1302 | destination = destination_dir; |
| 1303 | |
| 1304 | // Copy as is. |
| 1305 | if (!filesystem_da->dir_exists(destination_dir)) { |
| 1306 | Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir); |
| 1307 | if (make_dir_err) { |
| 1308 | return make_dir_err; |
| 1309 | } |
| 1310 | } |
| 1311 | Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination); |
| 1312 | if (err) { |
| 1313 | return err; |
| 1314 | } |
| 1315 | } else { |
| 1316 | // Unknown resource. |
| 1317 | asset_path = base_dir; |
| 1318 | |
| 1319 | String file_name; |
| 1320 | |
| 1321 | if (!p_custom_file_name) { |
| 1322 | file_name = p_asset.get_file(); |
| 1323 | } else { |
| 1324 | file_name = *p_custom_file_name; |
| 1325 | } |
| 1326 | |
| 1327 | destination_dir = p_out_dir.path_join(asset_path); |
| 1328 | asset_path = asset_path.path_join(file_name); |
| 1329 | destination = p_out_dir.path_join(asset_path); |
| 1330 | |
| 1331 | // Copy as is. |
| 1332 | if (!filesystem_da->dir_exists(destination_dir)) { |
| 1333 | Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir); |
| 1334 | if (make_dir_err) { |
| 1335 | return make_dir_err; |
| 1336 | } |
| 1337 | } |
| 1338 | Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination); |
| 1339 | if (err) { |
| 1340 | return err; |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | if (asset_path.ends_with("/")) { |
| 1345 | asset_path = asset_path.left(-1); |
| 1346 | } |
| 1347 | AppleEmbeddedExportAsset exported_asset = { binary_name.path_join(asset_path), p_is_framework, p_should_embed }; |
| 1348 | r_exported_assets.push_back(exported_asset); |
| 1349 | |
| 1350 | return OK; |
| 1351 | } |
| 1352 | |
| 1353 | Error EditorExportPlatformAppleEmbedded::_export_additional_assets(const Ref<EditorExportPreset> &p_preset, const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, bool p_should_embed, Vector<AppleEmbeddedExportAsset> &r_exported_assets) { |
| 1354 | for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) { |
| 1355 | const String &asset = p_assets[f_idx]; |
| 1356 | if (asset.begins_with("res://")) { |
| 1357 | Error err = _copy_asset(p_preset, p_out_dir, asset, nullptr, p_is_framework, p_should_embed, r_exported_assets); |
| 1358 | ERR_FAIL_COND_V(err != OK, err); |
| 1359 | } else if (asset.is_absolute_path() && ProjectSettings::get_singleton()->localize_path(asset).begins_with("res://")) { |
| 1360 | Error err = _copy_asset(p_preset, p_out_dir, ProjectSettings::get_singleton()->localize_path(asset), nullptr, p_is_framework, p_should_embed, r_exported_assets); |
| 1361 | ERR_FAIL_COND_V(err != OK, err); |
| 1362 | } else { |
| 1363 | // either SDK-builtin or already a part of the export template |
| 1364 | AppleEmbeddedExportAsset exported_asset = { asset, p_is_framework, p_should_embed }; |
| 1365 | r_exported_assets.push_back(exported_asset); |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | return OK; |
| 1370 | } |
| 1371 | |
| 1372 | Error EditorExportPlatformAppleEmbedded::_export_additional_assets(const Ref<EditorExportPreset> &p_preset, const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<AppleEmbeddedExportAsset> &r_exported_assets) { |
| 1373 | Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins(); |
| 1374 | for (int i = 0; i < export_plugins.size(); i++) { |
| 1375 | Vector<String> linked_frameworks = export_plugins[i]->get_apple_embedded_platform_frameworks(); |
| 1376 | Error err = _export_additional_assets(p_preset, p_out_dir, linked_frameworks, true, false, r_exported_assets); |
| 1377 | ERR_FAIL_COND_V(err, err); |
| 1378 | |
| 1379 | Vector<String> embedded_frameworks = export_plugins[i]->get_apple_embedded_platform_embedded_frameworks(); |
| 1380 | err = _export_additional_assets(p_preset, p_out_dir, embedded_frameworks, true, true, r_exported_assets); |
| 1381 | ERR_FAIL_COND_V(err, err); |
| 1382 | |
| 1383 | Vector<String> project_static_libs = export_plugins[i]->get_apple_embedded_platform_project_static_libs(); |
| 1384 | for (int j = 0; j < project_static_libs.size(); j++) { |
| 1385 | project_static_libs.write[j] = project_static_libs[j].get_file(); // Only the file name as it's copied to the project |
| 1386 | } |
| 1387 | err = _export_additional_assets(p_preset, p_out_dir, project_static_libs, true, false, r_exported_assets); |
| 1388 | ERR_FAIL_COND_V(err, err); |
| 1389 | |
| 1390 | Vector<String> apple_embedded_platform_bundle_files = export_plugins[i]->get_apple_embedded_platform_bundle_files(); |
| 1391 | err = _export_additional_assets(p_preset, p_out_dir, apple_embedded_platform_bundle_files, false, false, r_exported_assets); |
| 1392 | ERR_FAIL_COND_V(err, err); |
| 1393 | } |
| 1394 | |
| 1395 | Vector<String> library_paths; |
| 1396 | for (int i = 0; i < p_libraries.size(); ++i) { |
| 1397 | library_paths.push_back(p_libraries[i].path); |
| 1398 | } |
| 1399 | Error err = _export_additional_assets(p_preset, p_out_dir, library_paths, true, true, r_exported_assets); |
| 1400 | ERR_FAIL_COND_V(err, err); |
| 1401 | |
| 1402 | return OK; |
| 1403 | } |
| 1404 | |
| 1405 | Vector<String> EditorExportPlatformAppleEmbedded::_get_preset_architectures(const Ref<EditorExportPreset> &p_preset) const { |
| 1406 | Vector<ExportArchitecture> all_archs = _get_supported_architectures(); |
| 1407 | Vector<String> enabled_archs; |
| 1408 | for (int i = 0; i < all_archs.size(); ++i) { |
| 1409 | bool is_enabled = p_preset->get("architectures/" + all_archs[i].name); |
| 1410 | if (is_enabled) { |
| 1411 | enabled_archs.push_back(all_archs[i].name); |
| 1412 | } |
| 1413 | } |
| 1414 | return enabled_archs; |
| 1415 | } |
| 1416 | |
| 1417 | Error EditorExportPlatformAppleEmbedded::_export_apple_embedded_plugins(const Ref<EditorExportPreset> &p_preset, AppleEmbeddedConfigData &p_config_data, const String &dest_dir, Vector<AppleEmbeddedExportAsset> &r_exported_assets, bool p_debug) { |
| 1418 | String plugin_definition_cpp_code; |
| 1419 | String plugin_initialization_cpp_code; |
| 1420 | String plugin_deinitialization_cpp_code; |
| 1421 | |
| 1422 | Vector<String> plugin_linked_dependencies; |
| 1423 | Vector<String> plugin_embedded_dependencies; |
| 1424 | Vector<String> plugin_files; |
| 1425 | |
| 1426 | Vector<PluginConfigAppleEmbedded> enabled_plugins = get_enabled_plugins(get_platform_name(), p_preset); |
| 1427 | |
| 1428 | Vector<String> added_linked_dependenciy_names; |
| 1429 | Vector<String> added_embedded_dependenciy_names; |
| 1430 | HashMap<String, String> plist_values; |
| 1431 | |
| 1432 | HashSet<String> plugin_linker_flags; |
| 1433 | |
| 1434 | Error err; |
| 1435 | |
| 1436 | for (int i = 0; i < enabled_plugins.size(); i++) { |
| 1437 | PluginConfigAppleEmbedded plugin = enabled_plugins[i]; |
| 1438 | |
| 1439 | // Export plugin binary. |
| 1440 | String plugin_main_binary = PluginConfigAppleEmbedded::get_plugin_main_binary(plugin, p_debug); |
| 1441 | String plugin_binary_result_file = plugin.binary.get_file(); |
| 1442 | // We shouldn't embed .xcframework that contains static libraries. |
| 1443 | // Static libraries are not embedded anyway. |
| 1444 | err = _copy_asset(p_preset, dest_dir, plugin_main_binary, &plugin_binary_result_file, true, false, r_exported_assets); |
| 1445 | ERR_FAIL_COND_V(err != OK, err); |
| 1446 | |
| 1447 | // Adding dependencies. |
| 1448 | // Use separate container for names to check for duplicates. |
| 1449 | for (int j = 0; j < plugin.linked_dependencies.size(); j++) { |
| 1450 | String dependency = plugin.linked_dependencies[j]; |
| 1451 | String name = dependency.get_file(); |
| 1452 | |
| 1453 | if (added_linked_dependenciy_names.has(name)) { |
| 1454 | continue; |
| 1455 | } |
| 1456 | |
| 1457 | added_linked_dependenciy_names.push_back(name); |
| 1458 | plugin_linked_dependencies.push_back(dependency); |
| 1459 | } |
| 1460 | |
| 1461 | for (int j = 0; j < plugin.system_dependencies.size(); j++) { |
| 1462 | String dependency = plugin.system_dependencies[j]; |
| 1463 | String name = dependency.get_file(); |
| 1464 | |
| 1465 | if (added_linked_dependenciy_names.has(name)) { |
| 1466 | continue; |
| 1467 | } |
| 1468 | |
| 1469 | added_linked_dependenciy_names.push_back(name); |
| 1470 | plugin_linked_dependencies.push_back(dependency); |
| 1471 | } |
| 1472 | |
| 1473 | for (int j = 0; j < plugin.embedded_dependencies.size(); j++) { |
| 1474 | String dependency = plugin.embedded_dependencies[j]; |
| 1475 | String name = dependency.get_file(); |
| 1476 | |
| 1477 | if (added_embedded_dependenciy_names.has(name)) { |
| 1478 | continue; |
| 1479 | } |
| 1480 | |
| 1481 | added_embedded_dependenciy_names.push_back(name); |
| 1482 | plugin_embedded_dependencies.push_back(dependency); |
| 1483 | } |
| 1484 | |
| 1485 | plugin_files.append_array(plugin.files_to_copy); |
| 1486 | |
| 1487 | // Capabilities |
| 1488 | // Also checking for duplicates. |
| 1489 | for (int j = 0; j < plugin.capabilities.size(); j++) { |
| 1490 | String capability = plugin.capabilities[j]; |
| 1491 | |
| 1492 | if (p_config_data.capabilities.has(capability)) { |
| 1493 | continue; |
| 1494 | } |
| 1495 | |
| 1496 | p_config_data.capabilities.push_back(capability); |
| 1497 | } |
| 1498 | |
| 1499 | // Linker flags |
| 1500 | // Checking duplicates |
| 1501 | for (int j = 0; j < plugin.linker_flags.size(); j++) { |
| 1502 | String linker_flag = plugin.linker_flags[j]; |
| 1503 | plugin_linker_flags.insert(linker_flag); |
| 1504 | } |
| 1505 | |
| 1506 | // Plist |
| 1507 | // Using hash map container to remove duplicates |
| 1508 | |
| 1509 | for (const KeyValue<String, PluginConfigAppleEmbedded::PlistItem> &E : plugin.plist) { |
| 1510 | String key = E.key; |
| 1511 | const PluginConfigAppleEmbedded::PlistItem &item = E.value; |
| 1512 | |
| 1513 | String value; |
| 1514 | |
| 1515 | switch (item.type) { |
| 1516 | case PluginConfigAppleEmbedded::PlistItemType::STRING_INPUT: { |
| 1517 | String preset_name = "plugins_plist/" + key; |
| 1518 | String input_value = p_preset->get(preset_name); |
| 1519 | value = "<string>" + input_value + "</string>"; |
| 1520 | } break; |
| 1521 | default: |
| 1522 | value = item.value; |
| 1523 | break; |
| 1524 | } |
| 1525 | |
| 1526 | if (key.is_empty() || value.is_empty()) { |
| 1527 | continue; |
| 1528 | } |
| 1529 | |
| 1530 | String plist_key = "<key>" + key + "</key>"; |
| 1531 | |
| 1532 | plist_values[plist_key] = value; |
| 1533 | } |
| 1534 | |
| 1535 | // CPP Code |
| 1536 | String definition_comment = "// Plugin: " + plugin.name + "\n"; |
| 1537 | String initialization_method = plugin.initialization_method + "();\n"; |
| 1538 | String deinitialization_method = plugin.deinitialization_method + "();\n"; |
| 1539 | |
| 1540 | plugin_definition_cpp_code += definition_comment + |
| 1541 | "extern void " + initialization_method + |
| 1542 | "extern void " + deinitialization_method + "\n"; |
| 1543 | |
| 1544 | plugin_initialization_cpp_code += "\t" + initialization_method; |
| 1545 | plugin_deinitialization_cpp_code += "\t" + deinitialization_method; |
| 1546 | } |
| 1547 | |
| 1548 | // Updating `Info.plist` |
| 1549 | { |
| 1550 | for (const KeyValue<String, String> &E : plist_values) { |
| 1551 | String key = E.key; |
| 1552 | String value = E.value; |
| 1553 | |
| 1554 | if (key.is_empty() || value.is_empty()) { |
| 1555 | continue; |
| 1556 | } |
| 1557 | |
| 1558 | p_config_data.plist_content += key + value + "\n"; |
| 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | // Export files |
| 1563 | { |
| 1564 | // Export linked plugin dependency |
| 1565 | err = _export_additional_assets(p_preset, dest_dir, plugin_linked_dependencies, true, false, r_exported_assets); |
| 1566 | ERR_FAIL_COND_V(err != OK, err); |
| 1567 | |
| 1568 | // Export embedded plugin dependency |
| 1569 | err = _export_additional_assets(p_preset, dest_dir, plugin_embedded_dependencies, true, true, r_exported_assets); |
| 1570 | ERR_FAIL_COND_V(err != OK, err); |
| 1571 | |
| 1572 | // Export plugin files |
| 1573 | err = _export_additional_assets(p_preset, dest_dir, plugin_files, false, false, r_exported_assets); |
| 1574 | ERR_FAIL_COND_V(err != OK, err); |
| 1575 | } |
| 1576 | |
| 1577 | // Update CPP |
| 1578 | { |
| 1579 | Dictionary plugin_format; |
| 1580 | plugin_format["definition"] = plugin_definition_cpp_code; |
| 1581 | plugin_format["initialization"] = plugin_initialization_cpp_code; |
| 1582 | plugin_format["deinitialization"] = plugin_deinitialization_cpp_code; |
| 1583 | |
| 1584 | String plugin_cpp_code = "\n// Godot Plugins\n" |
| 1585 | "void godot_apple_embedded_plugins_initialize();\n" |
| 1586 | "void godot_apple_embedded_plugins_deinitialize();\n" |
| 1587 | "// Exported Plugins\n\n" |
| 1588 | "$definition" |
| 1589 | "// Use Plugins\n" |
| 1590 | "void godot_apple_embedded_plugins_initialize() {\n" |
| 1591 | "$initialization" |
| 1592 | "}\n\n" |
| 1593 | "void godot_apple_embedded_plugins_deinitialize() {\n" |
| 1594 | "$deinitialization" |
| 1595 | "}\n"; |
| 1596 | |
| 1597 | p_config_data.cpp_code += plugin_cpp_code.format(plugin_format, "$_"); |
| 1598 | } |
| 1599 | |
| 1600 | // Update Linker Flag Values |
| 1601 | { |
| 1602 | String result_linker_flags = " "; |
| 1603 | for (const String &E : plugin_linker_flags) { |
| 1604 | const String &flag = E; |
| 1605 | |
| 1606 | if (flag.length() == 0) { |
| 1607 | continue; |
| 1608 | } |
| 1609 | |
| 1610 | if (result_linker_flags.length() > 0) { |
| 1611 | result_linker_flags += ' '; |
| 1612 | } |
| 1613 | |
| 1614 | result_linker_flags += flag; |
| 1615 | } |
| 1616 | result_linker_flags = result_linker_flags.replace("\"", "\\\""); |
| 1617 | p_config_data.linker_flags += result_linker_flags; |
| 1618 | } |
| 1619 | |
| 1620 | return OK; |
| 1621 | } |
| 1622 | |
| 1623 | Error EditorExportPlatformAppleEmbedded::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) { |
| 1624 | return _export_project_helper(p_preset, p_debug, p_path, p_flags, false); |
| 1625 | } |
| 1626 | |
| 1627 | Error EditorExportPlatformAppleEmbedded::_export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags, bool p_oneclick) { |
| 1628 | ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags); |
| 1629 | |
| 1630 | const String dest_dir = p_path.get_base_dir() + "/"; |
| 1631 | const String binary_name = p_path.get_file().get_basename(); |
| 1632 | const String binary_dir = dest_dir + binary_name; |
| 1633 | |
| 1634 | if (!DirAccess::exists(dest_dir)) { |
| 1635 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Target folder does not exist or is inaccessible: \"%s\""), dest_dir)); |
| 1636 | return ERR_FILE_BAD_PATH; |
| 1637 | } |
| 1638 | |
| 1639 | bool export_project_only = p_preset->get("application/export_project_only"); |
| 1640 | if (p_oneclick) { |
| 1641 | export_project_only = false; // Skip for one-click deploy. |
| 1642 | } |
| 1643 | |
| 1644 | EditorProgress ep("export", export_project_only ? TTR("Exporting for " + get_name() + " (Project Files Only)") : TTR("Exporting for " + get_name() + ""), export_project_only ? 2 : 5, true); |
| 1645 | |
| 1646 | String team_id = p_preset->get("application/app_store_team_id"); |
| 1647 | ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project."); |
| 1648 | |
| 1649 | String src_pkg_name; |
| 1650 | if (p_debug) { |
| 1651 | src_pkg_name = p_preset->get("custom_template/debug"); |
| 1652 | } else { |
| 1653 | src_pkg_name = p_preset->get("custom_template/release"); |
| 1654 | } |
| 1655 | |
| 1656 | if (src_pkg_name.is_empty()) { |
| 1657 | String err; |
| 1658 | src_pkg_name = find_export_template(get_platform_name() + ".zip", &err); |
| 1659 | if (src_pkg_name.is_empty()) { |
| 1660 | add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found.")); |
| 1661 | return ERR_FILE_NOT_FOUND; |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | { |
| 1666 | bool delete_old = p_preset->get("application/delete_old_export_files_unconditionally"); |
| 1667 | Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 1668 | if (da.is_valid()) { |
| 1669 | String current_dir = da->get_current_dir(); |
| 1670 | |
| 1671 | // Remove leftovers from last export so they don't interfere in case some files are no longer needed. |
| 1672 | if (da->change_dir(binary_dir + ".xcodeproj") == OK) { |
| 1673 | // Check directory content before deleting. |
| 1674 | int expected_files = 0; |
| 1675 | int total_files = 0; |
| 1676 | if (!delete_old) { |
| 1677 | da->list_dir_begin(); |
| 1678 | for (String n = da->get_next(); !n.is_empty(); n = da->get_next()) { |
| 1679 | if (!n.begins_with(".")) { // Ignore ".", ".." and hidden files. |
| 1680 | if (da->current_is_dir()) { |
| 1681 | if (n == "xcshareddata" || n == "project.xcworkspace") { |
| 1682 | expected_files++; |
| 1683 | } |
| 1684 | } else { |
| 1685 | if (n == "project.pbxproj") { |
| 1686 | expected_files++; |
| 1687 | } |
| 1688 | } |
| 1689 | total_files++; |
| 1690 | } |
| 1691 | } |
| 1692 | da->list_dir_end(); |
| 1693 | } |
| 1694 | if ((total_files == 0) || (expected_files >= Math::floor(total_files * 0.8))) { |
| 1695 | da->erase_contents_recursive(); |
| 1696 | } else { |
| 1697 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Unexpected files found in the export destination directory \"%s.xcodeproj\", delete it manually or select another destination."), binary_dir)); |
| 1698 | return ERR_CANT_CREATE; |
| 1699 | } |
| 1700 | } |
| 1701 | da->change_dir(current_dir); |
| 1702 | |
| 1703 | if (da->change_dir(binary_dir) == OK) { |
| 1704 | // Check directory content before deleting. |
| 1705 | int expected_files = 0; |
| 1706 | int total_files = 0; |
| 1707 | if (!delete_old) { |
| 1708 | da->list_dir_begin(); |
| 1709 | for (String n = da->get_next(); !n.is_empty(); n = da->get_next()) { |
| 1710 | if (!n.begins_with(".")) { // Ignore ".", ".." and hidden files. |
| 1711 | if (da->current_is_dir()) { |
| 1712 | if (n == "dylibs" || n == "Images.xcassets" || n.ends_with(".lproj") || n == "godot-publish-dotnet" || n.ends_with(".xcframework") || n.ends_with(".framework")) { |
| 1713 | expected_files++; |
| 1714 | } |
| 1715 | } else { |
| 1716 | if (n == binary_name + "-Info.plist" || n == binary_name + ".entitlements" || n == "Launch Screen.storyboard" || n == "export_options.plist" || n.begins_with("dummy.") || n.ends_with(".gdip")) { |
| 1717 | expected_files++; |
| 1718 | } |
| 1719 | } |
| 1720 | total_files++; |
| 1721 | } |
| 1722 | } |
| 1723 | da->list_dir_end(); |
| 1724 | } |
| 1725 | if ((total_files == 0) || (expected_files >= Math::floor(total_files * 0.8))) { |
| 1726 | da->erase_contents_recursive(); |
| 1727 | } else { |
| 1728 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Unexpected files found in the export destination directory \"%s\", delete it manually or select another destination."), binary_dir)); |
| 1729 | return ERR_CANT_CREATE; |
| 1730 | } |
| 1731 | } |
| 1732 | da->change_dir(current_dir); |
| 1733 | |
| 1734 | if (!da->dir_exists(binary_dir)) { |
| 1735 | Error err = da->make_dir(binary_dir); |
| 1736 | if (err != OK) { |
| 1737 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Failed to create the directory: \"%s\""), binary_dir)); |
| 1738 | return err; |
| 1739 | } |
| 1740 | } |
| 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | if (ep.step("Making .pck", 0)) { |
| 1745 | return ERR_SKIP; |
| 1746 | } |
| 1747 | String pack_path = binary_dir + ".pck"; |
| 1748 | Vector<SharedObject> libraries; |
| 1749 | Error err = save_pack(p_preset, p_debug, pack_path, &libraries); |
| 1750 | if (err) { |
| 1751 | // Message is supplied by the subroutine method. |
| 1752 | return err; |
| 1753 | } |
| 1754 | |
| 1755 | if (ep.step("Extracting and configuring Xcode project", 1)) { |
| 1756 | return ERR_SKIP; |
| 1757 | } |
| 1758 | |
| 1759 | String library_to_use = "libgodot." + get_platform_name() + "." + String(p_debug ? "debug" : "release") + ".xcframework"; |
| 1760 | |
| 1761 | print_line("Static framework: " + library_to_use); |
| 1762 | String pkg_name; |
| 1763 | if (String(get_project_setting(p_preset, "application/config/name")) != "") { |
| 1764 | pkg_name = String(get_project_setting(p_preset, "application/config/name")); |
| 1765 | } else { |
| 1766 | pkg_name = "Unnamed"; |
| 1767 | } |
| 1768 | |
| 1769 | bool found_library = false; |
| 1770 | |
| 1771 | HashSet<String> files_to_parse; |
| 1772 | const String project_file = "godot_apple_embedded.xcodeproj/project.pbxproj"; |
| 1773 | files_to_parse.insert(project_file); |
| 1774 | files_to_parse.insert("godot_apple_embedded.xcodeproj/project.xcworkspace/contents.xcworkspacedata"); |
| 1775 | files_to_parse.insert("godot_apple_embedded.xcodeproj/xcshareddata/xcschemes/godot_apple_embedded.xcscheme"); |
| 1776 | files_to_parse.insert("godot_apple_embedded/godot_apple_embedded-Info.plist"); |
| 1777 | files_to_parse.insert("godot_apple_embedded/godot_apple_embedded.entitlements"); |
| 1778 | files_to_parse.insert("godot_apple_embedded/export_options.plist"); |
| 1779 | files_to_parse.insert("godot_apple_embedded/dummy.cpp"); |
| 1780 | files_to_parse.insert("godot_apple_embedded/Launch Screen.storyboard"); |
| 1781 | files_to_parse.insert("PrivacyInfo.xcprivacy"); |
| 1782 | |
| 1783 | AppleEmbeddedConfigData config_data = { |
| 1784 | pkg_name, |
| 1785 | binary_name, |
| 1786 | _get_additional_plist_content(), |
| 1787 | String(" ").join(_get_preset_architectures(p_preset)), |
| 1788 | _get_linker_flags(), |
| 1789 | _get_cpp_code(), |
| 1790 | "", |
| 1791 | "", |
| 1792 | "", |
| 1793 | "", |
| 1794 | Vector<String>(), |
| 1795 | }; |
| 1796 | |
| 1797 | config_data.plist_content += p_preset->get("application/additional_plist_content").operator String() + "\n"; |
| 1798 | |
| 1799 | Vector<AppleEmbeddedExportAsset> assets; |
| 1800 | |
| 1801 | Ref<DirAccess> tmp_app_path = DirAccess::create_for_path(dest_dir); |
| 1802 | if (tmp_app_path.is_null()) { |
| 1803 | add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not create and open the directory: \"%s\""), dest_dir)); |
| 1804 | return ERR_CANT_CREATE; |
| 1805 | } |
| 1806 | |
| 1807 | print_line("Unzipping..."); |
| 1808 | Ref<FileAccess> io_fa; |
| 1809 | zlib_filefunc_def io = zipio_create_io(&io_fa); |
| 1810 | unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io); |
| 1811 | if (!src_pkg_zip) { |
| 1812 | add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Could not open export template (not a zip file?): \"%s\".", src_pkg_name)); |
| 1813 | return ERR_CANT_OPEN; |
| 1814 | } |
| 1815 | |
| 1816 | err = _export_apple_embedded_plugins(p_preset, config_data, binary_dir, assets, p_debug); |
| 1817 | if (err != OK) { |
| 1818 | // TODO: Improve error reporting by using `add_message` throughout all methods called via `_export_apple_embedded_plugins`. |
| 1819 | // For now a generic top level message would be fine, but we're ought to use proper reporting here instead of |
| 1820 | // just fail macros and non-descriptive error return values. |
| 1821 | add_message(EXPORT_MESSAGE_ERROR, TTR("Apple Embedded Plugins"), vformat(TTR("Failed to export Apple Embedded plugins with code %d. Please check the output log."), err)); |
| 1822 | return err; |
| 1823 | } |
| 1824 | |
| 1825 | //export rest of the files |
| 1826 | int ret = unzGoToFirstFile(src_pkg_zip); |
| 1827 | Vector<uint8_t> project_file_data; |
| 1828 | while (ret == UNZ_OK) { |
| 1829 | #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED) |
| 1830 | bool is_execute = false; |
| 1831 | #endif |
| 1832 | |
| 1833 | //get filename |
| 1834 | unz_file_info info; |
| 1835 | char fname[16384]; |
| 1836 | ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0); |
| 1837 | if (ret != UNZ_OK) { |
| 1838 | break; |
| 1839 | } |
| 1840 | |
| 1841 | String file = String::utf8(fname); |
| 1842 | |
| 1843 | print_line("READ: " + file); |
| 1844 | Vector<uint8_t> data; |
| 1845 | data.resize(info.uncompressed_size); |
| 1846 | |
| 1847 | //read |
| 1848 | unzOpenCurrentFile(src_pkg_zip); |
| 1849 | unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size()); |
| 1850 | unzCloseCurrentFile(src_pkg_zip); |
| 1851 | |
| 1852 | //write |
| 1853 | |
| 1854 | if (files_to_parse.has(file)) { |
| 1855 | _fix_config_file(p_preset, data, config_data, p_debug); |
| 1856 | } else if (file.begins_with("libgodot." + get_platform_name())) { |
| 1857 | if (!file.begins_with(library_to_use) || file.ends_with(String("/empty"))) { |
| 1858 | ret = unzGoToNextFile(src_pkg_zip); |
| 1859 | continue; //ignore! |
| 1860 | } |
| 1861 | found_library = true; |
| 1862 | #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED) |
| 1863 | is_execute = true; |
| 1864 | #endif |
| 1865 | file = file.replace(library_to_use, binary_name + ".xcframework"); |
| 1866 | } |
| 1867 | |
| 1868 | if (file == project_file) { |
| 1869 | project_file_data = data; |
| 1870 | } |
| 1871 | |
| 1872 | ///@TODO need to parse logo files |
| 1873 | |
| 1874 | if (data.size() > 0) { |
| 1875 | file = file.replace("godot_apple_embedded", binary_name); |
| 1876 | |
| 1877 | print_line("ADDING: " + file + " size: " + itos(data.size())); |
| 1878 | |
| 1879 | /* write it into our folder structure */ |
| 1880 | file = dest_dir + file; |
| 1881 | |
| 1882 | /* make sure this folder exists */ |
| 1883 | String dir_name = file.get_base_dir(); |
| 1884 | if (!tmp_app_path->dir_exists(dir_name)) { |
| 1885 | print_line("Creating " + dir_name); |
| 1886 | Error dir_err = tmp_app_path->make_dir_recursive(dir_name); |
| 1887 | if (dir_err) { |
| 1888 | unzClose(src_pkg_zip); |
| 1889 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create a directory at path \"%s\"."), dir_name)); |
| 1890 | return ERR_CANT_CREATE; |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | /* write the file */ |
| 1895 | { |
| 1896 | Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE); |
| 1897 | if (f.is_null()) { |
| 1898 | unzClose(src_pkg_zip); |
| 1899 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write to a file at path \"%s\"."), file)); |
| 1900 | return ERR_CANT_CREATE; |
| 1901 | }; |
| 1902 | f->store_buffer(data.ptr(), data.size()); |
| 1903 | } |
| 1904 | |
| 1905 | #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED) |
| 1906 | if (is_execute) { |
| 1907 | // we need execute rights on this file |
| 1908 | chmod(file.utf8().get_data(), 0755); |
| 1909 | } |
| 1910 | #endif |
| 1911 | } |
| 1912 | |
| 1913 | ret = unzGoToNextFile(src_pkg_zip); |
| 1914 | } |
| 1915 | |
| 1916 | // We're done with our source zip. |
| 1917 | unzClose(src_pkg_zip); |
| 1918 | |
| 1919 | if (!found_library) { |
| 1920 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Requested template library '%s' not found. It might be missing from your template archive."), library_to_use)); |
| 1921 | return ERR_FILE_NOT_FOUND; |
| 1922 | } |
| 1923 | |
| 1924 | Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized"); |
| 1925 | Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized"); |
| 1926 | Dictionary photolibrary_usage_descriptions = p_preset->get("privacy/photolibrary_usage_description_localized"); |
| 1927 | |
| 1928 | const String project_name = get_project_setting(p_preset, "application/config/name"); |
| 1929 | const Dictionary appnames = get_project_setting(p_preset, "application/config/name_localized"); |
| 1930 | const StringName domain_name = "godot.project_name_localization"; |
| 1931 | Ref<TranslationDomain> domain = TranslationServer::get_singleton()->get_or_add_domain(domain_name); |
| 1932 | TranslationServer::get_singleton()->load_project_translations(domain); |
| 1933 | const Vector<String> locales = domain->get_loaded_locales(); |
| 1934 | |
| 1935 | if (!locales.is_empty()) { |
| 1936 | { |
| 1937 | String fname = binary_dir + "/en.lproj"; |
| 1938 | tmp_app_path->make_dir_recursive(fname); |
| 1939 | Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE); |
| 1940 | f->store_line("/* Localized versions of Info.plist keys */"); |
| 1941 | f->store_line(""); |
| 1942 | f->store_line("CFBundleDisplayName = \"" + project_name.xml_escape(true) + "\";"); |
| 1943 | f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String().xml_escape(true) + "\";"); |
| 1944 | f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String().xml_escape(true) + "\";"); |
| 1945 | f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photolibrary_usage_description").operator String().xml_escape(true) + "\";"); |
| 1946 | } |
| 1947 | |
| 1948 | for (const String &lang : locales) { |
| 1949 | if (lang == "en") { |
| 1950 | continue; |
| 1951 | } |
| 1952 | |
| 1953 | String fname = binary_dir + "/" + lang + ".lproj"; |
| 1954 | tmp_app_path->make_dir_recursive(fname); |
| 1955 | Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE); |
| 1956 | f->store_line("/* Localized versions of Info.plist keys */"); |
| 1957 | f->store_line(""); |
| 1958 | |
| 1959 | if (appnames.is_empty()) { |
| 1960 | domain->set_locale_override(lang); |
| 1961 | const String &name = domain->translate(project_name, String()); |
| 1962 | if (name != project_name) { |
| 1963 | f->store_line("CFBundleDisplayName = \"" + name.xml_escape(true) + "\";"); |
| 1964 | } |
| 1965 | } else if (appnames.has(lang)) { |
| 1966 | f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String().xml_escape(true) + "\";"); |
| 1967 | } |
| 1968 | |
| 1969 | if (camera_usage_descriptions.has(lang)) { |
| 1970 | f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1971 | } |
| 1972 | if (microphone_usage_descriptions.has(lang)) { |
| 1973 | f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1974 | } |
| 1975 | if (photolibrary_usage_descriptions.has(lang)) { |
| 1976 | f->store_line("NSPhotoLibraryUsageDescription = \"" + photolibrary_usage_descriptions[lang].operator String().xml_escape(true) + "\";"); |
| 1977 | } |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | // Copy project static libs to the project |
| 1982 | Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins(); |
| 1983 | for (int i = 0; i < export_plugins.size(); i++) { |
| 1984 | Vector<String> project_static_libs = export_plugins[i]->get_apple_embedded_platform_project_static_libs(); |
| 1985 | for (int j = 0; j < project_static_libs.size(); j++) { |
| 1986 | const String &static_lib_path = project_static_libs[j]; |
| 1987 | String dest_lib_file_path = dest_dir + static_lib_path.get_file(); |
| 1988 | Error lib_copy_err = tmp_app_path->copy(static_lib_path, dest_lib_file_path); |
| 1989 | if (lib_copy_err != OK) { |
| 1990 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not copy a file at path \"%s\" to \"%s\"."), static_lib_path, dest_lib_file_path)); |
| 1991 | return lib_copy_err; |
| 1992 | } |
| 1993 | } |
| 1994 | } |
| 1995 | |
| 1996 | String iconset_dir = binary_dir + "/Images.xcassets/AppIcon.appiconset/"; |
| 1997 | err = OK; |
| 1998 | if (!tmp_app_path->dir_exists(iconset_dir)) { |
| 1999 | err = tmp_app_path->make_dir_recursive(iconset_dir); |
| 2000 | } |
| 2001 | if (err != OK) { |
| 2002 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create a directory at path \"%s\"."), iconset_dir)); |
| 2003 | return err; |
| 2004 | } |
| 2005 | |
| 2006 | err = _export_icons(p_preset, iconset_dir); |
| 2007 | if (err != OK) { |
| 2008 | // Message is supplied by the subroutine method. |
| 2009 | return err; |
| 2010 | } |
| 2011 | |
| 2012 | { |
| 2013 | String splash_image_path = binary_dir + "/Images.xcassets/SplashImage.imageset/"; |
| 2014 | |
| 2015 | Ref<DirAccess> launch_screen_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 2016 | if (launch_screen_da.is_null()) { |
| 2017 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not access the filesystem.")); |
| 2018 | return ERR_CANT_CREATE; |
| 2019 | } |
| 2020 | |
| 2021 | print_line("Exporting launch screen storyboard"); |
| 2022 | |
| 2023 | err = _export_loading_screen_file(p_preset, splash_image_path); |
| 2024 | if (err != OK) { |
| 2025 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Failed to create a file at path \"%s\" with code %d."), splash_image_path, err)); |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | if (err != OK) { |
| 2030 | return err; |
| 2031 | } |
| 2032 | |
| 2033 | print_line("Exporting additional assets"); |
| 2034 | _export_additional_assets(p_preset, binary_dir, libraries, assets); |
| 2035 | _add_assets_to_project(dest_dir, p_preset, project_file_data, assets); |
| 2036 | String project_file_name = binary_dir + ".xcodeproj/project.pbxproj"; |
| 2037 | { |
| 2038 | Ref<FileAccess> f = FileAccess::open(project_file_name, FileAccess::WRITE); |
| 2039 | if (f.is_null()) { |
| 2040 | add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write to a file at path \"%s\"."), project_file_name)); |
| 2041 | return ERR_CANT_CREATE; |
| 2042 | }; |
| 2043 | f->store_buffer(project_file_data.ptr(), project_file_data.size()); |
| 2044 | } |
| 2045 | |
| 2046 | #ifdef MACOS_ENABLED |
| 2047 | { |
| 2048 | if (ep.step("Code-signing dylibs", 2)) { |
| 2049 | return ERR_SKIP; |
| 2050 | } |
| 2051 | Ref<DirAccess> dylibs_dir = DirAccess::open(binary_dir + "/dylibs"); |
| 2052 | ERR_FAIL_COND_V(dylibs_dir.is_null(), ERR_CANT_OPEN); |
| 2053 | CodesignData codesign_data(p_preset, p_debug); |
| 2054 | err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data); |
| 2055 | if (err != OK) { |
| 2056 | add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Code signing failed, see editor log for details.")); |
| 2057 | return err; |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | if (export_project_only) { |
| 2062 | return OK; |
| 2063 | } |
| 2064 | |
| 2065 | if (ep.step("Making .xcarchive", 3)) { |
| 2066 | return ERR_SKIP; |
| 2067 | } |
| 2068 | |
| 2069 | String platform_name = get_platform_name(); |
| 2070 | |
| 2071 | String archive_path = p_path.get_basename() + ".xcarchive"; |
| 2072 | List<String> archive_args; |
| 2073 | archive_args.push_back("-project"); |
| 2074 | archive_args.push_back(binary_dir + ".xcodeproj"); |
| 2075 | archive_args.push_back("-scheme"); |
| 2076 | archive_args.push_back(binary_name); |
| 2077 | archive_args.push_back("-sdk"); |
| 2078 | archive_args.push_back(get_sdk_name()); |
| 2079 | archive_args.push_back("-configuration"); |
| 2080 | archive_args.push_back(p_debug ? "Debug" : "Release"); |
| 2081 | archive_args.push_back("-destination"); |
| 2082 | archive_args.push_back("generic/platform=" + get_platform_name()); |
| 2083 | archive_args.push_back("archive"); |
| 2084 | archive_args.push_back("-allowProvisioningUpdates"); |
| 2085 | archive_args.push_back("-archivePath"); |
| 2086 | archive_args.push_back(archive_path); |
| 2087 | |
| 2088 | bool archive_succeeded = false; |
| 2089 | int result = _execute("xcodebuild", archive_args, [&archive_succeeded](const String &p_data) { |
| 2090 | print_line(p_data); |
| 2091 | DisplayServer::get_singleton()->process_events(); |
| 2092 | Main::iteration(); |
| 2093 | if (!archive_succeeded && p_data.contains("** ARCHIVE SUCCEEDED **")) { |
| 2094 | archive_succeeded = true; |
| 2095 | } |
| 2096 | }); |
| 2097 | if (result != 0) { |
| 2098 | add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), vformat(TTR("Failed to run xcodebuild with code %d"), err)); |
| 2099 | return ERR_CANT_CREATE; |
| 2100 | } |
| 2101 | |
| 2102 | if (!archive_succeeded) { |
| 2103 | add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR("Xcode project build failed, see editor log for details.")); |
| 2104 | return FAILED; |
| 2105 | } |
| 2106 | |
| 2107 | if (!p_oneclick) { |
| 2108 | if (ep.step("Making .ipa", 4)) { |
| 2109 | return ERR_SKIP; |
| 2110 | } |
| 2111 | |
| 2112 | List<String> export_args; |
| 2113 | export_args.push_back("-exportArchive"); |
| 2114 | export_args.push_back("-archivePath"); |
| 2115 | export_args.push_back(archive_path); |
| 2116 | export_args.push_back("-exportOptionsPlist"); |
| 2117 | export_args.push_back(binary_dir + "/export_options.plist"); |
| 2118 | export_args.push_back("-allowProvisioningUpdates"); |
| 2119 | export_args.push_back("-exportPath"); |
| 2120 | export_args.push_back(dest_dir); |
| 2121 | |
| 2122 | bool export_succeeded = false; |
| 2123 | result = _execute("xcodebuild", export_args, [&export_succeeded](const String &p_data) { |
| 2124 | print_line(p_data); |
| 2125 | DisplayServer::get_singleton()->process_events(); |
| 2126 | Main::iteration(); |
| 2127 | if (!export_succeeded && p_data.contains("** EXPORT SUCCEEDED **")) { |
| 2128 | export_succeeded = true; |
| 2129 | } |
| 2130 | }); |
| 2131 | if (result != 0) { |
| 2132 | add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), vformat(TTR("Failed to run xcodebuild with code %d"), err)); |
| 2133 | return err; |
| 2134 | } |
| 2135 | |
| 2136 | if (!export_succeeded) { |
| 2137 | add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR(".ipa export failed, see editor log for details.")); |
| 2138 | return FAILED; |
| 2139 | } |
| 2140 | } |
| 2141 | #else |
| 2142 | add_message(EXPORT_MESSAGE_WARNING, TTR("Xcode Build"), TTR(".ipa can only be built on macOS. Leaving Xcode project without building the package.")); |
| 2143 | #endif |
| 2144 | |
| 2145 | return OK; |
| 2146 | } |
| 2147 | |
| 2148 | bool EditorExportPlatformAppleEmbedded::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const { |
| 2149 | #if defined(MODULE_MONO_ENABLED) && !defined(MACOS_ENABLED) |
| 2150 | // TODO: Remove this restriction when we don't rely on macOS tools to package up the native libraries anymore. |
| 2151 | r_error += TTR("Exporting to an Apple Embedded platform when using C#/.NET is experimental and requires macOS.") + "\n"; |
| 2152 | return false; |
| 2153 | #else |
| 2154 | |
| 2155 | String err; |
| 2156 | bool valid = false; |
| 2157 | |
| 2158 | #if defined(MODULE_MONO_ENABLED) |
| 2159 | // Apple Embedded export is still a work in progress, keep a message as a warning. |
| 2160 | err += TTR("Exporting to an Apple Embedded platform when using C#/.NET is experimental.") + "\n"; |
| 2161 | #endif |
| 2162 | // Look for export templates (first official, and if defined custom templates). |
| 2163 | |
| 2164 | bool dvalid = exists_export_template(get_platform_name() + ".zip", &err); |
| 2165 | bool rvalid = dvalid; // Both in the same ZIP. |
| 2166 | |
| 2167 | if (p_preset->get("custom_template/debug") != "") { |
| 2168 | dvalid = FileAccess::exists(p_preset->get("custom_template/debug")); |
| 2169 | if (!dvalid) { |
| 2170 | err += TTR("Custom debug template not found.") + "\n"; |
| 2171 | } |
| 2172 | } |
| 2173 | if (p_preset->get("custom_template/release") != "") { |
| 2174 | rvalid = FileAccess::exists(p_preset->get("custom_template/release")); |
| 2175 | if (!rvalid) { |
| 2176 | err += TTR("Custom release template not found.") + "\n"; |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | valid = dvalid || rvalid; |
| 2181 | r_missing_templates = !valid; |
| 2182 | |
| 2183 | const String &additional_plist_content = p_preset->get("application/additional_plist_content"); |
| 2184 | if (!additional_plist_content.is_empty()) { |
| 2185 | const String &plist = vformat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 2186 | "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" |
| 2187 | "<plist version=\"1.0\">" |
| 2188 | "<dict>\n" |
| 2189 | "%s\n" |
| 2190 | "</dict>\n" |
| 2191 | "</plist>\n", |
| 2192 | additional_plist_content); |
| 2193 | |
| 2194 | String plist_err; |
| 2195 | Ref<PList> plist_parser; |
| 2196 | plist_parser.instantiate(); |
| 2197 | if (!plist_parser->load_string(plist, plist_err)) { |
| 2198 | err += TTR("Invalid additional PList content: ") + plist_err + "\n"; |
| 2199 | valid = false; |
| 2200 | } |
| 2201 | } |
| 2202 | |
| 2203 | if (!err.is_empty()) { |
| 2204 | r_error = err; |
| 2205 | } |
| 2206 | |
| 2207 | return valid; |
| 2208 | #endif // !(MODULE_MONO_ENABLED && !MACOS_ENABLED) |
| 2209 | } |
| 2210 | |
| 2211 | bool EditorExportPlatformAppleEmbedded::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const { |
| 2212 | String err; |
| 2213 | bool valid = true; |
| 2214 | |
| 2215 | // Validate the project configuration. |
| 2216 | |
| 2217 | List<ExportOption> options; |
| 2218 | get_export_options(&options); |
| 2219 | for (const EditorExportPlatform::ExportOption &E : options) { |
| 2220 | if (get_export_option_visibility(p_preset.ptr(), E.option.name)) { |
| 2221 | String warn = get_export_option_warning(p_preset.ptr(), E.option.name); |
| 2222 | if (!warn.is_empty()) { |
| 2223 | err += warn + "\n"; |
| 2224 | if (E.required) { |
| 2225 | valid = false; |
| 2226 | } |
| 2227 | } |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | if (!ResourceImporterTextureSettings::should_import_etc2_astc()) { |
| 2232 | valid = false; |
| 2233 | } |
| 2234 | |
| 2235 | if (!err.is_empty()) { |
| 2236 | r_error = err; |
| 2237 | } |
| 2238 | |
| 2239 | return valid; |
| 2240 | } |
| 2241 | |
| 2242 | int EditorExportPlatformAppleEmbedded::get_options_count() const { |
| 2243 | MutexLock lock(device_lock); |
| 2244 | return devices.size(); |
| 2245 | } |
| 2246 | |
| 2247 | String EditorExportPlatformAppleEmbedded::get_options_tooltip() const { |
| 2248 | return TTR("Select device from the list"); |
| 2249 | } |
| 2250 | |
| 2251 | Ref<Texture2D> EditorExportPlatformAppleEmbedded::get_option_icon(int p_index) const { |
| 2252 | MutexLock lock(device_lock); |
| 2253 | |
| 2254 | Ref<Texture2D> icon; |
| 2255 | if (p_index >= 0 || p_index < devices.size()) { |
| 2256 | Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme(); |
| 2257 | if (theme.is_valid()) { |
| 2258 | if (devices[p_index].wifi) { |
| 2259 | icon = theme->get_icon("IOSDeviceWireless", EditorStringName(EditorIcons)); |
| 2260 | } else { |
| 2261 | icon = theme->get_icon("IOSDeviceWired", EditorStringName(EditorIcons)); |
| 2262 | } |
| 2263 | } |
| 2264 | } |
| 2265 | return icon; |
| 2266 | } |
| 2267 | |
| 2268 | String EditorExportPlatformAppleEmbedded::get_option_label(int p_index) const { |
| 2269 | ERR_FAIL_INDEX_V(p_index, devices.size(), ""); |
| 2270 | MutexLock lock(device_lock); |
| 2271 | return devices[p_index].name; |
| 2272 | } |
| 2273 | |
| 2274 | String EditorExportPlatformAppleEmbedded::get_option_tooltip(int p_index) const { |
| 2275 | ERR_FAIL_INDEX_V(p_index, devices.size(), ""); |
| 2276 | MutexLock lock(device_lock); |
| 2277 | return "UUID: " + devices[p_index].id; |
| 2278 | } |
| 2279 | |
| 2280 | bool EditorExportPlatformAppleEmbedded::is_package_name_valid(const String &p_package, String *r_error) const { |
| 2281 | String pname = p_package; |
| 2282 | |
| 2283 | if (pname.length() == 0) { |
| 2284 | if (r_error) { |
| 2285 | *r_error = TTR("Identifier is missing."); |
| 2286 | } |
| 2287 | return false; |
| 2288 | } |
| 2289 | |
| 2290 | for (int i = 0; i < pname.length(); i++) { |
| 2291 | char32_t c = pname[i]; |
| 2292 | if (!(is_ascii_alphanumeric_char(c) || c == '-' || c == '.')) { |
| 2293 | if (r_error) { |
| 2294 | *r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c)); |
| 2295 | } |
| 2296 | return false; |
| 2297 | } |
| 2298 | } |
| 2299 | |
| 2300 | return true; |
| 2301 | } |
| 2302 | |
| 2303 | #ifdef MACOS_ENABLED |
| 2304 | bool EditorExportPlatformAppleEmbedded::_check_xcode_install() { |
| 2305 | static bool xcode_found = false; |
| 2306 | if (!xcode_found) { |
| 2307 | Vector<String> mdfind_paths; |
| 2308 | List<String> mdfind_args; |
| 2309 | mdfind_args.push_back("kMDItemCFBundleIdentifier=com.apple.dt.Xcode"); |
| 2310 | |
| 2311 | String output; |
| 2312 | Error err = OS::get_singleton()->execute("mdfind", mdfind_args, &output); |
| 2313 | if (err == OK) { |
| 2314 | mdfind_paths = output.split("\n"); |
| 2315 | } |
| 2316 | for (const String &found_path : mdfind_paths) { |
| 2317 | xcode_found = !found_path.is_empty() && DirAccess::dir_exists_absolute(found_path.strip_edges()); |
| 2318 | if (xcode_found) { |
| 2319 | break; |
| 2320 | } |
| 2321 | } |
| 2322 | } |
| 2323 | return xcode_found; |
| 2324 | } |
| 2325 | |
| 2326 | void EditorExportPlatformAppleEmbedded::_check_for_changes_poll_thread(void *ud) { |
| 2327 | EditorExportPlatformAppleEmbedded *ea = static_cast<EditorExportPlatformAppleEmbedded *>(ud); |
| 2328 | |
| 2329 | String device_types; |
| 2330 | bool first = true; |
| 2331 | for (const String &d : ea->get_device_types()) { |
| 2332 | if (first) { |
| 2333 | first = false; |
| 2334 | } else { |
| 2335 | device_types += "|"; |
| 2336 | } |
| 2337 | device_types += d; |
| 2338 | } |
| 2339 | |
| 2340 | while (!ea->quit_request.is_set()) { |
| 2341 | // Nothing to do if we already know the plugins have changed. |
| 2342 | if (!ea->plugins_changed.is_set()) { |
| 2343 | MutexLock lock(ea->plugins_lock); |
| 2344 | |
| 2345 | Vector<PluginConfigAppleEmbedded> loaded_plugins = get_plugins(ea->get_platform_name()); |
| 2346 | |
| 2347 | if (ea->plugins.size() != loaded_plugins.size()) { |
| 2348 | ea->plugins_changed.set(); |
| 2349 | } else { |
| 2350 | for (int i = 0; i < ea->plugins.size(); i++) { |
| 2351 | if (ea->plugins[i].name != loaded_plugins[i].name || ea->plugins[i].last_updated != loaded_plugins[i].last_updated) { |
| 2352 | ea->plugins_changed.set(); |
| 2353 | break; |
| 2354 | } |
| 2355 | } |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | // Check for devices updates. |
| 2360 | Vector<Device> ldevices; |
| 2361 | |
| 2362 | // Enum real devices (via ios_deploy, pre Xcode 15). |
| 2363 | String ios_deploy_setting = "export/" + ea->get_platform_name() + "/ios_deploy"; |
| 2364 | if (EditorSettings::get_singleton() && EditorSettings::get_singleton()->has_setting(ios_deploy_setting)) { |
| 2365 | String idepl = EDITOR_GET(ios_deploy_setting); |
| 2366 | if (ea->has_runnable_preset.is_set() && !idepl.is_empty()) { |
| 2367 | String devices_json; |
| 2368 | List<String> args; |
| 2369 | args.push_back("-c"); |
| 2370 | args.push_back("-timeout"); |
| 2371 | args.push_back("1"); |
| 2372 | args.push_back("-j"); |
| 2373 | args.push_back("-u"); |
| 2374 | args.push_back("-I"); |
| 2375 | |
| 2376 | int ec = 0; |
| 2377 | Error err = OS::get_singleton()->execute(idepl, args, &devices_json, &ec, true); |
| 2378 | if (err == OK && ec == 0) { |
| 2379 | Ref<JSON> json; |
| 2380 | json.instantiate(); |
| 2381 | devices_json = "{ \"devices\":[" + devices_json.replace("}{", "},{") + "]}"; |
| 2382 | err = json->parse(devices_json); |
| 2383 | if (err == OK) { |
| 2384 | Dictionary data = json->get_data(); |
| 2385 | Array devices = data["devices"]; |
| 2386 | for (int i = 0; i < devices.size(); i++) { |
| 2387 | Dictionary device_event = devices[i]; |
| 2388 | if (device_event["Event"] == "DeviceDetected") { |
| 2389 | Dictionary device_info = device_event["Device"]; |
| 2390 | Device nd; |
| 2391 | nd.id = device_info["DeviceIdentifier"]; |
| 2392 | nd.name = device_info["DeviceName"].operator String() + " (ios_deploy, " + ((device_event["Interface"] == "WIFI") ? "network" : "wired") + ")"; |
| 2393 | nd.wifi = device_event["Interface"] == "WIFI"; |
| 2394 | nd.use_ios_deploy = true; |
| 2395 | ldevices.push_back(nd); |
| 2396 | } |
| 2397 | } |
| 2398 | } |
| 2399 | } |
| 2400 | } |
| 2401 | } |
| 2402 | // Enum devices (via Xcode). |
| 2403 | if (ea->has_runnable_preset.is_set() && _check_xcode_install() && (FileAccess::exists("/usr/bin/xcrun") || FileAccess::exists("/bin/xcrun"))) { |
| 2404 | String devices_json; |
| 2405 | List<String> args; |
| 2406 | args.push_back("devicectl"); |
| 2407 | args.push_back("list"); |
| 2408 | args.push_back("devices"); |
| 2409 | args.push_back("-j"); |
| 2410 | args.push_back("-"); |
| 2411 | args.push_back("-q"); |
| 2412 | // Add a timeout, so the process doesn't hang indefinitely, which can prevent Godot shutting down. |
| 2413 | args.push_back("--timeout"); |
| 2414 | args.push_back("5"); |
| 2415 | args.push_back("--filter"); |
| 2416 | args.push_back(vformat("hardwareProperties.deviceType MATCHES '%s'", device_types)); |
| 2417 | |
| 2418 | int ec = 0; |
| 2419 | Error err = OS::get_singleton()->execute("xcrun", args, &devices_json, &ec, false); |
| 2420 | if (err == OK && ec == 0) { |
| 2421 | Ref<JSON> json; |
| 2422 | json.instantiate(); |
| 2423 | err = json->parse(devices_json); |
| 2424 | if (err == OK) { |
| 2425 | const Dictionary &data = json->get_data(); |
| 2426 | const Dictionary &result = data["result"]; |
| 2427 | const Array &devices = result["devices"]; |
| 2428 | for (int i = 0; i < devices.size(); i++) { |
| 2429 | const Dictionary &device_info = devices[i]; |
| 2430 | const Dictionary &conn_props = device_info["connectionProperties"]; |
| 2431 | const Dictionary &dev_props = device_info["deviceProperties"]; |
| 2432 | if (dev_props.has("developerModeStatus") && conn_props.has("pairingState") && conn_props.has("transportType") && conn_props["pairingState"] == "paired" && dev_props["developerModeStatus"] == "enabled") { |
| 2433 | Device nd; |
| 2434 | nd.id = device_info["identifier"]; |
| 2435 | nd.name = dev_props["name"].operator String() + " (devicectl, " + ((conn_props["transportType"] == "localNetwork") ? "network" : "wired") + ")"; |
| 2436 | nd.wifi = conn_props["transportType"] == "localNetwork"; |
| 2437 | ldevices.push_back(nd); |
| 2438 | } |
| 2439 | } |
| 2440 | } |
| 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | // Update device list. |
| 2445 | { |
| 2446 | MutexLock lock(ea->device_lock); |
| 2447 | |
| 2448 | bool different = false; |
| 2449 | |
| 2450 | if (ea->devices.size() != ldevices.size()) { |
| 2451 | different = true; |
| 2452 | } else { |
| 2453 | for (int i = 0; i < ea->devices.size(); i++) { |
| 2454 | if (ea->devices[i].id != ldevices[i].id) { |
| 2455 | different = true; |
| 2456 | break; |
| 2457 | } |
| 2458 | } |
| 2459 | } |
| 2460 | |
| 2461 | if (different) { |
| 2462 | ea->devices = ldevices; |
| 2463 | ea->devices_changed.set(); |
| 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | uint64_t sleep = 200; |
| 2468 | uint64_t wait = 3000000; |
| 2469 | uint64_t time = OS::get_singleton()->get_ticks_usec(); |
| 2470 | while (OS::get_singleton()->get_ticks_usec() - time < wait) { |
| 2471 | OS::get_singleton()->delay_usec(1000 * sleep); |
| 2472 | if (ea->quit_request.is_set()) { |
| 2473 | break; |
| 2474 | } |
| 2475 | } |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | void EditorExportPlatformAppleEmbedded::_update_preset_status() { |
| 2480 | const int preset_count = EditorExport::get_singleton()->get_export_preset_count(); |
| 2481 | bool has_runnable = false; |
| 2482 | |
| 2483 | for (int i = 0; i < preset_count; i++) { |
| 2484 | const Ref<EditorExportPreset> &preset = EditorExport::get_singleton()->get_export_preset(i); |
| 2485 | if (preset->get_platform() == this && preset->is_runnable()) { |
| 2486 | has_runnable = true; |
| 2487 | break; |
| 2488 | } |
| 2489 | } |
| 2490 | |
| 2491 | if (has_runnable) { |
| 2492 | has_runnable_preset.set(); |
| 2493 | } else { |
| 2494 | has_runnable_preset.clear(); |
| 2495 | } |
| 2496 | devices_changed.set(); |
| 2497 | } |
| 2498 | |
| 2499 | class FileReader { |
| 2500 | Ref<FileAccess> f; |
| 2501 | LocalVector<char> buf; |
| 2502 | |
| 2503 | void append_span(Span<char> p_span, String &p_data) { |
| 2504 | uint32_t old_size = p_data.size(); |
| 2505 | if (p_data.append_utf8(p_span) != OK) { |
| 2506 | p_data.resize_uninitialized(old_size); // Back up to original size. |
| 2507 | if (old_size > 0) { |
| 2508 | p_data[old_size - 1] = '\0'; |
| 2509 | } |
| 2510 | p_data.append_latin1(p_span); |
| 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | public: |
| 2515 | uint32_t get_lines(String &p_data) { |
| 2516 | uint64_t available = f->get_length() - f->get_position(); |
| 2517 | if (available == 0) { |
| 2518 | return 0; |
| 2519 | } |
| 2520 | |
| 2521 | uint32_t start = buf.size(); |
| 2522 | buf.resize_uninitialized(buf.size() + available); |
| 2523 | f->get_buffer((uint8_t *)buf.ptr() + start, available); |
| 2524 | const char *end = &buf[buf.size() - 1]; |
| 2525 | const char *p = end; |
| 2526 | uint32_t n = available; |
| 2527 | bool found = false; |
| 2528 | // Scan for a newline starting from the end of the appended bytes. |
| 2529 | while (n--) { |
| 2530 | if (*p == '\n') { |
| 2531 | found = true; |
| 2532 | break; |
| 2533 | } |
| 2534 | p--; |
| 2535 | } |
| 2536 | if (found) { |
| 2537 | size_t len = static_cast<size_t>(p - buf.ptr()) + 1; |
| 2538 | Span<char> new_data(buf.ptr(), len); |
| 2539 | append_span(new_data, p_data); |
| 2540 | size_t remain = static_cast<size_t>(end - p); |
| 2541 | // If there is unprocessed data in the buffer, move it to the front. |
| 2542 | if (remain > 0) { |
| 2543 | // Move to next char after '\n'. |
| 2544 | p++; |
| 2545 | memmove(buf.ptr(), p, remain); |
| 2546 | } |
| 2547 | buf.resize_uninitialized(remain); |
| 2548 | } |
| 2549 | return available; |
| 2550 | } |
| 2551 | |
| 2552 | // Flush any remaining data. |
| 2553 | uint32_t flush(String &p_data) { |
| 2554 | Span<char> new_data = buf.span(); |
| 2555 | if (new_data.size() > 0) { |
| 2556 | append_span(new_data, p_data); |
| 2557 | } |
| 2558 | return new_data.size(); |
| 2559 | } |
| 2560 | |
| 2561 | FileReader(Ref<FileAccess> p_f) : |
| 2562 | f(p_f) { |
| 2563 | } |
| 2564 | }; |
| 2565 | |
| 2566 | int EditorExportPlatformAppleEmbedded::_execute(const String &p_path, const List<String> &p_arguments, std::function<void(const String &)> p_on_data) { |
| 2567 | Dictionary pipe_info = OS::get_singleton()->execute_with_pipe(p_path, p_arguments, false); |
| 2568 | ERR_FAIL_COND_V_MSG(pipe_info.is_empty(), 1, "execute_with_pipe failed"); |
| 2569 | |
| 2570 | Ref<FileAccess> fa_stdout = pipe_info["stdio"]; |
| 2571 | Ref<FileAccess> fa_stderr = pipe_info["stderr"]; |
| 2572 | OS::ProcessID pid = pipe_info["pid"]; |
| 2573 | |
| 2574 | FileReader stdout_r(fa_stdout); |
| 2575 | FileReader stderr_r(fa_stderr); |
| 2576 | |
| 2577 | while (true) { |
| 2578 | String output; |
| 2579 | stdout_r.get_lines(output); |
| 2580 | stderr_r.get_lines(output); |
| 2581 | if (!output.is_empty()) { |
| 2582 | p_on_data(output); |
| 2583 | } |
| 2584 | |
| 2585 | // If the process is no longer running and no new data arrived, we're done. |
| 2586 | if (output.is_empty() && !OS::get_singleton()->is_process_running(pid)) { |
| 2587 | break; |
| 2588 | } |
| 2589 | |
| 2590 | OS::get_singleton()->delay_usec(1000); |
| 2591 | } |
| 2592 | |
| 2593 | // Flush any remaining content |
| 2594 | String output; |
| 2595 | stdout_r.flush(output); |
| 2596 | stderr_r.flush(output); |
| 2597 | if (!output.is_empty()) { |
| 2598 | p_on_data(output); |
| 2599 | } |
| 2600 | |
| 2601 | fa_stdout->close(); |
| 2602 | fa_stderr->close(); |
| 2603 | |
| 2604 | return OS::get_singleton()->get_process_exit_code(pid); |
| 2605 | } |
| 2606 | |
| 2607 | #endif |
| 2608 | |
| 2609 | Error EditorExportPlatformAppleEmbedded::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) { |
| 2610 | #ifdef MACOS_ENABLED |
| 2611 | ERR_FAIL_INDEX_V(p_device, devices.size(), ERR_INVALID_PARAMETER); |
| 2612 | |
| 2613 | String can_export_error; |
| 2614 | bool can_export_missing_templates; |
| 2615 | if (!can_export(p_preset, can_export_error, can_export_missing_templates)) { |
| 2616 | add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), can_export_error); |
| 2617 | return ERR_UNCONFIGURED; |
| 2618 | } |
| 2619 | |
| 2620 | MutexLock lock(device_lock); |
| 2621 | |
| 2622 | EditorProgress ep("run", vformat(TTR("Running on %s"), devices[p_device].name), 3); |
| 2623 | |
| 2624 | String id = "tmpexport." + uitos(OS::get_singleton()->get_unix_time()); |
| 2625 | |
| 2626 | Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 2627 | ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + EditorPaths::get_singleton()->get_temp_dir() + "'."); |
| 2628 | filesystem_da->make_dir_recursive(EditorPaths::get_singleton()->get_temp_dir().path_join(id)); |
| 2629 | String tmp_export_path = EditorPaths::get_singleton()->get_temp_dir().path_join(id).path_join("export.ipa"); |
| 2630 | |
| 2631 | #define CLEANUP_AND_RETURN(m_err) \ |
| 2632 | { \ |
| 2633 | if (filesystem_da->change_dir(EditorPaths::get_singleton()->get_temp_dir().path_join(id)) == OK) { \ |
| 2634 | filesystem_da->erase_contents_recursive(); \ |
| 2635 | filesystem_da->change_dir(".."); \ |
| 2636 | filesystem_da->remove(id); \ |
| 2637 | } \ |
| 2638 | return m_err; \ |
| 2639 | } \ |
| 2640 | ((void)0) |
| 2641 | |
| 2642 | Device dev = devices[p_device]; |
| 2643 | |
| 2644 | // Export before sending to device. |
| 2645 | Error err = _export_project_helper(p_preset, true, tmp_export_path, p_debug_flags, true); |
| 2646 | |
| 2647 | if (err != OK) { |
| 2648 | CLEANUP_AND_RETURN(err); |
| 2649 | } |
| 2650 | |
| 2651 | Vector<String> cmd_args_list; |
| 2652 | String host = EDITOR_GET("network/debug/remote_host"); |
| 2653 | int remote_port = (int)EDITOR_GET("network/debug/remote_port"); |
| 2654 | |
| 2655 | if (p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST)) { |
| 2656 | host = "localhost"; |
| 2657 | } |
| 2658 | |
| 2659 | if (p_debug_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT)) { |
| 2660 | int port = EDITOR_GET("filesystem/file_server/port"); |
| 2661 | String passwd = EDITOR_GET("filesystem/file_server/password"); |
| 2662 | cmd_args_list.push_back("--remote-fs"); |
| 2663 | cmd_args_list.push_back(host + ":" + itos(port)); |
| 2664 | if (!passwd.is_empty()) { |
| 2665 | cmd_args_list.push_back("--remote-fs-password"); |
| 2666 | cmd_args_list.push_back(passwd); |
| 2667 | } |
| 2668 | } |
| 2669 | |
| 2670 | if (p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG)) { |
| 2671 | cmd_args_list.push_back("--remote-debug"); |
| 2672 | |
| 2673 | cmd_args_list.push_back(get_debug_protocol() + host + ":" + String::num_int64(remote_port)); |
| 2674 | |
| 2675 | List<String> breakpoints; |
| 2676 | ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); |
| 2677 | |
| 2678 | if (breakpoints.size()) { |
| 2679 | cmd_args_list.push_back("--breakpoints"); |
| 2680 | String bpoints; |
| 2681 | for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) { |
| 2682 | bpoints += E->get().replace(" ", "%20"); |
| 2683 | if (E->next()) { |
| 2684 | bpoints += ","; |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | cmd_args_list.push_back(bpoints); |
| 2689 | } |
| 2690 | } |
| 2691 | |
| 2692 | if (p_debug_flags.has_flag(DEBUG_FLAG_VIEW_COLLISIONS)) { |
| 2693 | cmd_args_list.push_back("--debug-collisions"); |
| 2694 | } |
| 2695 | |
| 2696 | if (p_debug_flags.has_flag(DEBUG_FLAG_VIEW_NAVIGATION)) { |
| 2697 | cmd_args_list.push_back("--debug-navigation"); |
| 2698 | } |
| 2699 | |
| 2700 | if (dev.use_ios_deploy) { |
| 2701 | // Deploy and run on real device (via ios-deploy). |
| 2702 | if (ep.step("Installing and running on device...", 4)) { |
| 2703 | CLEANUP_AND_RETURN(ERR_SKIP); |
| 2704 | } else { |
| 2705 | List<String> args; |
| 2706 | args.push_back("-u"); |
| 2707 | args.push_back("-I"); |
| 2708 | args.push_back("--id"); |
| 2709 | args.push_back(dev.id); |
| 2710 | args.push_back("--justlaunch"); |
| 2711 | args.push_back("--bundle"); |
| 2712 | args.push_back(EditorPaths::get_singleton()->get_temp_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app")); |
| 2713 | String app_args; |
| 2714 | for (const String &E : cmd_args_list) { |
| 2715 | app_args += E + " "; |
| 2716 | } |
| 2717 | if (!app_args.is_empty()) { |
| 2718 | args.push_back("--args"); |
| 2719 | args.push_back(app_args); |
| 2720 | } |
| 2721 | |
| 2722 | String idepl = EDITOR_GET("export/" + get_platform_name() + "/ios_deploy"); |
| 2723 | if (idepl.is_empty()) { |
| 2724 | idepl = "ios-deploy"; |
| 2725 | } |
| 2726 | String log; |
| 2727 | int ec; |
| 2728 | err = OS::get_singleton()->execute(idepl, args, &log, &ec, true); |
| 2729 | if (err != OK) { |
| 2730 | add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start ios-deploy executable.")); |
| 2731 | CLEANUP_AND_RETURN(err); |
| 2732 | } |
| 2733 | if (ec != 0) { |
| 2734 | print_line("ios-deploy:\n" + log); |
| 2735 | add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation/running failed, see editor log for details.")); |
| 2736 | CLEANUP_AND_RETURN(ERR_UNCONFIGURED); |
| 2737 | } |
| 2738 | } |
| 2739 | } else { |
| 2740 | // Deploy and run on real device (via Xcode). |
| 2741 | if (ep.step("Installing to device...", 3)) { |
| 2742 | CLEANUP_AND_RETURN(ERR_SKIP); |
| 2743 | } else { |
| 2744 | List<String> args; |
| 2745 | args.push_back("devicectl"); |
| 2746 | args.push_back("device"); |
| 2747 | args.push_back("install"); |
| 2748 | args.push_back("app"); |
| 2749 | args.push_back("-d"); |
| 2750 | args.push_back(dev.id); |
| 2751 | args.push_back(EditorPaths::get_singleton()->get_temp_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app")); |
| 2752 | |
| 2753 | String log; |
| 2754 | int ec = _execute("xcrun", args, [&log](const String &p_data) { |
| 2755 | log.append_utf32(p_data.span()); |
| 2756 | }); |
| 2757 | if (ec != 0) { |
| 2758 | print_line("device install:\n" + log); |
| 2759 | add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation failed, see editor log for details.")); |
| 2760 | CLEANUP_AND_RETURN(ERR_UNCONFIGURED); |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | if (ep.step("Running on device...", 4)) { |
| 2765 | CLEANUP_AND_RETURN(ERR_SKIP); |
| 2766 | } else { |
| 2767 | List<String> args; |
| 2768 | args.push_back("devicectl"); |
| 2769 | args.push_back("device"); |
| 2770 | args.push_back("process"); |
| 2771 | args.push_back("launch"); |
| 2772 | args.push_back("--terminate-existing"); |
| 2773 | args.push_back("-d"); |
| 2774 | args.push_back(dev.id); |
| 2775 | args.push_back(p_preset->get("application/bundle_identifier")); |
| 2776 | for (const String &E : cmd_args_list) { |
| 2777 | args.push_back(E); |
| 2778 | } |
| 2779 | |
| 2780 | String log; |
| 2781 | int ec = _execute("xcrun", args, [&log](const String &p_data) { |
| 2782 | log.append_utf32(p_data.span()); |
| 2783 | }); |
| 2784 | if (ec != 0) { |
| 2785 | print_line("devicectl launch:\n" + log); |
| 2786 | add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Running failed, see editor log for details.")); |
| 2787 | } |
| 2788 | } |
| 2789 | } |
| 2790 | |
| 2791 | CLEANUP_AND_RETURN(OK); |
| 2792 | |
| 2793 | #undef CLEANUP_AND_RETURN |
| 2794 | #else |
| 2795 | return ERR_UNCONFIGURED; |
| 2796 | #endif |
| 2797 | } |
| 2798 | |
| 2799 | void EditorExportPlatformAppleEmbedded::_initialize(const char *p_platform_logo_svg, const char *p_run_icon_svg) { |
| 2800 | Ref<Image> img = memnew(Image); |
| 2801 | const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE); |
| 2802 | |
| 2803 | ImageLoaderSVG::create_image_from_string(img, p_platform_logo_svg, EDSCALE, upsample, false); |
| 2804 | logo = ImageTexture::create_from_image(img); |
| 2805 | |
| 2806 | ImageLoaderSVG::create_image_from_string(img, p_run_icon_svg, EDSCALE, upsample, false); |
| 2807 | run_icon = ImageTexture::create_from_image(img); |
| 2808 | |
| 2809 | plugins_changed.set(); |
| 2810 | devices_changed.set(); |
| 2811 | #ifdef MACOS_ENABLED |
| 2812 | _update_preset_status(); |
| 2813 | #endif |
| 2814 | } |
| 2815 | |
| 2816 | EditorExportPlatformAppleEmbedded::~EditorExportPlatformAppleEmbedded() { |
| 2817 | } |