export_plugin.cpp 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217
  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 "core/string/translation.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/editor_scale.h"
  35. #include "editor/export/editor_export.h"
  36. #include "modules/modules_enabled.gen.h" // For mono and svg.
  37. #ifdef MODULE_SVG_ENABLED
  38. #include "modules/svg/image_loader_svg.h"
  39. #endif
  40. void EditorExportPlatformIOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
  41. // Vulkan and OpenGL ES 3.0 both mandate ETC2 support.
  42. r_features->push_back("etc2");
  43. r_features->push_back("astc");
  44. Vector<String> architectures = _get_preset_architectures(p_preset);
  45. for (int i = 0; i < architectures.size(); ++i) {
  46. r_features->push_back(architectures[i]);
  47. }
  48. }
  49. Vector<EditorExportPlatformIOS::ExportArchitecture> EditorExportPlatformIOS::_get_supported_architectures() const {
  50. Vector<ExportArchitecture> archs;
  51. archs.push_back(ExportArchitecture("arm64", true));
  52. return archs;
  53. }
  54. struct IconInfo {
  55. const char *preset_key;
  56. const char *idiom;
  57. const char *export_name;
  58. const char *actual_size_side;
  59. const char *scale;
  60. const char *unscaled_size;
  61. const bool force_opaque;
  62. };
  63. static const IconInfo icon_infos[] = {
  64. // Home screen on iPhone
  65. { PNAME("icons/iphone_120x120"), "iphone", "Icon-120.png", "120", "2x", "60x60", false },
  66. { PNAME("icons/iphone_120x120"), "iphone", "Icon-120.png", "120", "3x", "40x40", false },
  67. { PNAME("icons/iphone_180x180"), "iphone", "Icon-180.png", "180", "3x", "60x60", false },
  68. // Home screen on iPad
  69. { PNAME("icons/ipad_76x76"), "ipad", "Icon-76.png", "76", "1x", "76x76", false },
  70. { PNAME("icons/ipad_152x152"), "ipad", "Icon-152.png", "152", "2x", "76x76", false },
  71. { PNAME("icons/ipad_167x167"), "ipad", "Icon-167.png", "167", "2x", "83.5x83.5", false },
  72. // App Store
  73. { PNAME("icons/app_store_1024x1024"), "ios-marketing", "Icon-1024.png", "1024", "1x", "1024x1024", true },
  74. // Spotlight
  75. { PNAME("icons/spotlight_40x40"), "ipad", "Icon-40.png", "40", "1x", "40x40", false },
  76. { PNAME("icons/spotlight_80x80"), "iphone", "Icon-80.png", "80", "2x", "40x40", false },
  77. { PNAME("icons/spotlight_80x80"), "ipad", "Icon-80.png", "80", "2x", "40x40", false },
  78. // Settings
  79. { PNAME("icons/settings_58x58"), "iphone", "Icon-58.png", "58", "2x", "29x29", false },
  80. { PNAME("icons/settings_58x58"), "ipad", "Icon-58.png", "58", "2x", "29x29", false },
  81. { PNAME("icons/settings_87x87"), "iphone", "Icon-87.png", "87", "3x", "29x29", false },
  82. // Notification
  83. { PNAME("icons/notification_40x40"), "iphone", "Icon-40.png", "40", "2x", "20x20", false },
  84. { PNAME("icons/notification_40x40"), "ipad", "Icon-40.png", "40", "2x", "20x20", false },
  85. { PNAME("icons/notification_60x60"), "iphone", "Icon-60.png", "60", "3x", "20x20", false }
  86. };
  87. struct LoadingScreenInfo {
  88. const char *preset_key;
  89. const char *export_name;
  90. int width = 0;
  91. int height = 0;
  92. bool rotate = false;
  93. };
  94. static const LoadingScreenInfo loading_screen_infos[] = {
  95. { PNAME("landscape_launch_screens/iphone_2436x1125"), "Default-Landscape-X.png", 2436, 1125, false },
  96. { PNAME("landscape_launch_screens/iphone_2208x1242"), "Default-Landscape-736h@3x.png", 2208, 1242, false },
  97. { PNAME("landscape_launch_screens/ipad_1024x768"), "Default-Landscape.png", 1024, 768, false },
  98. { PNAME("landscape_launch_screens/ipad_2048x1536"), "Default-Landscape@2x.png", 2048, 1536, false },
  99. { PNAME("portrait_launch_screens/iphone_640x960"), "Default-480h@2x.png", 640, 960, false },
  100. { PNAME("portrait_launch_screens/iphone_640x1136"), "Default-568h@2x.png", 640, 1136, false },
  101. { PNAME("portrait_launch_screens/iphone_750x1334"), "Default-667h@2x.png", 750, 1334, false },
  102. { PNAME("portrait_launch_screens/iphone_1125x2436"), "Default-Portrait-X.png", 1125, 2436, false },
  103. { PNAME("portrait_launch_screens/ipad_768x1024"), "Default-Portrait.png", 768, 1024, false },
  104. { PNAME("portrait_launch_screens/ipad_1536x2048"), "Default-Portrait@2x.png", 1536, 2048, false },
  105. { PNAME("portrait_launch_screens/iphone_1242x2208"), "Default-Portrait-736h@3x.png", 1242, 2208, false }
  106. };
  107. struct APIAccessInfo {
  108. String prop_name;
  109. String type_name;
  110. Vector<String> prop_flag_value;
  111. Vector<String> prop_flag_name;
  112. int default_value;
  113. };
  114. static const APIAccessInfo api_info[] = {
  115. { "file_timestamp",
  116. "NSPrivacyAccessedAPICategoryFileTimestamp",
  117. { "DDA9.1", "C617.1", "3B52.1" },
  118. { "Display to user on-device:", "Inside app or group container", "Files provided to app by user" },
  119. 3 },
  120. { "system_boot_time",
  121. "NSPrivacyAccessedAPICategorySystemBootTime",
  122. { "35F9.1", "8FFB.1", "3D61.1" },
  123. { "Measure time on-device", "Calculate absolute event timestamps", "User-initiated bug report" },
  124. 1 },
  125. { "disk_space",
  126. "NSPrivacyAccessedAPICategoryDiskSpace",
  127. { "E174.1", "85F4.1", "7D9E.1", "B728.1" },
  128. { "Write or delete file on-device", "Display to user on-device", "User-initiated bug report", "Health research app" },
  129. 3 },
  130. { "active_keyboard",
  131. "NSPrivacyAccessedAPICategoryActiveKeyboards",
  132. { "3EC4.1", "54BD.1" },
  133. { "Custom keyboard app on-device", "Customize UI on-device:2" },
  134. 0 },
  135. { "user_defaults",
  136. "NSPrivacyAccessedAPICategoryUserDefaults",
  137. { "1C8F.1", "AC6B.1", "CA92.1" },
  138. { "Access info from same App Group", "Access managed app configuration", "Access info from same app" },
  139. 0 }
  140. };
  141. struct DataCollectionInfo {
  142. String prop_name;
  143. String type_name;
  144. };
  145. static const DataCollectionInfo data_collect_type_info[] = {
  146. { "name", "NSPrivacyCollectedDataTypeName" },
  147. { "email_address", "NSPrivacyCollectedDataTypeEmailAddress" },
  148. { "phone_number", "NSPrivacyCollectedDataTypePhoneNumber" },
  149. { "physical_address", "NSPrivacyCollectedDataTypePhysicalAddress" },
  150. { "other_contact_info", "NSPrivacyCollectedDataTypeOtherUserContactInfo" },
  151. { "health", "NSPrivacyCollectedDataTypeHealth" },
  152. { "fitness", "NSPrivacyCollectedDataTypeFitness" },
  153. { "payment_info", "NSPrivacyCollectedDataTypePaymentInfo" },
  154. { "credit_info", "NSPrivacyCollectedDataTypeCreditInfo" },
  155. { "other_financial_info", "NSPrivacyCollectedDataTypeOtherFinancialInfo" },
  156. { "precise_location", "NSPrivacyCollectedDataTypePreciseLocation" },
  157. { "coarse_location", "NSPrivacyCollectedDataTypeCoarseLocation" },
  158. { "sensitive_info", "NSPrivacyCollectedDataTypeSensitiveInfo" },
  159. { "contacts", "NSPrivacyCollectedDataTypeContacts" },
  160. { "emails_or_text_messages", "NSPrivacyCollectedDataTypeEmailsOrTextMessages" },
  161. { "photos_or_videos", "NSPrivacyCollectedDataTypePhotosorVideos" },
  162. { "audio_data", "NSPrivacyCollectedDataTypeAudioData" },
  163. { "gameplay_content", "NSPrivacyCollectedDataTypeGameplayContent" },
  164. { "customer_support", "NSPrivacyCollectedDataTypeCustomerSupport" },
  165. { "other_user_content", "NSPrivacyCollectedDataTypeOtherUserContent" },
  166. { "browsing_history", "NSPrivacyCollectedDataTypeBrowsingHistory" },
  167. { "search_hhistory", "NSPrivacyCollectedDataTypeSearchHistory" },
  168. { "user_id", "NSPrivacyCollectedDataTypeUserID" },
  169. { "device_id", "NSPrivacyCollectedDataTypeDeviceID" },
  170. { "purchase_history", "NSPrivacyCollectedDataTypePurchaseHistory" },
  171. { "product_interaction", "NSPrivacyCollectedDataTypeProductInteraction" },
  172. { "advertising_data", "NSPrivacyCollectedDataTypeAdvertisingData" },
  173. { "other_usage_data", "NSPrivacyCollectedDataTypeOtherUsageData" },
  174. { "crash_data", "NSPrivacyCollectedDataTypeCrashData" },
  175. { "performance_data", "NSPrivacyCollectedDataTypePerformanceData" },
  176. { "other_diagnostic_data", "NSPrivacyCollectedDataTypeOtherDiagnosticData" },
  177. { "environment_scanning", "NSPrivacyCollectedDataTypeEnvironmentScanning" },
  178. { "hands", "NSPrivacyCollectedDataTypeHands" },
  179. { "head", "NSPrivacyCollectedDataTypeHead" },
  180. { "other_data_types", "NSPrivacyCollectedDataTypeOtherDataTypes" },
  181. };
  182. static const DataCollectionInfo data_collect_purpose_info[] = {
  183. { "Analytics", "NSPrivacyCollectedDataTypePurposeAnalytics" },
  184. { "App Functionality", "NSPrivacyCollectedDataTypePurposeAppFunctionality" },
  185. { "Developer Advertising", "NSPrivacyCollectedDataTypePurposeDeveloperAdvertising" },
  186. { "Third-party Advertising", "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising" },
  187. { "Product Personalization", "NSPrivacyCollectedDataTypePurposeProductPersonalization" },
  188. { "Other", "NSPrivacyCollectedDataTypePurposeOther" },
  189. };
  190. String EditorExportPlatformIOS::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const {
  191. if (p_preset) {
  192. if (p_name == "application/app_store_team_id") {
  193. String team_id = p_preset->get("application/app_store_team_id");
  194. if (team_id.is_empty()) {
  195. return TTR("App Store Team ID not specified.") + "\n";
  196. }
  197. } else if (p_name == "application/bundle_identifier") {
  198. String identifier = p_preset->get("application/bundle_identifier");
  199. String pn_err;
  200. if (!is_package_name_valid(identifier, &pn_err)) {
  201. return TTR("Invalid Identifier:") + " " + pn_err;
  202. }
  203. } else if (p_name == "privacy/file_timestamp_access_reasons") {
  204. int access = p_preset->get("privacy/file_timestamp_access_reasons");
  205. if (access == 0) {
  206. return TTR("At least one file timestamp access reason should be selected.");
  207. }
  208. } else if (p_name == "privacy/disk_space_access_reasons") {
  209. int access = p_preset->get("privacy/disk_space_access_reasons");
  210. if (access == 0) {
  211. return TTR("At least one disk space access reason should be selected.");
  212. }
  213. } else if (p_name == "privacy/system_boot_time_access_reasons") {
  214. int access = p_preset->get("privacy/system_boot_time_access_reasons");
  215. if (access == 0) {
  216. return TTR("At least one system boot time access reason should be selected.");
  217. }
  218. }
  219. }
  220. return String();
  221. }
  222. bool EditorExportPlatformIOS::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {
  223. if (p_preset) {
  224. bool sb = p_preset->get("storyboard/use_launch_screen_storyboard");
  225. if (!sb && p_option != "storyboard/use_launch_screen_storyboard" && p_option.begins_with("storyboard/")) {
  226. return false;
  227. }
  228. }
  229. return true;
  230. }
  231. void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options) const {
  232. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  233. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  234. Vector<ExportArchitecture> architectures = _get_supported_architectures();
  235. for (int i = 0; i < architectures.size(); ++i) {
  236. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("architectures"), architectures[i].name)), architectures[i].is_default));
  237. }
  238. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_store_team_id"), "", false, true));
  239. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_debug", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
  240. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Developer"), ""));
  241. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_debug", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 1));
  242. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_release", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
  243. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Distribution"), ""));
  244. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_release", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 0));
  245. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/targeted_device_family", PROPERTY_HINT_ENUM, "iPhone,iPad,iPhone & iPad"), 2));
  246. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "", false, true));
  247. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  248. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  249. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  250. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
  251. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/launch_screens_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
  252. Vector<PluginConfigIOS> found_plugins = get_plugins();
  253. for (int i = 0; i < found_plugins.size(); i++) {
  254. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("%s/%s", PNAME("plugins"), found_plugins[i].name)), false));
  255. }
  256. HashSet<String> plist_keys;
  257. for (int i = 0; i < found_plugins.size(); i++) {
  258. // Editable plugin plist values
  259. PluginConfigIOS plugin = found_plugins[i];
  260. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  261. switch (E.value.type) {
  262. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  263. String preset_name = "plugins_plist/" + E.key;
  264. if (!plist_keys.has(preset_name)) {
  265. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, preset_name), E.value.value));
  266. plist_keys.insert(preset_name);
  267. }
  268. } break;
  269. default:
  270. continue;
  271. }
  272. }
  273. }
  274. plugins_changed.clear();
  275. plugins = found_plugins;
  276. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/access_wifi"), false));
  277. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/push_notifications"), false));
  278. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_files_app"), false));
  279. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "user_data/accessible_from_itunes_sharing"), false));
  280. 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"), ""));
  281. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  282. 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"), ""));
  283. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  284. 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"), ""));
  285. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photolibrary_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  286. for (uint64_t i = 0; i < sizeof(api_info) / sizeof(api_info[0]); ++i) {
  287. String prop_name = vformat("privacy/%s_access_reasons", api_info[i].prop_name);
  288. String hint;
  289. for (int j = 0; j < api_info[i].prop_flag_value.size(); j++) {
  290. if (j != 0) {
  291. hint += ",";
  292. }
  293. hint += vformat("%s - %s:%d", api_info[i].prop_flag_value[j], api_info[i].prop_flag_name[j], (1 << j));
  294. }
  295. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, prop_name, PROPERTY_HINT_FLAGS, hint), api_info[i].default_value));
  296. }
  297. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "privacy/tracking_enabled"), false));
  298. r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "privacy/tracking_domains"), Vector<String>()));
  299. {
  300. String hint;
  301. for (uint64_t i = 0; i < sizeof(data_collect_purpose_info) / sizeof(data_collect_purpose_info[0]); ++i) {
  302. if (i != 0) {
  303. hint += ",";
  304. }
  305. hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i));
  306. }
  307. for (uint64_t i = 0; i < sizeof(data_collect_type_info) / sizeof(data_collect_type_info[0]); ++i) {
  308. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false));
  309. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false));
  310. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false));
  311. 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));
  312. }
  313. }
  314. HashSet<String> used_names;
  315. for (uint64_t i = 0; i < sizeof(icon_infos) / sizeof(icon_infos[0]); ++i) {
  316. if (!used_names.has(icon_infos[i].preset_key)) {
  317. used_names.insert(icon_infos[i].preset_key);
  318. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, icon_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  319. }
  320. }
  321. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_launch_screen_storyboard"), true, true));
  322. 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));
  323. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@2x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  324. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "storyboard/custom_image@3x", PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  325. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "storyboard/use_custom_bg_color"), false));
  326. r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "storyboard/custom_bg_color"), Color()));
  327. for (uint64_t i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  328. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, loading_screen_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png,*.jpg,*.jpeg"), ""));
  329. }
  330. }
  331. void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug) {
  332. static const String export_method_string[] = {
  333. "app-store",
  334. "development",
  335. "ad-hoc",
  336. "enterprise"
  337. };
  338. static const String storyboard_image_scale_mode[] = {
  339. "center",
  340. "scaleAspectFit",
  341. "scaleAspectFill",
  342. "scaleToFill"
  343. };
  344. 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");
  345. 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");
  346. 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");
  347. 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 Distribution");
  348. String str;
  349. String strnew;
  350. str.parse_utf8((const char *)pfile.ptr(), pfile.size());
  351. Vector<String> lines = str.split("\n");
  352. for (int i = 0; i < lines.size(); i++) {
  353. if (lines[i].find("$binary") != -1) {
  354. strnew += lines[i].replace("$binary", p_config.binary_name) + "\n";
  355. } else if (lines[i].find("$modules_buildfile") != -1) {
  356. strnew += lines[i].replace("$modules_buildfile", p_config.modules_buildfile) + "\n";
  357. } else if (lines[i].find("$modules_fileref") != -1) {
  358. strnew += lines[i].replace("$modules_fileref", p_config.modules_fileref) + "\n";
  359. } else if (lines[i].find("$modules_buildphase") != -1) {
  360. strnew += lines[i].replace("$modules_buildphase", p_config.modules_buildphase) + "\n";
  361. } else if (lines[i].find("$modules_buildgrp") != -1) {
  362. strnew += lines[i].replace("$modules_buildgrp", p_config.modules_buildgrp) + "\n";
  363. } else if (lines[i].find("$name") != -1) {
  364. strnew += lines[i].replace("$name", p_config.pkg_name) + "\n";
  365. } else if (lines[i].find("$bundle_identifier") != -1) {
  366. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  367. } else if (lines[i].find("$short_version") != -1) {
  368. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  369. } else if (lines[i].find("$version") != -1) {
  370. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  371. } else if (lines[i].find("$signature") != -1) {
  372. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  373. } else if (lines[i].find("$team_id") != -1) {
  374. strnew += lines[i].replace("$team_id", p_preset->get("application/app_store_team_id")) + "\n";
  375. } else if (lines[i].find("$default_build_config") != -1) {
  376. strnew += lines[i].replace("$default_build_config", p_debug ? "Debug" : "Release") + "\n";
  377. } else if (lines[i].find("$export_method") != -1) {
  378. int export_method = p_preset->get(p_debug ? "application/export_method_debug" : "application/export_method_release");
  379. strnew += lines[i].replace("$export_method", export_method_string[export_method]) + "\n";
  380. } else if (lines[i].find("$provisioning_profile_uuid_release") != -1) {
  381. strnew += lines[i].replace("$provisioning_profile_uuid_release", p_preset->get_or_env("application/provisioning_profile_uuid_release", ENV_IOS_PROFILE_UUID_RELEASE)) + "\n";
  382. } else if (lines[i].find("$provisioning_profile_uuid_debug") != -1) {
  383. strnew += lines[i].replace("$provisioning_profile_uuid_debug", p_preset->get_or_env("application/provisioning_profile_uuid_debug", ENV_IOS_PROFILE_UUID_DEBUG)) + "\n";
  384. } else if (lines[i].find("$code_sign_style_debug") != -1) {
  385. if (dbg_manual) {
  386. strnew += lines[i].replace("$code_sign_style_debug", "Manual") + "\n";
  387. } else {
  388. strnew += lines[i].replace("$code_sign_style_debug", "Automatic") + "\n";
  389. }
  390. } else if (lines[i].find("$code_sign_style_release") != -1) {
  391. if (rel_manual) {
  392. strnew += lines[i].replace("$code_sign_style_release", "Manual") + "\n";
  393. } else {
  394. strnew += lines[i].replace("$code_sign_style_release", "Automatic") + "\n";
  395. }
  396. } else if (lines[i].find("$provisioning_profile_uuid") != -1) {
  397. 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);
  398. strnew += lines[i].replace("$provisioning_profile_uuid", uuid) + "\n";
  399. } else if (lines[i].find("$code_sign_identity_debug") != -1) {
  400. strnew += lines[i].replace("$code_sign_identity_debug", dbg_sign_id) + "\n";
  401. } else if (lines[i].find("$code_sign_identity_release") != -1) {
  402. strnew += lines[i].replace("$code_sign_identity_release", rel_sign_id) + "\n";
  403. } else if (lines[i].find("$additional_plist_content") != -1) {
  404. strnew += lines[i].replace("$additional_plist_content", p_config.plist_content) + "\n";
  405. } else if (lines[i].find("$godot_archs") != -1) {
  406. strnew += lines[i].replace("$godot_archs", p_config.architectures) + "\n";
  407. } else if (lines[i].find("$linker_flags") != -1) {
  408. strnew += lines[i].replace("$linker_flags", p_config.linker_flags) + "\n";
  409. } else if (lines[i].find("$targeted_device_family") != -1) {
  410. String xcode_value;
  411. switch ((int)p_preset->get("application/targeted_device_family")) {
  412. case 0: // iPhone
  413. xcode_value = "1";
  414. break;
  415. case 1: // iPad
  416. xcode_value = "2";
  417. break;
  418. case 2: // iPhone & iPad
  419. xcode_value = "1,2";
  420. break;
  421. }
  422. strnew += lines[i].replace("$targeted_device_family", xcode_value) + "\n";
  423. } else if (lines[i].find("$cpp_code") != -1) {
  424. strnew += lines[i].replace("$cpp_code", p_config.cpp_code) + "\n";
  425. } else if (lines[i].find("$docs_in_place") != -1) {
  426. strnew += lines[i].replace("$docs_in_place", ((bool)p_preset->get("user_data/accessible_from_files_app")) ? "<true/>" : "<false/>") + "\n";
  427. } else if (lines[i].find("$docs_sharing") != -1) {
  428. strnew += lines[i].replace("$docs_sharing", ((bool)p_preset->get("user_data/accessible_from_itunes_sharing")) ? "<true/>" : "<false/>") + "\n";
  429. } else if (lines[i].find("$entitlements_push_notifications") != -1) {
  430. bool is_on = p_preset->get("capabilities/push_notifications");
  431. strnew += lines[i].replace("$entitlements_push_notifications", is_on ? "<key>aps-environment</key><string>development</string>" : "") + "\n";
  432. } else if (lines[i].find("$required_device_capabilities") != -1) {
  433. String capabilities;
  434. // I've removed armv7 as we can run on 64bit only devices
  435. // Note that capabilities listed here are requirements for the app to be installed.
  436. // They don't enable anything.
  437. Vector<String> capabilities_list = p_config.capabilities;
  438. if ((bool)p_preset->get("capabilities/access_wifi") && !capabilities_list.has("wifi")) {
  439. capabilities_list.push_back("wifi");
  440. }
  441. for (int idx = 0; idx < capabilities_list.size(); idx++) {
  442. capabilities += "<string>" + capabilities_list[idx] + "</string>\n";
  443. }
  444. strnew += lines[i].replace("$required_device_capabilities", capabilities);
  445. } else if (lines[i].find("$interface_orientations") != -1) {
  446. String orientations;
  447. const DisplayServer::ScreenOrientation screen_orientation =
  448. DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation")));
  449. switch (screen_orientation) {
  450. case DisplayServer::SCREEN_LANDSCAPE:
  451. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  452. break;
  453. case DisplayServer::SCREEN_PORTRAIT:
  454. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  455. break;
  456. case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
  457. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  458. break;
  459. case DisplayServer::SCREEN_REVERSE_PORTRAIT:
  460. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  461. break;
  462. case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
  463. // Allow both landscape orientations depending on sensor direction.
  464. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  465. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  466. break;
  467. case DisplayServer::SCREEN_SENSOR_PORTRAIT:
  468. // Allow both portrait orientations depending on sensor direction.
  469. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  470. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  471. break;
  472. case DisplayServer::SCREEN_SENSOR:
  473. // Allow all screen orientations depending on sensor direction.
  474. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  475. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  476. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  477. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  478. break;
  479. }
  480. strnew += lines[i].replace("$interface_orientations", orientations);
  481. } else if (lines[i].find("$camera_usage_description") != -1) {
  482. String description = p_preset->get("privacy/camera_usage_description");
  483. strnew += lines[i].replace("$camera_usage_description", description) + "\n";
  484. } else if (lines[i].find("$microphone_usage_description") != -1) {
  485. String description = p_preset->get("privacy/microphone_usage_description");
  486. strnew += lines[i].replace("$microphone_usage_description", description) + "\n";
  487. } else if (lines[i].find("$photolibrary_usage_description") != -1) {
  488. String description = p_preset->get("privacy/photolibrary_usage_description");
  489. strnew += lines[i].replace("$photolibrary_usage_description", description) + "\n";
  490. } else if (lines[i].find("$plist_launch_screen_name") != -1) {
  491. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  492. String value = is_on ? "<key>UILaunchStoryboardName</key>\n<string>Launch Screen</string>" : "";
  493. strnew += lines[i].replace("$plist_launch_screen_name", value) + "\n";
  494. } else if (lines[i].find("$pbx_launch_screen_file_reference") != -1) {
  495. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  496. String value = is_on ? "90DD2D9D24B36E8000717FE1 = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = \"Launch Screen.storyboard\"; sourceTree = \"<group>\"; };" : "";
  497. strnew += lines[i].replace("$pbx_launch_screen_file_reference", value) + "\n";
  498. } else if (lines[i].find("$pbx_launch_screen_copy_files") != -1) {
  499. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  500. String value = is_on ? "90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */," : "";
  501. strnew += lines[i].replace("$pbx_launch_screen_copy_files", value) + "\n";
  502. } else if (lines[i].find("$pbx_launch_screen_build_phase") != -1) {
  503. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  504. String value = is_on ? "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */," : "";
  505. strnew += lines[i].replace("$pbx_launch_screen_build_phase", value) + "\n";
  506. } else if (lines[i].find("$pbx_launch_screen_build_reference") != -1) {
  507. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  508. String value = is_on ? "90DD2D9E24B36E8000717FE1 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 90DD2D9D24B36E8000717FE1 /* Launch Screen.storyboard */; };" : "";
  509. strnew += lines[i].replace("$pbx_launch_screen_build_reference", value) + "\n";
  510. } else if (lines[i].find("$pbx_launch_image_usage_setting") != -1) {
  511. bool is_on = p_preset->get("storyboard/use_launch_screen_storyboard");
  512. String value = is_on ? "" : "ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;";
  513. strnew += lines[i].replace("$pbx_launch_image_usage_setting", value) + "\n";
  514. } else if (lines[i].find("$launch_screen_image_mode") != -1) {
  515. int image_scale_mode = p_preset->get("storyboard/image_scale_mode");
  516. String value;
  517. switch (image_scale_mode) {
  518. case 0: {
  519. String logo_path = GLOBAL_GET("application/boot_splash/image");
  520. bool is_on = GLOBAL_GET("application/boot_splash/fullsize");
  521. // If custom logo is not specified, Godot does not scale default one, so we should do the same.
  522. value = (is_on && logo_path.length() > 0) ? "scaleAspectFit" : "center";
  523. } break;
  524. default: {
  525. value = storyboard_image_scale_mode[image_scale_mode - 1];
  526. }
  527. }
  528. strnew += lines[i].replace("$launch_screen_image_mode", value) + "\n";
  529. } else if (lines[i].find("$launch_screen_background_color") != -1) {
  530. bool use_custom = p_preset->get("storyboard/use_custom_bg_color");
  531. Color color = use_custom ? p_preset->get("storyboard/custom_bg_color") : GLOBAL_GET("application/boot_splash/bg_color");
  532. const String value_format = "red=\"$red\" green=\"$green\" blue=\"$blue\" alpha=\"$alpha\"";
  533. Dictionary value_dictionary;
  534. value_dictionary["red"] = color.r;
  535. value_dictionary["green"] = color.g;
  536. value_dictionary["blue"] = color.b;
  537. value_dictionary["alpha"] = color.a;
  538. String value = value_format.format(value_dictionary, "$_");
  539. strnew += lines[i].replace("$launch_screen_background_color", value) + "\n";
  540. } else if (lines[i].find("$pbx_locale_file_reference") != -1) {
  541. String locale_files;
  542. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  543. if (translations.size() > 0) {
  544. HashSet<String> languages;
  545. for (const String &E : translations) {
  546. Ref<Translation> tr = ResourceLoader::load(E);
  547. if (tr.is_valid() && tr->get_locale() != "en") {
  548. languages.insert(tr->get_locale());
  549. }
  550. }
  551. int index = 0;
  552. for (const String &lang : languages) {
  553. 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";
  554. index++;
  555. }
  556. }
  557. strnew += lines[i].replace("$pbx_locale_file_reference", locale_files);
  558. } else if (lines[i].find("$pbx_locale_build_reference") != -1) {
  559. String locale_files;
  560. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  561. if (translations.size() > 0) {
  562. HashSet<String> languages;
  563. for (const String &E : translations) {
  564. Ref<Translation> tr = ResourceLoader::load(E);
  565. if (tr.is_valid() && tr->get_locale() != "en") {
  566. languages.insert(tr->get_locale());
  567. }
  568. }
  569. int index = 0;
  570. for (const String &lang : languages) {
  571. locale_files += "D0BCFE4518AEBDA2004A" + itos(index).pad_zeros(4) + " /* " + lang + " */,\n";
  572. index++;
  573. }
  574. }
  575. strnew += lines[i].replace("$pbx_locale_build_reference", locale_files);
  576. } else if (lines[i].find("$swift_runtime_migration") != -1) {
  577. String value = !p_config.use_swift_runtime ? "" : "LastSwiftMigration = 1250;";
  578. strnew += lines[i].replace("$swift_runtime_migration", value) + "\n";
  579. } else if (lines[i].find("$swift_runtime_build_settings") != -1) {
  580. String value = !p_config.use_swift_runtime ? "" : R"(
  581. CLANG_ENABLE_MODULES = YES;
  582. SWIFT_OBJC_BRIDGING_HEADER = "$binary/dummy.h";
  583. SWIFT_VERSION = 5.0;
  584. )";
  585. value = value.replace("$binary", p_config.binary_name);
  586. strnew += lines[i].replace("$swift_runtime_build_settings", value) + "\n";
  587. } else if (lines[i].find("$swift_runtime_fileref") != -1) {
  588. String value = !p_config.use_swift_runtime ? "" : R"(
  589. 90B4C2AA2680BC560039117A /* dummy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "dummy.h"; sourceTree = "<group>"; };
  590. 90B4C2B52680C7E90039117A /* dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "dummy.swift"; sourceTree = "<group>"; };
  591. )";
  592. strnew += lines[i].replace("$swift_runtime_fileref", value) + "\n";
  593. } else if (lines[i].find("$swift_runtime_binary_files") != -1) {
  594. String value = !p_config.use_swift_runtime ? "" : R"(
  595. 90B4C2AA2680BC560039117A /* dummy.h */,
  596. 90B4C2B52680C7E90039117A /* dummy.swift */,
  597. )";
  598. strnew += lines[i].replace("$swift_runtime_binary_files", value) + "\n";
  599. } else if (lines[i].find("$swift_runtime_buildfile") != -1) {
  600. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90B4C2B52680C7E90039117A /* dummy.swift */; };";
  601. strnew += lines[i].replace("$swift_runtime_buildfile", value) + "\n";
  602. } else if (lines[i].find("$swift_runtime_build_phase") != -1) {
  603. String value = !p_config.use_swift_runtime ? "" : "90B4C2B62680C7E90039117A /* dummy.swift */,";
  604. strnew += lines[i].replace("$swift_runtime_build_phase", value) + "\n";
  605. } else if (lines[i].find("$priv_collection") != -1) {
  606. bool section_opened = false;
  607. for (uint64_t j = 0; j < sizeof(data_collect_type_info) / sizeof(data_collect_type_info[0]); ++j) {
  608. bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name));
  609. bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name));
  610. bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name));
  611. int purposes = p_preset->get(vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[j].prop_name));
  612. if (data_collected) {
  613. if (!section_opened) {
  614. section_opened = true;
  615. strnew += "\t<key>NSPrivacyCollectedDataTypes</key>\n";
  616. strnew += "\t<array>\n";
  617. }
  618. strnew += "\t\t<dict>\n";
  619. strnew += "\t\t\t<key>NSPrivacyCollectedDataType</key>\n";
  620. strnew += vformat("\t\t\t<string>%s</string>\n", data_collect_type_info[j].type_name);
  621. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeLinked</key>\n";
  622. if (linked) {
  623. strnew += "\t\t\t\t<true/>\n";
  624. } else {
  625. strnew += "\t\t\t\t<false/>\n";
  626. }
  627. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeTracking</key>\n";
  628. if (tracking) {
  629. strnew += "\t\t\t\t<true/>\n";
  630. } else {
  631. strnew += "\t\t\t\t<false/>\n";
  632. }
  633. if (purposes != 0) {
  634. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n";
  635. strnew += "\t\t\t\t<array>\n";
  636. for (uint64_t k = 0; k < sizeof(data_collect_purpose_info) / sizeof(data_collect_purpose_info[0]); ++k) {
  637. if (purposes & (1 << k)) {
  638. strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name);
  639. }
  640. }
  641. strnew += "\t\t\t\t</array>\n";
  642. }
  643. strnew += "\t\t\t</dict>\n";
  644. }
  645. }
  646. if (section_opened) {
  647. strnew += "\t</array>\n";
  648. }
  649. } else if (lines[i].find("$priv_tracking") != -1) {
  650. bool tracking = p_preset->get("privacy/tracking_enabled");
  651. strnew += "\t<key>NSPrivacyTracking</key>\n";
  652. if (tracking) {
  653. strnew += "\t<true/>\n";
  654. } else {
  655. strnew += "\t<false/>\n";
  656. }
  657. Vector<String> tracking_domains = p_preset->get("privacy/tracking_domains");
  658. if (!tracking_domains.is_empty()) {
  659. strnew += "\t<key>NSPrivacyTrackingDomains</key>\n";
  660. strnew += "\t<array>\n";
  661. for (const String &E : tracking_domains) {
  662. strnew += "\t\t<string>" + E + "</string>\n";
  663. }
  664. strnew += "\t</array>\n";
  665. }
  666. } else if (lines[i].find("$priv_api_types") != -1) {
  667. strnew += "\t<array>\n";
  668. for (uint64_t j = 0; j < sizeof(api_info) / sizeof(api_info[0]); ++j) {
  669. int api_access = p_preset->get(vformat("privacy/%s_access_reasons", api_info[j].prop_name));
  670. if (api_access != 0) {
  671. strnew += "\t\t<dict>\n";
  672. strnew += "\t\t\t<key>NSPrivacyAccessedAPITypeReasons</key>\n";
  673. strnew += "\t\t\t<array>\n";
  674. for (int k = 0; k < api_info[j].prop_flag_value.size(); k++) {
  675. if (api_access & (1 << k)) {
  676. strnew += vformat("\t\t\t\t<string>%s</string>\n", api_info[j].prop_flag_value[k]);
  677. }
  678. }
  679. strnew += "\t\t\t</array>\n";
  680. strnew += "\t\t\t<key>NSPrivacyAccessedAPIType</key>\n";
  681. strnew += vformat("\t\t\t<string>%s</string>\n", api_info[j].type_name);
  682. strnew += "\t\t</dict>\n";
  683. }
  684. }
  685. strnew += "\t</array>\n";
  686. } else {
  687. strnew += lines[i] + "\n";
  688. }
  689. }
  690. // !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...
  691. // should apply the same fix in our macOS export.
  692. CharString cs = strnew.utf8();
  693. pfile.resize(cs.size() - 1);
  694. for (int i = 0; i < cs.size() - 1; i++) {
  695. pfile.write[i] = cs[i];
  696. }
  697. }
  698. String EditorExportPlatformIOS::_get_additional_plist_content() {
  699. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  700. String result;
  701. for (int i = 0; i < export_plugins.size(); ++i) {
  702. result += export_plugins[i]->get_ios_plist_content();
  703. }
  704. return result;
  705. }
  706. String EditorExportPlatformIOS::_get_linker_flags() {
  707. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  708. String result;
  709. for (int i = 0; i < export_plugins.size(); ++i) {
  710. String flags = export_plugins[i]->get_ios_linker_flags();
  711. if (flags.length() == 0) {
  712. continue;
  713. }
  714. if (result.length() > 0) {
  715. result += ' ';
  716. }
  717. result += flags;
  718. }
  719. // the flags will be enclosed in quotes, so need to escape them
  720. return result.replace("\"", "\\\"");
  721. }
  722. String EditorExportPlatformIOS::_get_cpp_code() {
  723. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  724. String result;
  725. for (int i = 0; i < export_plugins.size(); ++i) {
  726. result += export_plugins[i]->get_ios_cpp_code();
  727. }
  728. return result;
  729. }
  730. void EditorExportPlatformIOS::_blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot) {
  731. ERR_FAIL_COND(p_dst.is_null());
  732. ERR_FAIL_COND(p_src.is_null());
  733. int sw = p_rot ? p_src->get_height() : p_src->get_width();
  734. int sh = p_rot ? p_src->get_width() : p_src->get_height();
  735. int x_pos = (p_dst->get_width() - sw) / 2;
  736. int y_pos = (p_dst->get_height() - sh) / 2;
  737. int xs = (x_pos >= 0) ? 0 : -x_pos;
  738. int ys = (y_pos >= 0) ? 0 : -y_pos;
  739. if (sw + x_pos > p_dst->get_width()) {
  740. sw = p_dst->get_width() - x_pos;
  741. }
  742. if (sh + y_pos > p_dst->get_height()) {
  743. sh = p_dst->get_height() - y_pos;
  744. }
  745. for (int y = ys; y < sh; y++) {
  746. for (int x = xs; x < sw; x++) {
  747. Color sc = p_rot ? p_src->get_pixel(p_src->get_width() - y - 1, x) : p_src->get_pixel(x, y);
  748. Color dc = p_dst->get_pixel(x_pos + x, y_pos + y);
  749. dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r);
  750. dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g);
  751. dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b);
  752. dc.a = (double)(sc.a + dc.a * (1.0 - sc.a));
  753. p_dst->set_pixel(x_pos + x, y_pos + y, dc);
  754. }
  755. }
  756. }
  757. Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
  758. String json_description = "{\"images\":[";
  759. String sizes;
  760. Ref<DirAccess> da = DirAccess::open(p_iconset_dir);
  761. ERR_FAIL_COND_V_MSG(da.is_null(), ERR_CANT_OPEN, "Cannot open directory '" + p_iconset_dir + "'.");
  762. Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
  763. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  764. IconInfo info = icon_infos[i];
  765. int side_size = String(info.actual_size_side).to_int();
  766. String icon_path = p_preset->get(info.preset_key);
  767. if (icon_path.length() == 0) {
  768. // Resize main app icon
  769. icon_path = GLOBAL_GET("application/config/icon");
  770. Ref<Image> img = memnew(Image);
  771. Error err = ImageLoader::load_image(icon_path, img);
  772. if (err != OK) {
  773. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  774. return ERR_UNCONFIGURED;
  775. } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  776. add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
  777. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  778. Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
  779. new_img->fill(boot_bg_color);
  780. _blend_and_rotate(new_img, img, false);
  781. err = new_img->save_png(p_iconset_dir + info.export_name);
  782. } else {
  783. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  784. err = img->save_png(p_iconset_dir + info.export_name);
  785. }
  786. if (err) {
  787. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  788. return err;
  789. }
  790. } else {
  791. // Load custom icon and resize if required
  792. Ref<Image> img = memnew(Image);
  793. Error err = ImageLoader::load_image(icon_path, img);
  794. if (err != OK) {
  795. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path));
  796. return ERR_UNCONFIGURED;
  797. } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) {
  798. add_message(EXPORT_MESSAGE_WARNING, TTR("Export Icons"), vformat("Icon (%s) must be opaque.", info.preset_key));
  799. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  800. Ref<Image> new_img = Image::create_empty(side_size, side_size, false, Image::FORMAT_RGBA8);
  801. new_img->fill(boot_bg_color);
  802. _blend_and_rotate(new_img, img, false);
  803. err = new_img->save_png(p_iconset_dir + info.export_name);
  804. } else if (img->get_width() != side_size || img->get_height() != side_size) {
  805. 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)));
  806. img->resize(side_size, side_size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  807. err = img->save_png(p_iconset_dir + info.export_name);
  808. } else {
  809. err = da->copy(icon_path, p_iconset_dir + info.export_name);
  810. }
  811. if (err) {
  812. add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Failed to export icon (%s): '%s'.", info.preset_key, icon_path));
  813. return err;
  814. }
  815. }
  816. sizes += String(info.actual_size_side) + "\n";
  817. if (i > 0) {
  818. json_description += ",";
  819. }
  820. json_description += String("{");
  821. json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
  822. json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
  823. json_description += String("\"scale\":") + "\"" + info.scale + "\",";
  824. json_description += String("\"filename\":") + "\"" + info.export_name + "\"";
  825. json_description += String("}");
  826. }
  827. json_description += "]}";
  828. Ref<FileAccess> json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
  829. ERR_FAIL_COND_V(json_file.is_null(), ERR_CANT_CREATE);
  830. CharString json_utf8 = json_description.utf8();
  831. json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
  832. Ref<FileAccess> sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
  833. ERR_FAIL_COND_V(sizes_file.is_null(), ERR_CANT_CREATE);
  834. CharString sizes_utf8 = sizes.utf8();
  835. sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
  836. return OK;
  837. }
  838. Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  839. const String custom_launch_image_2x = p_preset->get("storyboard/custom_image@2x");
  840. const String custom_launch_image_3x = p_preset->get("storyboard/custom_image@3x");
  841. if (custom_launch_image_2x.length() > 0 && custom_launch_image_3x.length() > 0) {
  842. Ref<Image> image;
  843. String image_path = p_dest_dir.path_join("splash@2x.png");
  844. image.instantiate();
  845. Error err = ImageLoader::load_image(custom_launch_image_2x, image);
  846. if (err) {
  847. image.unref();
  848. return err;
  849. }
  850. if (image->save_png(image_path) != OK) {
  851. return ERR_FILE_CANT_WRITE;
  852. }
  853. image.unref();
  854. image_path = p_dest_dir.path_join("splash@3x.png");
  855. image.instantiate();
  856. err = ImageLoader::load_image(custom_launch_image_3x, image);
  857. if (err) {
  858. image.unref();
  859. return err;
  860. }
  861. if (image->save_png(image_path) != OK) {
  862. return ERR_FILE_CANT_WRITE;
  863. }
  864. } else {
  865. Ref<Image> splash;
  866. const String splash_path = GLOBAL_GET("application/boot_splash/image");
  867. if (!splash_path.is_empty()) {
  868. splash.instantiate();
  869. const Error err = ImageLoader::load_image(splash_path, splash);
  870. if (err) {
  871. splash.unref();
  872. }
  873. }
  874. if (splash.is_null()) {
  875. splash = Ref<Image>(memnew(Image(boot_splash_png)));
  876. }
  877. // Using same image for both @2x and @3x
  878. // because Godot's own boot logo uses single image for all resolutions.
  879. // Also not using @1x image, because devices using this image variant
  880. // are not supported by iOS 9, which is minimal target.
  881. const String splash_png_path_2x = p_dest_dir.path_join("splash@2x.png");
  882. const String splash_png_path_3x = p_dest_dir.path_join("splash@3x.png");
  883. if (splash->save_png(splash_png_path_2x) != OK) {
  884. return ERR_FILE_CANT_WRITE;
  885. }
  886. if (splash->save_png(splash_png_path_3x) != OK) {
  887. return ERR_FILE_CANT_WRITE;
  888. }
  889. }
  890. return OK;
  891. }
  892. Error EditorExportPlatformIOS::_export_loading_screen_images(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  893. Ref<DirAccess> da = DirAccess::open(p_dest_dir);
  894. ERR_FAIL_COND_V_MSG(da.is_null(), ERR_CANT_OPEN, "Cannot open directory '" + p_dest_dir + "'.");
  895. for (uint64_t i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  896. LoadingScreenInfo info = loading_screen_infos[i];
  897. String loading_screen_file = p_preset->get(info.preset_key);
  898. Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
  899. String boot_logo_path = GLOBAL_GET("application/boot_splash/image");
  900. bool boot_logo_scale = GLOBAL_GET("application/boot_splash/fullsize");
  901. if (loading_screen_file.size() > 0) {
  902. // Load custom loading screens, and resize if required.
  903. Ref<Image> img = memnew(Image);
  904. Error err = ImageLoader::load_image(loading_screen_file, img);
  905. if (err != OK) {
  906. ERR_PRINT("Invalid loading screen (" + String(info.preset_key) + "): '" + loading_screen_file + "'.");
  907. return ERR_UNCONFIGURED;
  908. }
  909. if (img->get_width() != info.width || img->get_height() != info.height) {
  910. WARN_PRINT("Loading screen (" + String(info.preset_key) + "): '" + loading_screen_file + "' has incorrect size (" + String::num_int64(img->get_width()) + "x" + String::num_int64(img->get_height()) + ") and was automatically resized to " + String::num_int64(info.width) + "x" + String::num_int64(info.height) + ".");
  911. float aspect_ratio = (float)img->get_width() / (float)img->get_height();
  912. if (boot_logo_scale) {
  913. if (info.height * aspect_ratio <= info.width) {
  914. img->resize(info.height * aspect_ratio, info.height, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  915. } else {
  916. img->resize(info.width, info.width / aspect_ratio, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  917. }
  918. }
  919. Ref<Image> new_img = Image::create_empty(info.width, info.height, false, Image::FORMAT_RGBA8);
  920. new_img->fill(boot_bg_color);
  921. _blend_and_rotate(new_img, img, false);
  922. err = new_img->save_png(p_dest_dir + info.export_name);
  923. } else {
  924. err = da->copy(loading_screen_file, p_dest_dir + info.export_name);
  925. }
  926. if (err) {
  927. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from path '" + loading_screen_file + "'.";
  928. ERR_PRINT(err_str.utf8().get_data());
  929. return err;
  930. }
  931. } else {
  932. // Generate loading screen from the splash screen
  933. Ref<Image> img = Image::create_empty(info.width, info.height, false, Image::FORMAT_RGBA8);
  934. img->fill(boot_bg_color);
  935. Ref<Image> img_bs;
  936. if (boot_logo_path.length() > 0) {
  937. img_bs = Ref<Image>(memnew(Image));
  938. ImageLoader::load_image(boot_logo_path, img_bs);
  939. }
  940. if (!img_bs.is_valid()) {
  941. img_bs = Ref<Image>(memnew(Image(boot_splash_png)));
  942. }
  943. if (img_bs.is_valid()) {
  944. float aspect_ratio = (float)img_bs->get_width() / (float)img_bs->get_height();
  945. if (info.rotate) {
  946. if (boot_logo_scale) {
  947. if (info.width * aspect_ratio <= info.height) {
  948. img_bs->resize(info.width * aspect_ratio, info.width, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  949. } else {
  950. img_bs->resize(info.height, info.height / aspect_ratio, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  951. }
  952. }
  953. } else {
  954. if (boot_logo_scale) {
  955. if (info.height * aspect_ratio <= info.width) {
  956. img_bs->resize(info.height * aspect_ratio, info.height, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  957. } else {
  958. img_bs->resize(info.width, info.width / aspect_ratio, (Image::Interpolation)(p_preset->get("application/launch_screens_interpolation").operator int()));
  959. }
  960. }
  961. }
  962. _blend_and_rotate(img, img_bs, info.rotate);
  963. }
  964. Error err = img->save_png(p_dest_dir + info.export_name);
  965. if (err) {
  966. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from splash screen.";
  967. WARN_PRINT(err_str.utf8().get_data());
  968. }
  969. }
  970. }
  971. return OK;
  972. }
  973. Error EditorExportPlatformIOS::_walk_dir_recursive(Ref<DirAccess> &p_da, FileHandler p_handler, void *p_userdata) {
  974. Vector<String> dirs;
  975. String current_dir = p_da->get_current_dir();
  976. p_da->list_dir_begin();
  977. String path = p_da->get_next();
  978. while (!path.is_empty()) {
  979. if (p_da->current_is_dir()) {
  980. if (path != "." && path != "..") {
  981. dirs.push_back(path);
  982. }
  983. } else {
  984. Error err = p_handler(current_dir.path_join(path), p_userdata);
  985. if (err) {
  986. p_da->list_dir_end();
  987. return err;
  988. }
  989. }
  990. path = p_da->get_next();
  991. }
  992. p_da->list_dir_end();
  993. for (int i = 0; i < dirs.size(); ++i) {
  994. String dir = dirs[i];
  995. p_da->change_dir(dir);
  996. Error err = _walk_dir_recursive(p_da, p_handler, p_userdata);
  997. p_da->change_dir("..");
  998. if (err) {
  999. return err;
  1000. }
  1001. }
  1002. return OK;
  1003. }
  1004. struct CodesignData {
  1005. const Ref<EditorExportPreset> &preset;
  1006. bool debug = false;
  1007. CodesignData(const Ref<EditorExportPreset> &p_preset, bool p_debug) :
  1008. preset(p_preset),
  1009. debug(p_debug) {
  1010. }
  1011. };
  1012. Error EditorExportPlatformIOS::_codesign(String p_file, void *p_userdata) {
  1013. if (p_file.ends_with(".dylib")) {
  1014. CodesignData *data = static_cast<CodesignData *>(p_userdata);
  1015. print_line(String("Signing ") + p_file);
  1016. String sign_id;
  1017. if (data->debug) {
  1018. sign_id = data->preset->get("application/code_sign_identity_debug").operator String().is_empty() ? "iPhone Developer" : data->preset->get("application/code_sign_identity_debug");
  1019. } else {
  1020. sign_id = data->preset->get("application/code_sign_identity_release").operator String().is_empty() ? "iPhone Distribution" : data->preset->get("application/code_sign_identity_release");
  1021. }
  1022. List<String> codesign_args;
  1023. codesign_args.push_back("-f");
  1024. codesign_args.push_back("-s");
  1025. codesign_args.push_back(sign_id);
  1026. codesign_args.push_back(p_file);
  1027. String str;
  1028. Error err = OS::get_singleton()->execute("codesign", codesign_args, &str, nullptr, true);
  1029. print_verbose("codesign (" + p_file + "):\n" + str);
  1030. return err;
  1031. }
  1032. return OK;
  1033. }
  1034. struct PbxId {
  1035. private:
  1036. static char _hex_char(uint8_t four_bits) {
  1037. if (four_bits < 10) {
  1038. return ('0' + four_bits);
  1039. }
  1040. return 'A' + (four_bits - 10);
  1041. }
  1042. static String _hex_pad(uint32_t num) {
  1043. Vector<char> ret;
  1044. ret.resize(sizeof(num) * 2);
  1045. for (uint64_t i = 0; i < sizeof(num) * 2; ++i) {
  1046. uint8_t four_bits = (num >> (sizeof(num) * 8 - (i + 1) * 4)) & 0xF;
  1047. ret.write[i] = _hex_char(four_bits);
  1048. }
  1049. return String::utf8(ret.ptr(), ret.size());
  1050. }
  1051. public:
  1052. uint32_t high_bits;
  1053. uint32_t mid_bits;
  1054. uint32_t low_bits;
  1055. String str() const {
  1056. return _hex_pad(high_bits) + _hex_pad(mid_bits) + _hex_pad(low_bits);
  1057. }
  1058. PbxId &operator++() {
  1059. low_bits++;
  1060. if (!low_bits) {
  1061. mid_bits++;
  1062. if (!mid_bits) {
  1063. high_bits++;
  1064. }
  1065. }
  1066. return *this;
  1067. }
  1068. };
  1069. struct ExportLibsData {
  1070. Vector<String> lib_paths;
  1071. String dest_dir;
  1072. };
  1073. void EditorExportPlatformIOS::_add_assets_to_project(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) {
  1074. // that is just a random number, we just need Godot IDs not to clash with
  1075. // existing IDs in the project.
  1076. PbxId current_id = { 0x58938401, 0, 0 };
  1077. String pbx_files;
  1078. String pbx_frameworks_build;
  1079. String pbx_frameworks_refs;
  1080. String pbx_resources_build;
  1081. String pbx_resources_refs;
  1082. String pbx_embeded_frameworks;
  1083. const String file_info_format = String("$build_id = {isa = PBXBuildFile; fileRef = $ref_id; };\n") +
  1084. "$ref_id = {isa = PBXFileReference; lastKnownFileType = $file_type; name = \"$name\"; path = \"$file_path\"; sourceTree = \"<group>\"; };\n";
  1085. for (int i = 0; i < p_additional_assets.size(); ++i) {
  1086. String additional_asset_info_format = file_info_format;
  1087. String build_id = (++current_id).str();
  1088. String ref_id = (++current_id).str();
  1089. String framework_id = "";
  1090. const IOSExportAsset &asset = p_additional_assets[i];
  1091. String type;
  1092. if (asset.exported_path.ends_with(".framework")) {
  1093. if (asset.should_embed) {
  1094. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  1095. framework_id = (++current_id).str();
  1096. pbx_embeded_frameworks += framework_id + ",\n";
  1097. }
  1098. type = "wrapper.framework";
  1099. } else if (asset.exported_path.ends_with(".xcframework")) {
  1100. if (asset.should_embed) {
  1101. additional_asset_info_format += "$framework_id = {isa = PBXBuildFile; fileRef = $ref_id; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };\n";
  1102. framework_id = (++current_id).str();
  1103. pbx_embeded_frameworks += framework_id + ",\n";
  1104. }
  1105. type = "wrapper.xcframework";
  1106. } else if (asset.exported_path.ends_with(".dylib")) {
  1107. type = "compiled.mach-o.dylib";
  1108. } else if (asset.exported_path.ends_with(".a")) {
  1109. type = "archive.ar";
  1110. } else {
  1111. type = "file";
  1112. }
  1113. String &pbx_build = asset.is_framework ? pbx_frameworks_build : pbx_resources_build;
  1114. String &pbx_refs = asset.is_framework ? pbx_frameworks_refs : pbx_resources_refs;
  1115. if (pbx_build.length() > 0) {
  1116. pbx_build += ",\n";
  1117. pbx_refs += ",\n";
  1118. }
  1119. pbx_build += build_id;
  1120. pbx_refs += ref_id;
  1121. Dictionary format_dict;
  1122. format_dict["build_id"] = build_id;
  1123. format_dict["ref_id"] = ref_id;
  1124. format_dict["name"] = asset.exported_path.get_file();
  1125. format_dict["file_path"] = asset.exported_path;
  1126. format_dict["file_type"] = type;
  1127. if (framework_id.length() > 0) {
  1128. format_dict["framework_id"] = framework_id;
  1129. }
  1130. pbx_files += additional_asset_info_format.format(format_dict, "$_");
  1131. }
  1132. // Note, frameworks like gamekit are always included in our project.pbxprof file
  1133. // even if turned off in capabilities.
  1134. String str = String::utf8((const char *)p_project_data.ptr(), p_project_data.size());
  1135. str = str.replace("$additional_pbx_files", pbx_files);
  1136. str = str.replace("$additional_pbx_frameworks_build", pbx_frameworks_build);
  1137. str = str.replace("$additional_pbx_frameworks_refs", pbx_frameworks_refs);
  1138. str = str.replace("$additional_pbx_resources_build", pbx_resources_build);
  1139. str = str.replace("$additional_pbx_resources_refs", pbx_resources_refs);
  1140. str = str.replace("$pbx_embeded_frameworks", pbx_embeded_frameworks);
  1141. CharString cs = str.utf8();
  1142. p_project_data.resize(cs.size() - 1);
  1143. for (int i = 0; i < cs.size() - 1; i++) {
  1144. p_project_data.write[i] = cs[i];
  1145. }
  1146. }
  1147. Error EditorExportPlatformIOS::_copy_asset(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) {
  1148. String binary_name = p_out_dir.get_file().get_basename();
  1149. Ref<DirAccess> da = DirAccess::create_for_path(p_asset);
  1150. if (da.is_null()) {
  1151. ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't create directory: " + p_asset + ".");
  1152. }
  1153. bool file_exists = da->file_exists(p_asset);
  1154. bool dir_exists = da->dir_exists(p_asset);
  1155. if (!file_exists && !dir_exists) {
  1156. return ERR_FILE_NOT_FOUND;
  1157. }
  1158. String base_dir = p_asset.get_base_dir().replace("res://", "");
  1159. String destination_dir;
  1160. String destination;
  1161. String asset_path;
  1162. bool create_framework = false;
  1163. if (p_is_framework && p_asset.ends_with(".dylib")) {
  1164. // For iOS we need to turn .dylib into .framework
  1165. // to be able to send application to AppStore
  1166. asset_path = String("dylibs").path_join(base_dir);
  1167. String file_name;
  1168. if (!p_custom_file_name) {
  1169. file_name = p_asset.get_basename().get_file();
  1170. } else {
  1171. file_name = *p_custom_file_name;
  1172. }
  1173. String framework_name = file_name + ".framework";
  1174. asset_path = asset_path.path_join(framework_name);
  1175. destination_dir = p_out_dir.path_join(asset_path);
  1176. destination = destination_dir.path_join(file_name);
  1177. create_framework = true;
  1178. } else if (p_is_framework && (p_asset.ends_with(".framework") || p_asset.ends_with(".xcframework"))) {
  1179. asset_path = String("dylibs").path_join(base_dir);
  1180. String file_name;
  1181. if (!p_custom_file_name) {
  1182. file_name = p_asset.get_file();
  1183. } else {
  1184. file_name = *p_custom_file_name;
  1185. }
  1186. asset_path = asset_path.path_join(file_name);
  1187. destination_dir = p_out_dir.path_join(asset_path);
  1188. destination = destination_dir;
  1189. } else {
  1190. asset_path = base_dir;
  1191. String file_name;
  1192. if (!p_custom_file_name) {
  1193. file_name = p_asset.get_file();
  1194. } else {
  1195. file_name = *p_custom_file_name;
  1196. }
  1197. destination_dir = p_out_dir.path_join(asset_path);
  1198. asset_path = asset_path.path_join(file_name);
  1199. destination = p_out_dir.path_join(asset_path);
  1200. }
  1201. Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1202. ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_out_dir + "'.");
  1203. if (!filesystem_da->dir_exists(destination_dir)) {
  1204. Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir);
  1205. if (make_dir_err) {
  1206. return make_dir_err;
  1207. }
  1208. }
  1209. Error err = dir_exists ? da->copy_dir(p_asset, destination) : da->copy(p_asset, destination);
  1210. if (err) {
  1211. return err;
  1212. }
  1213. IOSExportAsset exported_asset = { binary_name.path_join(asset_path), p_is_framework, p_should_embed };
  1214. r_exported_assets.push_back(exported_asset);
  1215. if (create_framework) {
  1216. String file_name;
  1217. if (!p_custom_file_name) {
  1218. file_name = p_asset.get_basename().get_file();
  1219. } else {
  1220. file_name = *p_custom_file_name;
  1221. }
  1222. String framework_name = file_name + ".framework";
  1223. // Performing `install_name_tool -id @rpath/{name}.framework/{name} ./{name}` on dylib
  1224. {
  1225. List<String> install_name_args;
  1226. install_name_args.push_back("-id");
  1227. install_name_args.push_back(String("@rpath").path_join(framework_name).path_join(file_name));
  1228. install_name_args.push_back(destination);
  1229. OS::get_singleton()->execute("install_name_tool", install_name_args);
  1230. }
  1231. // Creating Info.plist
  1232. {
  1233. String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1234. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  1235. "<plist version=\"1.0\">\n"
  1236. "<dict>\n"
  1237. "<key>CFBundleShortVersionString</key>\n"
  1238. "<string>1.0</string>\n"
  1239. "<key>CFBundleIdentifier</key>\n"
  1240. "<string>com.gdextension.framework.$name</string>\n"
  1241. "<key>CFBundleName</key>\n"
  1242. "<string>$name</string>\n"
  1243. "<key>CFBundleExecutable</key>\n"
  1244. "<string>$name</string>\n"
  1245. "<key>DTPlatformName</key>\n"
  1246. "<string>iphoneos</string>\n"
  1247. "<key>CFBundleInfoDictionaryVersion</key>\n"
  1248. "<string>6.0</string>\n"
  1249. "<key>CFBundleVersion</key>\n"
  1250. "<string>1</string>\n"
  1251. "<key>CFBundlePackageType</key>\n"
  1252. "<string>FMWK</string>\n"
  1253. "<key>MinimumOSVersion</key>\n"
  1254. "<string>10.0</string>\n"
  1255. "</dict>\n"
  1256. "</plist>";
  1257. String info_plist = info_plist_format.replace("$name", file_name);
  1258. Ref<FileAccess> f = FileAccess::open(destination_dir.path_join("Info.plist"), FileAccess::WRITE);
  1259. if (f.is_valid()) {
  1260. f->store_string(info_plist);
  1261. }
  1262. }
  1263. }
  1264. return OK;
  1265. }
  1266. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, bool p_should_embed, Vector<IOSExportAsset> &r_exported_assets) {
  1267. for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) {
  1268. String asset = p_assets[f_idx];
  1269. if (!asset.begins_with("res://")) {
  1270. // either SDK-builtin or already a part of the export template
  1271. IOSExportAsset exported_asset = { asset, p_is_framework, p_should_embed };
  1272. r_exported_assets.push_back(exported_asset);
  1273. } else {
  1274. Error err = _copy_asset(p_out_dir, asset, nullptr, p_is_framework, p_should_embed, r_exported_assets);
  1275. ERR_FAIL_COND_V(err, err);
  1276. }
  1277. }
  1278. return OK;
  1279. }
  1280. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets) {
  1281. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1282. for (int i = 0; i < export_plugins.size(); i++) {
  1283. Vector<String> linked_frameworks = export_plugins[i]->get_ios_frameworks();
  1284. Error err = _export_additional_assets(p_out_dir, linked_frameworks, true, false, r_exported_assets);
  1285. ERR_FAIL_COND_V(err, err);
  1286. Vector<String> embedded_frameworks = export_plugins[i]->get_ios_embedded_frameworks();
  1287. err = _export_additional_assets(p_out_dir, embedded_frameworks, true, true, r_exported_assets);
  1288. ERR_FAIL_COND_V(err, err);
  1289. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1290. for (int j = 0; j < project_static_libs.size(); j++) {
  1291. project_static_libs.write[j] = project_static_libs[j].get_file(); // Only the file name as it's copied to the project
  1292. }
  1293. err = _export_additional_assets(p_out_dir, project_static_libs, true, false, r_exported_assets);
  1294. ERR_FAIL_COND_V(err, err);
  1295. Vector<String> ios_bundle_files = export_plugins[i]->get_ios_bundle_files();
  1296. err = _export_additional_assets(p_out_dir, ios_bundle_files, false, false, r_exported_assets);
  1297. ERR_FAIL_COND_V(err, err);
  1298. }
  1299. Vector<String> library_paths;
  1300. for (int i = 0; i < p_libraries.size(); ++i) {
  1301. library_paths.push_back(p_libraries[i].path);
  1302. }
  1303. Error err = _export_additional_assets(p_out_dir, library_paths, true, true, r_exported_assets);
  1304. ERR_FAIL_COND_V(err, err);
  1305. return OK;
  1306. }
  1307. Vector<String> EditorExportPlatformIOS::_get_preset_architectures(const Ref<EditorExportPreset> &p_preset) const {
  1308. Vector<ExportArchitecture> all_archs = _get_supported_architectures();
  1309. Vector<String> enabled_archs;
  1310. for (int i = 0; i < all_archs.size(); ++i) {
  1311. bool is_enabled = p_preset->get("architectures/" + all_archs[i].name);
  1312. if (is_enabled) {
  1313. enabled_archs.push_back(all_archs[i].name);
  1314. }
  1315. }
  1316. return enabled_archs;
  1317. }
  1318. 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) {
  1319. String plugin_definition_cpp_code;
  1320. String plugin_initialization_cpp_code;
  1321. String plugin_deinitialization_cpp_code;
  1322. Vector<String> plugin_linked_dependencies;
  1323. Vector<String> plugin_embedded_dependencies;
  1324. Vector<String> plugin_files;
  1325. Vector<PluginConfigIOS> enabled_plugins = get_enabled_plugins(p_preset);
  1326. Vector<String> added_linked_dependenciy_names;
  1327. Vector<String> added_embedded_dependenciy_names;
  1328. HashMap<String, String> plist_values;
  1329. HashSet<String> plugin_linker_flags;
  1330. Error err;
  1331. for (int i = 0; i < enabled_plugins.size(); i++) {
  1332. PluginConfigIOS plugin = enabled_plugins[i];
  1333. // Export plugin binary.
  1334. String plugin_main_binary = PluginConfigIOS::get_plugin_main_binary(plugin, p_debug);
  1335. String plugin_binary_result_file = plugin.binary.get_file();
  1336. // We shouldn't embed .xcframework that contains static libraries.
  1337. // Static libraries are not embedded anyway.
  1338. err = _copy_asset(dest_dir, plugin_main_binary, &plugin_binary_result_file, true, false, r_exported_assets);
  1339. ERR_FAIL_COND_V(err, err);
  1340. // Adding dependencies.
  1341. // Use separate container for names to check for duplicates.
  1342. for (int j = 0; j < plugin.linked_dependencies.size(); j++) {
  1343. String dependency = plugin.linked_dependencies[j];
  1344. String name = dependency.get_file();
  1345. if (added_linked_dependenciy_names.has(name)) {
  1346. continue;
  1347. }
  1348. added_linked_dependenciy_names.push_back(name);
  1349. plugin_linked_dependencies.push_back(dependency);
  1350. }
  1351. for (int j = 0; j < plugin.system_dependencies.size(); j++) {
  1352. String dependency = plugin.system_dependencies[j];
  1353. String name = dependency.get_file();
  1354. if (added_linked_dependenciy_names.has(name)) {
  1355. continue;
  1356. }
  1357. added_linked_dependenciy_names.push_back(name);
  1358. plugin_linked_dependencies.push_back(dependency);
  1359. }
  1360. for (int j = 0; j < plugin.embedded_dependencies.size(); j++) {
  1361. String dependency = plugin.embedded_dependencies[j];
  1362. String name = dependency.get_file();
  1363. if (added_embedded_dependenciy_names.has(name)) {
  1364. continue;
  1365. }
  1366. added_embedded_dependenciy_names.push_back(name);
  1367. plugin_embedded_dependencies.push_back(dependency);
  1368. }
  1369. plugin_files.append_array(plugin.files_to_copy);
  1370. // Capabilities
  1371. // Also checking for duplicates.
  1372. for (int j = 0; j < plugin.capabilities.size(); j++) {
  1373. String capability = plugin.capabilities[j];
  1374. if (p_config_data.capabilities.has(capability)) {
  1375. continue;
  1376. }
  1377. p_config_data.capabilities.push_back(capability);
  1378. }
  1379. // Linker flags
  1380. // Checking duplicates
  1381. for (int j = 0; j < plugin.linker_flags.size(); j++) {
  1382. String linker_flag = plugin.linker_flags[j];
  1383. plugin_linker_flags.insert(linker_flag);
  1384. }
  1385. // Plist
  1386. // Using hash map container to remove duplicates
  1387. for (const KeyValue<String, PluginConfigIOS::PlistItem> &E : plugin.plist) {
  1388. String key = E.key;
  1389. const PluginConfigIOS::PlistItem &item = E.value;
  1390. String value;
  1391. switch (item.type) {
  1392. case PluginConfigIOS::PlistItemType::STRING_INPUT: {
  1393. String preset_name = "plugins_plist/" + key;
  1394. String input_value = p_preset->get(preset_name);
  1395. value = "<string>" + input_value + "</string>";
  1396. } break;
  1397. default:
  1398. value = item.value;
  1399. break;
  1400. }
  1401. if (key.is_empty() || value.is_empty()) {
  1402. continue;
  1403. }
  1404. String plist_key = "<key>" + key + "</key>";
  1405. plist_values[plist_key] = value;
  1406. }
  1407. // CPP Code
  1408. String definition_comment = "// Plugin: " + plugin.name + "\n";
  1409. String initialization_method = plugin.initialization_method + "();\n";
  1410. String deinitialization_method = plugin.deinitialization_method + "();\n";
  1411. plugin_definition_cpp_code += definition_comment +
  1412. "extern void " + initialization_method +
  1413. "extern void " + deinitialization_method + "\n";
  1414. plugin_initialization_cpp_code += "\t" + initialization_method;
  1415. plugin_deinitialization_cpp_code += "\t" + deinitialization_method;
  1416. if (plugin.use_swift_runtime) {
  1417. p_config_data.use_swift_runtime = true;
  1418. }
  1419. }
  1420. // Updating `Info.plist`
  1421. {
  1422. for (const KeyValue<String, String> &E : plist_values) {
  1423. String key = E.key;
  1424. String value = E.value;
  1425. if (key.is_empty() || value.is_empty()) {
  1426. continue;
  1427. }
  1428. p_config_data.plist_content += key + value + "\n";
  1429. }
  1430. }
  1431. // Export files
  1432. {
  1433. // Export linked plugin dependency
  1434. err = _export_additional_assets(dest_dir, plugin_linked_dependencies, true, false, r_exported_assets);
  1435. ERR_FAIL_COND_V(err, err);
  1436. // Export embedded plugin dependency
  1437. err = _export_additional_assets(dest_dir, plugin_embedded_dependencies, true, true, r_exported_assets);
  1438. ERR_FAIL_COND_V(err, err);
  1439. // Export plugin files
  1440. err = _export_additional_assets(dest_dir, plugin_files, false, false, r_exported_assets);
  1441. ERR_FAIL_COND_V(err, err);
  1442. }
  1443. // Update CPP
  1444. {
  1445. Dictionary plugin_format;
  1446. plugin_format["definition"] = plugin_definition_cpp_code;
  1447. plugin_format["initialization"] = plugin_initialization_cpp_code;
  1448. plugin_format["deinitialization"] = plugin_deinitialization_cpp_code;
  1449. String plugin_cpp_code = "\n// Godot Plugins\n"
  1450. "void godot_ios_plugins_initialize();\n"
  1451. "void godot_ios_plugins_deinitialize();\n"
  1452. "// Exported Plugins\n\n"
  1453. "$definition"
  1454. "// Use Plugins\n"
  1455. "void godot_ios_plugins_initialize() {\n"
  1456. "$initialization"
  1457. "}\n\n"
  1458. "void godot_ios_plugins_deinitialize() {\n"
  1459. "$deinitialization"
  1460. "}\n";
  1461. p_config_data.cpp_code += plugin_cpp_code.format(plugin_format, "$_");
  1462. }
  1463. // Update Linker Flag Values
  1464. {
  1465. String result_linker_flags = " ";
  1466. for (const String &E : plugin_linker_flags) {
  1467. const String &flag = E;
  1468. if (flag.length() == 0) {
  1469. continue;
  1470. }
  1471. if (result_linker_flags.length() > 0) {
  1472. result_linker_flags += ' ';
  1473. }
  1474. result_linker_flags += flag;
  1475. }
  1476. result_linker_flags = result_linker_flags.replace("\"", "\\\"");
  1477. p_config_data.linker_flags += result_linker_flags;
  1478. }
  1479. return OK;
  1480. }
  1481. Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  1482. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  1483. String src_pkg_name;
  1484. String dest_dir = p_path.get_base_dir() + "/";
  1485. String binary_name = p_path.get_file().get_basename();
  1486. EditorProgress ep("export", "Exporting for iOS", 5, true);
  1487. String team_id = p_preset->get("application/app_store_team_id");
  1488. ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project.");
  1489. if (p_debug) {
  1490. src_pkg_name = p_preset->get("custom_template/debug");
  1491. } else {
  1492. src_pkg_name = p_preset->get("custom_template/release");
  1493. }
  1494. if (src_pkg_name.is_empty()) {
  1495. String err;
  1496. src_pkg_name = find_export_template("ios.zip", &err);
  1497. if (src_pkg_name.is_empty()) {
  1498. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found."));
  1499. return ERR_FILE_NOT_FOUND;
  1500. }
  1501. }
  1502. if (!DirAccess::exists(dest_dir)) {
  1503. return ERR_FILE_BAD_PATH;
  1504. }
  1505. {
  1506. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1507. if (da.is_valid()) {
  1508. String current_dir = da->get_current_dir();
  1509. // remove leftovers from last export so they don't interfere
  1510. // in case some files are no longer needed
  1511. if (da->change_dir(dest_dir + binary_name + ".xcodeproj") == OK) {
  1512. da->erase_contents_recursive();
  1513. }
  1514. if (da->change_dir(dest_dir + binary_name) == OK) {
  1515. da->erase_contents_recursive();
  1516. }
  1517. da->change_dir(current_dir);
  1518. if (!da->dir_exists(dest_dir + binary_name)) {
  1519. Error err = da->make_dir(dest_dir + binary_name);
  1520. if (err) {
  1521. return err;
  1522. }
  1523. }
  1524. }
  1525. }
  1526. if (ep.step("Making .pck", 0)) {
  1527. return ERR_SKIP;
  1528. }
  1529. String pack_path = dest_dir + binary_name + ".pck";
  1530. Vector<SharedObject> libraries;
  1531. Error err = save_pack(p_preset, p_debug, pack_path, &libraries);
  1532. if (err) {
  1533. return err;
  1534. }
  1535. if (ep.step("Extracting and configuring Xcode project", 1)) {
  1536. return ERR_SKIP;
  1537. }
  1538. String library_to_use = "libgodot.ios." + String(p_debug ? "debug" : "release") + ".xcframework";
  1539. print_line("Static framework: " + library_to_use);
  1540. String pkg_name;
  1541. if (String(GLOBAL_GET("application/config/name")) != "") {
  1542. pkg_name = String(GLOBAL_GET("application/config/name"));
  1543. } else {
  1544. pkg_name = "Unnamed";
  1545. }
  1546. bool found_library = false;
  1547. const String project_file = "godot_ios.xcodeproj/project.pbxproj";
  1548. HashSet<String> files_to_parse;
  1549. files_to_parse.insert("godot_ios/godot_ios-Info.plist");
  1550. files_to_parse.insert(project_file);
  1551. files_to_parse.insert("godot_ios/export_options.plist");
  1552. files_to_parse.insert("godot_ios/dummy.cpp");
  1553. files_to_parse.insert("godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata");
  1554. files_to_parse.insert("godot_ios.xcodeproj/xcshareddata/xcschemes/godot_ios.xcscheme");
  1555. files_to_parse.insert("godot_ios/godot_ios.entitlements");
  1556. files_to_parse.insert("godot_ios/Launch Screen.storyboard");
  1557. files_to_parse.insert("PrivacyInfo.xcprivacy");
  1558. IOSConfigData config_data = {
  1559. pkg_name,
  1560. binary_name,
  1561. _get_additional_plist_content(),
  1562. String(" ").join(_get_preset_architectures(p_preset)),
  1563. _get_linker_flags(),
  1564. _get_cpp_code(),
  1565. "",
  1566. "",
  1567. "",
  1568. "",
  1569. Vector<String>(),
  1570. false
  1571. };
  1572. Vector<IOSExportAsset> assets;
  1573. Ref<DirAccess> tmp_app_path = DirAccess::create_for_path(dest_dir);
  1574. ERR_FAIL_COND_V(tmp_app_path.is_null(), ERR_CANT_CREATE);
  1575. print_line("Unzipping...");
  1576. Ref<FileAccess> io_fa;
  1577. zlib_filefunc_def io = zipio_create_io(&io_fa);
  1578. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  1579. if (!src_pkg_zip) {
  1580. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Could not open export template (not a zip file?): \"%s\".", src_pkg_name));
  1581. return ERR_CANT_OPEN;
  1582. }
  1583. err = _export_ios_plugins(p_preset, config_data, dest_dir + binary_name, assets, p_debug);
  1584. ERR_FAIL_COND_V(err, err);
  1585. //export rest of the files
  1586. int ret = unzGoToFirstFile(src_pkg_zip);
  1587. Vector<uint8_t> project_file_data;
  1588. while (ret == UNZ_OK) {
  1589. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1590. bool is_execute = false;
  1591. #endif
  1592. //get filename
  1593. unz_file_info info;
  1594. char fname[16384];
  1595. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  1596. if (ret != UNZ_OK) {
  1597. break;
  1598. }
  1599. String file = String::utf8(fname);
  1600. print_line("READ: " + file);
  1601. Vector<uint8_t> data;
  1602. data.resize(info.uncompressed_size);
  1603. //read
  1604. unzOpenCurrentFile(src_pkg_zip);
  1605. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  1606. unzCloseCurrentFile(src_pkg_zip);
  1607. //write
  1608. if (files_to_parse.has(file)) {
  1609. _fix_config_file(p_preset, data, config_data, p_debug);
  1610. } else if (file.begins_with("libgodot.ios")) {
  1611. if (!file.begins_with(library_to_use) || file.ends_with(String("/empty"))) {
  1612. ret = unzGoToNextFile(src_pkg_zip);
  1613. continue; //ignore!
  1614. }
  1615. found_library = true;
  1616. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1617. is_execute = true;
  1618. #endif
  1619. file = file.replace(library_to_use, binary_name + ".xcframework");
  1620. }
  1621. if (file == project_file) {
  1622. project_file_data = data;
  1623. }
  1624. ///@TODO need to parse logo files
  1625. if (data.size() > 0) {
  1626. file = file.replace("godot_ios", binary_name);
  1627. print_line("ADDING: " + file + " size: " + itos(data.size()));
  1628. /* write it into our folder structure */
  1629. file = dest_dir + file;
  1630. /* make sure this folder exists */
  1631. String dir_name = file.get_base_dir();
  1632. if (!tmp_app_path->dir_exists(dir_name)) {
  1633. print_line("Creating " + dir_name);
  1634. Error dir_err = tmp_app_path->make_dir_recursive(dir_name);
  1635. if (dir_err) {
  1636. ERR_PRINT("Can't create '" + dir_name + "'.");
  1637. unzClose(src_pkg_zip);
  1638. return ERR_CANT_CREATE;
  1639. }
  1640. }
  1641. /* write the file */
  1642. {
  1643. Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);
  1644. if (f.is_null()) {
  1645. ERR_PRINT("Can't write '" + file + "'.");
  1646. unzClose(src_pkg_zip);
  1647. return ERR_CANT_CREATE;
  1648. };
  1649. f->store_buffer(data.ptr(), data.size());
  1650. }
  1651. #if defined(MACOS_ENABLED) || defined(LINUXBSD_ENABLED)
  1652. if (is_execute) {
  1653. // we need execute rights on this file
  1654. chmod(file.utf8().get_data(), 0755);
  1655. }
  1656. #endif
  1657. }
  1658. ret = unzGoToNextFile(src_pkg_zip);
  1659. }
  1660. /* we're done with our source zip */
  1661. unzClose(src_pkg_zip);
  1662. if (!found_library) {
  1663. ERR_PRINT("Requested template library '" + library_to_use + "' not found. It might be missing from your template archive.");
  1664. return ERR_FILE_NOT_FOUND;
  1665. }
  1666. Dictionary appnames = GLOBAL_GET("application/config/name_localized");
  1667. Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");
  1668. Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");
  1669. Dictionary photolibrary_usage_descriptions = p_preset->get("privacy/photolibrary_usage_description_localized");
  1670. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  1671. if (translations.size() > 0) {
  1672. {
  1673. String fname = dest_dir + binary_name + "/en.lproj";
  1674. tmp_app_path->make_dir_recursive(fname);
  1675. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1676. f->store_line("/* Localized versions of Info.plist keys */");
  1677. f->store_line("");
  1678. f->store_line("CFBundleDisplayName = \"" + GLOBAL_GET("application/config/name").operator String() + "\";");
  1679. f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String() + "\";");
  1680. f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String() + "\";");
  1681. f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photolibrary_usage_description").operator String() + "\";");
  1682. }
  1683. HashSet<String> languages;
  1684. for (const String &E : translations) {
  1685. Ref<Translation> tr = ResourceLoader::load(E);
  1686. if (tr.is_valid() && tr->get_locale() != "en") {
  1687. languages.insert(tr->get_locale());
  1688. }
  1689. }
  1690. for (const String &lang : languages) {
  1691. String fname = dest_dir + binary_name + "/" + lang + ".lproj";
  1692. tmp_app_path->make_dir_recursive(fname);
  1693. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1694. f->store_line("/* Localized versions of Info.plist keys */");
  1695. f->store_line("");
  1696. if (appnames.has(lang)) {
  1697. f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String() + "\";");
  1698. }
  1699. if (camera_usage_descriptions.has(lang)) {
  1700. f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String() + "\";");
  1701. }
  1702. if (microphone_usage_descriptions.has(lang)) {
  1703. f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String() + "\";");
  1704. }
  1705. if (photolibrary_usage_descriptions.has(lang)) {
  1706. f->store_line("NSPhotoLibraryUsageDescription = \"" + photolibrary_usage_descriptions[lang].operator String() + "\";");
  1707. }
  1708. }
  1709. }
  1710. // Copy project static libs to the project
  1711. Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
  1712. for (int i = 0; i < export_plugins.size(); i++) {
  1713. Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
  1714. for (int j = 0; j < project_static_libs.size(); j++) {
  1715. const String &static_lib_path = project_static_libs[j];
  1716. String dest_lib_file_path = dest_dir + static_lib_path.get_file();
  1717. Error lib_copy_err = tmp_app_path->copy(static_lib_path, dest_lib_file_path);
  1718. if (lib_copy_err != OK) {
  1719. ERR_PRINT("Can't copy '" + static_lib_path + "'.");
  1720. return lib_copy_err;
  1721. }
  1722. }
  1723. }
  1724. String iconset_dir = dest_dir + binary_name + "/Images.xcassets/AppIcon.appiconset/";
  1725. err = OK;
  1726. if (!tmp_app_path->dir_exists(iconset_dir)) {
  1727. err = tmp_app_path->make_dir_recursive(iconset_dir);
  1728. }
  1729. if (err) {
  1730. return err;
  1731. }
  1732. err = _export_icons(p_preset, iconset_dir);
  1733. if (err) {
  1734. return err;
  1735. }
  1736. {
  1737. bool use_storyboard = p_preset->get("storyboard/use_launch_screen_storyboard");
  1738. String launch_image_path = dest_dir + binary_name + "/Images.xcassets/LaunchImage.launchimage/";
  1739. String splash_image_path = dest_dir + binary_name + "/Images.xcassets/SplashImage.imageset/";
  1740. Ref<DirAccess> launch_screen_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1741. if (launch_screen_da.is_null()) {
  1742. return ERR_CANT_CREATE;
  1743. }
  1744. if (use_storyboard) {
  1745. print_line("Using Launch Storyboard");
  1746. if (launch_screen_da->change_dir(launch_image_path) == OK) {
  1747. launch_screen_da->erase_contents_recursive();
  1748. launch_screen_da->remove(launch_image_path);
  1749. }
  1750. err = _export_loading_screen_file(p_preset, splash_image_path);
  1751. } else {
  1752. print_line("Using Launch Images");
  1753. const String launch_screen_path = dest_dir + binary_name + "/Launch Screen.storyboard";
  1754. launch_screen_da->remove(launch_screen_path);
  1755. if (launch_screen_da->change_dir(splash_image_path) == OK) {
  1756. launch_screen_da->erase_contents_recursive();
  1757. launch_screen_da->remove(splash_image_path);
  1758. }
  1759. err = _export_loading_screen_images(p_preset, launch_image_path);
  1760. }
  1761. }
  1762. if (err) {
  1763. return err;
  1764. }
  1765. print_line("Exporting additional assets");
  1766. _export_additional_assets(dest_dir + binary_name, libraries, assets);
  1767. _add_assets_to_project(p_preset, project_file_data, assets);
  1768. String project_file_name = dest_dir + binary_name + ".xcodeproj/project.pbxproj";
  1769. {
  1770. Ref<FileAccess> f = FileAccess::open(project_file_name, FileAccess::WRITE);
  1771. if (f.is_null()) {
  1772. ERR_PRINT("Can't write '" + project_file_name + "'.");
  1773. return ERR_CANT_CREATE;
  1774. };
  1775. f->store_buffer(project_file_data.ptr(), project_file_data.size());
  1776. }
  1777. #ifdef MACOS_ENABLED
  1778. {
  1779. if (ep.step("Code-signing dylibs", 2)) {
  1780. return ERR_SKIP;
  1781. }
  1782. Ref<DirAccess> dylibs_dir = DirAccess::open(dest_dir + binary_name + "/dylibs");
  1783. ERR_FAIL_COND_V(dylibs_dir.is_null(), ERR_CANT_OPEN);
  1784. CodesignData codesign_data(p_preset, p_debug);
  1785. err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data);
  1786. if (err != OK) {
  1787. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  1788. return err;
  1789. }
  1790. }
  1791. if (ep.step("Making .xcarchive", 3)) {
  1792. return ERR_SKIP;
  1793. }
  1794. String archive_path = p_path.get_basename() + ".xcarchive";
  1795. List<String> archive_args;
  1796. archive_args.push_back("-project");
  1797. archive_args.push_back(dest_dir + binary_name + ".xcodeproj");
  1798. archive_args.push_back("-scheme");
  1799. archive_args.push_back(binary_name);
  1800. archive_args.push_back("-sdk");
  1801. archive_args.push_back("iphoneos");
  1802. archive_args.push_back("-configuration");
  1803. archive_args.push_back(p_debug ? "Debug" : "Release");
  1804. archive_args.push_back("-destination");
  1805. archive_args.push_back("generic/platform=iOS");
  1806. archive_args.push_back("archive");
  1807. archive_args.push_back("-allowProvisioningUpdates");
  1808. archive_args.push_back("-archivePath");
  1809. archive_args.push_back(archive_path);
  1810. String archive_str;
  1811. err = OS::get_singleton()->execute("xcodebuild", archive_args, &archive_str, nullptr, true);
  1812. ERR_FAIL_COND_V(err, err);
  1813. print_line("xcodebuild (.xcarchive):\n" + archive_str);
  1814. if (!archive_str.contains("** ARCHIVE SUCCEEDED **")) {
  1815. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR("Xcode project build failed, see editor log for details."));
  1816. return FAILED;
  1817. }
  1818. if (ep.step("Making .ipa", 4)) {
  1819. return ERR_SKIP;
  1820. }
  1821. List<String> export_args;
  1822. export_args.push_back("-exportArchive");
  1823. export_args.push_back("-archivePath");
  1824. export_args.push_back(archive_path);
  1825. export_args.push_back("-exportOptionsPlist");
  1826. export_args.push_back(dest_dir + binary_name + "/export_options.plist");
  1827. export_args.push_back("-allowProvisioningUpdates");
  1828. export_args.push_back("-exportPath");
  1829. export_args.push_back(dest_dir);
  1830. String export_str;
  1831. err = OS::get_singleton()->execute("xcodebuild", export_args, &export_str, nullptr, true);
  1832. ERR_FAIL_COND_V(err, err);
  1833. print_line("xcodebuild (.ipa):\n" + export_str);
  1834. if (!export_str.contains("** EXPORT SUCCEEDED **")) {
  1835. add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR(".ipa export failed, see editor log for details."));
  1836. return FAILED;
  1837. }
  1838. #else
  1839. add_message(EXPORT_MESSAGE_WARNING, TTR("Xcode Build"), TTR(".ipa can only be built on macOS. Leaving Xcode project without building the package."));
  1840. #endif
  1841. return OK;
  1842. }
  1843. bool EditorExportPlatformIOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {
  1844. String err;
  1845. bool valid = false;
  1846. #ifdef MODULE_MONO_ENABLED
  1847. err += TTR("Exporting to iOS is currently not supported in Godot 4 when using C#/.NET. Use Godot 3 to target iOS with C#/Mono instead.") + "\n";
  1848. err += TTR("If this project does not use C#, use a non-C# editor build to export the project.") + "\n";
  1849. // Don't check for additional errors, as this particular error cannot be resolved.
  1850. r_error = err;
  1851. return false;
  1852. #endif
  1853. // Look for export templates (first official, and if defined custom templates).
  1854. bool dvalid = exists_export_template("ios.zip", &err);
  1855. bool rvalid = dvalid; // Both in the same ZIP.
  1856. if (p_preset->get("custom_template/debug") != "") {
  1857. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  1858. if (!dvalid) {
  1859. err += TTR("Custom debug template not found.") + "\n";
  1860. }
  1861. }
  1862. if (p_preset->get("custom_template/release") != "") {
  1863. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  1864. if (!rvalid) {
  1865. err += TTR("Custom release template not found.") + "\n";
  1866. }
  1867. }
  1868. valid = dvalid || rvalid;
  1869. r_missing_templates = !valid;
  1870. if (!err.is_empty()) {
  1871. r_error = err;
  1872. }
  1873. return valid;
  1874. }
  1875. bool EditorExportPlatformIOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  1876. String err;
  1877. bool valid = true;
  1878. // Validate the project configuration.
  1879. List<ExportOption> options;
  1880. get_export_options(&options);
  1881. for (const EditorExportPlatform::ExportOption &E : options) {
  1882. if (get_export_option_visibility(p_preset.ptr(), E.option.name)) {
  1883. String warn = get_export_option_warning(p_preset.ptr(), E.option.name);
  1884. if (!warn.is_empty()) {
  1885. err += warn + "\n";
  1886. if (E.required) {
  1887. valid = false;
  1888. }
  1889. }
  1890. }
  1891. }
  1892. const String etc_error = test_etc2();
  1893. if (!etc_error.is_empty()) {
  1894. valid = false;
  1895. err += etc_error;
  1896. }
  1897. if (!err.is_empty()) {
  1898. r_error = err;
  1899. }
  1900. return valid;
  1901. }
  1902. EditorExportPlatformIOS::EditorExportPlatformIOS() {
  1903. if (EditorNode::get_singleton()) {
  1904. #ifdef MODULE_SVG_ENABLED
  1905. Ref<Image> img = memnew(Image);
  1906. const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
  1907. ImageLoaderSVG img_loader;
  1908. img_loader.create_image_from_string(img, _ios_logo_svg, EDSCALE, upsample, false);
  1909. logo = ImageTexture::create_from_image(img);
  1910. #endif
  1911. plugins_changed.set();
  1912. #ifndef ANDROID_ENABLED
  1913. check_for_changes_thread.start(_check_for_changes_poll_thread, this);
  1914. #endif
  1915. }
  1916. }
  1917. EditorExportPlatformIOS::~EditorExportPlatformIOS() {
  1918. #ifndef ANDROID_ENABLED
  1919. quit_request.set();
  1920. if (check_for_changes_thread.is_started()) {
  1921. check_for_changes_thread.wait_to_finish();
  1922. }
  1923. #endif
  1924. }