export_plugin.cpp 120 KB

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