export_plugin.cpp 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443
  1. /**************************************************************************/
  2. /* export_plugin.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "export_plugin.h"
  31. #include "logo_svg.gen.h"
  32. #include "run_icon_svg.gen.h"
  33. #include "core/io/json.h"
  34. #include "core/string/translation.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_paths.h"
  37. #include "editor/editor_scale.h"
  38. #include "editor/editor_string_names.h"
  39. #include "editor/export/editor_export.h"
  40. #include "editor/import/resource_importer_texture_settings.h"
  41. #include "editor/plugins/script_editor_plugin.h"
  42. #include "modules/modules_enabled.gen.h" // For mono and svg.
  43. #ifdef MODULE_SVG_ENABLED
  44. #include "modules/svg/image_loader_svg.h"
  45. #endif
  46. void EditorExportPlatformIOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
  47. // Vulkan and OpenGL ES 3.0 both mandate ETC2 support.
  48. r_features->push_back("etc2");
  49. r_features->push_back("astc");
  50. Vector<String> architectures = _get_preset_architectures(p_preset);
  51. for (int i = 0; i < architectures.size(); ++i) {
  52. r_features->push_back(architectures[i]);
  53. }
  54. }
  55. Vector<EditorExportPlatformIOS::ExportArchitecture> EditorExportPlatformIOS::_get_supported_architectures() const {
  56. Vector<ExportArchitecture> archs;
  57. archs.push_back(ExportArchitecture("arm64", true));
  58. return archs;
  59. }
  60. struct IconInfo {
  61. const char *preset_key;
  62. const char *idiom;
  63. const char *export_name;
  64. const char *actual_size_side;
  65. const char *scale;
  66. const char *unscaled_size;
  67. const bool force_opaque;
  68. };
  69. static const IconInfo icon_infos[] = {
  70. // Home screen on iPhone
  71. { PNAME("icons/iphone_120x120"), "iphone", "Icon-120.png", "120", "2x", "60x60", false },
  72. { PNAME("icons/iphone_120x120"), "iphone", "Icon-120.png", "120", "3x", "40x40", false },
  73. { PNAME("icons/iphone_180x180"), "iphone", "Icon-180.png", "180", "3x", "60x60", false },
  74. // Home screen on iPad
  75. { PNAME("icons/ipad_76x76"), "ipad", "Icon-76.png", "76", "1x", "76x76", false },
  76. { PNAME("icons/ipad_152x152"), "ipad", "Icon-152.png", "152", "2x", "76x76", false },
  77. { PNAME("icons/ipad_167x167"), "ipad", "Icon-167.png", "167", "2x", "83.5x83.5", false },
  78. // App Store
  79. { PNAME("icons/app_store_1024x1024"), "ios-marketing", "Icon-1024.png", "1024", "1x", "1024x1024", true },
  80. // Spotlight
  81. { PNAME("icons/spotlight_40x40"), "ipad", "Icon-40.png", "40", "1x", "40x40", false },
  82. { PNAME("icons/spotlight_80x80"), "iphone", "Icon-80.png", "80", "2x", "40x40", false },
  83. { PNAME("icons/spotlight_80x80"), "ipad", "Icon-80.png", "80", "2x", "40x40", false },
  84. // Settings
  85. { PNAME("icons/settings_58x58"), "iphone", "Icon-58.png", "58", "2x", "29x29", false },
  86. { PNAME("icons/settings_58x58"), "ipad", "Icon-58.png", "58", "2x", "29x29", false },
  87. { PNAME("icons/settings_87x87"), "iphone", "Icon-87.png", "87", "3x", "29x29", false },
  88. // Notification
  89. { PNAME("icons/notification_40x40"), "iphone", "Icon-40.png", "40", "2x", "20x20", false },
  90. { PNAME("icons/notification_40x40"), "ipad", "Icon-40.png", "40", "2x", "20x20", false },
  91. { PNAME("icons/notification_60x60"), "iphone", "Icon-60.png", "60", "3x", "20x20", false }
  92. };
  93. String EditorExportPlatformIOS::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const {
  94. if (p_preset) {
  95. if (p_name == "application/app_store_team_id") {
  96. String team_id = p_preset->get("application/app_store_team_id");
  97. if (team_id.is_empty()) {
  98. return TTR("App Store Team ID not specified.") + "\n";
  99. }
  100. } else if (p_name == "application/bundle_identifier") {
  101. String identifier = p_preset->get("application/bundle_identifier");
  102. String pn_err;
  103. if (!is_package_name_valid(identifier, &pn_err)) {
  104. return TTR("Invalid Identifier:") + " " + pn_err;
  105. }
  106. }
  107. }
  108. return String();
  109. }
  110. bool EditorExportPlatformIOS::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {
  111. return true;
  112. }
  113. void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options) const {
  114. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  115. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  116. Vector<ExportArchitecture> architectures = _get_supported_architectures();
  117. for (int i = 0; i < architectures.size(); ++i) {
  118. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("architectures"), architectures[i].name)), architectures[i].is_default));
  119. }
  120. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_store_team_id"), "", false, true));
  121. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_debug", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
  122. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Developer"), ""));
  123. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_debug", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 1));
  124. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_release", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
  125. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Distribution"), ""));
  126. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_release", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 0));
  127. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/targeted_device_family", PROPERTY_HINT_ENUM, "iPhone,iPad,iPhone & iPad"), 2));
  128. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "", false, true));
  129. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  130. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
  131. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
  132. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_ios_version"), "12.0"));
  133. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
  134. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/export_project_only"), false));
  135. Vector<PluginConfigIOS> found_plugins = get_plugins();
  136. for (int i = 0; i < found_plugins.size(); i++) {
  137. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("plugins"), found_plugins[i].name)), false));
  138. }
  139. HashSet<String> plist_keys;
  140. for (int i = 0; i < found_plugins.size(); i++) {
  141. // Editable plugin plist values
  142. PluginConfigIOS plugin = found_plugins[i];
  143. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  144. switch (E.value.type) {
  145. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  146. String preset_name = "plugins_plist/" + E.key;
  147. if (!plist_keys.has(preset_name)) {
  148. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, preset_name), E.value.value));
  149. plist_keys.insert(preset_name);
  150. }
  151. } break;
  152. default:
  153. continue;
  154. }
  155. }
  156. }
  157. plugins_changed.clear();
  158. plugins = found_plugins;
  159. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/access_wifi"), false));
  160. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/push_notifications"), false));
  161. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/performance_gaming_tier"), false));
  162. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/performance_a12"), false));
  163. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_files_app"), false));
  164. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_itunes_sharing"), false));
  165. 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"), ""));
  166. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  167. 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"), ""));
  168. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  169. 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"), ""));
  170. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photolibrary_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  171. HashSet<String> used_names;
  172. for (uint64_t i = 0; i < sizeof(icon_infos) / sizeof(icon_infos[0]); ++i) {
  173. if (!used_names.has(icon_infos[i].preset_key)) {
  174. used_names.insert(icon_infos[i].preset_key);
  175. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, icon_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  176. }
  177. }
  178. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "storyboard/image_scale_mode", PROPERTY_HINT_ENUM, "Same as Logo,Center,Scale to Fit,Scale to Fill,Scale"), 0));
  179. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@2x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  180. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@3x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  181. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_custom_bg_color"), false));
  182. r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "storyboard/custom_bg_color"), Color()));
  183. }
  184. void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug) {
  185. static const String export_method_string[] = {
  186. "app-store",
  187. "development",
  188. "ad-hoc",
  189. "enterprise"
  190. };
  191. static const String storyboard_image_scale_mode[] = {
  192. "center",
  193. "scaleAspectFit",
  194. "scaleAspectFill",
  195. "scaleToFill"
  196. };
  197. String dbg_sign_id = p_preset->get("application/code_sign_identity_debug").operator String().is_empty() ? "iPhone Developer" : p_preset->get("application/code_sign_identity_debug");
  198. String rel_sign_id = p_preset->get("application/code_sign_identity_release").operator String().is_empty() ? "iPhone Distribution" : p_preset->get("application/code_sign_identity_release");
  199. bool dbg_manual = !p_preset->get_or_env("application/provisioning_profile_uuid_debug", ENV_IOS_PROFILE_UUID_DEBUG).operator String().is_empty() || (dbg_sign_id != "iPhone Developer" && dbg_sign_id != "iPhone Distribution");
  200. bool rel_manual = !p_preset->get_or_env("application/provisioning_profile_uuid_release", ENV_IOS_PROFILE_UUID_RELEASE).operator String().is_empty() || (rel_sign_id != "iPhone Developer" && rel_sign_id != "iPhone Distribution");
  201. String str;
  202. String strnew;
  203. str.parse_utf8((const char *)pfile.ptr(), pfile.size());
  204. Vector<String> lines = str.split("\n");
  205. for (int i = 0; i < lines.size(); i++) {
  206. if (lines[i].find("$binary") != -1) {
  207. strnew += lines[i].replace("$binary", p_config.binary_name) + "\n";
  208. } else if (lines[i].find("$modules_buildfile") != -1) {
  209. strnew += lines[i].replace("$modules_buildfile", p_config.modules_buildfile) + "\n";
  210. } else if (lines[i].find("$modules_fileref") != -1) {
  211. strnew += lines[i].replace("$modules_fileref", p_config.modules_fileref) + "\n";
  212. } else if (lines[i].find("$modules_buildphase") != -1) {
  213. strnew += lines[i].replace("$modules_buildphase", p_config.modules_buildphase) + "\n";
  214. } else if (lines[i].find("$modules_buildgrp") != -1) {
  215. strnew += lines[i].replace("$modules_buildgrp", p_config.modules_buildgrp) + "\n";
  216. } else if (lines[i].find("$name") != -1) {
  217. strnew += lines[i].replace("$name", p_config.pkg_name) + "\n";
  218. } else if (lines[i].find("$bundle_identifier") != -1) {
  219. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  220. } else if (lines[i].find("$short_version") != -1) {
  221. strnew += lines[i].replace("$short_version", p_preset->get_version("application/short_version")) + "\n";
  222. } else if (lines[i].find("$version") != -1) {
  223. strnew += lines[i].replace("$version", p_preset->get_version("application/version")) + "\n";
  224. } else if (lines[i].find("$min_version") != -1) {
  225. strnew += lines[i].replace("$min_version", p_preset->get("application/min_ios_version")) + "\n";
  226. } else if (lines[i].find("$signature") != -1) {
  227. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  228. } else if (lines[i].find("$team_id") != -1) {
  229. strnew += lines[i].replace("$team_id", p_preset->get("application/app_store_team_id")) + "\n";
  230. } else if (lines[i].find("$default_build_config") != -1) {
  231. strnew += lines[i].replace("$default_build_config", p_debug ? "Debug" : "Release") + "\n";
  232. } else if (lines[i].find("$export_method") != -1) {
  233. int export_method = p_preset->get(p_debug ? "application/export_method_debug" : "application/export_method_release");
  234. strnew += lines[i].replace("$export_method", export_method_string[export_method]) + "\n";
  235. } else if (lines[i].find("$provisioning_profile_uuid_release") != -1) {
  236. strnew += lines[i].replace("$provisioning_profile_uuid_release", p_preset->get_or_env("application/provisioning_profile_uuid_release", ENV_IOS_PROFILE_UUID_RELEASE)) + "\n";
  237. } else if (lines[i].find("$provisioning_profile_uuid_debug") != -1) {
  238. strnew += lines[i].replace("$provisioning_profile_uuid_debug", p_preset->get_or_env("application/provisioning_profile_uuid_debug", ENV_IOS_PROFILE_UUID_DEBUG)) + "\n";
  239. } else if (lines[i].find("$code_sign_style_debug") != -1) {
  240. if (dbg_manual) {
  241. strnew += lines[i].replace("$code_sign_style_debug", "Manual") + "\n";
  242. } else {
  243. strnew += lines[i].replace("$code_sign_style_debug", "Automatic") + "\n";
  244. }
  245. } else if (lines[i].find("$code_sign_style_release") != -1) {
  246. if (rel_manual) {
  247. strnew += lines[i].replace("$code_sign_style_release", "Manual") + "\n";
  248. } else {
  249. strnew += lines[i].replace("$code_sign_style_release", "Automatic") + "\n";
  250. }
  251. } else if (lines[i].find("$provisioning_profile_uuid") != -1) {
  252. String uuid = p_debug ? p_preset->get_or_env("application/provisioning_profile_uuid_debug", ENV_IOS_PROFILE_UUID_DEBUG) : p_preset->get_or_env("application/provisioning_profile_uuid_release", ENV_IOS_PROFILE_UUID_RELEASE);
  253. strnew += lines[i].replace("$provisioning_profile_uuid", uuid) + "\n";
  254. } else if (lines[i].find("$code_sign_identity_debug") != -1) {
  255. strnew += lines[i].replace("$code_sign_identity_debug", dbg_sign_id) + "\n";
  256. } else if (lines[i].find("$code_sign_identity_release") != -1) {
  257. strnew += lines[i].replace("$code_sign_identity_release", rel_sign_id) + "\n";
  258. } else if (lines[i].find("$additional_plist_content") != -1) {
  259. strnew += lines[i].replace("$additional_plist_content", p_config.plist_content) + "\n";
  260. } else if (lines[i].find("$godot_archs") != -1) {
  261. strnew += lines[i].replace("$godot_archs", p_config.architectures) + "\n";
  262. } else if (lines[i].find("$linker_flags") != -1) {
  263. strnew += lines[i].replace("$linker_flags", p_config.linker_flags) + "\n";
  264. } else if (lines[i].find("$targeted_device_family") != -1) {
  265. String xcode_value;
  266. switch ((int)p_preset->get("application/targeted_device_family")) {
  267. case 0: // iPhone
  268. xcode_value = "1";
  269. break;
  270. case 1: // iPad
  271. xcode_value = "2";
  272. break;
  273. case 2: // iPhone & iPad
  274. xcode_value = "1,2";
  275. break;
  276. }
  277. strnew += lines[i].replace("$targeted_device_family", xcode_value) + "\n";
  278. } else if (lines[i].find("$cpp_code") != -1) {
  279. strnew += lines[i].replace("$cpp_code", p_config.cpp_code) + "\n";
  280. } else if (lines[i].find("$docs_in_place") != -1) {
  281. strnew += lines[i].replace("$docs_in_place", ((bool)p_preset->get("user_data/accessible_from_files_app")) ? "<true/>" : "<false/>") + "\n";
  282. } else if (lines[i].find("$docs_sharing") != -1) {
  283. strnew += lines[i].replace("$docs_sharing", ((bool)p_preset->get("user_data/accessible_from_itunes_sharing")) ? "<true/>" : "<false/>") + "\n";
  284. } else if (lines[i].find("$entitlements_push_notifications") != -1) {
  285. bool is_on = p_preset->get("capabilities/push_notifications");
  286. strnew += lines[i].replace("$entitlements_push_notifications", is_on ? "<key>aps-environment</key><string>development</string>" : "") + "\n";
  287. } else if (lines[i].find("$required_device_capabilities") != -1) {
  288. String capabilities;
  289. // I've removed armv7 as we can run on 64bit only devices
  290. // Note that capabilities listed here are requirements for the app to be installed.
  291. // They don't enable anything.
  292. Vector<String> capabilities_list = p_config.capabilities;
  293. if ((bool)p_preset->get("capabilities/access_wifi") && !capabilities_list.has("wifi")) {
  294. capabilities_list.push_back("wifi");
  295. }
  296. if ((bool)p_preset->get("capabilities/performance_gaming_tier") && !capabilities_list.has("iphone-performance-gaming-tier")) {
  297. capabilities_list.push_back("iphone-performance-gaming-tier");
  298. }
  299. if ((bool)p_preset->get("capabilities/performance_a12") && !capabilities_list.has("iphone-ipad-minimum-performance-a12")) {
  300. capabilities_list.push_back("iphone-ipad-minimum-performance-a12");
  301. }
  302. for (int idx = 0; idx < capabilities_list.size(); idx++) {
  303. capabilities += "<string>" + capabilities_list[idx] + "</string>\n";
  304. }
  305. strnew += lines[i].replace("$required_device_capabilities", capabilities);
  306. } else if (lines[i].find("$interface_orientations") != -1) {
  307. String orientations;
  308. const DisplayServer::ScreenOrientation screen_orientation =
  309. DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation")));
  310. switch (screen_orientation) {
  311. case DisplayServer::SCREEN_LANDSCAPE:
  312. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  313. break;
  314. case DisplayServer::SCREEN_PORTRAIT:
  315. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  316. break;
  317. case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
  318. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  319. break;
  320. case DisplayServer::SCREEN_REVERSE_PORTRAIT:
  321. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  322. break;
  323. case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
  324. // Allow both landscape orientations depending on sensor direction.
  325. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  326. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  327. break;
  328. case DisplayServer::SCREEN_SENSOR_PORTRAIT:
  329. // Allow both portrait orientations depending on sensor direction.
  330. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  331. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  332. break;
  333. case DisplayServer::SCREEN_SENSOR:
  334. // Allow all screen orientations depending on sensor direction.
  335. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  336. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  337. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  338. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  339. break;
  340. }
  341. strnew += lines[i].replace("$interface_orientations", orientations);
  342. } else if (lines[i].find("$camera_usage_description") != -1) {
  343. String description = p_preset->get("privacy/camera_usage_description");
  344. strnew += lines[i].replace("$camera_usage_description", description) + "\n";
  345. } else if (lines[i].find("$microphone_usage_description") != -1) {
  346. String description = p_preset->get("privacy/microphone_usage_description");
  347. strnew += lines[i].replace("$microphone_usage_description", description) + "\n";
  348. } else if (lines[i].find("$photolibrary_usage_description") != -1) {
  349. String description = p_preset->get("privacy/photolibrary_usage_description");
  350. strnew += lines[i].replace("$photolibrary_usage_description", description) + "\n";
  351. } else if (lines[i].find("$plist_launch_screen_name") != -1) {
  352. String value = "<key>UILaunchStoryboardName</key>\n<string>Launch Screen</string>";
  353. strnew += lines[i].replace("$plist_launch_screen_name", value) + "\n";
  354. } else if (lines[i].find("$pbx_launch_screen_file_reference") != -1) {
  355. String value = "90DD2D9D24B36E8000717FE1 = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = \"Launch Screen.storyboard\"; sourceTree = \"<group>\"; };";
  356. strnew += lines[i].replace("$pbx_launch_screen_file_reference", value) + "\n";
  357. } else if (lines[i].find("$pbx_launch_screen_copy_files") != -1) {
  358. String value = "90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */,";
  359. strnew += lines[i].replace("$pbx_launch_screen_copy_files", value) + "\n";
  360. } else if (lines[i].find("$pbx_launch_screen_build_phase") != -1) {
  361. String value = "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */,";
  362. strnew += lines[i].replace("$pbx_launch_screen_build_phase", value) + "\n";
  363. } else if (lines[i].find("$pbx_launch_screen_build_reference") != -1) {
  364. String value = "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */; };";
  365. strnew += lines[i].replace("$pbx_launch_screen_build_reference", value) + "\n";
  366. } else if (lines[i].find("$launch_screen_image_mode") != -1) {
  367. int image_scale_mode = p_preset->get("storyboard/image_scale_mode");
  368. String value;
  369. switch (image_scale_mode) {
  370. case 0: {
  371. String logo_path = GLOBAL_GET("application/boot_splash/image");
  372. bool is_on = GLOBAL_GET("application/boot_splash/fullsize");
  373. // If custom logo is not specified, Godot does not scale default one, so we should do the same.
  374. value = (is_on && logo_path.length() > 0) ? "scaleAspectFit" : "center";
  375. } break;
  376. default: {
  377. value = storyboard_image_scale_mode[image_scale_mode - 1];
  378. }
  379. }
  380. strnew += lines[i].replace("$launch_screen_image_mode", value) + "\n";
  381. } else if (lines[i].find("$launch_screen_background_color") != -1) {
  382. bool use_custom = p_preset->get("storyboard/use_custom_bg_color");
  383. Color color = use_custom ? p_preset->get("storyboard/custom_bg_color") : GLOBAL_GET("application/boot_splash/bg_color");
  384. const String value_format = "red=\"$red\" green=\"$green\" blue=\"$blue\" alpha=\"$alpha\"";
  385. Dictionary value_dictionary;
  386. value_dictionary["red"] = color.r;
  387. value_dictionary["green"] = color.g;
  388. value_dictionary["blue"] = color.b;
  389. value_dictionary["alpha"] = color.a;
  390. String value = value_format.format(value_dictionary, "$_");
  391. strnew += lines[i].replace("$launch_screen_background_color", value) + "\n";
  392. } else if (lines[i].find("$pbx_locale_file_reference") != -1) {
  393. String locale_files;
  394. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  395. if (translations.size() > 0) {
  396. HashSet<String> languages;
  397. for (const String &E : translations) {
  398. Ref<Translation> tr = ResourceLoader::load(E);
  399. if (tr.is_valid() && tr->get_locale() != "en") {
  400. languages.insert(tr->get_locale());
  401. }
  402. }
  403. int index = 0;
  404. for (const String &lang : languages) {
  405. 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";
  406. index++;
  407. }
  408. }
  409. strnew += lines[i].replace("$pbx_locale_file_reference", locale_files);
  410. } else if (lines[i].find("$pbx_locale_build_reference") != -1) {
  411. String locale_files;
  412. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  413. if (translations.size() > 0) {
  414. HashSet<String> languages;
  415. for (const String &E : translations) {
  416. Ref<Translation> tr = ResourceLoader::load(E);
  417. if (tr.is_valid() && tr->get_locale() != "en") {
  418. languages.insert(tr->get_locale());
  419. }
  420. }
  421. int index = 0;
  422. for (const String &lang : languages) {
  423. locale_files += "D0BCFE4518AEBDA2004A" + itos(index).pad_zeros(4) + " /* " + lang + " */,\n";
  424. index++;
  425. }
  426. }
  427. strnew += lines[i].replace("$pbx_locale_build_reference", locale_files);
  428. } else if (lines[i].find("$swift_runtime_migration") != -1) {
  429. String value = !p_config.use_swift_runtime ? "" : "LastSwiftMigration = 1250;";
  430. strnew += lines[i].replace("$swift_runtime_migration", value) + "\n";
  431. } else if (lines[i].find("$swift_runtime_build_settings") != -1) {
  432. String value = !p_config.use_swift_runtime ? "" : R"(
  433. CLANG_ENABLE_MODULES = YES;
  434. SWIFT_OBJC_BRIDGING_HEADER = "$binary/dummy.h";
  435. SWIFT_VERSION = 5.0;
  436. )";
  437. value = value.replace("$binary", p_config.binary_name);
  438. strnew += lines[i].replace("$swift_runtime_build_settings", value) + "\n";
  439. } else if (lines[i].find("$swift_runtime_fileref") != -1) {
  440. String value = !p_config.use_swift_runtime ? "" : R"(
  441. 90B4C2AA2680BC560039117A /* dummy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "dummy.h"; sourceTree = "<group>"; };
  442. 90B4C2B52680C7E90039117A /* dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "dummy.swift"; sourceTree = "<group>"; };
  443. )";
  444. strnew += lines[i].replace("$swift_runtime_fileref", value) + "\n";
  445. } else if (lines[i].find("$swift_runtime_binary_files") != -1) {
  446. String value = !p_config.use_swift_runtime ? "" : R"(
  447. 90B4C2AA2680BC560039117A /* dummy.h */,
  448. 90B4C2B52680C7E90039117A /* dummy.swift */,
  449. )";
  450. strnew += lines[i].replace("$swift_runtime_binary_files", value) + "\n";
  451. } else if (lines[i].find("$swift_runtime_buildfile") != -1) {
  452. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B4C2B52680C7E90039117A /* dummy.swift */; };";
  453. strnew += lines[i].replace("$swift_runtime_buildfile", value) + "\n";
  454. } else if (lines[i].find("$swift_runtime_build_phase") != -1) {
  455. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift */,";
  456. strnew += lines[i].replace("$swift_runtime_build_phase", value) + "\n";
  457. } else {
  458. strnew += lines[i] + "\n";
  459. }
  460. }
  461. // !BAS! I'm assuming the 9 in the original code was a typo. I've added -1 or else it seems to also be adding our terminating zero...
  462. // should apply the same fix in our macOS export.
  463. CharString cs = strnew.utf8();
  464. pfile.resize(cs.size() - 1);
  465. for (int i = 0; i < cs.size() - 1; i++) {
  466. pfile.write[i] = cs[i];
  467. }
  468. }
  469. String EditorExportPlatformIOS::_get_additional_plist_content() {
  470. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  471. String result;
  472. for (int i = 0; i < export_plugins.size(); ++i) {
  473. result += export_plugins[i]->get_ios_plist_content();
  474. }
  475. return result;
  476. }
  477. String EditorExportPlatformIOS::_get_linker_flags() {
  478. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  479. String result;
  480. for (int i = 0; i < export_plugins.size(); ++i) {
  481. String flags = export_plugins[i]->get_ios_linker_flags();
  482. if (flags.length() == 0) {
  483. continue;
  484. }
  485. if (result.length() > 0) {
  486. result += ' ';
  487. }
  488. result += flags;
  489. }
  490. // the flags will be enclosed in quotes, so need to escape them
  491. return result.replace("\"", "\\\"");
  492. }
  493. String EditorExportPlatformIOS::_get_cpp_code() {
  494. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  495. String result;
  496. for (int i = 0; i < export_plugins.size(); ++i) {
  497. result += export_plugins[i]->get_ios_cpp_code();
  498. }
  499. return result;
  500. }
  501. void EditorExportPlatformIOS::_blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot) {
  502. ERR_FAIL_COND(p_dst.is_null());
  503. ERR_FAIL_COND(p_src.is_null());
  504. int sw = p_rot ? p_src->get_height() : p_src->get_width();
  505. int sh = p_rot ? p_src->get_width() : p_src->get_height();
  506. int x_pos = (p_dst->get_width() - sw) / 2;
  507. int y_pos = (p_dst->get_height() - sh) / 2;
  508. int xs = (x_pos >= 0) ? 0 : -x_pos;
  509. int ys = (y_pos >= 0) ? 0 : -y_pos;
  510. if (sw + x_pos > p_dst->get_width()) {
  511. sw = p_dst->get_width() - x_pos;
  512. }
  513. if (sh + y_pos > p_dst->get_height()) {
  514. sh = p_dst->get_height() - y_pos;
  515. }
  516. for (int y = ys; y < sh; y++) {
  517. for (int x = xs; x < sw; x++) {
  518. Color sc = p_rot ? p_src->get_pixel(p_src->get_width() - y - 1, x) : p_src->get_pixel(x, y);
  519. Color dc = p_dst->get_pixel(x_pos + x, y_pos + y);
  520. dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r);
  521. dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g);
  522. dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b);
  523. dc.a = (double)(sc.a + dc.a * (1.0 - sc.a));
  524. p_dst->set_pixel(x_pos + x, y_pos + y, dc);
  525. }
  526. }
  527. }
  528. Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
  529. String json_description = "{\"images\":[";
  530. String sizes;
  531. Ref<DirAccess> da = DirAccess::open(p_iconset_dir);
  532. if (da.is_null()) {
  533. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not open a directory at path \"%s\"."), p_iconset_dir));
  534. return ERR_CANT_OPEN;
  535. }
  536. Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
  537. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  538. IconInfo info = icon_infos[i];
  539. int side_size = String(info.actual_size_side).to_int();
  540. String icon_path = p_preset->get(info.preset_key);
  541. if (icon_path.length() == 0) {
  542. // Resize main app icon
  543. icon_path = GLOBAL_GET("application/config/icon");
  544. Ref<Image> img = memnew(Image);
  545. Error err = ImageLoader::load_image(icon_path, img);
  546. if (err != OK) {
  547. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  548. return ERR_UNCONFIGURED;
  549. } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  550. add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
  551. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  552. Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
  553. new_img->fill(boot_bg_color);
  554. _blend_and_rotate(new_img, img, false);
  555. err = new_img->save_png(p_iconset_dir + info.export_name);
  556. } else {
  557. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  558. err = img->save_png(p_iconset_dir + info.export_name);
  559. }
  560. if (err) {
  561. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  562. return err;
  563. }
  564. } else {
  565. // Load custom icon and resize if required
  566. Ref<Image> img = memnew(Image);
  567. Error err = ImageLoader::load_image(icon_path, img);
  568. if (err != OK) {
  569. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  570. return ERR_UNCONFIGURED;
  571. } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  572. add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
  573. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  574. Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
  575. new_img->fill(boot_bg_color);
  576. _blend_and_rotate(new_img, img, false);
  577. err = new_img->save_png(p_iconset_dir + info.export_name);
  578. } else if (img->get_width() != side_size || img->get_height() != side_size) {
  579. add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s): '%s' has incorrect size %s and was automatically resized to %s.", info.preset_key, icon_path, img->get_size(), Vector2i(side_size, side_size)));
  580. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  581. err = img->save_png(p_iconset_dir + info.export_name);
  582. } else {
  583. err = da->copy(icon_path, p_iconset_dir + info.export_name);
  584. }
  585. if (err) {
  586. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  587. return err;
  588. }
  589. }
  590. sizes += String(info.actual_size_side) + "\n";
  591. if (i > 0) {
  592. json_description += ",";
  593. }
  594. json_description += String("{");
  595. json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
  596. json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
  597. json_description += String("\"scale\":") + "\"" + info.scale + "\",";
  598. json_description += String("\"filename\":") + "\"" + info.export_name + "\"";
  599. json_description += String("}");
  600. }
  601. json_description += "]}";
  602. Ref<FileAccess> json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
  603. if (json_file.is_null()) {
  604. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), p_iconset_dir + "Contents.json"));
  605. return ERR_CANT_CREATE;
  606. }
  607. CharString json_utf8 = json_description.utf8();
  608. json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
  609. Ref<FileAccess> sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
  610. if (sizes_file.is_null()) {
  611. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), p_iconset_dir + "sizes"));
  612. return ERR_CANT_CREATE;
  613. }
  614. CharString sizes_utf8 = sizes.utf8();
  615. sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
  616. return OK;
  617. }
  618. Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  619. const String custom_launch_image_2x = p_preset->get("storyboard/custom_image@2x");
  620. const String custom_launch_image_3x = p_preset->get("storyboard/custom_image@3x");
  621. if (custom_launch_image_2x.length() > 0 && custom_launch_image_3x.length() > 0) {
  622. Ref<Image> image;
  623. String image_path = p_dest_dir.path_join("[email protected]");
  624. image.instantiate();
  625. Error err = ImageLoader::load_image(custom_launch_image_2x, image);
  626. if (err) {
  627. image.unref();
  628. return err;
  629. }
  630. if (image->save_png(image_path) != OK) {
  631. return ERR_FILE_CANT_WRITE;
  632. }
  633. image.unref();
  634. image_path = p_dest_dir.path_join("[email protected]");
  635. image.instantiate();
  636. err = ImageLoader::load_image(custom_launch_image_3x, image);
  637. if (err) {
  638. image.unref();
  639. return err;
  640. }
  641. if (image->save_png(image_path) != OK) {
  642. return ERR_FILE_CANT_WRITE;
  643. }
  644. } else {
  645. Ref<Image> splash;
  646. const String splash_path = GLOBAL_GET("application/boot_splash/image");
  647. if (!splash_path.is_empty()) {
  648. splash.instantiate();
  649. const Error err = ImageLoader::load_image(splash_path, splash);
  650. if (err) {
  651. splash.unref();
  652. }
  653. }
  654. if (splash.is_null()) {
  655. splash = Ref<Image>(memnew(Image(boot_splash_png)));
  656. }
  657. // Using same image for both @2x and @3x
  658. // because Godot's own boot logo uses single image for all resolutions.
  659. // Also not using @1x image, because devices using this image variant
  660. // are not supported by iOS 9, which is minimal target.
  661. const String splash_png_path_2x = p_dest_dir.path_join("[email protected]");
  662. const String splash_png_path_3x = p_dest_dir.path_join("[email protected]");
  663. if (splash->save_png(splash_png_path_2x) != OK) {
  664. return ERR_FILE_CANT_WRITE;
  665. }
  666. if (splash->save_png(splash_png_path_3x) != OK) {
  667. return ERR_FILE_CANT_WRITE;
  668. }
  669. }
  670. return OK;
  671. }
  672. Error EditorExportPlatformIOS::_walk_dir_recursive(Ref<DirAccess> &p_da, FileHandler p_handler, void *p_userdata) {
  673. Vector<String> dirs;
  674. String current_dir = p_da->get_current_dir();
  675. p_da->list_dir_begin();
  676. String path = p_da->get_next();
  677. while (!path.is_empty()) {
  678. if (p_da->current_is_dir()) {
  679. if (path != "." && path != "..") {
  680. dirs.push_back(path);
  681. }
  682. } else {
  683. Error err = p_handler(current_dir.path_join(path), p_userdata);
  684. if (err) {
  685. p_da->list_dir_end();
  686. return err;
  687. }
  688. }
  689. path = p_da->get_next();
  690. }
  691. p_da->list_dir_end();
  692. for (int i = 0; i < dirs.size(); ++i) {
  693. p_da->change_dir(dirs[i]);
  694. Error err = _walk_dir_recursive(p_da, p_handler, p_userdata);
  695. p_da->change_dir("..");
  696. if (err) {
  697. return err;
  698. }
  699. }
  700. return OK;
  701. }
  702. struct CodesignData {
  703. const Ref<EditorExportPreset> &preset;
  704. bool debug = false;
  705. CodesignData(const Ref<EditorExportPreset> &p_preset, bool p_debug) :
  706. preset(p_preset),
  707. debug(p_debug) {
  708. }
  709. };
  710. Error EditorExportPlatformIOS::_codesign(String p_file, void *p_userdata) {
  711. if (p_file.ends_with(".dylib")) {
  712. CodesignData *data = static_cast<CodesignData *>(p_userdata);
  713. print_line(String("Signing ") + p_file);
  714. String sign_id;
  715. if (data->debug) {
  716. sign_id = data->preset->get("application/code_sign_identity_debug").operator String().is_empty() ? "iPhone Developer" : data->preset->get("application/code_sign_identity_debug");
  717. } else {
  718. sign_id = data->preset->get("application/code_sign_identity_release").operator String().is_empty() ? "iPhone Distribution" : data->preset->get("application/code_sign_identity_release");
  719. }
  720. List<String> codesign_args;
  721. codesign_args.push_back("-f");
  722. codesign_args.push_back("-s");
  723. codesign_args.push_back(sign_id);
  724. codesign_args.push_back(p_file);
  725. String str;
  726. Error err = OS::get_singleton()->execute("codesign", codesign_args, &str, nullptr, true);
  727. print_verbose("codesign (" + p_file + "):\n" + str);
  728. return err;
  729. }
  730. return OK;
  731. }
  732. struct PbxId {
  733. private:
  734. static char _hex_char(uint8_t four_bits) {
  735. if (four_bits < 10) {
  736. return ('0' + four_bits);
  737. }
  738. return 'A' + (four_bits - 10);
  739. }
  740. static String _hex_pad(uint32_t num) {
  741. Vector<char> ret;
  742. ret.resize(sizeof(num) * 2);
  743. for (uint64_t i = 0; i < sizeof(num) * 2; ++i) {
  744. uint8_t four_bits = (num >> (sizeof(num) * 8 - (i + 1) * 4)) & 0xF;
  745. ret.write[i] = _hex_char(four_bits);
  746. }
  747. return String::utf8(ret.ptr(), ret.size());
  748. }
  749. public:
  750. uint32_t high_bits;
  751. uint32_t mid_bits;
  752. uint32_t low_bits;
  753. String str() const {
  754. return _hex_pad(high_bits) + _hex_pad(mid_bits) + _hex_pad(low_bits);
  755. }
  756. PbxId &operator++() {
  757. low_bits++;
  758. if (!low_bits) {
  759. mid_bits++;
  760. if (!mid_bits) {
  761. high_bits++;
  762. }
  763. }
  764. return *this;
  765. }
  766. };
  767. struct ExportLibsData {
  768. Vector<String> lib_paths;
  769. String dest_dir;
  770. };
  771. void EditorExportPlatformIOS::_add_assets_to_project(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) {
  772. // that is just a random number, we just need Godot IDs not to clash with
  773. // existing IDs in the project.
  774. PbxId current_id = { 0x58938401, 0, 0 };
  775. String pbx_files;
  776. String pbx_frameworks_build;
  777. String pbx_frameworks_refs;
  778. String pbx_resources_build;
  779. String pbx_resources_refs;
  780. String pbx_embeded_frameworks;
  781. const String file_info_format = String("$build_id = {isa = PBXBuildFile; fileRef = $ref_id; };\n") +
  782. "$ref_id = {isa = PBXFileReference; lastKnownFileType = $file_type; name = \"$name\"; path = \"$file_path\"; sourceTree = \"<group>\"; };\n";
  783. for (int i = 0; i < p_additional_assets.size(); ++i) {
  784. String additional_asset_info_format = file_info_format;
  785. String build_id = (++current_id).str();
  786. String ref_id = (++current_id).str();
  787. String framework_id = "";
  788. const IOSExportAsset &asset = p_additional_assets[i];
  789. String type;
  790. if (asset.exported_path.ends_with(".framework")) {
  791. if (asset.should_embed) {
  792. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  793. framework_id = (++current_id).str();
  794. pbx_embeded_frameworks += framework_id + ",\n";
  795. }
  796. type = "wrapper.framework";
  797. } else if (asset.exported_path.ends_with(".xcframework")) {
  798. if (asset.should_embed) {
  799. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  800. framework_id = (++current_id).str();
  801. pbx_embeded_frameworks += framework_id + ",\n";
  802. }
  803. type = "wrapper.xcframework";
  804. } else if (asset.exported_path.ends_with(".dylib")) {
  805. type = "compiled.mach-o.dylib";
  806. } else if (asset.exported_path.ends_with(".a")) {
  807. type = "archive.ar";
  808. } else {
  809. type = "file";
  810. }
  811. String &pbx_build = asset.is_framework ? pbx_frameworks_build : pbx_resources_build;
  812. String &pbx_refs = asset.is_framework ? pbx_frameworks_refs : pbx_resources_refs;
  813. if (pbx_build.length() > 0) {
  814. pbx_build += ",\n";
  815. pbx_refs += ",\n";
  816. }
  817. pbx_build += build_id;
  818. pbx_refs += ref_id;
  819. Dictionary format_dict;
  820. format_dict["build_id"] = build_id;
  821. format_dict["ref_id"] = ref_id;
  822. format_dict["name"] = asset.exported_path.get_file();
  823. format_dict["file_path"] = asset.exported_path;
  824. format_dict["file_type"] = type;
  825. if (framework_id.length() > 0) {
  826. format_dict["framework_id"] = framework_id;
  827. }
  828. pbx_files += additional_asset_info_format.format(format_dict, "$_");
  829. }
  830. // Note, frameworks like gamekit are always included in our project.pbxprof file
  831. // even if turned off in capabilities.
  832. String str = String::utf8((const char *)p_project_data.ptr(), p_project_data.size());
  833. str = str.replace("$additional_pbx_files", pbx_files);
  834. str = str.replace("$additional_pbx_frameworks_build", pbx_frameworks_build);
  835. str = str.replace("$additional_pbx_frameworks_refs", pbx_frameworks_refs);
  836. str = str.replace("$additional_pbx_resources_build", pbx_resources_build);
  837. str = str.replace("$additional_pbx_resources_refs", pbx_resources_refs);
  838. str = str.replace("$pbx_embeded_frameworks", pbx_embeded_frameworks);
  839. CharString cs = str.utf8();
  840. p_project_data.resize(cs.size() - 1);
  841. for (int i = 0; i < cs.size() - 1; i++) {
  842. p_project_data.write[i] = cs[i];
  843. }
  844. }
  845. Error EditorExportPlatformIOS::_copy_asset(const String &p_out_dir, const String &p_asset, const String *p_custom_file_name, bool p_is_framework, bool p_should_embed, Vector<IOSExportAsset> &r_exported_assets) {
  846. String binary_name = p_out_dir.get_file().get_basename();
  847. Ref<DirAccess> da = DirAccess::create_for_path(p_asset);
  848. if (da.is_null()) {
  849. ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't create directory: " + p_asset + ".");
  850. }
  851. bool file_exists = da->file_exists(p_asset);
  852. bool dir_exists = da->dir_exists(p_asset);
  853. if (!file_exists && !dir_exists) {
  854. return ERR_FILE_NOT_FOUND;
  855. }
  856. String base_dir = p_asset.get_base_dir().replace("res://", "").replace(".godot/mono/temp/bin/", "");
  857. String asset = p_asset.ends_with("/") ? p_asset.left(p_asset.length() - 1) : p_asset;
  858. String destination_dir;
  859. String destination;
  860. String asset_path;
  861. bool create_framework = false;
  862. if (p_is_framework && asset.ends_with(".dylib")) {
  863. // For iOS we need to turn .dylib into .framework
  864. // to be able to send application to AppStore
  865. asset_path = String("dylibs").path_join(base_dir);
  866. String file_name;
  867. if (!p_custom_file_name) {
  868. file_name = p_asset.get_basename().get_file();
  869. } else {
  870. file_name = *p_custom_file_name;
  871. }
  872. String framework_name = file_name + ".framework";
  873. asset_path = asset_path.path_join(framework_name);
  874. destination_dir = p_out_dir.path_join(asset_path);
  875. destination = destination_dir.path_join(file_name);
  876. create_framework = true;
  877. } else if (p_is_framework && (asset.ends_with(".framework") || asset.ends_with(".xcframework"))) {
  878. asset_path = String("dylibs").path_join(base_dir);
  879. String file_name;
  880. if (!p_custom_file_name) {
  881. file_name = p_asset.get_file();
  882. } else {
  883. file_name = *p_custom_file_name;
  884. }
  885. asset_path = asset_path.path_join(file_name);
  886. destination_dir = p_out_dir.path_join(asset_path);
  887. destination = destination_dir;
  888. } else {
  889. asset_path = base_dir;
  890. String file_name;
  891. if (!p_custom_file_name) {
  892. file_name = p_asset.get_file();
  893. } else {
  894. file_name = *p_custom_file_name;
  895. }
  896. destination_dir = p_out_dir.path_join(asset_path);
  897. asset_path = asset_path.path_join(file_name);
  898. destination = p_out_dir.path_join(asset_path);
  899. }
  900. Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  901. ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_out_dir + "'.");
  902. if (!filesystem_da->dir_exists(destination_dir)) {
  903. Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir);
  904. if (make_dir_err) {
  905. return make_dir_err;
  906. }
  907. }
  908. Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination);
  909. if (err) {
  910. return err;
  911. }
  912. if (asset_path.ends_with("/")) {
  913. asset_path = asset_path.left(asset_path.length() - 1);
  914. }
  915. IOSExportAsset exported_asset = { binary_name.path_join(asset_path), p_is_framework, p_should_embed };
  916. r_exported_assets.push_back(exported_asset);
  917. if (create_framework) {
  918. String file_name;
  919. if (!p_custom_file_name) {
  920. file_name = p_asset.get_basename().get_file();
  921. } else {
  922. file_name = *p_custom_file_name;
  923. }
  924. String framework_name = file_name + ".framework";
  925. // Performing `install_name_tool -id @rpath/{name}.framework/{name} ./{name}` on dylib
  926. {
  927. List<String> install_name_args;
  928. install_name_args.push_back("-id");
  929. install_name_args.push_back(String("@rpath").path_join(framework_name).path_join(file_name));
  930. install_name_args.push_back(destination);
  931. OS::get_singleton()->execute("install_name_tool", install_name_args);
  932. }
  933. // Creating Info.plist
  934. {
  935. String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  936. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  937. "<plist version=\"1.0\">\n"
  938. "<dict>\n"
  939. "<key>CFBundleShortVersionString</key>\n"
  940. "<string>1.0</string>\n"
  941. "<key>CFBundleIdentifier</key>\n"
  942. "<string>com.gdextension.framework.$name</string>\n"
  943. "<key>CFBundleName</key>\n"
  944. "<string>$name</string>\n"
  945. "<key>CFBundleExecutable</key>\n"
  946. "<string>$name</string>\n"
  947. "<key>DTPlatformName</key>\n"
  948. "<string>iphoneos</string>\n"
  949. "<key>CFBundleInfoDictionaryVersion</key>\n"
  950. "<string>6.0</string>\n"
  951. "<key>CFBundleVersion</key>\n"
  952. "<string>1</string>\n"
  953. "<key>CFBundlePackageType</key>\n"
  954. "<string>FMWK</string>\n"
  955. "<key>MinimumOSVersion</key>\n"
  956. "<string>10.0</string>\n"
  957. "</dict>\n"
  958. "</plist>";
  959. String info_plist = info_plist_format.replace("$name", file_name);
  960. Ref<FileAccess> f = FileAccess::open(destination_dir.path_join("Info.plist"), FileAccess::WRITE);
  961. if (f.is_valid()) {
  962. f->store_string(info_plist);
  963. }
  964. }
  965. }
  966. return OK;
  967. }
  968. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, bool p_should_embed, Vector<IOSExportAsset> &r_exported_assets) {
  969. for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) {
  970. const String &asset = p_assets[f_idx];
  971. if (asset.begins_with("res://")) {
  972. Error err = _copy_asset(p_out_dir, asset, nullptr, p_is_framework, p_should_embed, r_exported_assets);
  973. ERR_FAIL_COND_V(err != OK, err);
  974. } else if (ProjectSettings::get_singleton()->localize_path(asset).begins_with("res://")) {
  975. Error err = _copy_asset(p_out_dir, ProjectSettings::get_singleton()->localize_path(asset), nullptr, p_is_framework, p_should_embed, r_exported_assets);
  976. ERR_FAIL_COND_V(err != OK, err);
  977. } else {
  978. // either SDK-builtin or already a part of the export template
  979. IOSExportAsset exported_asset = { asset, p_is_framework, p_should_embed };
  980. r_exported_assets.push_back(exported_asset);
  981. }
  982. }
  983. return OK;
  984. }
  985. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets) {
  986. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  987. for (int i = 0; i < export_plugins.size(); i++) {
  988. Vector<String> linked_frameworks = export_plugins[i]->get_ios_frameworks();
  989. Error err = _export_additional_assets(p_out_dir, linked_frameworks, true, false, r_exported_assets);
  990. ERR_FAIL_COND_V(err, err);
  991. Vector<String> embedded_frameworks = export_plugins[i]->get_ios_embedded_frameworks();
  992. err = _export_additional_assets(p_out_dir, embedded_frameworks, true, true, r_exported_assets);
  993. ERR_FAIL_COND_V(err, err);
  994. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  995. for (int j = 0; j < project_static_libs.size(); j++) {
  996. project_static_libs.write[j] = project_static_libs[j].get_file(); // Only the file name as it's copied to the project
  997. }
  998. err = _export_additional_assets(p_out_dir, project_static_libs, true, false, r_exported_assets);
  999. ERR_FAIL_COND_V(err, err);
  1000. Vector<String> ios_bundle_files = export_plugins[i]->get_ios_bundle_files();
  1001. err = _export_additional_assets(p_out_dir, ios_bundle_files, false, false, r_exported_assets);
  1002. ERR_FAIL_COND_V(err, err);
  1003. }
  1004. Vector<String> library_paths;
  1005. for (int i = 0; i < p_libraries.size(); ++i) {
  1006. library_paths.push_back(p_libraries[i].path);
  1007. }
  1008. Error err = _export_additional_assets(p_out_dir, library_paths, true, true, r_exported_assets);
  1009. ERR_FAIL_COND_V(err, err);
  1010. return OK;
  1011. }
  1012. Vector<String> EditorExportPlatformIOS::_get_preset_architectures(const Ref<EditorExportPreset> &p_preset) const {
  1013. Vector<ExportArchitecture> all_archs = _get_supported_architectures();
  1014. Vector<String> enabled_archs;
  1015. for (int i = 0; i < all_archs.size(); ++i) {
  1016. bool is_enabled = p_preset->get("architectures/" + all_archs[i].name);
  1017. if (is_enabled) {
  1018. enabled_archs.push_back(all_archs[i].name);
  1019. }
  1020. }
  1021. return enabled_archs;
  1022. }
  1023. Error EditorExportPlatformIOS::_export_ios_plugins(const Ref<EditorExportPreset> &p_preset, IOSConfigData &p_config_data, const String &dest_dir, Vector<IOSExportAsset> &r_exported_assets, bool p_debug) {
  1024. String plugin_definition_cpp_code;
  1025. String plugin_initialization_cpp_code;
  1026. String plugin_deinitialization_cpp_code;
  1027. Vector<String> plugin_linked_dependencies;
  1028. Vector<String> plugin_embedded_dependencies;
  1029. Vector<String> plugin_files;
  1030. Vector<PluginConfigIOS> enabled_plugins = get_enabled_plugins(p_preset);
  1031. Vector<String> added_linked_dependenciy_names;
  1032. Vector<String> added_embedded_dependenciy_names;
  1033. HashMap<String, String> plist_values;
  1034. HashSet<String> plugin_linker_flags;
  1035. Error err;
  1036. for (int i = 0; i < enabled_plugins.size(); i++) {
  1037. PluginConfigIOS plugin = enabled_plugins[i];
  1038. // Export plugin binary.
  1039. String plugin_main_binary = PluginConfigIOS::get_plugin_main_binary(plugin, p_debug);
  1040. String plugin_binary_result_file = plugin.binary.get_file();
  1041. // We shouldn't embed .xcframework that contains static libraries.
  1042. // Static libraries are not embedded anyway.
  1043. err = _copy_asset(dest_dir, plugin_main_binary, &plugin_binary_result_file, true, false, r_exported_assets);
  1044. ERR_FAIL_COND_V(err != OK, err);
  1045. // Adding dependencies.
  1046. // Use separate container for names to check for duplicates.
  1047. for (int j = 0; j < plugin.linked_dependencies.size(); j++) {
  1048. String dependency = plugin.linked_dependencies[j];
  1049. String name = dependency.get_file();
  1050. if (added_linked_dependenciy_names.has(name)) {
  1051. continue;
  1052. }
  1053. added_linked_dependenciy_names.push_back(name);
  1054. plugin_linked_dependencies.push_back(dependency);
  1055. }
  1056. for (int j = 0; j < plugin.system_dependencies.size(); j++) {
  1057. String dependency = plugin.system_dependencies[j];
  1058. String name = dependency.get_file();
  1059. if (added_linked_dependenciy_names.has(name)) {
  1060. continue;
  1061. }
  1062. added_linked_dependenciy_names.push_back(name);
  1063. plugin_linked_dependencies.push_back(dependency);
  1064. }
  1065. for (int j = 0; j < plugin.embedded_dependencies.size(); j++) {
  1066. String dependency = plugin.embedded_dependencies[j];
  1067. String name = dependency.get_file();
  1068. if (added_embedded_dependenciy_names.has(name)) {
  1069. continue;
  1070. }
  1071. added_embedded_dependenciy_names.push_back(name);
  1072. plugin_embedded_dependencies.push_back(dependency);
  1073. }
  1074. plugin_files.append_array(plugin.files_to_copy);
  1075. // Capabilities
  1076. // Also checking for duplicates.
  1077. for (int j = 0; j < plugin.capabilities.size(); j++) {
  1078. String capability = plugin.capabilities[j];
  1079. if (p_config_data.capabilities.has(capability)) {
  1080. continue;
  1081. }
  1082. p_config_data.capabilities.push_back(capability);
  1083. }
  1084. // Linker flags
  1085. // Checking duplicates
  1086. for (int j = 0; j < plugin.linker_flags.size(); j++) {
  1087. String linker_flag = plugin.linker_flags[j];
  1088. plugin_linker_flags.insert(linker_flag);
  1089. }
  1090. // Plist
  1091. // Using hash map container to remove duplicates
  1092. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  1093. String key = E.key;
  1094. const PluginConfigIOS::PlistItem &item = E.value;
  1095. String value;
  1096. switch (item.type) {
  1097. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  1098. String preset_name = "plugins_plist/" + key;
  1099. String input_value = p_preset->get(preset_name);
  1100. value = "<string>" + input_value + "</string>";
  1101. } break;
  1102. default:
  1103. value = item.value;
  1104. break;
  1105. }
  1106. if (key.is_empty() || value.is_empty()) {
  1107. continue;
  1108. }
  1109. String plist_key = "<key>" + key + "</key>";
  1110. plist_values[plist_key] = value;
  1111. }
  1112. // CPP Code
  1113. String definition_comment = "// Plugin: " + plugin.name + "\n";
  1114. String initialization_method = plugin.initialization_method + "();\n";
  1115. String deinitialization_method = plugin.deinitialization_method + "();\n";
  1116. plugin_definition_cpp_code += definition_comment +
  1117. "extern void " + initialization_method +
  1118. "extern void " + deinitialization_method + "\n";
  1119. plugin_initialization_cpp_code += "\t" + initialization_method;
  1120. plugin_deinitialization_cpp_code += "\t" + deinitialization_method;
  1121. if (plugin.use_swift_runtime) {
  1122. p_config_data.use_swift_runtime = true;
  1123. }
  1124. }
  1125. // Updating `Info.plist`
  1126. {
  1127. for (const KeyValue<String, String> &E : plist_values) {
  1128. String key = E.key;
  1129. String value = E.value;
  1130. if (key.is_empty() || value.is_empty()) {
  1131. continue;
  1132. }
  1133. p_config_data.plist_content += key + value + "\n";
  1134. }
  1135. }
  1136. // Export files
  1137. {
  1138. // Export linked plugin dependency
  1139. err = _export_additional_assets(dest_dir, plugin_linked_dependencies, true, false, r_exported_assets);
  1140. ERR_FAIL_COND_V(err != OK, err);
  1141. // Export embedded plugin dependency
  1142. err = _export_additional_assets(dest_dir, plugin_embedded_dependencies, true, true, r_exported_assets);
  1143. ERR_FAIL_COND_V(err != OK, err);
  1144. // Export plugin files
  1145. err = _export_additional_assets(dest_dir, plugin_files, false, false, r_exported_assets);
  1146. ERR_FAIL_COND_V(err != OK, err);
  1147. }
  1148. // Update CPP
  1149. {
  1150. Dictionary plugin_format;
  1151. plugin_format["definition"] = plugin_definition_cpp_code;
  1152. plugin_format["initialization"] = plugin_initialization_cpp_code;
  1153. plugin_format["deinitialization"] = plugin_deinitialization_cpp_code;
  1154. String plugin_cpp_code = "\n// Godot Plugins\n"
  1155. "void godot_ios_plugins_initialize();\n"
  1156. "void godot_ios_plugins_deinitialize();\n"
  1157. "// Exported Plugins\n\n"
  1158. "$definition"
  1159. "// Use Plugins\n"
  1160. "void godot_ios_plugins_initialize() {\n"
  1161. "$initialization"
  1162. "}\n\n"
  1163. "void godot_ios_plugins_deinitialize() {\n"
  1164. "$deinitialization"
  1165. "}\n";
  1166. p_config_data.cpp_code += plugin_cpp_code.format(plugin_format, "$_");
  1167. }
  1168. // Update Linker Flag Values
  1169. {
  1170. String result_linker_flags = " ";
  1171. for (const String &E : plugin_linker_flags) {
  1172. const String &flag = E;
  1173. if (flag.length() == 0) {
  1174. continue;
  1175. }
  1176. if (result_linker_flags.length() > 0) {
  1177. result_linker_flags += ' ';
  1178. }
  1179. result_linker_flags += flag;
  1180. }
  1181. result_linker_flags = result_linker_flags.replace("\"", "\\\"");
  1182. p_config_data.linker_flags += result_linker_flags;
  1183. }
  1184. return OK;
  1185. }
  1186. Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  1187. return _export_project_helper(p_preset, p_debug, p_path, p_flags, false, false);
  1188. }
  1189. Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags, bool p_simulator, bool p_oneclick) {
  1190. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  1191. const String dest_dir = p_path.get_base_dir() + "/";
  1192. const String binary_name = p_path.get_file().get_basename();
  1193. const String binary_dir = dest_dir + binary_name;
  1194. if (!DirAccess::exists(dest_dir)) {
  1195. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Target folder does not exist or is inaccessible: \"%s\""), dest_dir));
  1196. return ERR_FILE_BAD_PATH;
  1197. }
  1198. bool export_project_only = p_preset->get("application/export_project_only");
  1199. if (p_oneclick) {
  1200. export_project_only = false; // Skip for one-click deploy.
  1201. }
  1202. EditorProgress ep("export", export_project_only ? TTR("Exporting for iOS (Project Files Only)") : TTR("Exporting for iOS"), export_project_only ? 2 : 5, true);
  1203. String team_id = p_preset->get("application/app_store_team_id");
  1204. ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project.");
  1205. String src_pkg_name;
  1206. if (p_debug) {
  1207. src_pkg_name = p_preset->get("custom_template/debug");
  1208. } else {
  1209. src_pkg_name = p_preset->get("custom_template/release");
  1210. }
  1211. if (src_pkg_name.is_empty()) {
  1212. String err;
  1213. src_pkg_name = find_export_template("ios.zip", &err);
  1214. if (src_pkg_name.is_empty()) {
  1215. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found."));
  1216. return ERR_FILE_NOT_FOUND;
  1217. }
  1218. }
  1219. {
  1220. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1221. if (da.is_valid()) {
  1222. String current_dir = da->get_current_dir();
  1223. // remove leftovers from last export so they don't interfere
  1224. // in case some files are no longer needed
  1225. if (da->change_dir(binary_dir + ".xcodeproj") == OK) {
  1226. da->erase_contents_recursive();
  1227. }
  1228. if (da->change_dir(binary_dir) == OK) {
  1229. da->erase_contents_recursive();
  1230. }
  1231. da->change_dir(current_dir);
  1232. if (!da->dir_exists(binary_dir)) {
  1233. Error err = da->make_dir(binary_dir);
  1234. if (err != OK) {
  1235. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Failed to create the directory: \"%s\""), binary_dir));
  1236. return err;
  1237. }
  1238. }
  1239. }
  1240. }
  1241. if (ep.step("Making .pck", 0)) {
  1242. return ERR_SKIP;
  1243. }
  1244. String pack_path = binary_dir + ".pck";
  1245. Vector<SharedObject> libraries;
  1246. Error err = save_pack(p_preset, p_debug, pack_path, &libraries);
  1247. if (err) {
  1248. // Message is supplied by the subroutine method.
  1249. return err;
  1250. }
  1251. if (ep.step("Extracting and configuring Xcode project", 1)) {
  1252. return ERR_SKIP;
  1253. }
  1254. String library_to_use = "libgodot.ios." + String(p_debug ? "debug" : "release") + ".xcframework";
  1255. print_line("Static framework: " + library_to_use);
  1256. String pkg_name;
  1257. if (String(GLOBAL_GET("application/config/name")) != "") {
  1258. pkg_name = String(GLOBAL_GET("application/config/name"));
  1259. } else {
  1260. pkg_name = "Unnamed";
  1261. }
  1262. bool found_library = false;
  1263. const String project_file = "godot_ios.xcodeproj/project.pbxproj";
  1264. HashSet<String> files_to_parse;
  1265. files_to_parse.insert("godot_ios/godot_ios-Info.plist");
  1266. files_to_parse.insert(project_file);
  1267. files_to_parse.insert("godot_ios/export_options.plist");
  1268. files_to_parse.insert("godot_ios/dummy.cpp");
  1269. files_to_parse.insert("godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata");
  1270. files_to_parse.insert("godot_ios.xcodeproj/xcshareddata/xcschemes/godot_ios.xcscheme");
  1271. files_to_parse.insert("godot_ios/godot_ios.entitlements");
  1272. files_to_parse.insert("godot_ios/Launch Screen.storyboard");
  1273. IOSConfigData config_data = {
  1274. pkg_name,
  1275. binary_name,
  1276. _get_additional_plist_content(),
  1277. String(" ").join(_get_preset_architectures(p_preset)),
  1278. _get_linker_flags(),
  1279. _get_cpp_code(),
  1280. "",
  1281. "",
  1282. "",
  1283. "",
  1284. Vector<String>(),
  1285. false
  1286. };
  1287. Vector<IOSExportAsset> assets;
  1288. Ref<DirAccess> tmp_app_path = DirAccess::create_for_path(dest_dir);
  1289. if (tmp_app_path.is_null()) {
  1290. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not create and open the directory: \"%s\""), dest_dir));
  1291. return ERR_CANT_CREATE;
  1292. }
  1293. print_line("Unzipping...");
  1294. Ref<FileAccess> io_fa;
  1295. zlib_filefunc_def io = zipio_create_io(&io_fa);
  1296. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  1297. if (!src_pkg_zip) {
  1298. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Could not open export template (not a zip file?): \"%s\".", src_pkg_name));
  1299. return ERR_CANT_OPEN;
  1300. }
  1301. err = _export_ios_plugins(p_preset, config_data, binary_dir, assets, p_debug);
  1302. if (err != OK) {
  1303. // TODO: Improve error reporting by using `add_message` throughout all methods called via `_export_ios_plugins`.
  1304. // For now a generic top level message would be fine, but we're ought to use proper reporting here instead of
  1305. // just fail macros and non-descriptive error return values.
  1306. add_message(EXPORT_MESSAGE_ERROR, TTR("iOS Plugins"), vformat(TTR("Failed to export iOS plugins with code %d. Please check the output log."), err));
  1307. return err;
  1308. }
  1309. //export rest of the files
  1310. int ret = unzGoToFirstFile(src_pkg_zip);
  1311. Vector<uint8_t> project_file_data;
  1312. while (ret == UNZ_OK) {
  1313. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1314. bool is_execute = false;
  1315. #endif
  1316. //get filename
  1317. unz_file_info info;
  1318. char fname[16384];
  1319. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  1320. if (ret != UNZ_OK) {
  1321. break;
  1322. }
  1323. String file = String::utf8(fname);
  1324. print_line("READ: " + file);
  1325. Vector<uint8_t> data;
  1326. data.resize(info.uncompressed_size);
  1327. //read
  1328. unzOpenCurrentFile(src_pkg_zip);
  1329. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  1330. unzCloseCurrentFile(src_pkg_zip);
  1331. //write
  1332. if (files_to_parse.has(file)) {
  1333. _fix_config_file(p_preset, data, config_data, p_debug);
  1334. } else if (file.begins_with("libgodot.ios")) {
  1335. if (!file.begins_with(library_to_use) || file.ends_with(String("/empty"))) {
  1336. ret = unzGoToNextFile(src_pkg_zip);
  1337. continue; //ignore!
  1338. }
  1339. found_library = true;
  1340. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1341. is_execute = true;
  1342. #endif
  1343. file = file.replace(library_to_use, binary_name + ".xcframework");
  1344. }
  1345. if (file == project_file) {
  1346. project_file_data = data;
  1347. }
  1348. ///@TODO need to parse logo files
  1349. if (data.size() > 0) {
  1350. file = file.replace("godot_ios", binary_name);
  1351. print_line("ADDING: " + file + " size: " + itos(data.size()));
  1352. /* write it into our folder structure */
  1353. file = dest_dir + file;
  1354. /* make sure this folder exists */
  1355. String dir_name = file.get_base_dir();
  1356. if (!tmp_app_path->dir_exists(dir_name)) {
  1357. print_line("Creating " + dir_name);
  1358. Error dir_err = tmp_app_path->make_dir_recursive(dir_name);
  1359. if (dir_err) {
  1360. unzClose(src_pkg_zip);
  1361. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create a directory at path \"%s\"."), dir_name));
  1362. return ERR_CANT_CREATE;
  1363. }
  1364. }
  1365. /* write the file */
  1366. {
  1367. Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);
  1368. if (f.is_null()) {
  1369. unzClose(src_pkg_zip);
  1370. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write to a file at path \"%s\"."), file));
  1371. return ERR_CANT_CREATE;
  1372. };
  1373. f->store_buffer(data.ptr(), data.size());
  1374. }
  1375. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1376. if (is_execute) {
  1377. // we need execute rights on this file
  1378. chmod(file.utf8().get_data(), 0755);
  1379. }
  1380. #endif
  1381. }
  1382. ret = unzGoToNextFile(src_pkg_zip);
  1383. }
  1384. /* we're done with our source zip */
  1385. unzClose(src_pkg_zip);
  1386. if (!found_library) {
  1387. 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));
  1388. return ERR_FILE_NOT_FOUND;
  1389. }
  1390. Dictionary appnames = GLOBAL_GET("application/config/name_localized");
  1391. Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");
  1392. Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");
  1393. Dictionary photolibrary_usage_descriptions = p_preset->get("privacy/photolibrary_usage_description_localized");
  1394. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  1395. if (translations.size() > 0) {
  1396. {
  1397. String fname = binary_dir + "/en.lproj";
  1398. tmp_app_path->make_dir_recursive(fname);
  1399. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1400. f->store_line("/* Localized versions of Info.plist keys */");
  1401. f->store_line("");
  1402. f->store_line("CFBundleDisplayName = \"" + GLOBAL_GET("application/config/name").operator String() + "\";");
  1403. f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String() + "\";");
  1404. f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String() + "\";");
  1405. f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photolibrary_usage_description").operator String() + "\";");
  1406. }
  1407. HashSet<String> languages;
  1408. for (const String &E : translations) {
  1409. Ref<Translation> tr = ResourceLoader::load(E);
  1410. if (tr.is_valid() && tr->get_locale() != "en") {
  1411. languages.insert(tr->get_locale());
  1412. }
  1413. }
  1414. for (const String &lang : languages) {
  1415. String fname = binary_dir + "/" + lang + ".lproj";
  1416. tmp_app_path->make_dir_recursive(fname);
  1417. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1418. f->store_line("/* Localized versions of Info.plist keys */");
  1419. f->store_line("");
  1420. if (appnames.has(lang)) {
  1421. f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String() + "\";");
  1422. }
  1423. if (camera_usage_descriptions.has(lang)) {
  1424. f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String() + "\";");
  1425. }
  1426. if (microphone_usage_descriptions.has(lang)) {
  1427. f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String() + "\";");
  1428. }
  1429. if (photolibrary_usage_descriptions.has(lang)) {
  1430. f->store_line("NSPhotoLibraryUsageDescription = \"" + photolibrary_usage_descriptions[lang].operator String() + "\";");
  1431. }
  1432. }
  1433. }
  1434. // Copy project static libs to the project
  1435. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1436. for (int i = 0; i < export_plugins.size(); i++) {
  1437. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1438. for (int j = 0; j < project_static_libs.size(); j++) {
  1439. const String &static_lib_path = project_static_libs[j];
  1440. String dest_lib_file_path = dest_dir + static_lib_path.get_file();
  1441. Error lib_copy_err = tmp_app_path->copy(static_lib_path, dest_lib_file_path);
  1442. if (lib_copy_err != OK) {
  1443. 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));
  1444. return lib_copy_err;
  1445. }
  1446. }
  1447. }
  1448. String iconset_dir = binary_dir + "/Images.xcassets/AppIcon.appiconset/";
  1449. err = OK;
  1450. if (!tmp_app_path->dir_exists(iconset_dir)) {
  1451. err = tmp_app_path->make_dir_recursive(iconset_dir);
  1452. }
  1453. if (err != OK) {
  1454. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create a directory at path \"%s\"."), iconset_dir));
  1455. return err;
  1456. }
  1457. err = _export_icons(p_preset, iconset_dir);
  1458. if (err != OK) {
  1459. // Message is supplied by the subroutine method.
  1460. return err;
  1461. }
  1462. {
  1463. String splash_image_path = binary_dir + "/Images.xcassets/SplashImage.imageset/";
  1464. Ref<DirAccess> launch_screen_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1465. if (launch_screen_da.is_null()) {
  1466. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not access the filesystem."));
  1467. return ERR_CANT_CREATE;
  1468. }
  1469. print_line("Exporting launch screen storyboard");
  1470. err = _export_loading_screen_file(p_preset, splash_image_path);
  1471. if (err != OK) {
  1472. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Failed to create a file at path \"%s\" with code %d."), splash_image_path, err));
  1473. }
  1474. }
  1475. if (err != OK) {
  1476. return err;
  1477. }
  1478. print_line("Exporting additional assets");
  1479. _export_additional_assets(binary_dir, libraries, assets);
  1480. _add_assets_to_project(p_preset, project_file_data, assets);
  1481. String project_file_name = binary_dir + ".xcodeproj/project.pbxproj";
  1482. {
  1483. Ref<FileAccess> f = FileAccess::open(project_file_name, FileAccess::WRITE);
  1484. if (f.is_null()) {
  1485. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write to a file at path \"%s\"."), project_file_name));
  1486. return ERR_CANT_CREATE;
  1487. };
  1488. f->store_buffer(project_file_data.ptr(), project_file_data.size());
  1489. }
  1490. #ifdef MACOS_ENABLED
  1491. {
  1492. if (ep.step("Code-signing dylibs", 2)) {
  1493. return ERR_SKIP;
  1494. }
  1495. Ref<DirAccess> dylibs_dir = DirAccess::open(binary_dir + "/dylibs");
  1496. ERR_FAIL_COND_V(dylibs_dir.is_null(), ERR_CANT_OPEN);
  1497. CodesignData codesign_data(p_preset, p_debug);
  1498. err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data);
  1499. if (err != OK) {
  1500. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  1501. return err;
  1502. }
  1503. }
  1504. if (export_project_only) {
  1505. return OK;
  1506. }
  1507. if (ep.step("Making .xcarchive", 3)) {
  1508. return ERR_SKIP;
  1509. }
  1510. String archive_path = p_path.get_basename() + ".xcarchive";
  1511. List<String> archive_args;
  1512. archive_args.push_back("-project");
  1513. archive_args.push_back(binary_dir + ".xcodeproj");
  1514. archive_args.push_back("-scheme");
  1515. archive_args.push_back(binary_name);
  1516. archive_args.push_back("-sdk");
  1517. if (p_simulator) {
  1518. archive_args.push_back("iphonesimulator");
  1519. } else {
  1520. archive_args.push_back("iphoneos");
  1521. }
  1522. archive_args.push_back("-configuration");
  1523. archive_args.push_back(p_debug ? "Debug" : "Release");
  1524. archive_args.push_back("-destination");
  1525. if (p_simulator) {
  1526. archive_args.push_back("generic/platform=iOS Simulator");
  1527. } else {
  1528. archive_args.push_back("generic/platform=iOS");
  1529. }
  1530. archive_args.push_back("archive");
  1531. archive_args.push_back("-allowProvisioningUpdates");
  1532. archive_args.push_back("-archivePath");
  1533. archive_args.push_back(archive_path);
  1534. String archive_str;
  1535. err = OS::get_singleton()->execute("xcodebuild", archive_args, &archive_str, nullptr, true);
  1536. if (err != OK) {
  1537. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), vformat(TTR("Failed to run xcodebuild with code %d"), err));
  1538. return err;
  1539. }
  1540. print_line("xcodebuild (.xcarchive):\n" + archive_str);
  1541. if (!archive_str.contains("** ARCHIVE SUCCEEDED **")) {
  1542. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR("Xcode project build failed, see editor log for details."));
  1543. return FAILED;
  1544. }
  1545. if (!p_oneclick) {
  1546. if (ep.step("Making .ipa", 4)) {
  1547. return ERR_SKIP;
  1548. }
  1549. List<String> export_args;
  1550. export_args.push_back("-exportArchive");
  1551. export_args.push_back("-archivePath");
  1552. export_args.push_back(archive_path);
  1553. export_args.push_back("-exportOptionsPlist");
  1554. export_args.push_back(binary_dir + "/export_options.plist");
  1555. export_args.push_back("-allowProvisioningUpdates");
  1556. export_args.push_back("-exportPath");
  1557. export_args.push_back(dest_dir);
  1558. String export_str;
  1559. err = OS::get_singleton()->execute("xcodebuild", export_args, &export_str, nullptr, true);
  1560. if (err != OK) {
  1561. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), vformat(TTR("Failed to run xcodebuild with code %d"), err));
  1562. return err;
  1563. }
  1564. print_line("xcodebuild (.ipa):\n" + export_str);
  1565. if (!export_str.contains("** EXPORT SUCCEEDED **")) {
  1566. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR(".ipa export failed, see editor log for details."));
  1567. return FAILED;
  1568. }
  1569. }
  1570. #else
  1571. add_message(EXPORT_MESSAGE_WARNING, TTR("Xcode Build"), TTR(".ipa can only be built on macOS. Leaving Xcode project without building the package."));
  1572. #endif
  1573. return OK;
  1574. }
  1575. bool EditorExportPlatformIOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {
  1576. #if defined(MODULE_MONO_ENABLED) && !defined(MACOS_ENABLED)
  1577. // TODO: Remove this restriction when we don't rely on macOS tools to package up the native libraries anymore.
  1578. r_error += TTR("Exporting to iOS when using C#/.NET is experimental and requires macOS.") + "\n";
  1579. return false;
  1580. #else
  1581. String err;
  1582. bool valid = false;
  1583. #if defined(MODULE_MONO_ENABLED)
  1584. // iOS export is still a work in progress, keep a message as a warning.
  1585. err += TTR("Exporting to iOS when using C#/.NET is experimental.") + "\n";
  1586. #endif
  1587. // Look for export templates (first official, and if defined custom templates).
  1588. bool dvalid = exists_export_template("ios.zip", &err);
  1589. bool rvalid = dvalid; // Both in the same ZIP.
  1590. if (p_preset->get("custom_template/debug") != "") {
  1591. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  1592. if (!dvalid) {
  1593. err += TTR("Custom debug template not found.") + "\n";
  1594. }
  1595. }
  1596. if (p_preset->get("custom_template/release") != "") {
  1597. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  1598. if (!rvalid) {
  1599. err += TTR("Custom release template not found.") + "\n";
  1600. }
  1601. }
  1602. valid = dvalid || rvalid;
  1603. r_missing_templates = !valid;
  1604. if (!err.is_empty()) {
  1605. r_error = err;
  1606. }
  1607. return valid;
  1608. #endif // !(MODULE_MONO_ENABLED && !MACOS_ENABLED)
  1609. }
  1610. bool EditorExportPlatformIOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  1611. String err;
  1612. bool valid = true;
  1613. // Validate the project configuration.
  1614. List<ExportOption> options;
  1615. get_export_options(&options);
  1616. for (const EditorExportPlatform::ExportOption &E : options) {
  1617. if (get_export_option_visibility(p_preset.ptr(), E.option.name)) {
  1618. String warn = get_export_option_warning(p_preset.ptr(), E.option.name);
  1619. if (!warn.is_empty()) {
  1620. err += warn + "\n";
  1621. if (E.required) {
  1622. valid = false;
  1623. }
  1624. }
  1625. }
  1626. }
  1627. if (!ResourceImporterTextureSettings::should_import_etc2_astc()) {
  1628. valid = false;
  1629. }
  1630. if (!err.is_empty()) {
  1631. r_error = err;
  1632. }
  1633. return valid;
  1634. }
  1635. int EditorExportPlatformIOS::get_options_count() const {
  1636. MutexLock lock(device_lock);
  1637. return devices.size();
  1638. }
  1639. String EditorExportPlatformIOS::get_options_tooltip() const {
  1640. return TTR("Select device from the list");
  1641. }
  1642. Ref<ImageTexture> EditorExportPlatformIOS::get_option_icon(int p_index) const {
  1643. MutexLock lock(device_lock);
  1644. Ref<ImageTexture> icon;
  1645. if (p_index >= 0 || p_index < devices.size()) {
  1646. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  1647. if (theme.is_valid()) {
  1648. if (devices[p_index].simulator) {
  1649. icon = theme->get_icon("IOSSimulator", EditorStringName(EditorIcons));
  1650. } else if (devices[p_index].wifi) {
  1651. icon = theme->get_icon("IOSDeviceWireless", EditorStringName(EditorIcons));
  1652. } else {
  1653. icon = theme->get_icon("IOSDeviceWired", EditorStringName(EditorIcons));
  1654. }
  1655. }
  1656. }
  1657. return icon;
  1658. }
  1659. String EditorExportPlatformIOS::get_option_label(int p_index) const {
  1660. ERR_FAIL_INDEX_V(p_index, devices.size(), "");
  1661. MutexLock lock(device_lock);
  1662. return devices[p_index].name;
  1663. }
  1664. String EditorExportPlatformIOS::get_option_tooltip(int p_index) const {
  1665. ERR_FAIL_INDEX_V(p_index, devices.size(), "");
  1666. MutexLock lock(device_lock);
  1667. return "UUID: " + devices[p_index].id;
  1668. }
  1669. bool EditorExportPlatformIOS::is_package_name_valid(const String &p_package, String *r_error) const {
  1670. String pname = p_package;
  1671. if (pname.length() == 0) {
  1672. if (r_error) {
  1673. *r_error = TTR("Identifier is missing.");
  1674. }
  1675. return false;
  1676. }
  1677. for (int i = 0; i < pname.length(); i++) {
  1678. char32_t c = pname[i];
  1679. if (!(is_ascii_alphanumeric_char(c) || c == '-' || c == '.')) {
  1680. if (r_error) {
  1681. *r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
  1682. }
  1683. return false;
  1684. }
  1685. }
  1686. return true;
  1687. }
  1688. #ifdef MACOS_ENABLED
  1689. bool EditorExportPlatformIOS::_check_xcode_install() {
  1690. static bool xcode_found = false;
  1691. if (!xcode_found) {
  1692. Vector<String> mdfind_paths;
  1693. List<String> mdfind_args;
  1694. mdfind_args.push_back("kMDItemCFBundleIdentifier=com.apple.dt.Xcode");
  1695. String output;
  1696. Error err = OS::get_singleton()->execute("mdfind", mdfind_args, &output);
  1697. if (err == OK) {
  1698. mdfind_paths = output.split("\n");
  1699. }
  1700. for (const String &found_path : mdfind_paths) {
  1701. xcode_found = !found_path.is_empty() && DirAccess::dir_exists_absolute(found_path.strip_edges());
  1702. if (xcode_found) {
  1703. break;
  1704. }
  1705. }
  1706. }
  1707. return xcode_found;
  1708. }
  1709. void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) {
  1710. EditorExportPlatformIOS *ea = static_cast<EditorExportPlatformIOS *>(ud);
  1711. while (!ea->quit_request.is_set()) {
  1712. // Nothing to do if we already know the plugins have changed.
  1713. if (!ea->plugins_changed.is_set()) {
  1714. MutexLock lock(ea->plugins_lock);
  1715. Vector<PluginConfigIOS> loaded_plugins = get_plugins();
  1716. if (ea->plugins.size() != loaded_plugins.size()) {
  1717. ea->plugins_changed.set();
  1718. } else {
  1719. for (int i = 0; i < ea->plugins.size(); i++) {
  1720. if (ea->plugins[i].name != loaded_plugins[i].name || ea->plugins[i].last_updated != loaded_plugins[i].last_updated) {
  1721. ea->plugins_changed.set();
  1722. break;
  1723. }
  1724. }
  1725. }
  1726. }
  1727. // Check for devices updates.
  1728. Vector<Device> ldevices;
  1729. // Enum real devices (via ios_deploy, pre Xcode 15).
  1730. String idepl = EDITOR_GET("export/ios/ios_deploy");
  1731. if (!idepl.is_empty()) {
  1732. String devices;
  1733. List<String> args;
  1734. args.push_back("-c");
  1735. args.push_back("-timeout");
  1736. args.push_back("1");
  1737. args.push_back("-j");
  1738. args.push_back("-u");
  1739. args.push_back("-I");
  1740. int ec = 0;
  1741. Error err = OS::get_singleton()->execute(idepl, args, &devices, &ec, true);
  1742. if (err == OK && ec == 0) {
  1743. Ref<JSON> json;
  1744. json.instantiate();
  1745. devices = "{ \"devices\":[" + devices.replace("}{", "},{") + "]}";
  1746. err = json->parse(devices);
  1747. if (err == OK) {
  1748. Dictionary data = json->get_data();
  1749. Array devices = data["devices"];
  1750. for (int i = 0; i < devices.size(); i++) {
  1751. Dictionary device_event = devices[i];
  1752. if (device_event["Event"] == "DeviceDetected") {
  1753. Dictionary device_info = device_event["Device"];
  1754. Device nd;
  1755. nd.id = device_info["DeviceIdentifier"];
  1756. nd.name = device_info["DeviceName"].operator String() + " (ios_deploy, " + ((device_event["Interface"] == "WIFI") ? "network" : "wired") + ")";
  1757. nd.wifi = device_event["Interface"] == "WIFI";
  1758. nd.use_ios_deploy = true;
  1759. nd.simulator = false;
  1760. ldevices.push_back(nd);
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. // Enum simulators.
  1767. if (_check_xcode_install() && (FileAccess::exists("/usr/bin/xcrun") || FileAccess::exists("/bin/xcrun"))) {
  1768. {
  1769. String devices;
  1770. List<String> args;
  1771. args.push_back("devicectl");
  1772. args.push_back("list");
  1773. args.push_back("devices");
  1774. args.push_back("-j");
  1775. args.push_back("-");
  1776. args.push_back("-q");
  1777. int ec = 0;
  1778. Error err = OS::get_singleton()->execute("xcrun", args, &devices, &ec, true);
  1779. if (err == OK && ec == 0) {
  1780. Ref<JSON> json;
  1781. json.instantiate();
  1782. err = json->parse(devices);
  1783. if (err == OK) {
  1784. const Dictionary &data = json->get_data();
  1785. const Dictionary &result = data["result"];
  1786. const Array &devices = result["devices"];
  1787. for (int i = 0; i < devices.size(); i++) {
  1788. const Dictionary &device_info = devices[i];
  1789. const Dictionary &conn_props = device_info["connectionProperties"];
  1790. const Dictionary &dev_props = device_info["deviceProperties"];
  1791. if (conn_props["pairingState"] == "paired" && dev_props["developerModeStatus"] == "enabled") {
  1792. Device nd;
  1793. nd.id = device_info["identifier"];
  1794. nd.name = dev_props["name"].operator String() + " (devicectl, " + ((conn_props["transportType"] == "localNetwork") ? "network" : "wired") + ")";
  1795. nd.wifi = conn_props["transportType"] == "localNetwork";
  1796. nd.simulator = false;
  1797. ldevices.push_back(nd);
  1798. }
  1799. }
  1800. }
  1801. }
  1802. }
  1803. // Enum simulators.
  1804. {
  1805. String devices;
  1806. List<String> args;
  1807. args.push_back("simctl");
  1808. args.push_back("list");
  1809. args.push_back("devices");
  1810. args.push_back("-j");
  1811. int ec = 0;
  1812. Error err = OS::get_singleton()->execute("xcrun", args, &devices, &ec, true);
  1813. if (err == OK && ec == 0) {
  1814. Ref<JSON> json;
  1815. json.instantiate();
  1816. err = json->parse(devices);
  1817. if (err == OK) {
  1818. const Dictionary &data = json->get_data();
  1819. const Dictionary &devices = data["devices"];
  1820. for (const Variant *key = devices.next(nullptr); key; key = devices.next(key)) {
  1821. const Array &os_devices = devices[*key];
  1822. for (int i = 0; i < os_devices.size(); i++) {
  1823. const Dictionary &device_info = os_devices[i];
  1824. if (device_info["isAvailable"].operator bool() && device_info["state"] == "Booted") {
  1825. Device nd;
  1826. nd.id = device_info["udid"];
  1827. nd.name = device_info["name"].operator String() + " (simulator)";
  1828. nd.simulator = true;
  1829. ldevices.push_back(nd);
  1830. }
  1831. }
  1832. }
  1833. }
  1834. }
  1835. }
  1836. }
  1837. // Update device list.
  1838. {
  1839. MutexLock lock(ea->device_lock);
  1840. bool different = false;
  1841. if (ea->devices.size() != ldevices.size()) {
  1842. different = true;
  1843. } else {
  1844. for (int i = 0; i < ea->devices.size(); i++) {
  1845. if (ea->devices[i].id != ldevices[i].id) {
  1846. different = true;
  1847. break;
  1848. }
  1849. }
  1850. }
  1851. if (different) {
  1852. ea->devices = ldevices;
  1853. ea->devices_changed.set();
  1854. }
  1855. }
  1856. uint64_t sleep = 200;
  1857. uint64_t wait = 3000000;
  1858. uint64_t time = OS::get_singleton()->get_ticks_usec();
  1859. while (OS::get_singleton()->get_ticks_usec() - time < wait) {
  1860. OS::get_singleton()->delay_usec(1000 * sleep);
  1861. if (ea->quit_request.is_set()) {
  1862. break;
  1863. }
  1864. }
  1865. }
  1866. }
  1867. #endif
  1868. Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) {
  1869. #ifdef MACOS_ENABLED
  1870. ERR_FAIL_INDEX_V(p_device, devices.size(), ERR_INVALID_PARAMETER);
  1871. String can_export_error;
  1872. bool can_export_missing_templates;
  1873. if (!can_export(p_preset, can_export_error, can_export_missing_templates)) {
  1874. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), can_export_error);
  1875. return ERR_UNCONFIGURED;
  1876. }
  1877. MutexLock lock(device_lock);
  1878. EditorProgress ep("run", vformat(TTR("Running on %s"), devices[p_device].name), 3);
  1879. String id = "tmpexport." + uitos(OS::get_singleton()->get_unix_time());
  1880. Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1881. ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + EditorPaths::get_singleton()->get_cache_dir() + "'.");
  1882. filesystem_da->make_dir_recursive(EditorPaths::get_singleton()->get_cache_dir().path_join(id));
  1883. String tmp_export_path = EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.ipa");
  1884. #define CLEANUP_AND_RETURN(m_err) \
  1885. { \
  1886. if (filesystem_da->change_dir(EditorPaths::get_singleton()->get_cache_dir().path_join(id)) == OK) { \
  1887. filesystem_da->erase_contents_recursive(); \
  1888. filesystem_da->change_dir(".."); \
  1889. filesystem_da->remove(id); \
  1890. } \
  1891. return m_err; \
  1892. } \
  1893. ((void)0)
  1894. Device dev = devices[p_device];
  1895. // Export before sending to device.
  1896. Error err = _export_project_helper(p_preset, true, tmp_export_path, p_debug_flags, dev.simulator, true);
  1897. if (err != OK) {
  1898. CLEANUP_AND_RETURN(err);
  1899. }
  1900. Vector<String> cmd_args_list;
  1901. String host = EDITOR_GET("network/debug/remote_host");
  1902. int remote_port = (int)EDITOR_GET("network/debug/remote_port");
  1903. if (p_debug_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
  1904. host = "localhost";
  1905. }
  1906. if (p_debug_flags & DEBUG_FLAG_DUMB_CLIENT) {
  1907. int port = EDITOR_GET("filesystem/file_server/port");
  1908. String passwd = EDITOR_GET("filesystem/file_server/password");
  1909. cmd_args_list.push_back("--remote-fs");
  1910. cmd_args_list.push_back(host + ":" + itos(port));
  1911. if (!passwd.is_empty()) {
  1912. cmd_args_list.push_back("--remote-fs-password");
  1913. cmd_args_list.push_back(passwd);
  1914. }
  1915. }
  1916. if (p_debug_flags & DEBUG_FLAG_REMOTE_DEBUG) {
  1917. cmd_args_list.push_back("--remote-debug");
  1918. cmd_args_list.push_back(get_debug_protocol() + host + ":" + String::num(remote_port));
  1919. List<String> breakpoints;
  1920. ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
  1921. if (breakpoints.size()) {
  1922. cmd_args_list.push_back("--breakpoints");
  1923. String bpoints;
  1924. for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
  1925. bpoints += E->get().replace(" ", "%20");
  1926. if (E->next()) {
  1927. bpoints += ",";
  1928. }
  1929. }
  1930. cmd_args_list.push_back(bpoints);
  1931. }
  1932. }
  1933. if (p_debug_flags & DEBUG_FLAG_VIEW_COLLISIONS) {
  1934. cmd_args_list.push_back("--debug-collisions");
  1935. }
  1936. if (p_debug_flags & DEBUG_FLAG_VIEW_NAVIGATION) {
  1937. cmd_args_list.push_back("--debug-navigation");
  1938. }
  1939. if (dev.simulator) {
  1940. // Deploy and run on simulator.
  1941. if (ep.step("Installing to simulator...", 3)) {
  1942. CLEANUP_AND_RETURN(ERR_SKIP);
  1943. } else {
  1944. List<String> args;
  1945. args.push_back("simctl");
  1946. args.push_back("install");
  1947. args.push_back(dev.id);
  1948. args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
  1949. String log;
  1950. int ec;
  1951. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  1952. if (err != OK) {
  1953. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start simctl executable."));
  1954. CLEANUP_AND_RETURN(err);
  1955. }
  1956. if (ec != 0) {
  1957. print_line("simctl install:\n" + log);
  1958. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation failed, see editor log for details."));
  1959. CLEANUP_AND_RETURN(ERR_UNCONFIGURED);
  1960. }
  1961. }
  1962. if (ep.step("Running on simulator...", 4)) {
  1963. CLEANUP_AND_RETURN(ERR_SKIP);
  1964. } else {
  1965. List<String> args;
  1966. args.push_back("simctl");
  1967. args.push_back("launch");
  1968. args.push_back("--terminate-running-process");
  1969. args.push_back(dev.id);
  1970. args.push_back(p_preset->get("application/bundle_identifier"));
  1971. for (const String &E : cmd_args_list) {
  1972. args.push_back(E);
  1973. }
  1974. String log;
  1975. int ec;
  1976. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  1977. if (err != OK) {
  1978. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start simctl executable."));
  1979. CLEANUP_AND_RETURN(err);
  1980. }
  1981. if (ec != 0) {
  1982. print_line("simctl launch:\n" + log);
  1983. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Running failed, see editor log for details."));
  1984. }
  1985. }
  1986. } else if (dev.use_ios_deploy) {
  1987. // Deploy and run on real device (via ios-deploy).
  1988. if (ep.step("Installing and running on device...", 4)) {
  1989. CLEANUP_AND_RETURN(ERR_SKIP);
  1990. } else {
  1991. List<String> args;
  1992. args.push_back("-u");
  1993. args.push_back("-I");
  1994. args.push_back("--id");
  1995. args.push_back(dev.id);
  1996. args.push_back("--justlaunch");
  1997. args.push_back("--bundle");
  1998. args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
  1999. String app_args;
  2000. for (const String &E : cmd_args_list) {
  2001. app_args += E + " ";
  2002. }
  2003. if (!app_args.is_empty()) {
  2004. args.push_back("--args");
  2005. args.push_back(app_args);
  2006. }
  2007. String idepl = EDITOR_GET("export/ios/ios_deploy");
  2008. if (idepl.is_empty()) {
  2009. idepl = "ios-deploy";
  2010. }
  2011. String log;
  2012. int ec;
  2013. err = OS::get_singleton()->execute(idepl, args, &log, &ec, true);
  2014. if (err != OK) {
  2015. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start ios-deploy executable."));
  2016. CLEANUP_AND_RETURN(err);
  2017. }
  2018. if (ec != 0) {
  2019. print_line("ios-deploy:\n" + log);
  2020. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation/running failed, see editor log for details."));
  2021. CLEANUP_AND_RETURN(ERR_UNCONFIGURED);
  2022. }
  2023. }
  2024. } else {
  2025. // Deploy and run on real device.
  2026. if (ep.step("Installing to device...", 3)) {
  2027. CLEANUP_AND_RETURN(ERR_SKIP);
  2028. } else {
  2029. List<String> args;
  2030. args.push_back("devicectl");
  2031. args.push_back("device");
  2032. args.push_back("install");
  2033. args.push_back("app");
  2034. args.push_back("-d");
  2035. args.push_back(dev.id);
  2036. args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
  2037. String log;
  2038. int ec;
  2039. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  2040. if (err != OK) {
  2041. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start device executable."));
  2042. CLEANUP_AND_RETURN(err);
  2043. }
  2044. if (ec != 0) {
  2045. print_line("device install:\n" + log);
  2046. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation failed, see editor log for details."));
  2047. CLEANUP_AND_RETURN(ERR_UNCONFIGURED);
  2048. }
  2049. }
  2050. if (ep.step("Running on device...", 4)) {
  2051. CLEANUP_AND_RETURN(ERR_SKIP);
  2052. } else {
  2053. List<String> args;
  2054. args.push_back("devicectl");
  2055. args.push_back("device");
  2056. args.push_back("process");
  2057. args.push_back("launch");
  2058. args.push_back("--terminate-existing");
  2059. args.push_back("-d");
  2060. args.push_back(dev.id);
  2061. args.push_back(p_preset->get("application/bundle_identifier"));
  2062. for (const String &E : cmd_args_list) {
  2063. args.push_back(E);
  2064. }
  2065. String log;
  2066. int ec;
  2067. err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true);
  2068. if (err != OK) {
  2069. add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start devicectl executable."));
  2070. CLEANUP_AND_RETURN(err);
  2071. }
  2072. if (ec != 0) {
  2073. print_line("devicectl launch:\n" + log);
  2074. add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Running failed, see editor log for details."));
  2075. }
  2076. }
  2077. }
  2078. CLEANUP_AND_RETURN(OK);
  2079. #undef CLEANUP_AND_RETURN
  2080. #else
  2081. return ERR_UNCONFIGURED;
  2082. #endif
  2083. }
  2084. EditorExportPlatformIOS::EditorExportPlatformIOS() {
  2085. if (EditorNode::get_singleton()) {
  2086. #ifdef MODULE_SVG_ENABLED
  2087. Ref<Image> img = memnew(Image);
  2088. const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
  2089. ImageLoaderSVG::create_image_from_string(img, _ios_logo_svg, EDSCALE, upsample, false);
  2090. logo = ImageTexture::create_from_image(img);
  2091. ImageLoaderSVG::create_image_from_string(img, _ios_run_icon_svg, EDSCALE, upsample, false);
  2092. run_icon = ImageTexture::create_from_image(img);
  2093. #endif
  2094. plugins_changed.set();
  2095. devices_changed.set();
  2096. #ifdef MACOS_ENABLED
  2097. check_for_changes_thread.start(_check_for_changes_poll_thread, this);
  2098. #endif
  2099. }
  2100. }
  2101. EditorExportPlatformIOS::~EditorExportPlatformIOS() {
  2102. #ifdef MACOS_ENABLED
  2103. quit_request.set();
  2104. if (check_for_changes_thread.is_started()) {
  2105. check_for_changes_thread.wait_to_finish();
  2106. }
  2107. #endif
  2108. }