export_plugin.cpp 80 KB

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