export_plugin.cpp 115 KB

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