export_plugin.cpp 100 KB

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