export_plugin.cpp 121 KB

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