export_plugin.cpp 77 KB

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