export_plugin.cpp 125 KB

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