export_plugin.cpp 131 KB

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