export.cpp 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. /*************************************************************************/
  2. /* export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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/marshalls.h"
  32. #include "core/io/resource_saver.h"
  33. #include "core/io/zip_io.h"
  34. #include "core/os/file_access.h"
  35. #include "core/os/os.h"
  36. #include "core/project_settings.h"
  37. #include "core/version.h"
  38. #include "editor/editor_export.h"
  39. #include "editor/editor_node.h"
  40. #include "editor/editor_settings.h"
  41. #include "platform/iphone/logo.gen.h"
  42. #include "string.h"
  43. #include <sys/stat.h>
  44. class EditorExportPlatformIOS : public EditorExportPlatform {
  45. GDCLASS(EditorExportPlatformIOS, EditorExportPlatform);
  46. int version_code;
  47. Ref<ImageTexture> logo;
  48. typedef Error (*FileHandler)(String p_file, void *p_userdata);
  49. static Error _walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata);
  50. static Error _codesign(String p_file, void *p_userdata);
  51. struct IOSConfigData {
  52. String pkg_name;
  53. String binary_name;
  54. String plist_content;
  55. String architectures;
  56. String linker_flags;
  57. String cpp_code;
  58. };
  59. struct ExportArchitecture {
  60. String name;
  61. bool is_default;
  62. ExportArchitecture() :
  63. name(""),
  64. is_default(false) {
  65. }
  66. ExportArchitecture(String p_name, bool p_is_default) {
  67. name = p_name;
  68. is_default = p_is_default;
  69. }
  70. };
  71. struct IOSExportAsset {
  72. String exported_path;
  73. bool is_framework; // framework is anything linked to the binary, otherwise it's a resource
  74. };
  75. String _get_additional_plist_content();
  76. String _get_linker_flags();
  77. String _get_cpp_code();
  78. void _fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug);
  79. Error _export_loading_screens(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir);
  80. Error _export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir);
  81. Vector<ExportArchitecture> _get_supported_architectures();
  82. Vector<String> _get_preset_architectures(const Ref<EditorExportPreset> &p_preset);
  83. void _add_assets_to_project(Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets);
  84. Error _export_additional_assets(const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, Vector<IOSExportAsset> &r_exported_assets);
  85. Error _export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets);
  86. bool is_package_name_valid(const String &p_package, String *r_error = NULL) const {
  87. String pname = p_package;
  88. if (pname.length() == 0) {
  89. if (r_error) {
  90. *r_error = TTR("Identifier is missing.");
  91. }
  92. return false;
  93. }
  94. int segments = 0;
  95. bool first = true;
  96. for (int i = 0; i < pname.length(); i++) {
  97. CharType c = pname[i];
  98. if (first && c == '.') {
  99. if (r_error) {
  100. *r_error = TTR("Identifier segments must be of non-zero length.");
  101. }
  102. return false;
  103. }
  104. if (c == '.') {
  105. segments++;
  106. first = true;
  107. continue;
  108. }
  109. if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')) {
  110. if (r_error) {
  111. *r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
  112. }
  113. return false;
  114. }
  115. if (first && (c >= '0' && c <= '9')) {
  116. if (r_error) {
  117. *r_error = TTR("A digit cannot be the first character in a Identifier segment.");
  118. }
  119. return false;
  120. }
  121. if (first && c == '_') {
  122. if (r_error) {
  123. *r_error = vformat(TTR("The character '%s' cannot be the first character in a Identifier segment."), String::chr(c));
  124. }
  125. return false;
  126. }
  127. first = false;
  128. }
  129. if (segments == 0) {
  130. if (r_error) {
  131. *r_error = TTR("The Identifier must have at least one '.' separator.");
  132. }
  133. return false;
  134. }
  135. if (first) {
  136. if (r_error) {
  137. *r_error = TTR("Identifier segments must be of non-zero length.");
  138. }
  139. return false;
  140. }
  141. return true;
  142. }
  143. protected:
  144. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
  145. virtual void get_export_options(List<ExportOption> *r_options);
  146. public:
  147. virtual String get_name() const { return "iOS"; }
  148. virtual String get_os_name() const { return "iOS"; }
  149. virtual Ref<Texture> get_logo() const { return logo; }
  150. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
  151. List<String> list;
  152. list.push_back("ipa");
  153. return list;
  154. }
  155. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  156. virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  157. virtual void get_platform_features(List<String> *r_features) {
  158. r_features->push_back("mobile");
  159. r_features->push_back("iOS");
  160. }
  161. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
  162. }
  163. EditorExportPlatformIOS();
  164. ~EditorExportPlatformIOS();
  165. };
  166. void EditorExportPlatformIOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
  167. if (p_preset->get("texture_format/s3tc")) {
  168. r_features->push_back("s3tc");
  169. }
  170. if (p_preset->get("texture_format/etc")) {
  171. r_features->push_back("etc");
  172. }
  173. if (p_preset->get("texture_format/etc2")) {
  174. r_features->push_back("etc2");
  175. }
  176. Vector<String> architectures = _get_preset_architectures(p_preset);
  177. for (int i = 0; i < architectures.size(); ++i) {
  178. r_features->push_back(architectures[i]);
  179. }
  180. }
  181. Vector<EditorExportPlatformIOS::ExportArchitecture> EditorExportPlatformIOS::_get_supported_architectures() {
  182. Vector<ExportArchitecture> archs;
  183. archs.push_back(ExportArchitecture("armv7", true));
  184. archs.push_back(ExportArchitecture("arm64", true));
  185. return archs;
  186. }
  187. struct LoadingScreenInfo {
  188. const char *preset_key;
  189. const char *export_name;
  190. };
  191. static const LoadingScreenInfo loading_screen_infos[] = {
  192. { "landscape_launch_screens/iphone_2436x1125", "Default-Landscape-X.png" },
  193. { "landscape_launch_screens/iphone_2208x1242", "[email protected]" },
  194. { "landscape_launch_screens/ipad_1024x768", "Default-Landscape.png" },
  195. { "landscape_launch_screens/ipad_2048x1536", "[email protected]" },
  196. { "portrait_launch_screens/iphone_640x960", "[email protected]" },
  197. { "portrait_launch_screens/iphone_640x1136", "[email protected]" },
  198. { "portrait_launch_screens/iphone_750x1334", "[email protected]" },
  199. { "portrait_launch_screens/iphone_1125x2436", "Default-Portrait-X.png" },
  200. { "portrait_launch_screens/ipad_768x1024", "Default-Portrait.png" },
  201. { "portrait_launch_screens/ipad_1536x2048", "[email protected]" },
  202. { "portrait_launch_screens/iphone_1242x2208", "[email protected]" }
  203. };
  204. void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options) {
  205. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  206. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  207. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_store_team_id"), ""));
  208. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_debug"), ""));
  209. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_debug", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Developer"), "iPhone Developer"));
  210. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_debug", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 1));
  211. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/provisioning_profile_uuid_release"), ""));
  212. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/code_sign_identity_release", PROPERTY_HINT_PLACEHOLDER_TEXT, "iPhone Distribution"), ""));
  213. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_method_release", PROPERTY_HINT_ENUM, "App Store,Development,Ad-Hoc,Enterprise"), 0));
  214. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
  215. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine"));
  216. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), ""));
  217. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  218. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  219. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  220. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  221. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/arkit"), false));
  222. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/access_wifi"), false));
  223. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/game_center"), true));
  224. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/in_app_purchases"), false));
  225. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "capabilities/push_notifications"), false));
  226. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/camera_usage_description"), "Godot would like to use your camera"));
  227. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/microphone_usage_description"), "Godot would like to use your microphone"));
  228. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/photolibrary_usage_description"), "Godot would like to use your photos"));
  229. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/portrait"), true));
  230. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/landscape_left"), true));
  231. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/landscape_right"), true));
  232. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/portrait_upside_down"), true));
  233. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/iphone_120x120", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPhone/iPod Touch with retina display
  234. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/ipad_76x76", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPad
  235. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/app_store_1024x1024", PROPERTY_HINT_FILE, "*.png"), "")); // App Store
  236. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/iphone_180x180", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPhone with retina HD display
  237. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/ipad_152x152", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPad with retina display
  238. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/ipad_167x167", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPad Pro
  239. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/spotlight_40x40", PROPERTY_HINT_FILE, "*.png"), "")); // Spotlight
  240. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/spotlight_80x80", PROPERTY_HINT_FILE, "*.png"), "")); // Spotlight on devices with retina display
  241. for (unsigned int i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  242. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, loading_screen_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png"), ""));
  243. }
  244. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), false));
  245. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
  246. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), true));
  247. Vector<ExportArchitecture> architectures = _get_supported_architectures();
  248. for (int i = 0; i < architectures.size(); ++i) {
  249. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "architectures/" + architectures[i].name), architectures[i].is_default));
  250. }
  251. }
  252. void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug) {
  253. static const String export_method_string[] = {
  254. "app-store",
  255. "development",
  256. "ad-hoc",
  257. "enterprise"
  258. };
  259. String str;
  260. String strnew;
  261. str.parse_utf8((const char *)pfile.ptr(), pfile.size());
  262. Vector<String> lines = str.split("\n");
  263. for (int i = 0; i < lines.size(); i++) {
  264. if (lines[i].find("$binary") != -1) {
  265. strnew += lines[i].replace("$binary", p_config.binary_name) + "\n";
  266. } else if (lines[i].find("$name") != -1) {
  267. strnew += lines[i].replace("$name", p_config.pkg_name) + "\n";
  268. } else if (lines[i].find("$info") != -1) {
  269. strnew += lines[i].replace("$info", p_preset->get("application/info")) + "\n";
  270. } else if (lines[i].find("$identifier") != -1) {
  271. strnew += lines[i].replace("$identifier", p_preset->get("application/identifier")) + "\n";
  272. } else if (lines[i].find("$short_version") != -1) {
  273. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  274. } else if (lines[i].find("$version") != -1) {
  275. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  276. } else if (lines[i].find("$signature") != -1) {
  277. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  278. } else if (lines[i].find("$copyright") != -1) {
  279. strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
  280. } else if (lines[i].find("$team_id") != -1) {
  281. strnew += lines[i].replace("$team_id", p_preset->get("application/app_store_team_id")) + "\n";
  282. } else if (lines[i].find("$export_method") != -1) {
  283. int export_method = p_preset->get(p_debug ? "application/export_method_debug" : "application/export_method_release");
  284. strnew += lines[i].replace("$export_method", export_method_string[export_method]) + "\n";
  285. } else if (lines[i].find("$provisioning_profile_uuid_release") != -1) {
  286. strnew += lines[i].replace("$provisioning_profile_uuid_release", p_preset->get("application/provisioning_profile_uuid_release")) + "\n";
  287. } else if (lines[i].find("$provisioning_profile_uuid_debug") != -1) {
  288. strnew += lines[i].replace("$provisioning_profile_uuid_debug", p_preset->get("application/provisioning_profile_uuid_debug")) + "\n";
  289. } else if (lines[i].find("$provisioning_profile_uuid") != -1) {
  290. String uuid = p_debug ? p_preset->get("application/provisioning_profile_uuid_debug") : p_preset->get("application/provisioning_profile_uuid_release");
  291. strnew += lines[i].replace("$provisioning_profile_uuid", uuid) + "\n";
  292. } else if (lines[i].find("$code_sign_identity_debug") != -1) {
  293. strnew += lines[i].replace("$code_sign_identity_debug", p_preset->get("application/code_sign_identity_debug")) + "\n";
  294. } else if (lines[i].find("$code_sign_identity_release") != -1) {
  295. strnew += lines[i].replace("$code_sign_identity_release", p_preset->get("application/code_sign_identity_release")) + "\n";
  296. } else if (lines[i].find("$additional_plist_content") != -1) {
  297. strnew += lines[i].replace("$additional_plist_content", p_config.plist_content) + "\n";
  298. } else if (lines[i].find("$godot_archs") != -1) {
  299. strnew += lines[i].replace("$godot_archs", p_config.architectures) + "\n";
  300. } else if (lines[i].find("$linker_flags") != -1) {
  301. strnew += lines[i].replace("$linker_flags", p_config.linker_flags) + "\n";
  302. } else if (lines[i].find("$cpp_code") != -1) {
  303. strnew += lines[i].replace("$cpp_code", p_config.cpp_code) + "\n";
  304. } else if (lines[i].find("$access_wifi") != -1) {
  305. bool is_on = p_preset->get("capabilities/access_wifi");
  306. strnew += lines[i].replace("$access_wifi", is_on ? "1" : "0") + "\n";
  307. } else if (lines[i].find("$game_center") != -1) {
  308. bool is_on = p_preset->get("capabilities/game_center");
  309. strnew += lines[i].replace("$game_center", is_on ? "1" : "0") + "\n";
  310. } else if (lines[i].find("$in_app_purchases") != -1) {
  311. bool is_on = p_preset->get("capabilities/in_app_purchases");
  312. strnew += lines[i].replace("$in_app_purchases", is_on ? "1" : "0") + "\n";
  313. } else if (lines[i].find("$push_notifications") != -1) {
  314. bool is_on = p_preset->get("capabilities/push_notifications");
  315. strnew += lines[i].replace("$push_notifications", is_on ? "1" : "0") + "\n";
  316. } else if (lines[i].find("$required_device_capabilities") != -1) {
  317. String capabilities;
  318. // I've removed armv7 as we can run on 64bit only devices
  319. // Note that capabilities listed here are requirements for the app to be installed.
  320. // They don't enable anything.
  321. if ((bool)p_preset->get("capabilities/arkit")) {
  322. capabilities += "<string>arkit</string>\n";
  323. }
  324. if ((bool)p_preset->get("capabilities/game_center")) {
  325. capabilities += "<string>gamekit</string>\n";
  326. }
  327. if ((bool)p_preset->get("capabilities/access_wifi")) {
  328. capabilities += "<string>wifi</string>\n";
  329. }
  330. strnew += lines[i].replace("$required_device_capabilities", capabilities);
  331. } else if (lines[i].find("$interface_orientations") != -1) {
  332. String orientations;
  333. if ((bool)p_preset->get("orientation/portrait")) {
  334. orientations += "<string>UIInterfaceOrientationPortrait</string>\n";
  335. }
  336. if ((bool)p_preset->get("orientation/landscape_left")) {
  337. orientations += "<string>UIInterfaceOrientationLandscapeLeft</string>\n";
  338. }
  339. if ((bool)p_preset->get("orientation/landscape_right")) {
  340. orientations += "<string>UIInterfaceOrientationLandscapeRight</string>\n";
  341. }
  342. if ((bool)p_preset->get("orientation/portrait_upside_down")) {
  343. orientations += "<string>UIInterfaceOrientationPortraitUpsideDown</string>\n";
  344. }
  345. strnew += lines[i].replace("$interface_orientations", orientations);
  346. } else if (lines[i].find("$camera_usage_description") != -1) {
  347. String description = p_preset->get("privacy/camera_usage_description");
  348. strnew += lines[i].replace("$camera_usage_description", description) + "\n";
  349. } else if (lines[i].find("$microphone_usage_description") != -1) {
  350. String description = p_preset->get("privacy/microphone_usage_description");
  351. strnew += lines[i].replace("$microphone_usage_description", description) + "\n";
  352. } else if (lines[i].find("$photolibrary_usage_description") != -1) {
  353. String description = p_preset->get("privacy/photolibrary_usage_description");
  354. strnew += lines[i].replace("$photolibrary_usage_description", description) + "\n";
  355. } else {
  356. strnew += lines[i] + "\n";
  357. }
  358. }
  359. // !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...
  360. // should apply the same fix in our OSX export.
  361. CharString cs = strnew.utf8();
  362. pfile.resize(cs.size() - 1);
  363. for (int i = 0; i < cs.size() - 1; i++) {
  364. pfile.write[i] = cs[i];
  365. }
  366. }
  367. String EditorExportPlatformIOS::_get_additional_plist_content() {
  368. Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
  369. String result;
  370. for (int i = 0; i < export_plugins.size(); ++i) {
  371. result += export_plugins[i]->get_ios_plist_content();
  372. }
  373. return result;
  374. }
  375. String EditorExportPlatformIOS::_get_linker_flags() {
  376. Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
  377. String result;
  378. for (int i = 0; i < export_plugins.size(); ++i) {
  379. String flags = export_plugins[i]->get_ios_linker_flags();
  380. if (flags.length() == 0) continue;
  381. if (result.length() > 0) {
  382. result += ' ';
  383. }
  384. result += flags;
  385. }
  386. // the flags will be enclosed in quotes, so need to escape them
  387. return result.replace("\"", "\\\"");
  388. }
  389. String EditorExportPlatformIOS::_get_cpp_code() {
  390. Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
  391. String result;
  392. for (int i = 0; i < export_plugins.size(); ++i) {
  393. result += export_plugins[i]->get_ios_cpp_code();
  394. }
  395. return result;
  396. }
  397. struct IconInfo {
  398. const char *preset_key;
  399. const char *idiom;
  400. const char *export_name;
  401. const char *actual_size_side;
  402. const char *scale;
  403. const char *unscaled_size;
  404. bool is_required;
  405. };
  406. static const IconInfo icon_infos[] = {
  407. { "required_icons/iphone_120x120", "iphone", "Icon-120.png", "120", "2x", "60x60", true },
  408. { "required_icons/iphone_120x120", "iphone", "Icon-120.png", "120", "3x", "40x40", true },
  409. { "required_icons/ipad_76x76", "ipad", "Icon-76.png", "76", "1x", "76x76", false },
  410. { "required_icons/app_store_1024x1024", "ios-marketing", "Icon-1024.png", "1024", "1x", "1024x1024", false },
  411. { "optional_icons/iphone_180x180", "iphone", "Icon-180.png", "180", "3x", "60x60", false },
  412. { "optional_icons/ipad_152x152", "ipad", "Icon-152.png", "152", "2x", "76x76", false },
  413. { "optional_icons/ipad_167x167", "ipad", "Icon-167.png", "167", "2x", "83.5x83.5", false },
  414. { "optional_icons/spotlight_40x40", "ipad", "Icon-40.png", "40", "1x", "40x40", false },
  415. { "optional_icons/spotlight_80x80", "iphone", "Icon-80.png", "80", "2x", "40x40", false },
  416. { "optional_icons/spotlight_80x80", "ipad", "Icon-80.png", "80", "2x", "40x40", false }
  417. };
  418. Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
  419. String json_description = "{\"images\":[";
  420. String sizes;
  421. DirAccess *da = DirAccess::open(p_iconset_dir);
  422. ERR_FAIL_COND_V(!da, ERR_CANT_OPEN);
  423. for (unsigned int i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  424. IconInfo info = icon_infos[i];
  425. String icon_path = p_preset->get(info.preset_key);
  426. if (icon_path.length() == 0) {
  427. if (info.is_required) {
  428. ERR_PRINT("Required icon is not specified in the preset");
  429. return ERR_UNCONFIGURED;
  430. }
  431. continue;
  432. }
  433. Error err = da->copy(icon_path, p_iconset_dir + info.export_name);
  434. if (err) {
  435. memdelete(da);
  436. String err_str = String("Failed to export icon: ") + icon_path;
  437. ERR_PRINT(err_str.utf8().get_data());
  438. return err;
  439. }
  440. sizes += String(info.actual_size_side) + "\n";
  441. if (i > 0) {
  442. json_description += ",";
  443. }
  444. json_description += String("{");
  445. json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
  446. json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
  447. json_description += String("\"scale\":") + "\"" + info.scale + "\",";
  448. json_description += String("\"filename\":") + "\"" + info.export_name + "\"";
  449. json_description += String("}");
  450. }
  451. json_description += "]}";
  452. memdelete(da);
  453. FileAccess *json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
  454. ERR_FAIL_COND_V(!json_file, ERR_CANT_CREATE);
  455. CharString json_utf8 = json_description.utf8();
  456. json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
  457. memdelete(json_file);
  458. FileAccess *sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
  459. ERR_FAIL_COND_V(!sizes_file, ERR_CANT_CREATE);
  460. CharString sizes_utf8 = sizes.utf8();
  461. sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
  462. memdelete(sizes_file);
  463. return OK;
  464. }
  465. Error EditorExportPlatformIOS::_export_loading_screens(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  466. DirAccess *da = DirAccess::open(p_dest_dir);
  467. ERR_FAIL_COND_V(!da, ERR_CANT_OPEN);
  468. for (unsigned int i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  469. LoadingScreenInfo info = loading_screen_infos[i];
  470. String loading_screen_file = p_preset->get(info.preset_key);
  471. if (loading_screen_file.size() > 0) {
  472. Error err = da->copy(loading_screen_file, p_dest_dir + info.export_name);
  473. if (err) {
  474. memdelete(da);
  475. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from path: " + loading_screen_file;
  476. ERR_PRINT(err_str.utf8().get_data());
  477. return err;
  478. }
  479. }
  480. }
  481. memdelete(da);
  482. return OK;
  483. }
  484. Error EditorExportPlatformIOS::_walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata) {
  485. Vector<String> dirs;
  486. String path;
  487. String current_dir = p_da->get_current_dir();
  488. p_da->list_dir_begin();
  489. while ((path = p_da->get_next()).length() != 0) {
  490. if (p_da->current_is_dir()) {
  491. if (path != "." && path != "..") {
  492. dirs.push_back(path);
  493. }
  494. } else {
  495. Error err = p_handler(current_dir + "/" + path, p_userdata);
  496. if (err) {
  497. p_da->list_dir_end();
  498. return err;
  499. }
  500. }
  501. }
  502. p_da->list_dir_end();
  503. for (int i = 0; i < dirs.size(); ++i) {
  504. String dir = dirs[i];
  505. p_da->change_dir(dir);
  506. Error err = _walk_dir_recursive(p_da, p_handler, p_userdata);
  507. p_da->change_dir("..");
  508. if (err) {
  509. return err;
  510. }
  511. }
  512. return OK;
  513. }
  514. struct CodesignData {
  515. const Ref<EditorExportPreset> &preset;
  516. bool debug;
  517. CodesignData(const Ref<EditorExportPreset> &p_preset, bool p_debug) :
  518. preset(p_preset),
  519. debug(p_debug) {
  520. }
  521. };
  522. Error EditorExportPlatformIOS::_codesign(String p_file, void *p_userdata) {
  523. if (p_file.ends_with(".dylib")) {
  524. CodesignData *data = (CodesignData *)p_userdata;
  525. print_line(String("Signing ") + p_file);
  526. List<String> codesign_args;
  527. codesign_args.push_back("-f");
  528. codesign_args.push_back("-s");
  529. codesign_args.push_back(data->preset->get(data->debug ? "application/code_sign_identity_debug" : "application/code_sign_identity_release"));
  530. codesign_args.push_back(p_file);
  531. return OS::get_singleton()->execute("codesign", codesign_args, true);
  532. }
  533. return OK;
  534. }
  535. struct PbxId {
  536. private:
  537. static char _hex_char(uint8_t four_bits) {
  538. if (four_bits < 10) {
  539. return ('0' + four_bits);
  540. }
  541. return 'A' + (four_bits - 10);
  542. }
  543. static String _hex_pad(uint32_t num) {
  544. Vector<char> ret;
  545. ret.resize(sizeof(num) * 2);
  546. for (unsigned int i = 0; i < sizeof(num) * 2; ++i) {
  547. uint8_t four_bits = (num >> (sizeof(num) * 8 - (i + 1) * 4)) & 0xF;
  548. ret.write[i] = _hex_char(four_bits);
  549. }
  550. return String::utf8(ret.ptr(), ret.size());
  551. }
  552. public:
  553. uint32_t high_bits;
  554. uint32_t mid_bits;
  555. uint32_t low_bits;
  556. String str() const {
  557. return _hex_pad(high_bits) + _hex_pad(mid_bits) + _hex_pad(low_bits);
  558. }
  559. PbxId &operator++() {
  560. low_bits++;
  561. if (!low_bits) {
  562. mid_bits++;
  563. if (!mid_bits) {
  564. high_bits++;
  565. }
  566. }
  567. return *this;
  568. }
  569. };
  570. struct ExportLibsData {
  571. Vector<String> lib_paths;
  572. String dest_dir;
  573. };
  574. void EditorExportPlatformIOS::_add_assets_to_project(Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) {
  575. Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
  576. Vector<String> frameworks;
  577. for (int i = 0; i < export_plugins.size(); ++i) {
  578. Vector<String> plugin_frameworks = export_plugins[i]->get_ios_frameworks();
  579. for (int j = 0; j < plugin_frameworks.size(); ++j) {
  580. frameworks.push_back(plugin_frameworks[j]);
  581. }
  582. }
  583. // that is just a random number, we just need Godot IDs not to clash with
  584. // existing IDs in the project.
  585. PbxId current_id = { 0x58938401, 0, 0 };
  586. String pbx_files;
  587. String pbx_frameworks_build;
  588. String pbx_frameworks_refs;
  589. String pbx_resources_build;
  590. String pbx_resources_refs;
  591. const String file_info_format = String("$build_id = {isa = PBXBuildFile; fileRef = $ref_id; };\n") +
  592. "$ref_id = {isa = PBXFileReference; lastKnownFileType = $file_type; name = $name; path = \"$file_path\"; sourceTree = \"<group>\"; };\n";
  593. for (int i = 0; i < p_additional_assets.size(); ++i) {
  594. String build_id = (++current_id).str();
  595. String ref_id = (++current_id).str();
  596. const IOSExportAsset &asset = p_additional_assets[i];
  597. String type;
  598. if (asset.exported_path.ends_with(".framework")) {
  599. type = "wrapper.framework";
  600. } else if (asset.exported_path.ends_with(".dylib")) {
  601. type = "compiled.mach-o.dylib";
  602. } else if (asset.exported_path.ends_with(".a")) {
  603. type = "archive.ar";
  604. } else {
  605. type = "file";
  606. }
  607. String &pbx_build = asset.is_framework ? pbx_frameworks_build : pbx_resources_build;
  608. String &pbx_refs = asset.is_framework ? pbx_frameworks_refs : pbx_resources_refs;
  609. if (pbx_build.length() > 0) {
  610. pbx_build += ",\n";
  611. pbx_refs += ",\n";
  612. }
  613. pbx_build += build_id;
  614. pbx_refs += ref_id;
  615. Dictionary format_dict;
  616. format_dict["build_id"] = build_id;
  617. format_dict["ref_id"] = ref_id;
  618. format_dict["name"] = asset.exported_path.get_file();
  619. format_dict["file_path"] = asset.exported_path;
  620. format_dict["file_type"] = type;
  621. pbx_files += file_info_format.format(format_dict, "$_");
  622. }
  623. // Note, frameworks like gamekit are always included in our project.pbxprof file
  624. // even if turned off in capabilities.
  625. // Frameworks that are used by modules (like arkit) we may need to optionally add here.
  626. String str = String::utf8((const char *)p_project_data.ptr(), p_project_data.size());
  627. str = str.replace("$additional_pbx_files", pbx_files);
  628. str = str.replace("$additional_pbx_frameworks_build", pbx_frameworks_build);
  629. str = str.replace("$additional_pbx_frameworks_refs", pbx_frameworks_refs);
  630. str = str.replace("$additional_pbx_resources_build", pbx_resources_build);
  631. str = str.replace("$additional_pbx_resources_refs", pbx_resources_refs);
  632. CharString cs = str.utf8();
  633. p_project_data.resize(cs.size() - 1);
  634. for (int i = 0; i < cs.size() - 1; i++) {
  635. p_project_data.write[i] = cs[i];
  636. }
  637. }
  638. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, Vector<IOSExportAsset> &r_exported_assets) {
  639. DirAccess *filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  640. ERR_FAIL_COND_V(!filesystem_da, ERR_CANT_CREATE);
  641. for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) {
  642. String asset = p_assets[f_idx];
  643. if (!asset.begins_with("res://")) {
  644. // either SDK-builtin or already a part of the export template
  645. IOSExportAsset exported_asset = { asset, p_is_framework };
  646. r_exported_assets.push_back(exported_asset);
  647. } else {
  648. DirAccess *da = DirAccess::create_for_path(asset);
  649. if (!da) {
  650. memdelete(filesystem_da);
  651. ERR_FAIL_COND_V(!da, ERR_CANT_CREATE);
  652. }
  653. bool file_exists = da->file_exists(asset);
  654. bool dir_exists = da->dir_exists(asset);
  655. if (!file_exists && !dir_exists) {
  656. memdelete(da);
  657. memdelete(filesystem_da);
  658. return ERR_FILE_NOT_FOUND;
  659. }
  660. String additional_dir = p_is_framework && asset.ends_with(".dylib") ? "/dylibs/" : "/";
  661. String destination_dir = p_out_dir + additional_dir + asset.get_base_dir().replace("res://", "");
  662. if (!filesystem_da->dir_exists(destination_dir)) {
  663. Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir);
  664. if (make_dir_err) {
  665. memdelete(da);
  666. memdelete(filesystem_da);
  667. return make_dir_err;
  668. }
  669. }
  670. String destination = destination_dir + "/" + asset.get_file();
  671. Error err = dir_exists ? da->copy_dir(asset, destination) : da->copy(asset, destination);
  672. memdelete(da);
  673. if (err) {
  674. memdelete(filesystem_da);
  675. return err;
  676. }
  677. IOSExportAsset exported_asset = { destination, p_is_framework };
  678. r_exported_assets.push_back(exported_asset);
  679. }
  680. }
  681. memdelete(filesystem_da);
  682. return OK;
  683. }
  684. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets) {
  685. Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
  686. for (int i = 0; i < export_plugins.size(); i++) {
  687. Vector<String> frameworks = export_plugins[i]->get_ios_frameworks();
  688. Error err = _export_additional_assets(p_out_dir, frameworks, true, r_exported_assets);
  689. ERR_FAIL_COND_V(err, err);
  690. Vector<String> ios_bundle_files = export_plugins[i]->get_ios_bundle_files();
  691. err = _export_additional_assets(p_out_dir, ios_bundle_files, false, r_exported_assets);
  692. ERR_FAIL_COND_V(err, err);
  693. }
  694. Vector<String> library_paths;
  695. for (int i = 0; i < p_libraries.size(); ++i) {
  696. library_paths.push_back(p_libraries[i].path);
  697. }
  698. Error err = _export_additional_assets(p_out_dir, library_paths, true, r_exported_assets);
  699. ERR_FAIL_COND_V(err, err);
  700. return OK;
  701. }
  702. Vector<String> EditorExportPlatformIOS::_get_preset_architectures(const Ref<EditorExportPreset> &p_preset) {
  703. Vector<ExportArchitecture> all_archs = _get_supported_architectures();
  704. Vector<String> enabled_archs;
  705. for (int i = 0; i < all_archs.size(); ++i) {
  706. bool is_enabled = p_preset->get("architectures/" + all_archs[i].name);
  707. if (is_enabled) {
  708. enabled_archs.push_back(all_archs[i].name);
  709. }
  710. }
  711. return enabled_archs;
  712. }
  713. Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  714. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  715. String src_pkg_name;
  716. String dest_dir = p_path.get_base_dir() + "/";
  717. String binary_name = p_path.get_file().get_basename();
  718. EditorProgress ep("export", "Exporting for iOS", 5);
  719. String team_id = p_preset->get("application/app_store_team_id");
  720. ERR_EXPLAIN("App Store Team ID not specified - cannot configure the project.");
  721. ERR_FAIL_COND_V(team_id.length() == 0, ERR_CANT_OPEN);
  722. if (p_debug)
  723. src_pkg_name = p_preset->get("custom_package/debug");
  724. else
  725. src_pkg_name = p_preset->get("custom_package/release");
  726. if (src_pkg_name == "") {
  727. String err;
  728. src_pkg_name = find_export_template("iphone.zip", &err);
  729. if (src_pkg_name == "") {
  730. EditorNode::add_io_error(err);
  731. return ERR_FILE_NOT_FOUND;
  732. }
  733. }
  734. DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  735. if (da) {
  736. String current_dir = da->get_current_dir();
  737. // remove leftovers from last export so they don't interfere
  738. // in case some files are no longer needed
  739. if (da->change_dir(dest_dir + binary_name + ".xcodeproj") == OK) {
  740. da->erase_contents_recursive();
  741. }
  742. if (da->change_dir(dest_dir + binary_name) == OK) {
  743. da->erase_contents_recursive();
  744. }
  745. da->change_dir(current_dir);
  746. if (!da->dir_exists(dest_dir + binary_name)) {
  747. Error err = da->make_dir(dest_dir + binary_name);
  748. if (err) {
  749. memdelete(da);
  750. return err;
  751. }
  752. }
  753. memdelete(da);
  754. }
  755. ep.step("Making .pck", 0);
  756. String pack_path = dest_dir + binary_name + ".pck";
  757. Vector<SharedObject> libraries;
  758. Error err = save_pack(p_preset, pack_path, &libraries);
  759. if (err)
  760. return err;
  761. ep.step("Extracting and configuring Xcode project", 1);
  762. String library_to_use = "libgodot.iphone." + String(p_debug ? "debug" : "release") + ".fat.a";
  763. print_line("Static library: " + library_to_use);
  764. String pkg_name;
  765. if (p_preset->get("application/name") != "")
  766. pkg_name = p_preset->get("application/name"); // app_name
  767. else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "")
  768. pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  769. else
  770. pkg_name = "Unnamed";
  771. bool found_library = false;
  772. int total_size = 0;
  773. const String project_file = "godot_ios.xcodeproj/project.pbxproj";
  774. Set<String> files_to_parse;
  775. files_to_parse.insert("godot_ios/godot_ios-Info.plist");
  776. files_to_parse.insert(project_file);
  777. files_to_parse.insert("godot_ios/export_options.plist");
  778. files_to_parse.insert("godot_ios/dummy.cpp");
  779. files_to_parse.insert("godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata");
  780. files_to_parse.insert("godot_ios.xcodeproj/xcshareddata/xcschemes/godot_ios.xcscheme");
  781. IOSConfigData config_data = {
  782. pkg_name,
  783. binary_name,
  784. _get_additional_plist_content(),
  785. String(" ").join(_get_preset_architectures(p_preset)),
  786. _get_linker_flags(),
  787. _get_cpp_code()
  788. };
  789. DirAccess *tmp_app_path = DirAccess::create_for_path(dest_dir);
  790. ERR_FAIL_COND_V(!tmp_app_path, ERR_CANT_CREATE)
  791. print_line("Unzipping...");
  792. FileAccess *src_f = NULL;
  793. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  794. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  795. if (!src_pkg_zip) {
  796. EditorNode::add_io_error("Could not open export template (not a zip file?):\n" + src_pkg_name);
  797. return ERR_CANT_OPEN;
  798. }
  799. ERR_FAIL_COND_V(!src_pkg_zip, ERR_CANT_OPEN);
  800. int ret = unzGoToFirstFile(src_pkg_zip);
  801. Vector<uint8_t> project_file_data;
  802. while (ret == UNZ_OK) {
  803. #if defined(OSX_ENABLED) || defined(X11_ENABLED)
  804. bool is_execute = false;
  805. #endif
  806. //get filename
  807. unz_file_info info;
  808. char fname[16384];
  809. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, NULL, 0, NULL, 0);
  810. String file = fname;
  811. print_line("READ: " + file);
  812. Vector<uint8_t> data;
  813. data.resize(info.uncompressed_size);
  814. //read
  815. unzOpenCurrentFile(src_pkg_zip);
  816. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  817. unzCloseCurrentFile(src_pkg_zip);
  818. //write
  819. file = file.replace_first("iphone/", "");
  820. if (files_to_parse.has(file)) {
  821. _fix_config_file(p_preset, data, config_data, p_debug);
  822. } else if (file.begins_with("libgodot.iphone")) {
  823. if (file != library_to_use) {
  824. ret = unzGoToNextFile(src_pkg_zip);
  825. continue; //ignore!
  826. }
  827. found_library = true;
  828. #if defined(OSX_ENABLED) || defined(X11_ENABLED)
  829. is_execute = true;
  830. #endif
  831. file = "godot_ios.a";
  832. }
  833. if (file == project_file) {
  834. project_file_data = data;
  835. }
  836. ///@TODO need to parse logo files
  837. if (data.size() > 0) {
  838. file = file.replace("godot_ios", binary_name);
  839. print_line("ADDING: " + file + " size: " + itos(data.size()));
  840. total_size += data.size();
  841. /* write it into our folder structure */
  842. file = dest_dir + file;
  843. /* make sure this folder exists */
  844. String dir_name = file.get_base_dir();
  845. if (!tmp_app_path->dir_exists(dir_name)) {
  846. print_line("Creating " + dir_name);
  847. Error dir_err = tmp_app_path->make_dir_recursive(dir_name);
  848. if (dir_err) {
  849. ERR_PRINTS("Can't create '" + dir_name + "'.");
  850. unzClose(src_pkg_zip);
  851. memdelete(tmp_app_path);
  852. return ERR_CANT_CREATE;
  853. }
  854. }
  855. /* write the file */
  856. FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
  857. if (!f) {
  858. ERR_PRINTS("Can't write '" + file + "'.");
  859. unzClose(src_pkg_zip);
  860. memdelete(tmp_app_path);
  861. return ERR_CANT_CREATE;
  862. };
  863. f->store_buffer(data.ptr(), data.size());
  864. f->close();
  865. memdelete(f);
  866. #if defined(OSX_ENABLED) || defined(X11_ENABLED)
  867. if (is_execute) {
  868. // we need execute rights on this file
  869. chmod(file.utf8().get_data(), 0755);
  870. }
  871. #endif
  872. }
  873. ret = unzGoToNextFile(src_pkg_zip);
  874. }
  875. /* we're done with our source zip */
  876. unzClose(src_pkg_zip);
  877. if (!found_library) {
  878. ERR_PRINTS("Requested template library '" + library_to_use + "' not found. It might be missing from your template archive.");
  879. memdelete(tmp_app_path);
  880. return ERR_FILE_NOT_FOUND;
  881. }
  882. String iconset_dir = dest_dir + binary_name + "/Images.xcassets/AppIcon.appiconset/";
  883. err = OK;
  884. if (!tmp_app_path->dir_exists(iconset_dir)) {
  885. err = tmp_app_path->make_dir_recursive(iconset_dir);
  886. }
  887. memdelete(tmp_app_path);
  888. if (err)
  889. return err;
  890. err = _export_icons(p_preset, iconset_dir);
  891. if (err)
  892. return err;
  893. err = _export_loading_screens(p_preset, dest_dir + binary_name + "/Images.xcassets/LaunchImage.launchimage/");
  894. if (err)
  895. return err;
  896. print_line("Exporting additional assets");
  897. Vector<IOSExportAsset> assets;
  898. _export_additional_assets(dest_dir + binary_name, libraries, assets);
  899. _add_assets_to_project(project_file_data, assets);
  900. String project_file_name = dest_dir + binary_name + ".xcodeproj/project.pbxproj";
  901. FileAccess *f = FileAccess::open(project_file_name, FileAccess::WRITE);
  902. if (!f) {
  903. ERR_PRINTS("Can't write '" + project_file_name + "'.");
  904. return ERR_CANT_CREATE;
  905. };
  906. f->store_buffer(project_file_data.ptr(), project_file_data.size());
  907. f->close();
  908. memdelete(f);
  909. #ifdef OSX_ENABLED
  910. ep.step("Code-signing dylibs", 2);
  911. DirAccess *dylibs_dir = DirAccess::open(dest_dir + binary_name + "/dylibs");
  912. ERR_FAIL_COND_V(!dylibs_dir, ERR_CANT_OPEN);
  913. CodesignData codesign_data(p_preset, p_debug);
  914. err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data);
  915. memdelete(dylibs_dir);
  916. ERR_FAIL_COND_V(err, err);
  917. ep.step("Making .xcarchive", 3);
  918. String archive_path = p_path.get_basename() + ".xcarchive";
  919. List<String> archive_args;
  920. archive_args.push_back("-project");
  921. archive_args.push_back(dest_dir + binary_name + ".xcodeproj");
  922. archive_args.push_back("-scheme");
  923. archive_args.push_back(binary_name);
  924. archive_args.push_back("-sdk");
  925. archive_args.push_back("iphoneos");
  926. archive_args.push_back("-configuration");
  927. archive_args.push_back(p_debug ? "Debug" : "Release");
  928. archive_args.push_back("-destination");
  929. archive_args.push_back("generic/platform=iOS");
  930. archive_args.push_back("archive");
  931. archive_args.push_back("-archivePath");
  932. archive_args.push_back(archive_path);
  933. err = OS::get_singleton()->execute("xcodebuild", archive_args, true);
  934. ERR_FAIL_COND_V(err, err);
  935. ep.step("Making .ipa", 4);
  936. List<String> export_args;
  937. export_args.push_back("-exportArchive");
  938. export_args.push_back("-archivePath");
  939. export_args.push_back(archive_path);
  940. export_args.push_back("-exportOptionsPlist");
  941. export_args.push_back(dest_dir + binary_name + "/export_options.plist");
  942. export_args.push_back("-allowProvisioningUpdates");
  943. export_args.push_back("-exportPath");
  944. export_args.push_back(dest_dir);
  945. err = OS::get_singleton()->execute("xcodebuild", export_args, true);
  946. ERR_FAIL_COND_V(err, err);
  947. #else
  948. print_line(".ipa can only be built on macOS. Leaving Xcode project without building the package.");
  949. #endif
  950. return OK;
  951. }
  952. bool EditorExportPlatformIOS::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  953. String err;
  954. r_missing_templates = find_export_template("iphone.zip") == String();
  955. if (p_preset->get("custom_package/debug") != "") {
  956. if (FileAccess::exists(p_preset->get("custom_package/debug"))) {
  957. r_missing_templates = false;
  958. } else {
  959. err += TTR("Custom debug template not found.") + "\n";
  960. }
  961. }
  962. if (p_preset->get("custom_package/release") != "") {
  963. if (FileAccess::exists(p_preset->get("custom_package/release"))) {
  964. r_missing_templates = false;
  965. } else {
  966. err += TTR("Custom release template not found.") + "\n";
  967. }
  968. }
  969. bool valid = !r_missing_templates;
  970. String team_id = p_preset->get("application/app_store_team_id");
  971. if (team_id.length() == 0) {
  972. err += TTR("App Store Team ID not specified - cannot configure the project.") + "\n";
  973. valid = false;
  974. }
  975. String identifier = p_preset->get("application/identifier");
  976. String pn_err;
  977. if (!is_package_name_valid(identifier, &pn_err)) {
  978. err += TTR("Invalid Identifier:") + " " + pn_err + "\n";
  979. valid = false;
  980. }
  981. for (unsigned int i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  982. IconInfo info = icon_infos[i];
  983. String icon_path = p_preset->get(info.preset_key);
  984. if (icon_path.length() == 0) {
  985. if (info.is_required) {
  986. err += TTR("Required icon is not specified in the preset.") + "\n";
  987. valid = false;
  988. }
  989. break;
  990. }
  991. }
  992. if (!err.empty())
  993. r_error = err;
  994. return valid;
  995. }
  996. EditorExportPlatformIOS::EditorExportPlatformIOS() {
  997. Ref<Image> img = memnew(Image(_iphone_logo));
  998. logo.instance();
  999. logo->create_from_image(img);
  1000. }
  1001. EditorExportPlatformIOS::~EditorExportPlatformIOS() {
  1002. }
  1003. void register_iphone_exporter() {
  1004. Ref<EditorExportPlatformIOS> platform;
  1005. platform.instance();
  1006. EditorExport::get_singleton()->add_export_platform(platform);
  1007. }