export_plugin.cpp 118 KB

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