export.cpp 88 KB

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