export_plugin.cpp 127 KB

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