export_plugin.cpp 77 KB

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