export_plugin.cpp 118 KB

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