export_plugin.cpp 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  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 "core/string/translation.h"
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_scale.h"
  34. #include "platform/ios/logo_svg.gen.h"
  35. #include "modules/modules_enabled.gen.h" // For svg.
  36. #ifdef MODULE_SVG_ENABLED
  37. #include "modules/svg/image_loader_svg.h"
  38. #endif
  39. void EditorExportPlatformIOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
  40. // Vulkan and OpenGL ES 3.0 both mandate ETC2 support.
  41. r_features->push_back("etc2");
  42. r_features->push_back("astc");
  43. Vector<String> architectures = _get_preset_architectures(p_preset);
  44. for (int i = 0; i < architectures.size(); ++i) {
  45. r_features->push_back(architectures[i]);
  46. }
  47. }
  48. Vector<EditorExportPlatformIOS::ExportArchitecture> EditorExportPlatformIOS::_get_supported_architectures() const {
  49. Vector<ExportArchitecture> archs;
  50. archs.push_back(ExportArchitecture("arm64", true));
  51. return archs;
  52. }
  53. struct IconInfo {
  54. const char *preset_key;
  55. const char *idiom;
  56. const char *export_name;
  57. const char *actual_size_side;
  58. const char *scale;
  59. const char *unscaled_size;
  60. const bool force_opaque;
  61. };
  62. static const IconInfo icon_infos[] = {
  63. // Home screen on iPhone
  64. { PNAME("icons/iphone_120x120"), "iphone", "Icon-120.png", "120", "2x", "60x60", false },
  65. { PNAME("icons/iphone_120x120"), "iphone", "Icon-120.png", "120", "3x", "40x40", false },
  66. { PNAME("icons/iphone_180x180"), "iphone", "Icon-180.png", "180", "3x", "60x60", false },
  67. // Home screen on iPad
  68. { PNAME("icons/ipad_76x76"), "ipad", "Icon-76.png", "76", "1x", "76x76", false },
  69. { PNAME("icons/ipad_152x152"), "ipad", "Icon-152.png", "152", "2x", "76x76", false },
  70. { PNAME("icons/ipad_167x167"), "ipad", "Icon-167.png", "167", "2x", "83.5x83.5", false },
  71. // App Store
  72. { PNAME("icons/app_store_1024x1024"), "ios-marketing", "Icon-1024.png", "1024", "1x", "1024x1024", true },
  73. // Spotlight
  74. { PNAME("icons/spotlight_40x40"), "ipad", "Icon-40.png", "40", "1x", "40x40", false },
  75. { PNAME("icons/spotlight_80x80"), "iphone", "Icon-80.png", "80", "2x", "40x40", false },
  76. { PNAME("icons/spotlight_80x80"), "ipad", "Icon-80.png", "80", "2x", "40x40", false },
  77. // Settings
  78. { PNAME("icons/settings_58x58"), "iphone", "Icon-58.png", "58", "2x", "29x29", false },
  79. { PNAME("icons/settings_58x58"), "ipad", "Icon-58.png", "58", "2x", "29x29", false },
  80. { PNAME("icons/settings_87x87"), "iphone", "Icon-87.png", "87", "3x", "29x29", false },
  81. // Notification
  82. { PNAME("icons/notification_40x40"), "iphone", "Icon-40.png", "40", "2x", "20x20", false },
  83. { PNAME("icons/notification_40x40"), "ipad", "Icon-40.png", "40", "2x", "20x20", false },
  84. { PNAME("icons/notification_60x60"), "iphone", "Icon-60.png", "60", "3x", "20x20", false }
  85. };
  86. struct LoadingScreenInfo {
  87. const char *preset_key;
  88. const char *export_name;
  89. int width = 0;
  90. int height = 0;
  91. bool rotate = false;
  92. };
  93. static const LoadingScreenInfo loading_screen_infos[] = {
  94. { PNAME("landscape_launch_screens/iphone_2436x1125"), "Default-Landscape-X.png", 2436, 1125, false },
  95. { PNAME("landscape_launch_screens/iphone_2208x1242"), "[email protected]", 2208, 1242, false },
  96. { PNAME("landscape_launch_screens/ipad_1024x768"), "Default-Landscape.png", 1024, 768, false },
  97. { PNAME("landscape_launch_screens/ipad_2048x1536"), "[email protected]", 2048, 1536, false },
  98. { PNAME("portrait_launch_screens/iphone_640x960"), "[email protected]", 640, 960, true },
  99. { PNAME("portrait_launch_screens/iphone_640x1136"), "[email protected]", 640, 1136, true },
  100. { PNAME("portrait_launch_screens/iphone_750x1334"), "[email protected]", 750, 1334, true },
  101. { PNAME("portrait_launch_screens/iphone_1125x2436"), "Default-Portrait-X.png", 1125, 2436, true },
  102. { PNAME("portrait_launch_screens/ipad_768x1024"), "Default-Portrait.png", 768, 1024, true },
  103. { PNAME("portrait_launch_screens/ipad_1536x2048"), "[email protected]", 1536, 2048, true },
  104. { PNAME("portrait_launch_screens/iphone_1242x2208"), "[email protected]", 1242, 2208, true }
  105. };
  106. void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options) {
  107. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  108. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  109. Vector<ExportArchitecture> architectures = _get_supported_architectures();
  110. for (int i = 0; i < architectures.size(); ++i) {
  111. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("architectures"), architectures[i].name)), architectures[i].is_default));
  112. }
  113. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_store_team_id"), ""));
  114. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_debug"), ""));
  115. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Developer"), ""));
  116. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_debug", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 1));
  117. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_release"), ""));
  118. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Distribution"), ""));
  119. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_release", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 0));
  120. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/targeted_device_family", PROPERTY_HINT_ENUM, "iPhone,iPad,iPhone & iPad"), 2));
  121. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), ""));
  122. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  123. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  124. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  125. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
  126. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/launch_screens_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
  127. Vector<PluginConfigIOS> found_plugins = get_plugins();
  128. for (int i = 0; i < found_plugins.size(); i++) {
  129. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("plugins"), found_plugins[i].name)), false));
  130. }
  131. HashSet<String> plist_keys;
  132. for (int i = 0; i < found_plugins.size(); i++) {
  133. // Editable plugin plist values
  134. PluginConfigIOS plugin = found_plugins[i];
  135. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  136. switch (E.value.type) {
  137. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  138. String preset_name = "plugins_plist/" + E.key;
  139. if (!plist_keys.has(preset_name)) {
  140. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, preset_name), E.value.value));
  141. plist_keys.insert(preset_name);
  142. }
  143. } break;
  144. default:
  145. continue;
  146. }
  147. }
  148. }
  149. plugins_changed.clear();
  150. plugins = found_plugins;
  151. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/access_wifi"), false));
  152. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/push_notifications"), false));
  153. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_files_app"), false));
  154. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_itunes_sharing"), false));
  155. 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"), ""));
  156. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  157. 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"), ""));
  158. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  159. 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"), ""));
  160. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photolibrary_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  161. HashSet<String> used_names;
  162. for (uint64_t i = 0; i < sizeof(icon_infos) / sizeof(icon_infos[0]); ++i) {
  163. if (!used_names.has(icon_infos[i].preset_key)) {
  164. used_names.insert(icon_infos[i].preset_key);
  165. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, icon_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  166. }
  167. }
  168. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_launch_screen_storyboard"), false));
  169. 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));
  170. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@2x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  171. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@3x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  172. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_custom_bg_color"), false));
  173. r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "storyboard/custom_bg_color"), Color()));
  174. for (uint64_t i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  175. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, loading_screen_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  176. }
  177. }
  178. void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug) {
  179. static const String export_method_string[] = {
  180. "app-store",
  181. "development",
  182. "ad-hoc",
  183. "enterprise"
  184. };
  185. static const String storyboard_image_scale_mode[] = {
  186. "center",
  187. "scaleAspectFit",
  188. "scaleAspectFill",
  189. "scaleToFill"
  190. };
  191. 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");
  192. 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");
  193. bool dbg_manual = !p_preset->get("application/provisioning_profile_uuid_debug").operator String().is_empty() || (dbg_sign_id != "iPhone Developer");
  194. bool rel_manual = !p_preset->get("application/provisioning_profile_uuid_release").operator String().is_empty() || (rel_sign_id != "iPhone Distribution");
  195. String str;
  196. String strnew;
  197. str.parse_utf8((const char *)pfile.ptr(), pfile.size());
  198. Vector<String> lines = str.split("\n");
  199. for (int i = 0; i < lines.size(); i++) {
  200. if (lines[i].find("$binary") != -1) {
  201. strnew += lines[i].replace("$binary", p_config.binary_name) + "\n";
  202. } else if (lines[i].find("$modules_buildfile") != -1) {
  203. strnew += lines[i].replace("$modules_buildfile", p_config.modules_buildfile) + "\n";
  204. } else if (lines[i].find("$modules_fileref") != -1) {
  205. strnew += lines[i].replace("$modules_fileref", p_config.modules_fileref) + "\n";
  206. } else if (lines[i].find("$modules_buildphase") != -1) {
  207. strnew += lines[i].replace("$modules_buildphase", p_config.modules_buildphase) + "\n";
  208. } else if (lines[i].find("$modules_buildgrp") != -1) {
  209. strnew += lines[i].replace("$modules_buildgrp", p_config.modules_buildgrp) + "\n";
  210. } else if (lines[i].find("$name") != -1) {
  211. strnew += lines[i].replace("$name", p_config.pkg_name) + "\n";
  212. } else if (lines[i].find("$bundle_identifier") != -1) {
  213. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  214. } else if (lines[i].find("$short_version") != -1) {
  215. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  216. } else if (lines[i].find("$version") != -1) {
  217. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  218. } else if (lines[i].find("$signature") != -1) {
  219. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  220. } else if (lines[i].find("$team_id") != -1) {
  221. strnew += lines[i].replace("$team_id", p_preset->get("application/app_store_team_id")) + "\n";
  222. } else if (lines[i].find("$default_build_config") != -1) {
  223. strnew += lines[i].replace("$default_build_config", p_debug ? "Debug" : "Release") + "\n";
  224. } else if (lines[i].find("$export_method") != -1) {
  225. int export_method = p_preset->get(p_debug ? "application/export_method_debug" : "application/export_method_release");
  226. strnew += lines[i].replace("$export_method", export_method_string[export_method]) + "\n";
  227. } else if (lines[i].find("$provisioning_profile_uuid_release") != -1) {
  228. strnew += lines[i].replace("$provisioning_profile_uuid_release", p_preset->get("application/provisioning_profile_uuid_release")) + "\n";
  229. } else if (lines[i].find("$provisioning_profile_uuid_debug") != -1) {
  230. strnew += lines[i].replace("$provisioning_profile_uuid_debug", p_preset->get("application/provisioning_profile_uuid_debug")) + "\n";
  231. } else if (lines[i].find("$code_sign_style_debug") != -1) {
  232. if (dbg_manual) {
  233. strnew += lines[i].replace("$code_sign_style_debug", "Manual") + "\n";
  234. } else {
  235. strnew += lines[i].replace("$code_sign_style_debug", "Automatic") + "\n";
  236. }
  237. } else if (lines[i].find("$code_sign_style_release") != -1) {
  238. if (rel_manual) {
  239. strnew += lines[i].replace("$code_sign_style_release", "Manual") + "\n";
  240. } else {
  241. strnew += lines[i].replace("$code_sign_style_release", "Automatic") + "\n";
  242. }
  243. } else if (lines[i].find("$provisioning_profile_uuid") != -1) {
  244. String uuid = p_debug ? p_preset->get("application/provisioning_profile_uuid_debug") : p_preset->get("application/provisioning_profile_uuid_release");
  245. strnew += lines[i].replace("$provisioning_profile_uuid", uuid) + "\n";
  246. } else if (lines[i].find("$code_sign_identity_debug") != -1) {
  247. strnew += lines[i].replace("$code_sign_identity_debug", dbg_sign_id) + "\n";
  248. } else if (lines[i].find("$code_sign_identity_release") != -1) {
  249. strnew += lines[i].replace("$code_sign_identity_release", rel_sign_id) + "\n";
  250. } else if (lines[i].find("$additional_plist_content") != -1) {
  251. strnew += lines[i].replace("$additional_plist_content", p_config.plist_content) + "\n";
  252. } else if (lines[i].find("$godot_archs") != -1) {
  253. strnew += lines[i].replace("$godot_archs", p_config.architectures) + "\n";
  254. } else if (lines[i].find("$linker_flags") != -1) {
  255. strnew += lines[i].replace("$linker_flags", p_config.linker_flags) + "\n";
  256. } else if (lines[i].find("$targeted_device_family") != -1) {
  257. String xcode_value;
  258. switch ((int)p_preset->get("application/targeted_device_family")) {
  259. case 0: // iPhone
  260. xcode_value = "1";
  261. break;
  262. case 1: // iPad
  263. xcode_value = "2";
  264. break;
  265. case 2: // iPhone & iPad
  266. xcode_value = "1,2";
  267. break;
  268. }
  269. strnew += lines[i].replace("$targeted_device_family", xcode_value) + "\n";
  270. } else if (lines[i].find("$cpp_code") != -1) {
  271. strnew += lines[i].replace("$cpp_code", p_config.cpp_code) + "\n";
  272. } else if (lines[i].find("$docs_in_place") != -1) {
  273. strnew += lines[i].replace("$docs_in_place", ((bool)p_preset->get("user_data/accessible_from_files_app")) ? "<true/>" : "<false/>") + "\n";
  274. } else if (lines[i].find("$docs_sharing") != -1) {
  275. strnew += lines[i].replace("$docs_sharing", ((bool)p_preset->get("user_data/accessible_from_itunes_sharing")) ? "<true/>" : "<false/>") + "\n";
  276. } else if (lines[i].find("$entitlements_push_notifications") != -1) {
  277. bool is_on = p_preset->get("capabilities/push_notifications");
  278. strnew += lines[i].replace("$entitlements_push_notifications", is_on ? "<key>aps-environment</key><string>development</string>" : "") + "\n";
  279. } else if (lines[i].find("$required_device_capabilities") != -1) {
  280. String capabilities;
  281. // I've removed armv7 as we can run on 64bit only devices
  282. // Note that capabilities listed here are requirements for the app to be installed.
  283. // They don't enable anything.
  284. Vector<String> capabilities_list = p_config.capabilities;
  285. if ((bool)p_preset->get("capabilities/access_wifi") && !capabilities_list.has("wifi")) {
  286. capabilities_list.push_back("wifi");
  287. }
  288. for (int idx = 0; idx < capabilities_list.size(); idx++) {
  289. capabilities += "<string>" + capabilities_list[idx] + "</string>\n";
  290. }
  291. strnew += lines[i].replace("$required_device_capabilities", capabilities);
  292. } else if (lines[i].find("$interface_orientations") != -1) {
  293. String orientations;
  294. const DisplayServer::ScreenOrientation screen_orientation =
  295. DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation")));
  296. switch (screen_orientation) {
  297. case DisplayServer::SCREEN_LANDSCAPE:
  298. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  299. break;
  300. case DisplayServer::SCREEN_PORTRAIT:
  301. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  302. break;
  303. case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
  304. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  305. break;
  306. case DisplayServer::SCREEN_REVERSE_PORTRAIT:
  307. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  308. break;
  309. case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
  310. // Allow both landscape orientations depending on sensor direction.
  311. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  312. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  313. break;
  314. case DisplayServer::SCREEN_SENSOR_PORTRAIT:
  315. // Allow both portrait orientations depending on sensor direction.
  316. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  317. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  318. break;
  319. case DisplayServer::SCREEN_SENSOR:
  320. // Allow all screen orientations depending on sensor direction.
  321. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  322. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  323. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  324. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  325. break;
  326. }
  327. strnew += lines[i].replace("$interface_orientations", orientations);
  328. } else if (lines[i].find("$camera_usage_description") != -1) {
  329. String description = p_preset->get("privacy/camera_usage_description");
  330. strnew += lines[i].replace("$camera_usage_description", description) + "\n";
  331. } else if (lines[i].find("$microphone_usage_description") != -1) {
  332. String description = p_preset->get("privacy/microphone_usage_description");
  333. strnew += lines[i].replace("$microphone_usage_description", description) + "\n";
  334. } else if (lines[i].find("$photolibrary_usage_description") != -1) {
  335. String description = p_preset->get("privacy/photolibrary_usage_description");
  336. strnew += lines[i].replace("$photolibrary_usage_description", description) + "\n";
  337. } else if (lines[i].find("$plist_launch_screen_name") != -1) {
  338. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  339. String value = is_on ? "<key>UILaunchStoryboardName</key>\n<string>Launch Screen</string>" : "";
  340. strnew += lines[i].replace("$plist_launch_screen_name", value) + "\n";
  341. } else if (lines[i].find("$pbx_launch_screen_file_reference") != -1) {
  342. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  343. String value = is_on ? "90DD2D9D24B36E8000717FE1 = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = \"Launch Screen.storyboard\"; sourceTree = \"<group>\"; };" : "";
  344. strnew += lines[i].replace("$pbx_launch_screen_file_reference", value) + "\n";
  345. } else if (lines[i].find("$pbx_launch_screen_copy_files") != -1) {
  346. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  347. String value = is_on ? "90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */," : "";
  348. strnew += lines[i].replace("$pbx_launch_screen_copy_files", value) + "\n";
  349. } else if (lines[i].find("$pbx_launch_screen_build_phase") != -1) {
  350. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  351. String value = is_on ? "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */," : "";
  352. strnew += lines[i].replace("$pbx_launch_screen_build_phase", value) + "\n";
  353. } else if (lines[i].find("$pbx_launch_screen_build_reference") != -1) {
  354. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  355. String value = is_on ? "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */; };" : "";
  356. strnew += lines[i].replace("$pbx_launch_screen_build_reference", value) + "\n";
  357. } else if (lines[i].find("$pbx_launch_image_usage_setting") != -1) {
  358. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  359. String value = is_on ? "" : "ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;";
  360. strnew += lines[i].replace("$pbx_launch_image_usage_setting", value) + "\n";
  361. } else if (lines[i].find("$launch_screen_image_mode") != -1) {
  362. int image_scale_mode = p_preset->get("storyboard/image_scale_mode");
  363. String value;
  364. switch (image_scale_mode) {
  365. case 0: {
  366. String logo_path = GLOBAL_GET("application/boot_splash/image");
  367. bool is_on = GLOBAL_GET("application/boot_splash/fullsize");
  368. // If custom logo is not specified, Godot does not scale default one, so we should do the same.
  369. value = (is_on && logo_path.length() > 0) ? "scaleAspectFit" : "center";
  370. } break;
  371. default: {
  372. value = storyboard_image_scale_mode[image_scale_mode - 1];
  373. }
  374. }
  375. strnew += lines[i].replace("$launch_screen_image_mode", value) + "\n";
  376. } else if (lines[i].find("$launch_screen_background_color") != -1) {
  377. bool use_custom = p_preset->get("storyboard/use_custom_bg_color");
  378. Color color = use_custom ? p_preset->get("storyboard/custom_bg_color") : GLOBAL_GET("application/boot_splash/bg_color");
  379. const String value_format = "red=\"$red\" green=\"$green\" blue=\"$blue\" alpha=\"$alpha\"";
  380. Dictionary value_dictionary;
  381. value_dictionary["red"] = color.r;
  382. value_dictionary["green"] = color.g;
  383. value_dictionary["blue"] = color.b;
  384. value_dictionary["alpha"] = color.a;
  385. String value = value_format.format(value_dictionary, "$_");
  386. strnew += lines[i].replace("$launch_screen_background_color", value) + "\n";
  387. } else if (lines[i].find("$pbx_locale_file_reference") != -1) {
  388. String locale_files;
  389. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  390. if (translations.size() > 0) {
  391. HashSet<String> languages;
  392. for (const String &E : translations) {
  393. Ref<Translation> tr = ResourceLoader::load(E);
  394. if (tr.is_valid() && tr->get_locale() != "en") {
  395. languages.insert(tr->get_locale());
  396. }
  397. }
  398. int index = 0;
  399. for (const String &lang : languages) {
  400. 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";
  401. index++;
  402. }
  403. }
  404. strnew += lines[i].replace("$pbx_locale_file_reference", locale_files);
  405. } else if (lines[i].find("$pbx_locale_build_reference") != -1) {
  406. String locale_files;
  407. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  408. if (translations.size() > 0) {
  409. HashSet<String> languages;
  410. for (const String &E : translations) {
  411. Ref<Translation> tr = ResourceLoader::load(E);
  412. if (tr.is_valid() && tr->get_locale() != "en") {
  413. languages.insert(tr->get_locale());
  414. }
  415. }
  416. int index = 0;
  417. for (const String &lang : languages) {
  418. locale_files += "D0BCFE4518AEBDA2004A" + itos(index).pad_zeros(4) + " /* " + lang + " */,\n";
  419. index++;
  420. }
  421. }
  422. strnew += lines[i].replace("$pbx_locale_build_reference", locale_files);
  423. } else if (lines[i].find("$swift_runtime_migration") != -1) {
  424. String value = !p_config.use_swift_runtime ? "" : "LastSwiftMigration = 1250;";
  425. strnew += lines[i].replace("$swift_runtime_migration", value) + "\n";
  426. } else if (lines[i].find("$swift_runtime_build_settings") != -1) {
  427. String value = !p_config.use_swift_runtime ? "" : R"(
  428. CLANG_ENABLE_MODULES = YES;
  429. SWIFT_OBJC_BRIDGING_HEADER = "$binary/dummy.h";
  430. SWIFT_VERSION = 5.0;
  431. )";
  432. value = value.replace("$binary", p_config.binary_name);
  433. strnew += lines[i].replace("$swift_runtime_build_settings", value) + "\n";
  434. } else if (lines[i].find("$swift_runtime_fileref") != -1) {
  435. String value = !p_config.use_swift_runtime ? "" : R"(
  436. 90B4C2AA2680BC560039117A /* dummy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "dummy.h"; sourceTree = "<group>"; };
  437. 90B4C2B52680C7E90039117A /* dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "dummy.swift"; sourceTree = "<group>"; };
  438. )";
  439. strnew += lines[i].replace("$swift_runtime_fileref", value) + "\n";
  440. } else if (lines[i].find("$swift_runtime_binary_files") != -1) {
  441. String value = !p_config.use_swift_runtime ? "" : R"(
  442. 90B4C2AA2680BC560039117A /* dummy.h */,
  443. 90B4C2B52680C7E90039117A /* dummy.swift */,
  444. )";
  445. strnew += lines[i].replace("$swift_runtime_binary_files", value) + "\n";
  446. } else if (lines[i].find("$swift_runtime_buildfile") != -1) {
  447. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B4C2B52680C7E90039117A /* dummy.swift */; };";
  448. strnew += lines[i].replace("$swift_runtime_buildfile", value) + "\n";
  449. } else if (lines[i].find("$swift_runtime_build_phase") != -1) {
  450. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift */,";
  451. strnew += lines[i].replace("$swift_runtime_build_phase", value) + "\n";
  452. } else {
  453. strnew += lines[i] + "\n";
  454. }
  455. }
  456. // !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...
  457. // should apply the same fix in our macOS export.
  458. CharString cs = strnew.utf8();
  459. pfile.resize(cs.size() - 1);
  460. for (int i = 0; i < cs.size() - 1; i++) {
  461. pfile.write[i] = cs[i];
  462. }
  463. }
  464. String EditorExportPlatformIOS::_get_additional_plist_content() {
  465. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  466. String result;
  467. for (int i = 0; i < export_plugins.size(); ++i) {
  468. result += export_plugins[i]->get_ios_plist_content();
  469. }
  470. return result;
  471. }
  472. String EditorExportPlatformIOS::_get_linker_flags() {
  473. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  474. String result;
  475. for (int i = 0; i < export_plugins.size(); ++i) {
  476. String flags = export_plugins[i]->get_ios_linker_flags();
  477. if (flags.length() == 0) {
  478. continue;
  479. }
  480. if (result.length() > 0) {
  481. result += ' ';
  482. }
  483. result += flags;
  484. }
  485. // the flags will be enclosed in quotes, so need to escape them
  486. return result.replace("\"", "\\\"");
  487. }
  488. String EditorExportPlatformIOS::_get_cpp_code() {
  489. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  490. String result;
  491. for (int i = 0; i < export_plugins.size(); ++i) {
  492. result += export_plugins[i]->get_ios_cpp_code();
  493. }
  494. return result;
  495. }
  496. void EditorExportPlatformIOS::_blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot) {
  497. ERR_FAIL_COND(p_dst.is_null());
  498. ERR_FAIL_COND(p_src.is_null());
  499. int sw = p_rot ? p_src->get_height() : p_src->get_width();
  500. int sh = p_rot ? p_src->get_width() : p_src->get_height();
  501. int x_pos = (p_dst->get_width() - sw) / 2;
  502. int y_pos = (p_dst->get_height() - sh) / 2;
  503. int xs = (x_pos >= 0) ? 0 : -x_pos;
  504. int ys = (y_pos >= 0) ? 0 : -y_pos;
  505. if (sw + x_pos > p_dst->get_width()) {
  506. sw = p_dst->get_width() - x_pos;
  507. }
  508. if (sh + y_pos > p_dst->get_height()) {
  509. sh = p_dst->get_height() - y_pos;
  510. }
  511. for (int y = ys; y < sh; y++) {
  512. for (int x = xs; x < sw; x++) {
  513. Color sc = p_rot ? p_src->get_pixel(p_src->get_width() - y - 1, x) : p_src->get_pixel(x, y);
  514. Color dc = p_dst->get_pixel(x_pos + x, y_pos + y);
  515. dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r);
  516. dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g);
  517. dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b);
  518. dc.a = (double)(sc.a + dc.a * (1.0 - sc.a));
  519. p_dst->set_pixel(x_pos + x, y_pos + y, dc);
  520. }
  521. }
  522. }
  523. Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
  524. String json_description = "{\"images\":[";
  525. String sizes;
  526. Ref<DirAccess> da = DirAccess::open(p_iconset_dir);
  527. ERR_FAIL_COND_V_MSG(da.is_null(), ERR_CANT_OPEN, "Cannot open directory '" + p_iconset_dir + "'.");
  528. Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
  529. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  530. IconInfo info = icon_infos[i];
  531. int side_size = String(info.actual_size_side).to_int();
  532. String icon_path = p_preset->get(info.preset_key);
  533. if (icon_path.length() == 0) {
  534. // Resize main app icon
  535. icon_path = GLOBAL_GET("application/config/icon");
  536. Ref<Image> img = memnew(Image);
  537. Error err = ImageLoader::load_image(icon_path, img);
  538. if (err != OK) {
  539. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  540. return ERR_UNCONFIGURED;
  541. } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  542. add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
  543. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  544. Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
  545. new_img->fill(boot_bg_color);
  546. _blend_and_rotate(new_img, img, false);
  547. err = new_img->save_png(p_iconset_dir + info.export_name);
  548. } else {
  549. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  550. err = img->save_png(p_iconset_dir + info.export_name);
  551. }
  552. if (err) {
  553. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  554. return err;
  555. }
  556. } else {
  557. // Load custom icon and resize if required
  558. Ref<Image> img = memnew(Image);
  559. Error err = ImageLoader::load_image(icon_path, img);
  560. if (err != OK) {
  561. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  562. return ERR_UNCONFIGURED;
  563. } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  564. add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
  565. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  566. Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
  567. new_img->fill(boot_bg_color);
  568. _blend_and_rotate(new_img, img, false);
  569. err = new_img->save_png(p_iconset_dir + info.export_name);
  570. } else if (img->get_width() != side_size || img->get_height() != side_size) {
  571. 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)));
  572. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  573. err = img->save_png(p_iconset_dir + info.export_name);
  574. } else {
  575. err = da->copy(icon_path, p_iconset_dir + info.export_name);
  576. }
  577. if (err) {
  578. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  579. return err;
  580. }
  581. }
  582. sizes += String(info.actual_size_side) + "\n";
  583. if (i > 0) {
  584. json_description += ",";
  585. }
  586. json_description += String("{");
  587. json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
  588. json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
  589. json_description += String("\"scale\":") + "\"" + info.scale + "\",";
  590. json_description += String("\"filename\":") + "\"" + info.export_name + "\"";
  591. json_description += String("}");
  592. }
  593. json_description += "]}";
  594. Ref<FileAccess> json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
  595. ERR_FAIL_COND_V(json_file.is_null(), ERR_CANT_CREATE);
  596. CharString json_utf8 = json_description.utf8();
  597. json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
  598. Ref<FileAccess> sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
  599. ERR_FAIL_COND_V(sizes_file.is_null(), ERR_CANT_CREATE);
  600. CharString sizes_utf8 = sizes.utf8();
  601. sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
  602. return OK;
  603. }
  604. Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  605. const String custom_launch_image_2x = p_preset->get("storyboard/custom_image@2x");
  606. const String custom_launch_image_3x = p_preset->get("storyboard/custom_image@3x");
  607. if (custom_launch_image_2x.length() > 0 && custom_launch_image_3x.length() > 0) {
  608. Ref<Image> image;
  609. String image_path = p_dest_dir.path_join("[email protected]");
  610. image.instantiate();
  611. Error err = ImageLoader::load_image(custom_launch_image_2x, image);
  612. if (err) {
  613. image.unref();
  614. return err;
  615. }
  616. if (image->save_png(image_path) != OK) {
  617. return ERR_FILE_CANT_WRITE;
  618. }
  619. image.unref();
  620. image_path = p_dest_dir.path_join("[email protected]");
  621. image.instantiate();
  622. err = ImageLoader::load_image(custom_launch_image_3x, image);
  623. if (err) {
  624. image.unref();
  625. return err;
  626. }
  627. if (image->save_png(image_path) != OK) {
  628. return ERR_FILE_CANT_WRITE;
  629. }
  630. } else {
  631. Ref<Image> splash;
  632. const String splash_path = GLOBAL_GET("application/boot_splash/image");
  633. if (!splash_path.is_empty()) {
  634. splash.instantiate();
  635. const Error err = ImageLoader::load_image(splash_path, splash);
  636. if (err) {
  637. splash.unref();
  638. }
  639. }
  640. if (splash.is_null()) {
  641. splash = Ref<Image>(memnew(Image(boot_splash_png)));
  642. }
  643. // Using same image for both @2x and @3x
  644. // because Godot's own boot logo uses single image for all resolutions.
  645. // Also not using @1x image, because devices using this image variant
  646. // are not supported by iOS 9, which is minimal target.
  647. const String splash_png_path_2x = p_dest_dir.path_join("[email protected]");
  648. const String splash_png_path_3x = p_dest_dir.path_join("[email protected]");
  649. if (splash->save_png(splash_png_path_2x) != OK) {
  650. return ERR_FILE_CANT_WRITE;
  651. }
  652. if (splash->save_png(splash_png_path_3x) != OK) {
  653. return ERR_FILE_CANT_WRITE;
  654. }
  655. }
  656. return OK;
  657. }
  658. Error EditorExportPlatformIOS::_export_loading_screen_images(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  659. Ref<DirAccess> da = DirAccess::open(p_dest_dir);
  660. ERR_FAIL_COND_V_MSG(da.is_null(), ERR_CANT_OPEN, "Cannot open directory '" + p_dest_dir + "'.");
  661. for (uint64_t i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  662. LoadingScreenInfo info = loading_screen_infos[i];
  663. String loading_screen_file = p_preset->get(info.preset_key);
  664. Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
  665. String boot_logo_path = GLOBAL_GET("application/boot_splash/image");
  666. bool boot_logo_scale = GLOBAL_GET("application/boot_splash/fullsize");
  667. if (loading_screen_file.size() > 0) {
  668. // Load custom loading screens, and resize if required.
  669. Ref<Image> img = memnew(Image);
  670. Error err = ImageLoader::load_image(loading_screen_file, img);
  671. if (err != OK) {
  672. ERR_PRINT("Invalid loading screen (" + String(info.preset_key) + "): '" + loading_screen_file + "'.");
  673. return ERR_UNCONFIGURED;
  674. }
  675. if (img->get_width() != info.width || img->get_height() != info.height) {
  676. 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) + ".");
  677. float aspect_ratio = (float)img->get_width() / (float)img->get_height();
  678. if (boot_logo_scale) {
  679. if (info.height * aspect_ratio <= info.width) {
  680. img->resize(info.height * aspect_ratio, info.height, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  681. } else {
  682. img->resize(info.width, info.width / aspect_ratio, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  683. }
  684. }
  685. Ref<Image> new_img = Image::create_empty(info.width, info.height, false, Image::FORMAT_RGBA8);
  686. new_img->fill(boot_bg_color);
  687. _blend_and_rotate(new_img, img, false);
  688. err = new_img->save_png(p_dest_dir + info.export_name);
  689. } else {
  690. err = da->copy(loading_screen_file, p_dest_dir + info.export_name);
  691. }
  692. if (err) {
  693. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from path '" + loading_screen_file + "'.";
  694. ERR_PRINT(err_str.utf8().get_data());
  695. return err;
  696. }
  697. } else {
  698. // Generate loading screen from the splash screen
  699. Ref<Image> img = Image::create_empty(info.width, info.height, false, Image::FORMAT_RGBA8);
  700. img->fill(boot_bg_color);
  701. Ref<Image> img_bs;
  702. if (boot_logo_path.length() > 0) {
  703. img_bs = Ref<Image>(memnew(Image));
  704. ImageLoader::load_image(boot_logo_path, img_bs);
  705. }
  706. if (!img_bs.is_valid()) {
  707. img_bs = Ref<Image>(memnew(Image(boot_splash_png)));
  708. }
  709. if (img_bs.is_valid()) {
  710. float aspect_ratio = (float)img_bs->get_width() / (float)img_bs->get_height();
  711. if (info.rotate) {
  712. if (boot_logo_scale) {
  713. if (info.width * aspect_ratio <= info.height) {
  714. img_bs->resize(info.width * aspect_ratio, info.width, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  715. } else {
  716. img_bs->resize(info.height, info.height / aspect_ratio, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  717. }
  718. }
  719. } else {
  720. if (boot_logo_scale) {
  721. if (info.height * aspect_ratio <= info.width) {
  722. img_bs->resize(info.height * aspect_ratio, info.height, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  723. } else {
  724. img_bs->resize(info.width, info.width / aspect_ratio, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  725. }
  726. }
  727. }
  728. _blend_and_rotate(img, img_bs, info.rotate);
  729. }
  730. Error err = img->save_png(p_dest_dir + info.export_name);
  731. if (err) {
  732. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from splash screen.";
  733. WARN_PRINT(err_str.utf8().get_data());
  734. }
  735. }
  736. }
  737. return OK;
  738. }
  739. Error EditorExportPlatformIOS::_walk_dir_recursive(Ref<DirAccess> &p_da, FileHandler p_handler, void *p_userdata) {
  740. Vector<String> dirs;
  741. String current_dir = p_da->get_current_dir();
  742. p_da->list_dir_begin();
  743. String path = p_da->get_next();
  744. while (!path.is_empty()) {
  745. if (p_da->current_is_dir()) {
  746. if (path != "." && path != "..") {
  747. dirs.push_back(path);
  748. }
  749. } else {
  750. Error err = p_handler(current_dir.path_join(path), p_userdata);
  751. if (err) {
  752. p_da->list_dir_end();
  753. return err;
  754. }
  755. }
  756. path = p_da->get_next();
  757. }
  758. p_da->list_dir_end();
  759. for (int i = 0; i < dirs.size(); ++i) {
  760. String dir = dirs[i];
  761. p_da->change_dir(dir);
  762. Error err = _walk_dir_recursive(p_da, p_handler, p_userdata);
  763. p_da->change_dir("..");
  764. if (err) {
  765. return err;
  766. }
  767. }
  768. return OK;
  769. }
  770. struct CodesignData {
  771. const Ref<EditorExportPreset> &preset;
  772. bool debug = false;
  773. CodesignData(const Ref<EditorExportPreset> &p_preset, bool p_debug) :
  774. preset(p_preset),
  775. debug(p_debug) {
  776. }
  777. };
  778. Error EditorExportPlatformIOS::_codesign(String p_file, void *p_userdata) {
  779. if (p_file.ends_with(".dylib")) {
  780. CodesignData *data = static_cast<CodesignData *>(p_userdata);
  781. print_line(String("Signing ") + p_file);
  782. String sign_id;
  783. if (data->debug) {
  784. sign_id = data->preset->get("application/code_sign_identity_debug").operator String().is_empty() ? "iPhone Developer" : data->preset->get("application/code_sign_identity_debug");
  785. } else {
  786. sign_id = data->preset->get("application/code_sign_identity_release").operator String().is_empty() ? "iPhone Distribution" : data->preset->get("application/code_sign_identity_release");
  787. }
  788. List<String> codesign_args;
  789. codesign_args.push_back("-f");
  790. codesign_args.push_back("-s");
  791. codesign_args.push_back(sign_id);
  792. codesign_args.push_back(p_file);
  793. String str;
  794. Error err = OS::get_singleton()->execute("codesign", codesign_args, &str, nullptr, true);
  795. print_verbose("codesign (" + p_file + "):\n" + str);
  796. return err;
  797. }
  798. return OK;
  799. }
  800. struct PbxId {
  801. private:
  802. static char _hex_char(uint8_t four_bits) {
  803. if (four_bits < 10) {
  804. return ('0' + four_bits);
  805. }
  806. return 'A' + (four_bits - 10);
  807. }
  808. static String _hex_pad(uint32_t num) {
  809. Vector<char> ret;
  810. ret.resize(sizeof(num) * 2);
  811. for (uint64_t i = 0; i < sizeof(num) * 2; ++i) {
  812. uint8_t four_bits = (num >> (sizeof(num) * 8 - (i + 1) * 4)) & 0xF;
  813. ret.write[i] = _hex_char(four_bits);
  814. }
  815. return String::utf8(ret.ptr(), ret.size());
  816. }
  817. public:
  818. uint32_t high_bits;
  819. uint32_t mid_bits;
  820. uint32_t low_bits;
  821. String str() const {
  822. return _hex_pad(high_bits) + _hex_pad(mid_bits) + _hex_pad(low_bits);
  823. }
  824. PbxId &operator++() {
  825. low_bits++;
  826. if (!low_bits) {
  827. mid_bits++;
  828. if (!mid_bits) {
  829. high_bits++;
  830. }
  831. }
  832. return *this;
  833. }
  834. };
  835. struct ExportLibsData {
  836. Vector<String> lib_paths;
  837. String dest_dir;
  838. };
  839. void EditorExportPlatformIOS::_add_assets_to_project(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) {
  840. // that is just a random number, we just need Godot IDs not to clash with
  841. // existing IDs in the project.
  842. PbxId current_id = { 0x58938401, 0, 0 };
  843. String pbx_files;
  844. String pbx_frameworks_build;
  845. String pbx_frameworks_refs;
  846. String pbx_resources_build;
  847. String pbx_resources_refs;
  848. String pbx_embeded_frameworks;
  849. const String file_info_format = String("$build_id = {isa = PBXBuildFile; fileRef = $ref_id; };\n") +
  850. "$ref_id = {isa = PBXFileReference; lastKnownFileType = $file_type; name = \"$name\"; path = \"$file_path\"; sourceTree = \"<group>\"; };\n";
  851. for (int i = 0; i < p_additional_assets.size(); ++i) {
  852. String additional_asset_info_format = file_info_format;
  853. String build_id = (++current_id).str();
  854. String ref_id = (++current_id).str();
  855. String framework_id = "";
  856. const IOSExportAsset &asset = p_additional_assets[i];
  857. String type;
  858. if (asset.exported_path.ends_with(".framework")) {
  859. if (asset.should_embed) {
  860. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  861. framework_id = (++current_id).str();
  862. pbx_embeded_frameworks += framework_id + ",\n";
  863. }
  864. type = "wrapper.framework";
  865. } else if (asset.exported_path.ends_with(".xcframework")) {
  866. if (asset.should_embed) {
  867. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  868. framework_id = (++current_id).str();
  869. pbx_embeded_frameworks += framework_id + ",\n";
  870. }
  871. type = "wrapper.xcframework";
  872. } else if (asset.exported_path.ends_with(".dylib")) {
  873. type = "compiled.mach-o.dylib";
  874. } else if (asset.exported_path.ends_with(".a")) {
  875. type = "archive.ar";
  876. } else {
  877. type = "file";
  878. }
  879. String &pbx_build = asset.is_framework ? pbx_frameworks_build : pbx_resources_build;
  880. String &pbx_refs = asset.is_framework ? pbx_frameworks_refs : pbx_resources_refs;
  881. if (pbx_build.length() > 0) {
  882. pbx_build += ",\n";
  883. pbx_refs += ",\n";
  884. }
  885. pbx_build += build_id;
  886. pbx_refs += ref_id;
  887. Dictionary format_dict;
  888. format_dict["build_id"] = build_id;
  889. format_dict["ref_id"] = ref_id;
  890. format_dict["name"] = asset.exported_path.get_file();
  891. format_dict["file_path"] = asset.exported_path;
  892. format_dict["file_type"] = type;
  893. if (framework_id.length() > 0) {
  894. format_dict["framework_id"] = framework_id;
  895. }
  896. pbx_files += additional_asset_info_format.format(format_dict, "$_");
  897. }
  898. // Note, frameworks like gamekit are always included in our project.pbxprof file
  899. // even if turned off in capabilities.
  900. String str = String::utf8((const char *)p_project_data.ptr(), p_project_data.size());
  901. str = str.replace("$additional_pbx_files", pbx_files);
  902. str = str.replace("$additional_pbx_frameworks_build", pbx_frameworks_build);
  903. str = str.replace("$additional_pbx_frameworks_refs", pbx_frameworks_refs);
  904. str = str.replace("$additional_pbx_resources_build", pbx_resources_build);
  905. str = str.replace("$additional_pbx_resources_refs", pbx_resources_refs);
  906. str = str.replace("$pbx_embeded_frameworks", pbx_embeded_frameworks);
  907. CharString cs = str.utf8();
  908. p_project_data.resize(cs.size() - 1);
  909. for (int i = 0; i < cs.size() - 1; i++) {
  910. p_project_data.write[i] = cs[i];
  911. }
  912. }
  913. 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) {
  914. String binary_name = p_out_dir.get_file().get_basename();
  915. Ref<DirAccess> da = DirAccess::create_for_path(p_asset);
  916. if (da.is_null()) {
  917. ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't create directory: " + p_asset + ".");
  918. }
  919. bool file_exists = da->file_exists(p_asset);
  920. bool dir_exists = da->dir_exists(p_asset);
  921. if (!file_exists && !dir_exists) {
  922. return ERR_FILE_NOT_FOUND;
  923. }
  924. String base_dir = p_asset.get_base_dir().replace("res://", "");
  925. String destination_dir;
  926. String destination;
  927. String asset_path;
  928. bool create_framework = false;
  929. if (p_is_framework && p_asset.ends_with(".dylib")) {
  930. // For iOS we need to turn .dylib into .framework
  931. // to be able to send application to AppStore
  932. asset_path = String("dylibs").path_join(base_dir);
  933. String file_name;
  934. if (!p_custom_file_name) {
  935. file_name = p_asset.get_basename().get_file();
  936. } else {
  937. file_name = *p_custom_file_name;
  938. }
  939. String framework_name = file_name + ".framework";
  940. asset_path = asset_path.path_join(framework_name);
  941. destination_dir = p_out_dir.path_join(asset_path);
  942. destination = destination_dir.path_join(file_name);
  943. create_framework = true;
  944. } else if (p_is_framework && (p_asset.ends_with(".framework") || p_asset.ends_with(".xcframework"))) {
  945. asset_path = String("dylibs").path_join(base_dir);
  946. String file_name;
  947. if (!p_custom_file_name) {
  948. file_name = p_asset.get_file();
  949. } else {
  950. file_name = *p_custom_file_name;
  951. }
  952. asset_path = asset_path.path_join(file_name);
  953. destination_dir = p_out_dir.path_join(asset_path);
  954. destination = destination_dir;
  955. } else {
  956. asset_path = base_dir;
  957. String file_name;
  958. if (!p_custom_file_name) {
  959. file_name = p_asset.get_file();
  960. } else {
  961. file_name = *p_custom_file_name;
  962. }
  963. destination_dir = p_out_dir.path_join(asset_path);
  964. asset_path = asset_path.path_join(file_name);
  965. destination = p_out_dir.path_join(asset_path);
  966. }
  967. Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  968. ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_out_dir + "'.");
  969. if (!filesystem_da->dir_exists(destination_dir)) {
  970. Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir);
  971. if (make_dir_err) {
  972. return make_dir_err;
  973. }
  974. }
  975. Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination);
  976. if (err) {
  977. return err;
  978. }
  979. IOSExportAsset exported_asset = { binary_name.path_join(asset_path), p_is_framework, p_should_embed };
  980. r_exported_assets.push_back(exported_asset);
  981. if (create_framework) {
  982. String file_name;
  983. if (!p_custom_file_name) {
  984. file_name = p_asset.get_basename().get_file();
  985. } else {
  986. file_name = *p_custom_file_name;
  987. }
  988. String framework_name = file_name + ".framework";
  989. // Performing `install_name_tool -id @rpath/{name}.framework/{name} ./{name}` on dylib
  990. {
  991. List<String> install_name_args;
  992. install_name_args.push_back("-id");
  993. install_name_args.push_back(String("@rpath").path_join(framework_name).path_join(file_name));
  994. install_name_args.push_back(destination);
  995. OS::get_singleton()->execute("install_name_tool", install_name_args);
  996. }
  997. // Creating Info.plist
  998. {
  999. String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1000. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  1001. "<plist version=\"1.0\">\n"
  1002. "<dict>\n"
  1003. "<key>CFBundleShortVersionString</key>\n"
  1004. "<string>1.0</string>\n"
  1005. "<key>CFBundleIdentifier</key>\n"
  1006. "<string>com.gdextension.framework.$name</string>\n"
  1007. "<key>CFBundleName</key>\n"
  1008. "<string>$name</string>\n"
  1009. "<key>CFBundleExecutable</key>\n"
  1010. "<string>$name</string>\n"
  1011. "<key>DTPlatformName</key>\n"
  1012. "<string>iphoneos</string>\n"
  1013. "<key>CFBundleInfoDictionaryVersion</key>\n"
  1014. "<string>6.0</string>\n"
  1015. "<key>CFBundleVersion</key>\n"
  1016. "<string>1</string>\n"
  1017. "<key>CFBundlePackageType</key>\n"
  1018. "<string>FMWK</string>\n"
  1019. "<key>MinimumOSVersion</key>\n"
  1020. "<string>10.0</string>\n"
  1021. "</dict>\n"
  1022. "</plist>";
  1023. String info_plist = info_plist_format.replace("$name", file_name);
  1024. Ref<FileAccess> f = FileAccess::open(destination_dir.path_join("Info.plist"), FileAccess::WRITE);
  1025. if (f.is_valid()) {
  1026. f->store_string(info_plist);
  1027. }
  1028. }
  1029. }
  1030. return OK;
  1031. }
  1032. 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) {
  1033. for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) {
  1034. String asset = p_assets[f_idx];
  1035. if (!asset.begins_with("res://")) {
  1036. // either SDK-builtin or already a part of the export template
  1037. IOSExportAsset exported_asset = { asset, p_is_framework, p_should_embed };
  1038. r_exported_assets.push_back(exported_asset);
  1039. } else {
  1040. Error err = _copy_asset(p_out_dir, asset, nullptr, p_is_framework, p_should_embed, r_exported_assets);
  1041. ERR_FAIL_COND_V(err, err);
  1042. }
  1043. }
  1044. return OK;
  1045. }
  1046. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets) {
  1047. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1048. for (int i = 0; i < export_plugins.size(); i++) {
  1049. Vector<String> linked_frameworks = export_plugins[i]->get_ios_frameworks();
  1050. Error err = _export_additional_assets(p_out_dir, linked_frameworks, true, false, r_exported_assets);
  1051. ERR_FAIL_COND_V(err, err);
  1052. Vector<String> embedded_frameworks = export_plugins[i]->get_ios_embedded_frameworks();
  1053. err = _export_additional_assets(p_out_dir, embedded_frameworks, true, true, r_exported_assets);
  1054. ERR_FAIL_COND_V(err, err);
  1055. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1056. for (int j = 0; j < project_static_libs.size(); j++) {
  1057. project_static_libs.write[j] = project_static_libs[j].get_file(); // Only the file name as it's copied to the project
  1058. }
  1059. err = _export_additional_assets(p_out_dir, project_static_libs, true, false, r_exported_assets);
  1060. ERR_FAIL_COND_V(err, err);
  1061. Vector<String> ios_bundle_files = export_plugins[i]->get_ios_bundle_files();
  1062. err = _export_additional_assets(p_out_dir, ios_bundle_files, false, false, r_exported_assets);
  1063. ERR_FAIL_COND_V(err, err);
  1064. }
  1065. Vector<String> library_paths;
  1066. for (int i = 0; i < p_libraries.size(); ++i) {
  1067. library_paths.push_back(p_libraries[i].path);
  1068. }
  1069. Error err = _export_additional_assets(p_out_dir, library_paths, true, true, r_exported_assets);
  1070. ERR_FAIL_COND_V(err, err);
  1071. return OK;
  1072. }
  1073. Vector<String> EditorExportPlatformIOS::_get_preset_architectures(const Ref<EditorExportPreset> &p_preset) const {
  1074. Vector<ExportArchitecture> all_archs = _get_supported_architectures();
  1075. Vector<String> enabled_archs;
  1076. for (int i = 0; i < all_archs.size(); ++i) {
  1077. bool is_enabled = p_preset->get("architectures/" + all_archs[i].name);
  1078. if (is_enabled) {
  1079. enabled_archs.push_back(all_archs[i].name);
  1080. }
  1081. }
  1082. return enabled_archs;
  1083. }
  1084. 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) {
  1085. String plugin_definition_cpp_code;
  1086. String plugin_initialization_cpp_code;
  1087. String plugin_deinitialization_cpp_code;
  1088. Vector<String> plugin_linked_dependencies;
  1089. Vector<String> plugin_embedded_dependencies;
  1090. Vector<String> plugin_files;
  1091. Vector<PluginConfigIOS> enabled_plugins = get_enabled_plugins(p_preset);
  1092. Vector<String> added_linked_dependenciy_names;
  1093. Vector<String> added_embedded_dependenciy_names;
  1094. HashMap<String, String> plist_values;
  1095. HashSet<String> plugin_linker_flags;
  1096. Error err;
  1097. for (int i = 0; i < enabled_plugins.size(); i++) {
  1098. PluginConfigIOS plugin = enabled_plugins[i];
  1099. // Export plugin binary.
  1100. String plugin_main_binary = PluginConfigIOS::get_plugin_main_binary(plugin, p_debug);
  1101. String plugin_binary_result_file = plugin.binary.get_file();
  1102. // We shouldn't embed .xcframework that contains static libraries.
  1103. // Static libraries are not embedded anyway.
  1104. err = _copy_asset(dest_dir, plugin_main_binary, &plugin_binary_result_file, true, false, r_exported_assets);
  1105. ERR_FAIL_COND_V(err, err);
  1106. // Adding dependencies.
  1107. // Use separate container for names to check for duplicates.
  1108. for (int j = 0; j < plugin.linked_dependencies.size(); j++) {
  1109. String dependency = plugin.linked_dependencies[j];
  1110. String name = dependency.get_file();
  1111. if (added_linked_dependenciy_names.has(name)) {
  1112. continue;
  1113. }
  1114. added_linked_dependenciy_names.push_back(name);
  1115. plugin_linked_dependencies.push_back(dependency);
  1116. }
  1117. for (int j = 0; j < plugin.system_dependencies.size(); j++) {
  1118. String dependency = plugin.system_dependencies[j];
  1119. String name = dependency.get_file();
  1120. if (added_linked_dependenciy_names.has(name)) {
  1121. continue;
  1122. }
  1123. added_linked_dependenciy_names.push_back(name);
  1124. plugin_linked_dependencies.push_back(dependency);
  1125. }
  1126. for (int j = 0; j < plugin.embedded_dependencies.size(); j++) {
  1127. String dependency = plugin.embedded_dependencies[j];
  1128. String name = dependency.get_file();
  1129. if (added_embedded_dependenciy_names.has(name)) {
  1130. continue;
  1131. }
  1132. added_embedded_dependenciy_names.push_back(name);
  1133. plugin_embedded_dependencies.push_back(dependency);
  1134. }
  1135. plugin_files.append_array(plugin.files_to_copy);
  1136. // Capabilities
  1137. // Also checking for duplicates.
  1138. for (int j = 0; j < plugin.capabilities.size(); j++) {
  1139. String capability = plugin.capabilities[j];
  1140. if (p_config_data.capabilities.has(capability)) {
  1141. continue;
  1142. }
  1143. p_config_data.capabilities.push_back(capability);
  1144. }
  1145. // Linker flags
  1146. // Checking duplicates
  1147. for (int j = 0; j < plugin.linker_flags.size(); j++) {
  1148. String linker_flag = plugin.linker_flags[j];
  1149. plugin_linker_flags.insert(linker_flag);
  1150. }
  1151. // Plist
  1152. // Using hash map container to remove duplicates
  1153. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  1154. String key = E.key;
  1155. const PluginConfigIOS::PlistItem &item = E.value;
  1156. String value;
  1157. switch (item.type) {
  1158. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  1159. String preset_name = "plugins_plist/" + key;
  1160. String input_value = p_preset->get(preset_name);
  1161. value = "<string>" + input_value + "</string>";
  1162. } break;
  1163. default:
  1164. value = item.value;
  1165. break;
  1166. }
  1167. if (key.is_empty() || value.is_empty()) {
  1168. continue;
  1169. }
  1170. String plist_key = "<key>" + key + "</key>";
  1171. plist_values[plist_key] = value;
  1172. }
  1173. // CPP Code
  1174. String definition_comment = "// Plugin: " + plugin.name + "\n";
  1175. String initialization_method = plugin.initialization_method + "();\n";
  1176. String deinitialization_method = plugin.deinitialization_method + "();\n";
  1177. plugin_definition_cpp_code += definition_comment +
  1178. "extern void " + initialization_method +
  1179. "extern void " + deinitialization_method + "\n";
  1180. plugin_initialization_cpp_code += "\t" + initialization_method;
  1181. plugin_deinitialization_cpp_code += "\t" + deinitialization_method;
  1182. if (plugin.use_swift_runtime) {
  1183. p_config_data.use_swift_runtime = true;
  1184. }
  1185. }
  1186. // Updating `Info.plist`
  1187. {
  1188. for (const KeyValue<String, String> &E : plist_values) {
  1189. String key = E.key;
  1190. String value = E.value;
  1191. if (key.is_empty() || value.is_empty()) {
  1192. continue;
  1193. }
  1194. p_config_data.plist_content += key + value + "\n";
  1195. }
  1196. }
  1197. // Export files
  1198. {
  1199. // Export linked plugin dependency
  1200. err = _export_additional_assets(dest_dir, plugin_linked_dependencies, true, false, r_exported_assets);
  1201. ERR_FAIL_COND_V(err, err);
  1202. // Export embedded plugin dependency
  1203. err = _export_additional_assets(dest_dir, plugin_embedded_dependencies, true, true, r_exported_assets);
  1204. ERR_FAIL_COND_V(err, err);
  1205. // Export plugin files
  1206. err = _export_additional_assets(dest_dir, plugin_files, false, false, r_exported_assets);
  1207. ERR_FAIL_COND_V(err, err);
  1208. }
  1209. // Update CPP
  1210. {
  1211. Dictionary plugin_format;
  1212. plugin_format["definition"] = plugin_definition_cpp_code;
  1213. plugin_format["initialization"] = plugin_initialization_cpp_code;
  1214. plugin_format["deinitialization"] = plugin_deinitialization_cpp_code;
  1215. String plugin_cpp_code = "\n// Godot Plugins\n"
  1216. "void godot_ios_plugins_initialize();\n"
  1217. "void godot_ios_plugins_deinitialize();\n"
  1218. "// Exported Plugins\n\n"
  1219. "$definition"
  1220. "// Use Plugins\n"
  1221. "void godot_ios_plugins_initialize() {\n"
  1222. "$initialization"
  1223. "}\n\n"
  1224. "void godot_ios_plugins_deinitialize() {\n"
  1225. "$deinitialization"
  1226. "}\n";
  1227. p_config_data.cpp_code += plugin_cpp_code.format(plugin_format, "$_");
  1228. }
  1229. // Update Linker Flag Values
  1230. {
  1231. String result_linker_flags = " ";
  1232. for (const String &E : plugin_linker_flags) {
  1233. const String &flag = E;
  1234. if (flag.length() == 0) {
  1235. continue;
  1236. }
  1237. if (result_linker_flags.length() > 0) {
  1238. result_linker_flags += ' ';
  1239. }
  1240. result_linker_flags += flag;
  1241. }
  1242. result_linker_flags = result_linker_flags.replace("\"", "\\\"");
  1243. p_config_data.linker_flags += result_linker_flags;
  1244. }
  1245. return OK;
  1246. }
  1247. Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  1248. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  1249. String src_pkg_name;
  1250. String dest_dir = p_path.get_base_dir() + "/";
  1251. String binary_name = p_path.get_file().get_basename();
  1252. EditorProgress ep("export", "Exporting for iOS", 5, true);
  1253. String team_id = p_preset->get("application/app_store_team_id");
  1254. ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project.");
  1255. if (p_debug) {
  1256. src_pkg_name = p_preset->get("custom_template/debug");
  1257. } else {
  1258. src_pkg_name = p_preset->get("custom_template/release");
  1259. }
  1260. if (src_pkg_name.is_empty()) {
  1261. String err;
  1262. src_pkg_name = find_export_template("ios.zip", &err);
  1263. if (src_pkg_name.is_empty()) {
  1264. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found."));
  1265. return ERR_FILE_NOT_FOUND;
  1266. }
  1267. }
  1268. if (!DirAccess::exists(dest_dir)) {
  1269. return ERR_FILE_BAD_PATH;
  1270. }
  1271. {
  1272. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1273. if (da.is_valid()) {
  1274. String current_dir = da->get_current_dir();
  1275. // remove leftovers from last export so they don't interfere
  1276. // in case some files are no longer needed
  1277. if (da->change_dir(dest_dir + binary_name + ".xcodeproj") == OK) {
  1278. da->erase_contents_recursive();
  1279. }
  1280. if (da->change_dir(dest_dir + binary_name) == OK) {
  1281. da->erase_contents_recursive();
  1282. }
  1283. da->change_dir(current_dir);
  1284. if (!da->dir_exists(dest_dir + binary_name)) {
  1285. Error err = da->make_dir(dest_dir + binary_name);
  1286. if (err) {
  1287. return err;
  1288. }
  1289. }
  1290. }
  1291. }
  1292. if (ep.step("Making .pck", 0)) {
  1293. return ERR_SKIP;
  1294. }
  1295. String pack_path = dest_dir + binary_name + ".pck";
  1296. Vector<SharedObject> libraries;
  1297. Error err = save_pack(p_preset, p_debug, pack_path, &libraries);
  1298. if (err) {
  1299. return err;
  1300. }
  1301. if (ep.step("Extracting and configuring Xcode project", 1)) {
  1302. return ERR_SKIP;
  1303. }
  1304. String library_to_use = "libgodot.ios." + String(p_debug ? "debug" : "release") + ".xcframework";
  1305. print_line("Static framework: " + library_to_use);
  1306. String pkg_name;
  1307. if (String(GLOBAL_GET("application/config/name")) != "") {
  1308. pkg_name = String(GLOBAL_GET("application/config/name"));
  1309. } else {
  1310. pkg_name = "Unnamed";
  1311. }
  1312. bool found_library = false;
  1313. const String project_file = "godot_ios.xcodeproj/project.pbxproj";
  1314. HashSet<String> files_to_parse;
  1315. files_to_parse.insert("godot_ios/godot_ios-Info.plist");
  1316. files_to_parse.insert(project_file);
  1317. files_to_parse.insert("godot_ios/export_options.plist");
  1318. files_to_parse.insert("godot_ios/dummy.cpp");
  1319. files_to_parse.insert("godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata");
  1320. files_to_parse.insert("godot_ios.xcodeproj/xcshareddata/xcschemes/godot_ios.xcscheme");
  1321. files_to_parse.insert("godot_ios/godot_ios.entitlements");
  1322. files_to_parse.insert("godot_ios/Launch Screen.storyboard");
  1323. IOSConfigData config_data = {
  1324. pkg_name,
  1325. binary_name,
  1326. _get_additional_plist_content(),
  1327. String(" ").join(_get_preset_architectures(p_preset)),
  1328. _get_linker_flags(),
  1329. _get_cpp_code(),
  1330. "",
  1331. "",
  1332. "",
  1333. "",
  1334. Vector<String>(),
  1335. false
  1336. };
  1337. Vector<IOSExportAsset> assets;
  1338. Ref<DirAccess> tmp_app_path = DirAccess::create_for_path(dest_dir);
  1339. ERR_FAIL_COND_V(tmp_app_path.is_null(), ERR_CANT_CREATE);
  1340. print_line("Unzipping...");
  1341. Ref<FileAccess> io_fa;
  1342. zlib_filefunc_def io = zipio_create_io(&io_fa);
  1343. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  1344. if (!src_pkg_zip) {
  1345. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Could not open export template (not a zip file?): \"%s\".", src_pkg_name));
  1346. return ERR_CANT_OPEN;
  1347. }
  1348. err = _export_ios_plugins(p_preset, config_data, dest_dir + binary_name, assets, p_debug);
  1349. ERR_FAIL_COND_V(err, err);
  1350. //export rest of the files
  1351. int ret = unzGoToFirstFile(src_pkg_zip);
  1352. Vector<uint8_t> project_file_data;
  1353. while (ret == UNZ_OK) {
  1354. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1355. bool is_execute = false;
  1356. #endif
  1357. //get filename
  1358. unz_file_info info;
  1359. char fname[16384];
  1360. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  1361. if (ret != UNZ_OK) {
  1362. break;
  1363. }
  1364. String file = String::utf8(fname);
  1365. print_line("READ: " + file);
  1366. Vector<uint8_t> data;
  1367. data.resize(info.uncompressed_size);
  1368. //read
  1369. unzOpenCurrentFile(src_pkg_zip);
  1370. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  1371. unzCloseCurrentFile(src_pkg_zip);
  1372. //write
  1373. if (files_to_parse.has(file)) {
  1374. _fix_config_file(p_preset, data, config_data, p_debug);
  1375. } else if (file.begins_with("libgodot.ios")) {
  1376. if (!file.begins_with(library_to_use) || file.ends_with(String("/empty"))) {
  1377. ret = unzGoToNextFile(src_pkg_zip);
  1378. continue; //ignore!
  1379. }
  1380. found_library = true;
  1381. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1382. is_execute = true;
  1383. #endif
  1384. file = file.replace(library_to_use, binary_name + ".xcframework");
  1385. }
  1386. if (file == project_file) {
  1387. project_file_data = data;
  1388. }
  1389. ///@TODO need to parse logo files
  1390. if (data.size() > 0) {
  1391. file = file.replace("godot_ios", binary_name);
  1392. print_line("ADDING: " + file + " size: " + itos(data.size()));
  1393. /* write it into our folder structure */
  1394. file = dest_dir + file;
  1395. /* make sure this folder exists */
  1396. String dir_name = file.get_base_dir();
  1397. if (!tmp_app_path->dir_exists(dir_name)) {
  1398. print_line("Creating " + dir_name);
  1399. Error dir_err = tmp_app_path->make_dir_recursive(dir_name);
  1400. if (dir_err) {
  1401. ERR_PRINT("Can't create '" + dir_name + "'.");
  1402. unzClose(src_pkg_zip);
  1403. return ERR_CANT_CREATE;
  1404. }
  1405. }
  1406. /* write the file */
  1407. {
  1408. Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);
  1409. if (f.is_null()) {
  1410. ERR_PRINT("Can't write '" + file + "'.");
  1411. unzClose(src_pkg_zip);
  1412. return ERR_CANT_CREATE;
  1413. };
  1414. f->store_buffer(data.ptr(), data.size());
  1415. }
  1416. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1417. if (is_execute) {
  1418. // we need execute rights on this file
  1419. chmod(file.utf8().get_data(), 0755);
  1420. }
  1421. #endif
  1422. }
  1423. ret = unzGoToNextFile(src_pkg_zip);
  1424. }
  1425. /* we're done with our source zip */
  1426. unzClose(src_pkg_zip);
  1427. if (!found_library) {
  1428. ERR_PRINT("Requested template library '" + library_to_use + "' not found. It might be missing from your template archive.");
  1429. return ERR_FILE_NOT_FOUND;
  1430. }
  1431. Dictionary appnames = GLOBAL_GET("application/config/name_localized");
  1432. Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");
  1433. Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");
  1434. Dictionary photolibrary_usage_descriptions = p_preset->get("privacy/photolibrary_usage_description_localized");
  1435. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  1436. if (translations.size() > 0) {
  1437. {
  1438. String fname = dest_dir + binary_name + "/en.lproj";
  1439. tmp_app_path->make_dir_recursive(fname);
  1440. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1441. f->store_line("/* Localized versions of Info.plist keys */");
  1442. f->store_line("");
  1443. f->store_line("CFBundleDisplayName = \"" + GLOBAL_GET("application/config/name").operator String() + "\";");
  1444. f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String() + "\";");
  1445. f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String() + "\";");
  1446. f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photolibrary_usage_description").operator String() + "\";");
  1447. }
  1448. HashSet<String> languages;
  1449. for (const String &E : translations) {
  1450. Ref<Translation> tr = ResourceLoader::load(E);
  1451. if (tr.is_valid() && tr->get_locale() != "en") {
  1452. languages.insert(tr->get_locale());
  1453. }
  1454. }
  1455. for (const String &lang : languages) {
  1456. String fname = dest_dir + binary_name + "/" + lang + ".lproj";
  1457. tmp_app_path->make_dir_recursive(fname);
  1458. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1459. f->store_line("/* Localized versions of Info.plist keys */");
  1460. f->store_line("");
  1461. if (appnames.has(lang)) {
  1462. f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String() + "\";");
  1463. }
  1464. if (camera_usage_descriptions.has(lang)) {
  1465. f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String() + "\";");
  1466. }
  1467. if (microphone_usage_descriptions.has(lang)) {
  1468. f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String() + "\";");
  1469. }
  1470. if (photolibrary_usage_descriptions.has(lang)) {
  1471. f->store_line("NSPhotoLibraryUsageDescription = \"" + photolibrary_usage_descriptions[lang].operator String() + "\";");
  1472. }
  1473. }
  1474. }
  1475. // Copy project static libs to the project
  1476. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1477. for (int i = 0; i < export_plugins.size(); i++) {
  1478. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1479. for (int j = 0; j < project_static_libs.size(); j++) {
  1480. const String &static_lib_path = project_static_libs[j];
  1481. String dest_lib_file_path = dest_dir + static_lib_path.get_file();
  1482. Error lib_copy_err = tmp_app_path->copy(static_lib_path, dest_lib_file_path);
  1483. if (lib_copy_err != OK) {
  1484. ERR_PRINT("Can't copy '" + static_lib_path + "'.");
  1485. return lib_copy_err;
  1486. }
  1487. }
  1488. }
  1489. String iconset_dir = dest_dir + binary_name + "/Images.xcassets/AppIcon.appiconset/";
  1490. err = OK;
  1491. if (!tmp_app_path->dir_exists(iconset_dir)) {
  1492. err = tmp_app_path->make_dir_recursive(iconset_dir);
  1493. }
  1494. if (err) {
  1495. return err;
  1496. }
  1497. err = _export_icons(p_preset, iconset_dir);
  1498. if (err) {
  1499. return err;
  1500. }
  1501. {
  1502. bool use_storyboard = p_preset->get("storyboard/use_launch_screen_storyboard");
  1503. String launch_image_path = dest_dir + binary_name + "/Images.xcassets/LaunchImage.launchimage/";
  1504. String splash_image_path = dest_dir + binary_name + "/Images.xcassets/SplashImage.imageset/";
  1505. Ref<DirAccess> launch_screen_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1506. if (launch_screen_da.is_null()) {
  1507. return ERR_CANT_CREATE;
  1508. }
  1509. if (use_storyboard) {
  1510. print_line("Using Launch Storyboard");
  1511. if (launch_screen_da->change_dir(launch_image_path) == OK) {
  1512. launch_screen_da->erase_contents_recursive();
  1513. launch_screen_da->remove(launch_image_path);
  1514. }
  1515. err = _export_loading_screen_file(p_preset, splash_image_path);
  1516. } else {
  1517. print_line("Using Launch Images");
  1518. const String launch_screen_path = dest_dir + binary_name + "/Launch Screen.storyboard";
  1519. launch_screen_da->remove(launch_screen_path);
  1520. if (launch_screen_da->change_dir(splash_image_path) == OK) {
  1521. launch_screen_da->erase_contents_recursive();
  1522. launch_screen_da->remove(splash_image_path);
  1523. }
  1524. err = _export_loading_screen_images(p_preset, launch_image_path);
  1525. }
  1526. }
  1527. if (err) {
  1528. return err;
  1529. }
  1530. print_line("Exporting additional assets");
  1531. _export_additional_assets(dest_dir + binary_name, libraries, assets);
  1532. _add_assets_to_project(p_preset, project_file_data, assets);
  1533. String project_file_name = dest_dir + binary_name + ".xcodeproj/project.pbxproj";
  1534. {
  1535. Ref<FileAccess> f = FileAccess::open(project_file_name, FileAccess::WRITE);
  1536. if (f.is_null()) {
  1537. ERR_PRINT("Can't write '" + project_file_name + "'.");
  1538. return ERR_CANT_CREATE;
  1539. };
  1540. f->store_buffer(project_file_data.ptr(), project_file_data.size());
  1541. }
  1542. #ifdef MACOS_ENABLED
  1543. {
  1544. if (ep.step("Code-signing dylibs", 2)) {
  1545. return ERR_SKIP;
  1546. }
  1547. Ref<DirAccess> dylibs_dir = DirAccess::open(dest_dir + binary_name + "/dylibs");
  1548. ERR_FAIL_COND_V(dylibs_dir.is_null(), ERR_CANT_OPEN);
  1549. CodesignData codesign_data(p_preset, p_debug);
  1550. err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data);
  1551. if (err != OK) {
  1552. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  1553. return err;
  1554. }
  1555. }
  1556. if (ep.step("Making .xcarchive", 3)) {
  1557. return ERR_SKIP;
  1558. }
  1559. String archive_path = p_path.get_basename() + ".xcarchive";
  1560. List<String> archive_args;
  1561. archive_args.push_back("-project");
  1562. archive_args.push_back(dest_dir + binary_name + ".xcodeproj");
  1563. archive_args.push_back("-scheme");
  1564. archive_args.push_back(binary_name);
  1565. archive_args.push_back("-sdk");
  1566. archive_args.push_back("iphoneos");
  1567. archive_args.push_back("-configuration");
  1568. archive_args.push_back(p_debug ? "Debug" : "Release");
  1569. archive_args.push_back("-destination");
  1570. archive_args.push_back("generic/platform=iOS");
  1571. archive_args.push_back("archive");
  1572. archive_args.push_back("-allowProvisioningUpdates");
  1573. archive_args.push_back("-archivePath");
  1574. archive_args.push_back(archive_path);
  1575. String archive_str;
  1576. err = OS::get_singleton()->execute("xcodebuild", archive_args, &archive_str, nullptr, true);
  1577. ERR_FAIL_COND_V(err, err);
  1578. print_line("xcodebuild (.xcarchive):\n" + archive_str);
  1579. if (!archive_str.contains("** ARCHIVE SUCCEEDED **")) {
  1580. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR("Xcode project build failed, see editor log for details."));
  1581. return FAILED;
  1582. }
  1583. if (ep.step("Making .ipa", 4)) {
  1584. return ERR_SKIP;
  1585. }
  1586. List<String> export_args;
  1587. export_args.push_back("-exportArchive");
  1588. export_args.push_back("-archivePath");
  1589. export_args.push_back(archive_path);
  1590. export_args.push_back("-exportOptionsPlist");
  1591. export_args.push_back(dest_dir + binary_name + "/export_options.plist");
  1592. export_args.push_back("-allowProvisioningUpdates");
  1593. export_args.push_back("-exportPath");
  1594. export_args.push_back(dest_dir);
  1595. String export_str;
  1596. err = OS::get_singleton()->execute("xcodebuild", export_args, &export_str, nullptr, true);
  1597. ERR_FAIL_COND_V(err, err);
  1598. print_line("xcodebuild (.ipa):\n" + export_str);
  1599. if (!export_str.contains("** EXPORT SUCCEEDED **")) {
  1600. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR(".ipa export failed, see editor log for details."));
  1601. return FAILED;
  1602. }
  1603. #else
  1604. add_message(EXPORT_MESSAGE_WARNING, TTR("Xcode Build"), TTR(".ipa can only be built on macOS. Leaving Xcode project without building the package."));
  1605. #endif
  1606. return OK;
  1607. }
  1608. bool EditorExportPlatformIOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  1609. String err;
  1610. bool valid = false;
  1611. // Look for export templates (first official, and if defined custom templates).
  1612. bool dvalid = exists_export_template("ios.zip", &err);
  1613. bool rvalid = dvalid; // Both in the same ZIP.
  1614. if (p_preset->get("custom_template/debug") != "") {
  1615. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  1616. if (!dvalid) {
  1617. err += TTR("Custom debug template not found.") + "\n";
  1618. }
  1619. }
  1620. if (p_preset->get("custom_template/release") != "") {
  1621. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  1622. if (!rvalid) {
  1623. err += TTR("Custom release template not found.") + "\n";
  1624. }
  1625. }
  1626. valid = dvalid || rvalid;
  1627. r_missing_templates = !valid;
  1628. if (!err.is_empty()) {
  1629. r_error = err;
  1630. }
  1631. return valid;
  1632. }
  1633. bool EditorExportPlatformIOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  1634. String err;
  1635. bool valid = true;
  1636. // Validate the project configuration.
  1637. String team_id = p_preset->get("application/app_store_team_id");
  1638. if (team_id.length() == 0) {
  1639. err += TTR("App Store Team ID not specified - cannot configure the project.") + "\n";
  1640. valid = false;
  1641. }
  1642. String identifier = p_preset->get("application/bundle_identifier");
  1643. String pn_err;
  1644. if (!is_package_name_valid(identifier, &pn_err)) {
  1645. err += TTR("Invalid Identifier:") + " " + pn_err + "\n";
  1646. valid = false;
  1647. }
  1648. const String etc_error = test_etc2();
  1649. if (!etc_error.is_empty()) {
  1650. valid = false;
  1651. err += etc_error;
  1652. }
  1653. if (!err.is_empty()) {
  1654. r_error = err;
  1655. }
  1656. return valid;
  1657. }
  1658. EditorExportPlatformIOS::EditorExportPlatformIOS() {
  1659. #ifdef MODULE_SVG_ENABLED
  1660. Ref<Image> img = memnew(Image);
  1661. const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
  1662. ImageLoaderSVG img_loader;
  1663. img_loader.create_image_from_string(img, _ios_logo_svg, EDSCALE, upsample, false);
  1664. logo = ImageTexture::create_from_image(img);
  1665. #endif
  1666. plugins_changed.set();
  1667. #ifndef ANDROID_ENABLED
  1668. check_for_changes_thread.start(_check_for_changes_poll_thread, this);
  1669. #endif
  1670. }
  1671. EditorExportPlatformIOS::~EditorExportPlatformIOS() {
  1672. #ifndef ANDROID_ENABLED
  1673. quit_request.set();
  1674. check_for_changes_thread.wait_to_finish();
  1675. #endif
  1676. }