export_plugin.cpp 131 KB

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