export_plugin.cpp 131 KB

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