export.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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 = "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 = "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 = "The character '" + String::chr(c) + "' is not allowed in Identifier.";
  112. }
  113. return false;
  114. }
  115. if (first && (c >= '0' && c <= '9')) {
  116. if (r_error) {
  117. *r_error = "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 = "The character '" + String::chr(c) + "' cannot be the first character in a Identifier segment.";
  124. }
  125. return false;
  126. }
  127. first = false;
  128. }
  129. if (segments == 0) {
  130. if (r_error) {
  131. *r_error = "The Identifier must have at least one '.' separator.";
  132. }
  133. return false;
  134. }
  135. if (first) {
  136. if (r_error) {
  137. *r_error = "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", "Default-Landscape-736h@3x.png" },
  194. { "landscape_launch_screens/ipad_1024x768", "Default-Landscape.png" },
  195. { "landscape_launch_screens/ipad_2048x1536", "Default-Landscape@2x.png" },
  196. { "portrait_launch_screens/iphone_640x960", "Default-480h@2x.png" },
  197. { "portrait_launch_screens/iphone_640x1136", "Default-568h@2x.png" },
  198. { "portrait_launch_screens/iphone_750x1334", "Default-667h@2x.png" },
  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", "Default-Portrait@2x.png" },
  202. { "portrait_launch_screens/iphone_1242x2208", "Default-Portrait-736h@3x.png" }
  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"), ""));
  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, "come.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::STRING, "required_icons/iphone_120x120", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPhone/iPod Touch with retina display
  222. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/ipad_76x76", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPad
  223. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/app_store_1024x1024", PROPERTY_HINT_FILE, "*.png"), "")); // App Store
  224. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/iphone_180x180", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPhone with retina HD display
  225. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/ipad_152x152", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPad with retina display
  226. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/ipad_167x167", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPad Pro
  227. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/spotlight_40x40", PROPERTY_HINT_FILE, "*.png"), "")); // Spotlight
  228. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/spotlight_80x80", PROPERTY_HINT_FILE, "*.png"), "")); // Spotlight on devices with retina display
  229. for (unsigned int i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  230. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, loading_screen_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png"), ""));
  231. }
  232. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), false));
  233. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
  234. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), true));
  235. Vector<ExportArchitecture> architectures = _get_supported_architectures();
  236. for (int i = 0; i < architectures.size(); ++i) {
  237. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "architectures/" + architectures[i].name), architectures[i].is_default));
  238. }
  239. }
  240. void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &pfile, const IOSConfigData &p_config, bool p_debug) {
  241. static const String export_method_string[] = {
  242. "app-store",
  243. "development",
  244. "ad-hoc",
  245. "enterprise"
  246. };
  247. String str;
  248. String strnew;
  249. str.parse_utf8((const char *)pfile.ptr(), pfile.size());
  250. Vector<String> lines = str.split("\n");
  251. for (int i = 0; i < lines.size(); i++) {
  252. if (lines[i].find("$binary") != -1) {
  253. strnew += lines[i].replace("$binary", p_config.binary_name) + "\n";
  254. } else if (lines[i].find("$name") != -1) {
  255. strnew += lines[i].replace("$name", p_config.pkg_name) + "\n";
  256. } else if (lines[i].find("$info") != -1) {
  257. strnew += lines[i].replace("$info", p_preset->get("application/info")) + "\n";
  258. } else if (lines[i].find("$identifier") != -1) {
  259. strnew += lines[i].replace("$identifier", p_preset->get("application/identifier")) + "\n";
  260. } else if (lines[i].find("$short_version") != -1) {
  261. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  262. } else if (lines[i].find("$version") != -1) {
  263. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  264. } else if (lines[i].find("$signature") != -1) {
  265. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  266. } else if (lines[i].find("$copyright") != -1) {
  267. strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
  268. } else if (lines[i].find("$team_id") != -1) {
  269. strnew += lines[i].replace("$team_id", p_preset->get("application/app_store_team_id")) + "\n";
  270. } else if (lines[i].find("$export_method") != -1) {
  271. int export_method = p_preset->get(p_debug ? "application/export_method_debug" : "application/export_method_release");
  272. strnew += lines[i].replace("$export_method", export_method_string[export_method]) + "\n";
  273. } else if (lines[i].find("$provisioning_profile_uuid_release") != -1) {
  274. strnew += lines[i].replace("$provisioning_profile_uuid_release", p_preset->get("application/provisioning_profile_uuid_release")) + "\n";
  275. } else if (lines[i].find("$provisioning_profile_uuid_debug") != -1) {
  276. strnew += lines[i].replace("$provisioning_profile_uuid_debug", p_preset->get("application/provisioning_profile_uuid_debug")) + "\n";
  277. } else if (lines[i].find("$provisioning_profile_uuid") != -1) {
  278. String uuid = p_debug ? p_preset->get("application/provisioning_profile_uuid_debug") : p_preset->get("application/provisioning_profile_uuid_release");
  279. strnew += lines[i].replace("$provisioning_profile_uuid", uuid) + "\n";
  280. } else if (lines[i].find("$code_sign_identity_debug") != -1) {
  281. strnew += lines[i].replace("$code_sign_identity_debug", p_preset->get("application/code_sign_identity_debug")) + "\n";
  282. } else if (lines[i].find("$code_sign_identity_release") != -1) {
  283. strnew += lines[i].replace("$code_sign_identity_release", p_preset->get("application/code_sign_identity_release")) + "\n";
  284. } else if (lines[i].find("$additional_plist_content") != -1) {
  285. strnew += lines[i].replace("$additional_plist_content", p_config.plist_content) + "\n";
  286. } else if (lines[i].find("$godot_archs") != -1) {
  287. strnew += lines[i].replace("$godot_archs", p_config.architectures) + "\n";
  288. } else if (lines[i].find("$linker_flags") != -1) {
  289. strnew += lines[i].replace("$linker_flags", p_config.linker_flags) + "\n";
  290. } else if (lines[i].find("$cpp_code") != -1) {
  291. strnew += lines[i].replace("$cpp_code", p_config.cpp_code) + "\n";
  292. } else {
  293. strnew += lines[i] + "\n";
  294. }
  295. }
  296. // !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...
  297. // should apply the same fix in our OSX export.
  298. CharString cs = strnew.utf8();
  299. pfile.resize(cs.size() - 1);
  300. for (int i = 0; i < cs.size() - 1; i++) {
  301. pfile.write[i] = cs[i];
  302. }
  303. }
  304. String EditorExportPlatformIOS::_get_additional_plist_content() {
  305. Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
  306. String result;
  307. for (int i = 0; i < export_plugins.size(); ++i) {
  308. result += export_plugins[i]->get_ios_plist_content();
  309. }
  310. return result;
  311. }
  312. String EditorExportPlatformIOS::_get_linker_flags() {
  313. Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
  314. String result;
  315. for (int i = 0; i < export_plugins.size(); ++i) {
  316. String flags = export_plugins[i]->get_ios_linker_flags();
  317. if (flags.length() == 0) continue;
  318. if (result.length() > 0) {
  319. result += ' ';
  320. }
  321. result += flags;
  322. }
  323. // the flags will be enclosed in quotes, so need to escape them
  324. return result.replace("\"", "\\\"");
  325. }
  326. String EditorExportPlatformIOS::_get_cpp_code() {
  327. Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
  328. String result;
  329. for (int i = 0; i < export_plugins.size(); ++i) {
  330. result += export_plugins[i]->get_ios_cpp_code();
  331. }
  332. return result;
  333. }
  334. struct IconInfo {
  335. const char *preset_key;
  336. const char *idiom;
  337. const char *export_name;
  338. const char *actual_size_side;
  339. const char *scale;
  340. const char *unscaled_size;
  341. bool is_required;
  342. };
  343. static const IconInfo icon_infos[] = {
  344. { "required_icons/iphone_120x120", "iphone", "Icon-120.png", "120", "2x", "60x60", true },
  345. { "required_icons/iphone_120x120", "iphone", "Icon-120.png", "120", "3x", "40x40", true },
  346. { "required_icons/ipad_76x76", "ipad", "Icon-76.png", "76", "1x", "76x76", false },
  347. { "required_icons/app_store_1024x1024", "ios-marketing", "Icon-1024.png", "1024", "1x", "1024x1024", false },
  348. { "optional_icons/iphone_180x180", "iphone", "Icon-180.png", "180", "3x", "60x60", false },
  349. { "optional_icons/ipad_152x152", "ipad", "Icon-152.png", "152", "2x", "76x76", false },
  350. { "optional_icons/ipad_167x167", "ipad", "Icon-167.png", "167", "2x", "83.5x83.5", false },
  351. { "optional_icons/spotlight_40x40", "ipad", "Icon-40.png", "40", "1x", "40x40", false },
  352. { "optional_icons/spotlight_80x80", "iphone", "Icon-80.png", "80", "2x", "40x40", false },
  353. { "optional_icons/spotlight_80x80", "ipad", "Icon-80.png", "80", "2x", "40x40", false }
  354. };
  355. Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_preset, const String &p_iconset_dir) {
  356. String json_description = "{\"images\":[";
  357. String sizes;
  358. DirAccess *da = DirAccess::open(p_iconset_dir);
  359. ERR_FAIL_COND_V(!da, ERR_CANT_OPEN);
  360. for (unsigned int i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  361. IconInfo info = icon_infos[i];
  362. String icon_path = p_preset->get(info.preset_key);
  363. if (icon_path.length() == 0) {
  364. if (info.is_required) {
  365. ERR_PRINT("Required icon is not specified in the preset");
  366. return ERR_UNCONFIGURED;
  367. }
  368. continue;
  369. }
  370. Error err = da->copy(icon_path, p_iconset_dir + info.export_name);
  371. if (err) {
  372. memdelete(da);
  373. String err_str = String("Failed to export icon: ") + icon_path;
  374. ERR_PRINT(err_str.utf8().get_data());
  375. return err;
  376. }
  377. sizes += String(info.actual_size_side) + "\n";
  378. if (i > 0) {
  379. json_description += ",";
  380. }
  381. json_description += String("{");
  382. json_description += String("\"idiom\":") + "\"" + info.idiom + "\",";
  383. json_description += String("\"size\":") + "\"" + info.unscaled_size + "\",";
  384. json_description += String("\"scale\":") + "\"" + info.scale + "\",";
  385. json_description += String("\"filename\":") + "\"" + info.export_name + "\"";
  386. json_description += String("}");
  387. }
  388. json_description += "]}";
  389. memdelete(da);
  390. FileAccess *json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE);
  391. ERR_FAIL_COND_V(!json_file, ERR_CANT_CREATE);
  392. CharString json_utf8 = json_description.utf8();
  393. json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length());
  394. memdelete(json_file);
  395. FileAccess *sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE);
  396. ERR_FAIL_COND_V(!sizes_file, ERR_CANT_CREATE);
  397. CharString sizes_utf8 = sizes.utf8();
  398. sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length());
  399. memdelete(sizes_file);
  400. return OK;
  401. }
  402. Error EditorExportPlatformIOS::_export_loading_screens(const Ref<EditorExportPreset> &p_preset, const String &p_dest_dir) {
  403. DirAccess *da = DirAccess::open(p_dest_dir);
  404. ERR_FAIL_COND_V(!da, ERR_CANT_OPEN);
  405. for (unsigned int i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
  406. LoadingScreenInfo info = loading_screen_infos[i];
  407. String loading_screen_file = p_preset->get(info.preset_key);
  408. if (loading_screen_file.size() > 0) {
  409. Error err = da->copy(loading_screen_file, p_dest_dir + info.export_name);
  410. if (err) {
  411. memdelete(da);
  412. String err_str = String("Failed to export loading screen (") + info.preset_key + ") from path: " + loading_screen_file;
  413. ERR_PRINT(err_str.utf8().get_data());
  414. return err;
  415. }
  416. }
  417. }
  418. memdelete(da);
  419. return OK;
  420. }
  421. Error EditorExportPlatformIOS::_walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata) {
  422. Vector<String> dirs;
  423. String path;
  424. String current_dir = p_da->get_current_dir();
  425. p_da->list_dir_begin();
  426. while ((path = p_da->get_next()).length() != 0) {
  427. if (p_da->current_is_dir()) {
  428. if (path != "." && path != "..") {
  429. dirs.push_back(path);
  430. }
  431. } else {
  432. Error err = p_handler(current_dir + "/" + path, p_userdata);
  433. if (err) {
  434. p_da->list_dir_end();
  435. return err;
  436. }
  437. }
  438. }
  439. p_da->list_dir_end();
  440. for (int i = 0; i < dirs.size(); ++i) {
  441. String dir = dirs[i];
  442. p_da->change_dir(dir);
  443. Error err = _walk_dir_recursive(p_da, p_handler, p_userdata);
  444. p_da->change_dir("..");
  445. if (err) {
  446. return err;
  447. }
  448. }
  449. return OK;
  450. }
  451. struct CodesignData {
  452. const Ref<EditorExportPreset> &preset;
  453. bool debug;
  454. CodesignData(const Ref<EditorExportPreset> &p_preset, bool p_debug) :
  455. preset(p_preset),
  456. debug(p_debug) {
  457. }
  458. };
  459. Error EditorExportPlatformIOS::_codesign(String p_file, void *p_userdata) {
  460. if (p_file.ends_with(".dylib")) {
  461. CodesignData *data = (CodesignData *)p_userdata;
  462. print_line(String("Signing ") + p_file);
  463. List<String> codesign_args;
  464. codesign_args.push_back("-f");
  465. codesign_args.push_back("-s");
  466. codesign_args.push_back(data->preset->get(data->debug ? "application/code_sign_identity_debug" : "application/code_sign_identity_release"));
  467. codesign_args.push_back(p_file);
  468. return OS::get_singleton()->execute("codesign", codesign_args, true);
  469. }
  470. return OK;
  471. }
  472. struct PbxId {
  473. private:
  474. static char _hex_char(uint8_t four_bits) {
  475. if (four_bits < 10) {
  476. return ('0' + four_bits);
  477. }
  478. return 'A' + (four_bits - 10);
  479. }
  480. static String _hex_pad(uint32_t num) {
  481. Vector<char> ret;
  482. ret.resize(sizeof(num) * 2);
  483. for (unsigned int i = 0; i < sizeof(num) * 2; ++i) {
  484. uint8_t four_bits = (num >> (sizeof(num) * 8 - (i + 1) * 4)) & 0xF;
  485. ret.write[i] = _hex_char(four_bits);
  486. }
  487. return String::utf8(ret.ptr(), ret.size());
  488. }
  489. public:
  490. uint32_t high_bits;
  491. uint32_t mid_bits;
  492. uint32_t low_bits;
  493. String str() const {
  494. return _hex_pad(high_bits) + _hex_pad(mid_bits) + _hex_pad(low_bits);
  495. }
  496. PbxId &operator++() {
  497. low_bits++;
  498. if (!low_bits) {
  499. mid_bits++;
  500. if (!mid_bits) {
  501. high_bits++;
  502. }
  503. }
  504. return *this;
  505. }
  506. };
  507. struct ExportLibsData {
  508. Vector<String> lib_paths;
  509. String dest_dir;
  510. };
  511. void EditorExportPlatformIOS::_add_assets_to_project(Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) {
  512. Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
  513. Vector<String> frameworks;
  514. for (int i = 0; i < export_plugins.size(); ++i) {
  515. Vector<String> plugin_frameworks = export_plugins[i]->get_ios_frameworks();
  516. for (int j = 0; j < plugin_frameworks.size(); ++j) {
  517. frameworks.push_back(plugin_frameworks[j]);
  518. }
  519. }
  520. // that is just a random number, we just need Godot IDs not to clash with
  521. // existing IDs in the project.
  522. PbxId current_id = { 0x58938401, 0, 0 };
  523. String pbx_files;
  524. String pbx_frameworks_build;
  525. String pbx_frameworks_refs;
  526. String pbx_resources_build;
  527. String pbx_resources_refs;
  528. const String file_info_format = String("$build_id = {isa = PBXBuildFile; fileRef = $ref_id; };\n") +
  529. "$ref_id = {isa = PBXFileReference; lastKnownFileType = $file_type; name = $name; path = \"$file_path\"; sourceTree = \"<group>\"; };\n";
  530. for (int i = 0; i < p_additional_assets.size(); ++i) {
  531. String build_id = (++current_id).str();
  532. String ref_id = (++current_id).str();
  533. const IOSExportAsset &asset = p_additional_assets[i];
  534. String type;
  535. if (asset.exported_path.ends_with(".framework")) {
  536. type = "wrapper.framework";
  537. } else if (asset.exported_path.ends_with(".dylib")) {
  538. type = "compiled.mach-o.dylib";
  539. } else if (asset.exported_path.ends_with(".a")) {
  540. type = "archive.ar";
  541. } else {
  542. type = "file";
  543. }
  544. String &pbx_build = asset.is_framework ? pbx_frameworks_build : pbx_resources_build;
  545. String &pbx_refs = asset.is_framework ? pbx_frameworks_refs : pbx_resources_refs;
  546. if (pbx_build.length() > 0) {
  547. pbx_build += ",\n";
  548. pbx_refs += ",\n";
  549. }
  550. pbx_build += build_id;
  551. pbx_refs += ref_id;
  552. Dictionary format_dict;
  553. format_dict["build_id"] = build_id;
  554. format_dict["ref_id"] = ref_id;
  555. format_dict["name"] = asset.exported_path.get_file();
  556. format_dict["file_path"] = asset.exported_path;
  557. format_dict["file_type"] = type;
  558. pbx_files += file_info_format.format(format_dict, "$_");
  559. }
  560. String str = String::utf8((const char *)p_project_data.ptr(), p_project_data.size());
  561. str = str.replace("$additional_pbx_files", pbx_files);
  562. str = str.replace("$additional_pbx_frameworks_build", pbx_frameworks_build);
  563. str = str.replace("$additional_pbx_frameworks_refs", pbx_frameworks_refs);
  564. str = str.replace("$additional_pbx_resources_build", pbx_resources_build);
  565. str = str.replace("$additional_pbx_resources_refs", pbx_resources_refs);
  566. CharString cs = str.utf8();
  567. p_project_data.resize(cs.size() - 1);
  568. for (int i = 0; i < cs.size() - 1; i++) {
  569. p_project_data.write[i] = cs[i];
  570. }
  571. }
  572. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, Vector<IOSExportAsset> &r_exported_assets) {
  573. DirAccess *filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  574. ERR_FAIL_COND_V(!filesystem_da, ERR_CANT_CREATE);
  575. for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) {
  576. String asset = p_assets[f_idx];
  577. if (!asset.begins_with("res://")) {
  578. // either SDK-builtin or already a part of the export template
  579. IOSExportAsset exported_asset = { asset, p_is_framework };
  580. r_exported_assets.push_back(exported_asset);
  581. } else {
  582. DirAccess *da = DirAccess::create_for_path(asset);
  583. if (!da) {
  584. memdelete(filesystem_da);
  585. ERR_FAIL_COND_V(!da, ERR_CANT_CREATE);
  586. }
  587. bool file_exists = da->file_exists(asset);
  588. bool dir_exists = da->dir_exists(asset);
  589. if (!file_exists && !dir_exists) {
  590. memdelete(da);
  591. memdelete(filesystem_da);
  592. return ERR_FILE_NOT_FOUND;
  593. }
  594. String additional_dir = p_is_framework && asset.ends_with(".dylib") ? "/dylibs/" : "/";
  595. String destination_dir = p_out_dir + additional_dir + asset.get_base_dir().replace("res://", "");
  596. if (!filesystem_da->dir_exists(destination_dir)) {
  597. Error make_dir_err = filesystem_da->make_dir_recursive(destination_dir);
  598. if (make_dir_err) {
  599. memdelete(da);
  600. memdelete(filesystem_da);
  601. return make_dir_err;
  602. }
  603. }
  604. String destination = destination_dir + "/" + asset.get_file();
  605. Error err = dir_exists ? da->copy_dir(asset, destination) : da->copy(asset, destination);
  606. memdelete(da);
  607. if (err) {
  608. memdelete(filesystem_da);
  609. return err;
  610. }
  611. IOSExportAsset exported_asset = { destination, p_is_framework };
  612. r_exported_assets.push_back(exported_asset);
  613. }
  614. }
  615. memdelete(filesystem_da);
  616. return OK;
  617. }
  618. Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets) {
  619. Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
  620. for (int i = 0; i < export_plugins.size(); i++) {
  621. Vector<String> frameworks = export_plugins[i]->get_ios_frameworks();
  622. Error err = _export_additional_assets(p_out_dir, frameworks, true, r_exported_assets);
  623. ERR_FAIL_COND_V(err, err);
  624. Vector<String> ios_bundle_files = export_plugins[i]->get_ios_bundle_files();
  625. err = _export_additional_assets(p_out_dir, ios_bundle_files, false, r_exported_assets);
  626. ERR_FAIL_COND_V(err, err);
  627. }
  628. Vector<String> library_paths;
  629. for (int i = 0; i < p_libraries.size(); ++i) {
  630. library_paths.push_back(p_libraries[i].path);
  631. }
  632. Error err = _export_additional_assets(p_out_dir, library_paths, true, r_exported_assets);
  633. ERR_FAIL_COND_V(err, err);
  634. return OK;
  635. }
  636. Vector<String> EditorExportPlatformIOS::_get_preset_architectures(const Ref<EditorExportPreset> &p_preset) {
  637. Vector<ExportArchitecture> all_archs = _get_supported_architectures();
  638. Vector<String> enabled_archs;
  639. for (int i = 0; i < all_archs.size(); ++i) {
  640. bool is_enabled = p_preset->get("architectures/" + all_archs[i].name);
  641. if (is_enabled) {
  642. enabled_archs.push_back(all_archs[i].name);
  643. }
  644. }
  645. return enabled_archs;
  646. }
  647. Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  648. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  649. String src_pkg_name;
  650. String dest_dir = p_path.get_base_dir() + "/";
  651. String binary_name = p_path.get_file().get_basename();
  652. EditorProgress ep("export", "Exporting for iOS", 5);
  653. String team_id = p_preset->get("application/app_store_team_id");
  654. ERR_EXPLAIN("App Store Team ID not specified - cannot configure the project.");
  655. ERR_FAIL_COND_V(team_id.length() == 0, ERR_CANT_OPEN);
  656. if (p_debug)
  657. src_pkg_name = p_preset->get("custom_package/debug");
  658. else
  659. src_pkg_name = p_preset->get("custom_package/release");
  660. if (src_pkg_name == "") {
  661. String err;
  662. src_pkg_name = find_export_template("iphone.zip", &err);
  663. if (src_pkg_name == "") {
  664. EditorNode::add_io_error(err);
  665. return ERR_FILE_NOT_FOUND;
  666. }
  667. }
  668. DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  669. if (da) {
  670. String current_dir = da->get_current_dir();
  671. // remove leftovers from last export so they don't interfere
  672. // in case some files are no longer needed
  673. if (da->change_dir(dest_dir + binary_name + ".xcodeproj") == OK) {
  674. da->erase_contents_recursive();
  675. }
  676. if (da->change_dir(dest_dir + binary_name) == OK) {
  677. da->erase_contents_recursive();
  678. }
  679. da->change_dir(current_dir);
  680. if (!da->dir_exists(dest_dir + binary_name)) {
  681. Error err = da->make_dir(dest_dir + binary_name);
  682. if (err) {
  683. memdelete(da);
  684. return err;
  685. }
  686. }
  687. memdelete(da);
  688. }
  689. ep.step("Making .pck", 0);
  690. String pack_path = dest_dir + binary_name + ".pck";
  691. Vector<SharedObject> libraries;
  692. Error err = save_pack(p_preset, pack_path, &libraries);
  693. if (err)
  694. return err;
  695. ep.step("Extracting and configuring Xcode project", 1);
  696. String library_to_use = "libgodot.iphone." + String(p_debug ? "debug" : "release") + ".fat.a";
  697. print_line("Static library: " + library_to_use);
  698. String pkg_name;
  699. if (p_preset->get("application/name") != "")
  700. pkg_name = p_preset->get("application/name"); // app_name
  701. else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "")
  702. pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  703. else
  704. pkg_name = "Unnamed";
  705. bool found_library = false;
  706. int total_size = 0;
  707. const String project_file = "godot_ios.xcodeproj/project.pbxproj";
  708. Set<String> files_to_parse;
  709. files_to_parse.insert("godot_ios/godot_ios-Info.plist");
  710. files_to_parse.insert(project_file);
  711. files_to_parse.insert("godot_ios/export_options.plist");
  712. files_to_parse.insert("godot_ios/dummy.cpp");
  713. files_to_parse.insert("godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata");
  714. files_to_parse.insert("godot_ios.xcodeproj/xcshareddata/xcschemes/godot_ios.xcscheme");
  715. IOSConfigData config_data = {
  716. pkg_name,
  717. binary_name,
  718. _get_additional_plist_content(),
  719. String(" ").join(_get_preset_architectures(p_preset)),
  720. _get_linker_flags(),
  721. _get_cpp_code()
  722. };
  723. DirAccess *tmp_app_path = DirAccess::create_for_path(dest_dir);
  724. ERR_FAIL_COND_V(!tmp_app_path, ERR_CANT_CREATE)
  725. print_line("Unzipping...");
  726. FileAccess *src_f = NULL;
  727. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  728. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  729. if (!src_pkg_zip) {
  730. EditorNode::add_io_error("Could not open export template (not a zip file?):\n" + src_pkg_name);
  731. return ERR_CANT_OPEN;
  732. }
  733. ERR_FAIL_COND_V(!src_pkg_zip, ERR_CANT_OPEN);
  734. int ret = unzGoToFirstFile(src_pkg_zip);
  735. Vector<uint8_t> project_file_data;
  736. while (ret == UNZ_OK) {
  737. #if defined(OSX_ENABLED) || defined(X11_ENABLED)
  738. bool is_execute = false;
  739. #endif
  740. //get filename
  741. unz_file_info info;
  742. char fname[16384];
  743. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, NULL, 0, NULL, 0);
  744. String file = fname;
  745. print_line("READ: " + file);
  746. Vector<uint8_t> data;
  747. data.resize(info.uncompressed_size);
  748. //read
  749. unzOpenCurrentFile(src_pkg_zip);
  750. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  751. unzCloseCurrentFile(src_pkg_zip);
  752. //write
  753. file = file.replace_first("iphone/", "");
  754. if (files_to_parse.has(file)) {
  755. _fix_config_file(p_preset, data, config_data, p_debug);
  756. } else if (file.begins_with("libgodot.iphone")) {
  757. if (file != library_to_use) {
  758. ret = unzGoToNextFile(src_pkg_zip);
  759. continue; //ignore!
  760. }
  761. found_library = true;
  762. #if defined(OSX_ENABLED) || defined(X11_ENABLED)
  763. is_execute = true;
  764. #endif
  765. file = "godot_ios.a";
  766. }
  767. if (file == project_file) {
  768. project_file_data = data;
  769. }
  770. ///@TODO need to parse logo files
  771. if (data.size() > 0) {
  772. file = file.replace("godot_ios", binary_name);
  773. print_line("ADDING: " + file + " size: " + itos(data.size()));
  774. total_size += data.size();
  775. /* write it into our folder structure */
  776. file = dest_dir + file;
  777. /* make sure this folder exists */
  778. String dir_name = file.get_base_dir();
  779. if (!tmp_app_path->dir_exists(dir_name)) {
  780. print_line("Creating " + dir_name);
  781. Error dir_err = tmp_app_path->make_dir_recursive(dir_name);
  782. if (dir_err) {
  783. ERR_PRINTS("Can't create '" + dir_name + "'.");
  784. unzClose(src_pkg_zip);
  785. memdelete(tmp_app_path);
  786. return ERR_CANT_CREATE;
  787. }
  788. }
  789. /* write the file */
  790. FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
  791. if (!f) {
  792. ERR_PRINTS("Can't write '" + file + "'.");
  793. unzClose(src_pkg_zip);
  794. memdelete(tmp_app_path);
  795. return ERR_CANT_CREATE;
  796. };
  797. f->store_buffer(data.ptr(), data.size());
  798. f->close();
  799. memdelete(f);
  800. #if defined(OSX_ENABLED) || defined(X11_ENABLED)
  801. if (is_execute) {
  802. // we need execute rights on this file
  803. chmod(file.utf8().get_data(), 0755);
  804. }
  805. #endif
  806. }
  807. ret = unzGoToNextFile(src_pkg_zip);
  808. }
  809. /* we're done with our source zip */
  810. unzClose(src_pkg_zip);
  811. if (!found_library) {
  812. ERR_PRINTS("Requested template library '" + library_to_use + "' not found. It might be missing from your template archive.");
  813. memdelete(tmp_app_path);
  814. return ERR_FILE_NOT_FOUND;
  815. }
  816. String iconset_dir = dest_dir + binary_name + "/Images.xcassets/AppIcon.appiconset/";
  817. err = OK;
  818. if (!tmp_app_path->dir_exists(iconset_dir)) {
  819. err = tmp_app_path->make_dir_recursive(iconset_dir);
  820. }
  821. memdelete(tmp_app_path);
  822. if (err)
  823. return err;
  824. err = _export_icons(p_preset, iconset_dir);
  825. if (err)
  826. return err;
  827. err = _export_loading_screens(p_preset, dest_dir + binary_name + "/Images.xcassets/LaunchImage.launchimage/");
  828. if (err)
  829. return err;
  830. print_line("Exporting additional assets");
  831. Vector<IOSExportAsset> assets;
  832. _export_additional_assets(dest_dir + binary_name, libraries, assets);
  833. _add_assets_to_project(project_file_data, assets);
  834. String project_file_name = dest_dir + binary_name + ".xcodeproj/project.pbxproj";
  835. FileAccess *f = FileAccess::open(project_file_name, FileAccess::WRITE);
  836. if (!f) {
  837. ERR_PRINTS("Can't write '" + project_file_name + "'.");
  838. return ERR_CANT_CREATE;
  839. };
  840. f->store_buffer(project_file_data.ptr(), project_file_data.size());
  841. f->close();
  842. memdelete(f);
  843. #ifdef OSX_ENABLED
  844. ep.step("Code-signing dylibs", 2);
  845. DirAccess *dylibs_dir = DirAccess::open(dest_dir + binary_name + "/dylibs");
  846. ERR_FAIL_COND_V(!dylibs_dir, ERR_CANT_OPEN);
  847. CodesignData codesign_data(p_preset, p_debug);
  848. err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data);
  849. memdelete(dylibs_dir);
  850. ERR_FAIL_COND_V(err, err);
  851. ep.step("Making .xcarchive", 3);
  852. String archive_path = p_path.get_basename() + ".xcarchive";
  853. List<String> archive_args;
  854. archive_args.push_back("-project");
  855. archive_args.push_back(dest_dir + binary_name + ".xcodeproj");
  856. archive_args.push_back("-scheme");
  857. archive_args.push_back(binary_name);
  858. archive_args.push_back("-sdk");
  859. archive_args.push_back("iphoneos");
  860. archive_args.push_back("-configuration");
  861. archive_args.push_back(p_debug ? "Debug" : "Release");
  862. archive_args.push_back("-destination");
  863. archive_args.push_back("generic/platform=iOS");
  864. archive_args.push_back("archive");
  865. archive_args.push_back("-archivePath");
  866. archive_args.push_back(archive_path);
  867. err = OS::get_singleton()->execute("xcodebuild", archive_args, true);
  868. ERR_FAIL_COND_V(err, err);
  869. ep.step("Making .ipa", 4);
  870. List<String> export_args;
  871. export_args.push_back("-exportArchive");
  872. export_args.push_back("-archivePath");
  873. export_args.push_back(archive_path);
  874. export_args.push_back("-exportOptionsPlist");
  875. export_args.push_back(dest_dir + binary_name + "/export_options.plist");
  876. export_args.push_back("-allowProvisioningUpdates");
  877. export_args.push_back("-exportPath");
  878. export_args.push_back(dest_dir);
  879. err = OS::get_singleton()->execute("xcodebuild", export_args, true);
  880. ERR_FAIL_COND_V(err, err);
  881. #else
  882. print_line(".ipa can only be built on macOS. Leaving Xcode project without building the package.");
  883. #endif
  884. return OK;
  885. }
  886. bool EditorExportPlatformIOS::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  887. bool valid = true;
  888. String err;
  889. if (!exists_export_template("iphone.zip", &err)) {
  890. valid = false;
  891. }
  892. if (p_preset->get("custom_package/debug") != "" && !FileAccess::exists(p_preset->get("custom_package/debug"))) {
  893. valid = false;
  894. err += "Custom debug package not found.\n";
  895. }
  896. if (p_preset->get("custom_package/release") != "" && !FileAccess::exists(p_preset->get("custom_package/release"))) {
  897. valid = false;
  898. err += "Custom release package not found.\n";
  899. }
  900. String team_id = p_preset->get("application/app_store_team_id");
  901. if (team_id.length() == 0) {
  902. err += "App Store Team ID not specified - cannot configure the project.\n";
  903. }
  904. String identifier = p_preset->get("application/identifier");
  905. String pn_err;
  906. if (!is_package_name_valid(identifier, &pn_err)) {
  907. err += "Invalid Identifier - " + pn_err + "\n";
  908. }
  909. for (unsigned int i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  910. IconInfo info = icon_infos[i];
  911. String icon_path = p_preset->get(info.preset_key);
  912. if (icon_path.length() == 0) {
  913. if (info.is_required) {
  914. err += "Required icon is not specified in the preset.\n";
  915. }
  916. break;
  917. }
  918. }
  919. if (!err.empty())
  920. r_error = err;
  921. r_missing_templates = !valid;
  922. return err.empty();
  923. }
  924. EditorExportPlatformIOS::EditorExportPlatformIOS() {
  925. Ref<Image> img = memnew(Image(_iphone_logo));
  926. logo.instance();
  927. logo->create_from_image(img);
  928. }
  929. EditorExportPlatformIOS::~EditorExportPlatformIOS() {
  930. }
  931. void register_iphone_exporter() {
  932. Ref<EditorExportPlatformIOS> platform;
  933. platform.instance();
  934. EditorExport::get_singleton()->add_export_platform(platform);
  935. }