export_plugin.cpp 98 KB

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