export_plugin.cpp 117 KB

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