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