export_plugin.cpp 94 KB

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