export_plugin.cpp 130 KB

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