export_plugin.cpp 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  1. /*************************************************************************/
  2. /* export_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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 "modules/modules_enabled.gen.h" // For regex.
  31. #include "codesign.h"
  32. #include "export_plugin.h"
  33. void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
  34. if (p_preset->get("texture_format/s3tc")) {
  35. r_features->push_back("s3tc");
  36. }
  37. if (p_preset->get("texture_format/etc")) {
  38. r_features->push_back("etc");
  39. }
  40. if (p_preset->get("texture_format/etc2")) {
  41. r_features->push_back("etc2");
  42. }
  43. r_features->push_back("64");
  44. }
  45. bool EditorExportPlatformOSX::get_export_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
  46. // These options are not supported by built-in codesign, used on non macOS host.
  47. if (!OS::get_singleton()->has_feature("macos")) {
  48. if (p_option == "codesign/identity" || p_option == "codesign/timestamp" || p_option == "codesign/hardened_runtime" || p_option == "codesign/custom_options" || p_option.begins_with("notarization/")) {
  49. return false;
  50. }
  51. }
  52. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  53. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  54. if (p_option == "codesign/entitlements/allow_jit_code_execution" || p_option == "codesign/entitlements/allow_unsigned_executable_memory" || p_option == "codesign/entitlements/allow_dyld_environment_variables") {
  55. return false;
  56. }
  57. }
  58. return true;
  59. }
  60. void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) {
  61. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  62. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  63. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
  64. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine"));
  65. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.png,*.icns"), ""));
  66. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), ""));
  67. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  68. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_category", PROPERTY_HINT_ENUM, "Business,Developer-tools,Education,Entertainment,Finance,Games,Action-games,Adventure-games,Arcade-games,Board-games,Card-games,Casino-games,Dice-games,Educational-games,Family-games,Kids-games,Music-games,Puzzle-games,Racing-games,Role-playing-games,Simulation-games,Sports-games,Strategy-games,Trivia-games,Word-games,Graphics-design,Healthcare-fitness,Lifestyle,Medical,Music,News,Photography,Productivity,Reference,Social-networking,Sports,Travel,Utilities,Video,Weather"), "Games"));
  69. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  70. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  71. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  72. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false));
  73. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/microphone_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the microphone"), ""));
  74. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/camera_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the camera"), ""));
  75. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/location_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the location information"), ""));
  76. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/address_book_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the address book"), ""));
  77. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/calendar_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the calendar"), ""));
  78. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/photos_library_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the photo library"), ""));
  79. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/desktop_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Desktop folder"), ""));
  80. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/documents_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Documents folder"), ""));
  81. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/downloads_folder_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use Downloads folder"), ""));
  82. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/network_volumes_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use network volumes"), ""));
  83. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/removable_volumes_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use removable volumes"), ""));
  84. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/enable"), true));
  85. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), ""));
  86. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/timestamp"), true));
  87. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/replace_existing_signature"), true));
  88. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/hardened_runtime"), true));
  89. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), ""));
  90. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false));
  91. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false));
  92. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false));
  93. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false));
  94. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false));
  95. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false));
  96. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/location"), false));
  97. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/address_book"), false));
  98. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/calendars"), false));
  99. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/photos_library"), false));
  100. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/apple_events"), false));
  101. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/debugging"), false));
  102. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/enabled"), false));
  103. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_server"), false));
  104. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_client"), false));
  105. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_usb"), false));
  106. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_bluetooth"), false));
  107. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_downloads", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  108. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_pictures", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  109. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_music", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  110. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_movies", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  111. r_options->push_back(ExportOption(PropertyInfo(Variant::ARRAY, "codesign/entitlements/app_sandbox/helper_executables", PROPERTY_HINT_ARRAY_TYPE, itos(Variant::STRING) + "/" + itos(PROPERTY_HINT_GLOBAL_FILE) + ":"), Array()));
  112. r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
  113. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "notarization/enable"), false));
  114. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple ID email"), ""));
  115. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_password", PROPERTY_HINT_PLACEHOLDER_TEXT, "Enable two-factor authentication and provide app-specific password"), ""));
  116. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_team_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide team ID if your Apple ID belongs to multiple teams"), ""));
  117. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
  118. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
  119. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
  120. }
  121. void _rgba8_to_packbits_encode(int p_ch, int p_size, Vector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {
  122. int src_len = p_size * p_size;
  123. Vector<uint8_t> result;
  124. result.resize(src_len * 1.25); //temp vector for rle encoded data, make it 25% larger for worst case scenario
  125. int res_size = 0;
  126. uint8_t buf[128];
  127. int buf_size = 0;
  128. int i = 0;
  129. while (i < src_len) {
  130. uint8_t cur = p_source.ptr()[i * 4 + p_ch];
  131. if (i < src_len - 2) {
  132. if ((p_source.ptr()[(i + 1) * 4 + p_ch] == cur) && (p_source.ptr()[(i + 2) * 4 + p_ch] == cur)) {
  133. if (buf_size > 0) {
  134. result.write[res_size++] = (uint8_t)(buf_size - 1);
  135. memcpy(&result.write[res_size], &buf, buf_size);
  136. res_size += buf_size;
  137. buf_size = 0;
  138. }
  139. uint8_t lim = i + 130 >= src_len ? src_len - i - 1 : 130;
  140. bool hit_lim = true;
  141. for (int j = 3; j <= lim; j++) {
  142. if (p_source.ptr()[(i + j) * 4 + p_ch] != cur) {
  143. hit_lim = false;
  144. i = i + j - 1;
  145. result.write[res_size++] = (uint8_t)(j - 3 + 0x80);
  146. result.write[res_size++] = cur;
  147. break;
  148. }
  149. }
  150. if (hit_lim) {
  151. result.write[res_size++] = (uint8_t)(lim - 3 + 0x80);
  152. result.write[res_size++] = cur;
  153. i = i + lim;
  154. }
  155. } else {
  156. buf[buf_size++] = cur;
  157. if (buf_size == 128) {
  158. result.write[res_size++] = (uint8_t)(buf_size - 1);
  159. memcpy(&result.write[res_size], &buf, buf_size);
  160. res_size += buf_size;
  161. buf_size = 0;
  162. }
  163. }
  164. } else {
  165. buf[buf_size++] = cur;
  166. result.write[res_size++] = (uint8_t)(buf_size - 1);
  167. memcpy(&result.write[res_size], &buf, buf_size);
  168. res_size += buf_size;
  169. buf_size = 0;
  170. }
  171. i++;
  172. }
  173. int ofs = p_dest.size();
  174. p_dest.resize(p_dest.size() + res_size);
  175. memcpy(&p_dest.write[ofs], result.ptr(), res_size);
  176. }
  177. void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
  178. Ref<ImageTexture> it = memnew(ImageTexture);
  179. Vector<uint8_t> data;
  180. data.resize(8);
  181. data.write[0] = 'i';
  182. data.write[1] = 'c';
  183. data.write[2] = 'n';
  184. data.write[3] = 's';
  185. struct MacOSIconInfo {
  186. const char *name;
  187. const char *mask_name;
  188. bool is_png;
  189. int size;
  190. };
  191. static const MacOSIconInfo icon_infos[] = {
  192. { "ic10", "", true, 1024 }, //1024×1024 32-bit PNG and 512×512@2x 32-bit "retina" PNG
  193. { "ic09", "", true, 512 }, //512×512 32-bit PNG
  194. { "ic14", "", true, 512 }, //256×256@2x 32-bit "retina" PNG
  195. { "ic08", "", true, 256 }, //256×256 32-bit PNG
  196. { "ic13", "", true, 256 }, //128×128@2x 32-bit "retina" PNG
  197. { "ic07", "", true, 128 }, //128×128 32-bit PNG
  198. { "ic12", "", true, 64 }, //32×32@2× 32-bit "retina" PNG
  199. { "ic11", "", true, 32 }, //16×16@2× 32-bit "retina" PNG
  200. { "il32", "l8mk", false, 32 }, //32×32 24-bit RLE + 8-bit uncompressed mask
  201. { "is32", "s8mk", false, 16 } //16×16 24-bit RLE + 8-bit uncompressed mask
  202. };
  203. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  204. Ref<Image> copy = p_icon; // does this make sense? doesn't this just increase the reference count instead of making a copy? Do we even need a copy?
  205. copy->convert(Image::FORMAT_RGBA8);
  206. copy->resize(icon_infos[i].size, icon_infos[i].size);
  207. if (icon_infos[i].is_png) {
  208. // Encode PNG icon.
  209. it->create_from_image(copy);
  210. String path = EditorPaths::get_singleton()->get_cache_dir().plus_file("icon.png");
  211. ResourceSaver::save(path, it);
  212. FileAccess *f = FileAccess::open(path, FileAccess::READ);
  213. if (!f) {
  214. // Clean up generated file.
  215. DirAccess::remove_file_or_error(path);
  216. ERR_FAIL();
  217. }
  218. int ofs = data.size();
  219. uint64_t len = f->get_length();
  220. data.resize(data.size() + len + 8);
  221. f->get_buffer(&data.write[ofs + 8], len);
  222. memdelete(f);
  223. len += 8;
  224. len = BSWAP32(len);
  225. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  226. encode_uint32(len, &data.write[ofs + 4]);
  227. // Clean up generated file.
  228. DirAccess::remove_file_or_error(path);
  229. } else {
  230. Vector<uint8_t> src_data = copy->get_data();
  231. //encode 24bit RGB RLE icon
  232. {
  233. int ofs = data.size();
  234. data.resize(data.size() + 8);
  235. _rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // encode R
  236. _rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // encode G
  237. _rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // encode B
  238. int len = data.size() - ofs;
  239. len = BSWAP32(len);
  240. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  241. encode_uint32(len, &data.write[ofs + 4]);
  242. }
  243. //encode 8bit mask uncompressed icon
  244. {
  245. int ofs = data.size();
  246. int len = copy->get_width() * copy->get_height();
  247. data.resize(data.size() + len + 8);
  248. for (int j = 0; j < len; j++) {
  249. data.write[ofs + 8 + j] = src_data.ptr()[j * 4 + 3];
  250. }
  251. len += 8;
  252. len = BSWAP32(len);
  253. memcpy(&data.write[ofs], icon_infos[i].mask_name, 4);
  254. encode_uint32(len, &data.write[ofs + 4]);
  255. }
  256. }
  257. }
  258. uint32_t total_len = data.size();
  259. total_len = BSWAP32(total_len);
  260. encode_uint32(total_len, &data.write[4]);
  261. p_data = data;
  262. }
  263. void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) {
  264. String str;
  265. String strnew;
  266. str.parse_utf8((const char *)plist.ptr(), plist.size());
  267. Vector<String> lines = str.split("\n");
  268. for (int i = 0; i < lines.size(); i++) {
  269. if (lines[i].find("$binary") != -1) {
  270. strnew += lines[i].replace("$binary", p_binary) + "\n";
  271. } else if (lines[i].find("$name") != -1) {
  272. strnew += lines[i].replace("$name", p_binary) + "\n";
  273. } else if (lines[i].find("$info") != -1) {
  274. strnew += lines[i].replace("$info", p_preset->get("application/info")) + "\n";
  275. } else if (lines[i].find("$bundle_identifier") != -1) {
  276. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  277. } else if (lines[i].find("$short_version") != -1) {
  278. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  279. } else if (lines[i].find("$version") != -1) {
  280. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  281. } else if (lines[i].find("$signature") != -1) {
  282. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  283. } else if (lines[i].find("$app_category") != -1) {
  284. String cat = p_preset->get("application/app_category");
  285. strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n";
  286. } else if (lines[i].find("$copyright") != -1) {
  287. strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
  288. } else if (lines[i].find("$highres") != -1) {
  289. strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "\t<true/>" : "\t<false/>") + "\n";
  290. } else if (lines[i].find("$usage_descriptions") != -1) {
  291. String descriptions;
  292. if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
  293. descriptions += "\t<key>NSMicrophoneUsageDescription</key>\n";
  294. descriptions += "\t<string>" + (String)p_preset->get("privacy/microphone_usage_description") + "</string>\n";
  295. }
  296. if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
  297. descriptions += "\t<key>NSCameraUsageDescription</key>\n";
  298. descriptions += "\t<string>" + (String)p_preset->get("privacy/camera_usage_description") + "</string>\n";
  299. }
  300. if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
  301. descriptions += "\t<key>NSLocationUsageDescription</key>\n";
  302. descriptions += "\t<string>" + (String)p_preset->get("privacy/location_usage_description") + "</string>\n";
  303. }
  304. if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
  305. descriptions += "\t<key>NSContactsUsageDescription</key>\n";
  306. descriptions += "\t<string>" + (String)p_preset->get("privacy/address_book_usage_description") + "</string>\n";
  307. }
  308. if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
  309. descriptions += "\t<key>NSCalendarsUsageDescription</key>\n";
  310. descriptions += "\t<string>" + (String)p_preset->get("privacy/calendar_usage_description") + "</string>\n";
  311. }
  312. if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
  313. descriptions += "\t<key>NSPhotoLibraryUsageDescription</key>\n";
  314. descriptions += "\t<string>" + (String)p_preset->get("privacy/photos_library_usage_description") + "</string>\n";
  315. }
  316. if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {
  317. descriptions += "\t<key>NSDesktopFolderUsageDescription</key>\n";
  318. descriptions += "\t<string>" + (String)p_preset->get("privacy/desktop_folder_usage_description") + "</string>\n";
  319. }
  320. if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {
  321. descriptions += "\t<key>NSDocumentsFolderUsageDescription</key>\n";
  322. descriptions += "\t<string>" + (String)p_preset->get("privacy/documents_folder_usage_description") + "</string>\n";
  323. }
  324. if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {
  325. descriptions += "\t<key>NSDownloadsFolderUsageDescription</key>\n";
  326. descriptions += "\t<string>" + (String)p_preset->get("privacy/downloads_folder_usage_description") + "</string>\n";
  327. }
  328. if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {
  329. descriptions += "\t<key>NSNetworkVolumesUsageDescription</key>\n";
  330. descriptions += "\t<string>" + (String)p_preset->get("privacy/network_volumes_usage_description") + "</string>\n";
  331. }
  332. if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {
  333. descriptions += "\t<key>NSRemovableVolumesUsageDescription</key>\n";
  334. descriptions += "\t<string>" + (String)p_preset->get("privacy/removable_volumes_usage_description") + "</string>\n";
  335. }
  336. if (!descriptions.is_empty()) {
  337. strnew += lines[i].replace("$usage_descriptions", descriptions);
  338. }
  339. } else {
  340. strnew += lines[i] + "\n";
  341. }
  342. }
  343. CharString cs = strnew.utf8();
  344. plist.resize(cs.size() - 1);
  345. for (int i = 0; i < cs.size() - 1; i++) {
  346. plist.write[i] = cs[i];
  347. }
  348. }
  349. /**
  350. * If we're running the OSX version of the Godot editor we'll:
  351. * - export our application bundle to a temporary folder
  352. * - attempt to code sign it
  353. * - and then wrap it up in a DMG
  354. */
  355. Error EditorExportPlatformOSX::_notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  356. #ifdef OSX_ENABLED
  357. List<String> args;
  358. args.push_back("altool");
  359. args.push_back("--notarize-app");
  360. args.push_back("--primary-bundle-id");
  361. args.push_back(p_preset->get("application/bundle_identifier"));
  362. args.push_back("--username");
  363. args.push_back(p_preset->get("notarization/apple_id_name"));
  364. args.push_back("--password");
  365. args.push_back(p_preset->get("notarization/apple_id_password"));
  366. args.push_back("--type");
  367. args.push_back("osx");
  368. if (p_preset->get("notarization/apple_team_id")) {
  369. args.push_back("--asc-provider");
  370. args.push_back(p_preset->get("notarization/apple_team_id"));
  371. }
  372. args.push_back("--file");
  373. args.push_back(p_path);
  374. String str;
  375. Error err = OS::get_singleton()->execute("xcrun", args, &str, nullptr, true);
  376. ERR_FAIL_COND_V(err != OK, err);
  377. print_verbose("altool (" + p_path + "):\n" + str);
  378. if (str.find("RequestUUID") == -1) {
  379. EditorNode::add_io_error("altool: " + str);
  380. return FAILED;
  381. } else {
  382. print_line(TTR("Note: The notarization process generally takes less than an hour. When the process is completed, you'll receive an email."));
  383. print_line(" " + TTR("You can check progress manually by opening a Terminal and running the following command:"));
  384. print_line(" \"xcrun altool --notarization-history 0 -u <your email> -p <app-specific pwd>\"");
  385. print_line(" " + TTR("Run the following command to staple notarization ticket to the exported application (optional):"));
  386. print_line(" \"xcrun stapler staple <app path>\"");
  387. }
  388. #endif
  389. return OK;
  390. }
  391. Error EditorExportPlatformOSX::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path) {
  392. bool force_builtin_codesign = EditorSettings::get_singleton()->get("export/macos/force_builtin_codesign");
  393. bool ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  394. if ((!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) || force_builtin_codesign) {
  395. print_verbose("using built-in codesign...");
  396. #ifdef MODULE_REGEX_ENABLED
  397. #ifdef OSX_ENABLED
  398. if (p_preset->get("codesign/timestamp")) {
  399. WARN_PRINT("Timestamping is not compatible with ad-hoc signature, and was disabled!");
  400. }
  401. if (p_preset->get("codesign/hardened_runtime")) {
  402. WARN_PRINT("Hardened Runtime is not compatible with ad-hoc signature, and was disabled!");
  403. }
  404. #endif
  405. String error_msg;
  406. Error err = CodeSign::codesign(false, p_preset->get("codesign/replace_existing_signature"), p_path, p_ent_path, error_msg);
  407. if (err != OK) {
  408. EditorNode::add_io_error("Built-in CodeSign: " + error_msg);
  409. return FAILED;
  410. }
  411. #else
  412. ERR_FAIL_V_MSG(FAILED, "Built-in CodeSign require regex module");
  413. #endif
  414. return OK;
  415. } else {
  416. print_verbose("using external codesign...");
  417. List<String> args;
  418. if (p_preset->get("codesign/timestamp")) {
  419. if (ad_hoc) {
  420. WARN_PRINT("Timestamping is not compatible with ad-hoc signature, and was disabled!");
  421. } else {
  422. args.push_back("--timestamp");
  423. }
  424. }
  425. if (p_preset->get("codesign/hardened_runtime")) {
  426. if (ad_hoc) {
  427. WARN_PRINT("Hardened Runtime is not compatible with ad-hoc signature, and was disabled!");
  428. } else {
  429. args.push_back("--options");
  430. args.push_back("runtime");
  431. }
  432. }
  433. if (p_path.get_extension() != "dmg") {
  434. args.push_back("--entitlements");
  435. args.push_back(p_ent_path);
  436. }
  437. PackedStringArray user_args = p_preset->get("codesign/custom_options");
  438. for (int i = 0; i < user_args.size(); i++) {
  439. String user_arg = user_args[i].strip_edges();
  440. if (!user_arg.is_empty()) {
  441. args.push_back(user_arg);
  442. }
  443. }
  444. args.push_back("-s");
  445. if (ad_hoc) {
  446. args.push_back("-");
  447. } else {
  448. args.push_back(p_preset->get("codesign/identity"));
  449. }
  450. args.push_back("-v"); /* provide some more feedback */
  451. if (p_preset->get("codesign/replace_existing_signature")) {
  452. args.push_back("-f");
  453. }
  454. args.push_back(p_path);
  455. String str;
  456. Error err = OS::get_singleton()->execute("codesign", args, &str, nullptr, true);
  457. ERR_FAIL_COND_V(err != OK, err);
  458. print_verbose("codesign (" + p_path + "):\n" + str);
  459. if (str.find("no identity found") != -1) {
  460. EditorNode::add_io_error("CodeSign: " + TTR("No identity found."));
  461. return FAILED;
  462. }
  463. if ((str.find("unrecognized blob type") != -1) || (str.find("cannot read entitlement data") != -1)) {
  464. EditorNode::add_io_error("CodeSign: " + TTR("Invalid entitlements file."));
  465. return FAILED;
  466. }
  467. return OK;
  468. }
  469. }
  470. Error EditorExportPlatformOSX::_code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path,
  471. const String &p_ent_path, bool p_should_error_on_non_code) {
  472. #ifdef OSX_ENABLED
  473. static Vector<String> extensions_to_sign;
  474. if (extensions_to_sign.is_empty()) {
  475. extensions_to_sign.push_back("dylib");
  476. extensions_to_sign.push_back("framework");
  477. }
  478. Error dir_access_error;
  479. DirAccessRef dir_access{ DirAccess::open(p_path, &dir_access_error) };
  480. if (dir_access_error != OK) {
  481. return dir_access_error;
  482. }
  483. dir_access->list_dir_begin();
  484. String current_file{ dir_access->get_next() };
  485. while (!current_file.is_empty()) {
  486. String current_file_path{ p_path.plus_file(current_file) };
  487. if (current_file == ".." || current_file == ".") {
  488. current_file = dir_access->get_next();
  489. continue;
  490. }
  491. if (extensions_to_sign.find(current_file.get_extension()) > -1) {
  492. Error code_sign_error{ _code_sign(p_preset, current_file_path, p_ent_path) };
  493. if (code_sign_error != OK) {
  494. return code_sign_error;
  495. }
  496. } else if (dir_access->current_is_dir()) {
  497. Error code_sign_error{ _code_sign_directory(p_preset, current_file_path, p_ent_path, p_should_error_on_non_code) };
  498. if (code_sign_error != OK) {
  499. return code_sign_error;
  500. }
  501. } else if (p_should_error_on_non_code) {
  502. ERR_PRINT(vformat("Cannot sign file %s.", current_file));
  503. return Error::FAILED;
  504. }
  505. current_file = dir_access->get_next();
  506. }
  507. #endif
  508. return OK;
  509. }
  510. Error EditorExportPlatformOSX::_copy_and_sign_files(DirAccessRef &dir_access, const String &p_src_path,
  511. const String &p_in_app_path, bool p_sign_enabled,
  512. const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,
  513. bool p_should_error_on_non_code_sign) {
  514. Error err{ OK };
  515. if (dir_access->dir_exists(p_src_path)) {
  516. #ifndef UNIX_ENABLED
  517. WARN_PRINT("Relative symlinks are not supported, exported " + p_src_path.get_file() + " might be broken!");
  518. #endif
  519. print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path);
  520. err = dir_access->make_dir_recursive(p_in_app_path);
  521. if (err == OK) {
  522. err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true);
  523. }
  524. } else {
  525. print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path);
  526. err = dir_access->copy(p_src_path, p_in_app_path);
  527. }
  528. if (err == OK && p_sign_enabled) {
  529. if (dir_access->dir_exists(p_src_path) && p_src_path.get_extension().is_empty()) {
  530. // If it is a directory, find and sign all dynamic libraries.
  531. err = _code_sign_directory(p_preset, p_in_app_path, p_ent_path, p_should_error_on_non_code_sign);
  532. } else {
  533. err = _code_sign(p_preset, p_in_app_path, p_ent_path);
  534. }
  535. }
  536. return err;
  537. }
  538. Error EditorExportPlatformOSX::_export_osx_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin,
  539. const String &p_app_path_name, DirAccessRef &dir_access,
  540. bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,
  541. const String &p_ent_path) {
  542. Error error{ OK };
  543. const Vector<String> &osx_plugins{ p_editor_export_plugin->get_osx_plugin_files() };
  544. for (int i = 0; i < osx_plugins.size(); ++i) {
  545. String src_path{ ProjectSettings::get_singleton()->globalize_path(osx_plugins[i]) };
  546. String path_in_app{ p_app_path_name + "/Contents/PlugIns/" + src_path.get_file() };
  547. error = _copy_and_sign_files(dir_access, src_path, path_in_app, p_sign_enabled, p_preset, p_ent_path, false);
  548. if (error != OK) {
  549. break;
  550. }
  551. }
  552. return error;
  553. }
  554. Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
  555. List<String> args;
  556. if (FileAccess::exists(p_dmg_path)) {
  557. OS::get_singleton()->move_to_trash(p_dmg_path);
  558. }
  559. args.push_back("create");
  560. args.push_back(p_dmg_path);
  561. args.push_back("-volname");
  562. args.push_back(p_pkg_name);
  563. args.push_back("-fs");
  564. args.push_back("HFS+");
  565. args.push_back("-srcfolder");
  566. args.push_back(p_app_path_name);
  567. String str;
  568. Error err = OS::get_singleton()->execute("hdiutil", args, &str, nullptr, true);
  569. ERR_FAIL_COND_V(err != OK, err);
  570. print_verbose("hdiutil returned: " + str);
  571. if (str.find("create failed") != -1) {
  572. if (str.find("File exists") != -1) {
  573. EditorNode::add_io_error("hdiutil: " + TTR("DMG creation failed, file already exists."));
  574. } else {
  575. EditorNode::add_io_error("hdiutil: " + TTR("DMG create failed."));
  576. }
  577. return FAILED;
  578. }
  579. return OK;
  580. }
  581. Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  582. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  583. String src_pkg_name;
  584. EditorProgress ep("export", "Exporting for OSX", 3, true);
  585. if (p_debug) {
  586. src_pkg_name = p_preset->get("custom_template/debug");
  587. } else {
  588. src_pkg_name = p_preset->get("custom_template/release");
  589. }
  590. if (src_pkg_name.is_empty()) {
  591. String err;
  592. src_pkg_name = find_export_template("osx.zip", &err);
  593. if (src_pkg_name.is_empty()) {
  594. EditorNode::add_io_error(err);
  595. return ERR_FILE_NOT_FOUND;
  596. }
  597. }
  598. if (!DirAccess::exists(p_path.get_base_dir())) {
  599. return ERR_FILE_BAD_PATH;
  600. }
  601. FileAccess *src_f = nullptr;
  602. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  603. if (ep.step(TTR("Creating app bundle"), 0)) {
  604. return ERR_SKIP;
  605. }
  606. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  607. if (!src_pkg_zip) {
  608. EditorNode::add_io_error(TTR("Could not find template app to export:") + "\n" + src_pkg_name);
  609. return ERR_FILE_NOT_FOUND;
  610. }
  611. int ret = unzGoToFirstFile(src_pkg_zip);
  612. String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + ".64";
  613. String pkg_name;
  614. if (p_preset->get("application/name") != "") {
  615. pkg_name = p_preset->get("application/name"); // app_name
  616. } else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") {
  617. pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  618. } else {
  619. pkg_name = "Unnamed";
  620. }
  621. pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
  622. String export_format;
  623. if (use_dmg() && p_path.ends_with("dmg")) {
  624. export_format = "dmg";
  625. } else if (p_path.ends_with("zip")) {
  626. export_format = "zip";
  627. } else if (p_path.ends_with("app")) {
  628. export_format = "app";
  629. } else {
  630. EditorNode::add_io_error("Invalid export format");
  631. return ERR_CANT_CREATE;
  632. }
  633. // Create our application bundle.
  634. String tmp_app_dir_name = pkg_name + ".app";
  635. String tmp_app_path_name;
  636. if (export_format == "app") {
  637. tmp_app_path_name = p_path;
  638. } else {
  639. tmp_app_path_name = EditorPaths::get_singleton()->get_cache_dir().plus_file(tmp_app_dir_name);
  640. }
  641. print_verbose("Exporting to " + tmp_app_path_name);
  642. Error err = OK;
  643. DirAccessRef tmp_app_dir = DirAccess::create_for_path(tmp_app_path_name);
  644. if (!tmp_app_dir) {
  645. err = ERR_CANT_CREATE;
  646. }
  647. if (DirAccess::exists(tmp_app_dir_name)) {
  648. if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {
  649. tmp_app_dir->erase_contents_recursive();
  650. }
  651. }
  652. Array helpers = p_preset->get("codesign/entitlements/app_sandbox/helper_executables");
  653. // Create our folder structure.
  654. if (err == OK) {
  655. print_verbose("Creating " + tmp_app_path_name + "/Contents/MacOS");
  656. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
  657. }
  658. if (err == OK) {
  659. print_verbose("Creating " + tmp_app_path_name + "/Contents/Frameworks");
  660. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");
  661. }
  662. if ((err == OK) && helpers.size() > 0) {
  663. print_line("Creating " + tmp_app_path_name + "/Contents/Helpers");
  664. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Helpers");
  665. }
  666. if (err == OK) {
  667. print_verbose("Creating " + tmp_app_path_name + "/Contents/Resources");
  668. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
  669. }
  670. Vector<String> translations = ProjectSettings::get_singleton()->get("internationalization/locale/translations");
  671. if (translations.size() > 0) {
  672. {
  673. String fname = tmp_app_path_name + "/Contents/Resources/en.lproj";
  674. tmp_app_dir->make_dir_recursive(fname);
  675. FileAccessRef f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  676. }
  677. for (const String &E : translations) {
  678. Ref<Translation> tr = ResourceLoader::load(E);
  679. if (tr.is_valid()) {
  680. String fname = tmp_app_path_name + "/Contents/Resources/" + tr->get_locale() + ".lproj";
  681. tmp_app_dir->make_dir_recursive(fname);
  682. FileAccessRef f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  683. }
  684. }
  685. }
  686. // Now process our template.
  687. bool found_binary = false;
  688. Vector<String> dylibs_found;
  689. while (ret == UNZ_OK && err == OK) {
  690. bool is_execute = false;
  691. // Get filename.
  692. unz_file_info info;
  693. char fname[16384];
  694. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  695. String file = String::utf8(fname);
  696. Vector<uint8_t> data;
  697. data.resize(info.uncompressed_size);
  698. // Read.
  699. unzOpenCurrentFile(src_pkg_zip);
  700. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  701. unzCloseCurrentFile(src_pkg_zip);
  702. // Write.
  703. file = file.replace_first("osx_template.app/", "");
  704. if (((info.external_fa >> 16L) & 0120000) == 0120000) {
  705. #ifndef UNIX_ENABLED
  706. WARN_PRINT(vformat("Relative symlinks are not supported on this OS, exported project might be broken!"));
  707. #endif
  708. // Handle symlinks in the archive.
  709. file = tmp_app_path_name.plus_file(file);
  710. if (err == OK) {
  711. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  712. }
  713. if (err == OK) {
  714. String lnk_data = String::utf8((const char *)data.ptr(), data.size());
  715. err = tmp_app_dir->create_link(lnk_data, file);
  716. print_verbose(vformat("ADDING SYMLINK %s => %s\n", file, lnk_data));
  717. }
  718. ret = unzGoToNextFile(src_pkg_zip);
  719. continue; // next
  720. }
  721. if (file == "Contents/Info.plist") {
  722. _fix_plist(p_preset, data, pkg_name);
  723. }
  724. if (file.begins_with("Contents/MacOS/godot_")) {
  725. if (file != "Contents/MacOS/" + binary_to_use) {
  726. ret = unzGoToNextFile(src_pkg_zip);
  727. continue; // skip
  728. }
  729. found_binary = true;
  730. is_execute = true;
  731. file = "Contents/MacOS/" + pkg_name;
  732. }
  733. if (file == "Contents/Resources/icon.icns") {
  734. // See if there is an icon.
  735. String iconpath;
  736. if (p_preset->get("application/icon") != "") {
  737. iconpath = p_preset->get("application/icon");
  738. } else {
  739. iconpath = ProjectSettings::get_singleton()->get("application/config/icon");
  740. }
  741. if (!iconpath.is_empty()) {
  742. if (iconpath.get_extension() == "icns") {
  743. FileAccess *icon = FileAccess::open(iconpath, FileAccess::READ);
  744. if (icon) {
  745. data.resize(icon->get_length());
  746. icon->get_buffer(&data.write[0], icon->get_length());
  747. icon->close();
  748. memdelete(icon);
  749. }
  750. } else {
  751. Ref<Image> icon;
  752. icon.instantiate();
  753. icon->load(iconpath);
  754. if (!icon->is_empty()) {
  755. _make_icon(icon, data);
  756. }
  757. }
  758. }
  759. }
  760. if (data.size() > 0) {
  761. if (file.find("/data.mono.osx.64.release_debug/") != -1) {
  762. if (!p_debug) {
  763. ret = unzGoToNextFile(src_pkg_zip);
  764. continue; // skip
  765. }
  766. file = file.replace("/data.mono.osx.64.release_debug/", "/GodotSharp/");
  767. }
  768. if (file.find("/data.mono.osx.64.release/") != -1) {
  769. if (p_debug) {
  770. ret = unzGoToNextFile(src_pkg_zip);
  771. continue; // skip
  772. }
  773. file = file.replace("/data.mono.osx.64.release/", "/GodotSharp/");
  774. }
  775. if (file.ends_with(".dylib")) {
  776. dylibs_found.push_back(file);
  777. }
  778. print_verbose("ADDING: " + file + " size: " + itos(data.size()));
  779. // Write it into our application bundle.
  780. file = tmp_app_path_name.plus_file(file);
  781. if (err == OK) {
  782. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  783. }
  784. if (err == OK) {
  785. FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
  786. if (f) {
  787. f->store_buffer(data.ptr(), data.size());
  788. f->close();
  789. if (is_execute) {
  790. // chmod with 0755 if the file is executable.
  791. FileAccess::set_unix_permissions(file, 0755);
  792. }
  793. memdelete(f);
  794. } else {
  795. err = ERR_CANT_CREATE;
  796. }
  797. }
  798. }
  799. ret = unzGoToNextFile(src_pkg_zip);
  800. }
  801. // We're done with our source zip.
  802. unzClose(src_pkg_zip);
  803. if (!found_binary) {
  804. ERR_PRINT(vformat("Requested template binary '%s' not found. It might be missing from your template archive.", binary_to_use));
  805. err = ERR_FILE_NOT_FOUND;
  806. }
  807. if (err == OK) {
  808. if (ep.step(TTR("Making PKG"), 1)) {
  809. return ERR_SKIP;
  810. }
  811. String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
  812. Vector<SharedObject> shared_objects;
  813. err = save_pack(p_preset, pack_path, &shared_objects);
  814. // See if we can code sign our new package.
  815. bool sign_enabled = p_preset->get("codesign/enable");
  816. String ent_path = p_preset->get("codesign/entitlements/custom_file");
  817. String hlp_ent_path = EditorPaths::get_singleton()->get_cache_dir().plus_file(pkg_name + "_helper.entitlements");
  818. if (sign_enabled && (ent_path.is_empty())) {
  819. ent_path = EditorPaths::get_singleton()->get_cache_dir().plus_file(pkg_name + ".entitlements");
  820. FileAccess *ent_f = FileAccess::open(ent_path, FileAccess::WRITE);
  821. if (ent_f) {
  822. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  823. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  824. ent_f->store_line("<plist version=\"1.0\">");
  825. ent_f->store_line("<dict>");
  826. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  827. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  828. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  829. ent_f->store_line("<true/>");
  830. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  831. ent_f->store_line("<true/>");
  832. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  833. ent_f->store_line("<true/>");
  834. } else {
  835. if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) {
  836. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  837. ent_f->store_line("<true/>");
  838. }
  839. if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) {
  840. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  841. ent_f->store_line("<true/>");
  842. }
  843. if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) {
  844. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  845. ent_f->store_line("<true/>");
  846. }
  847. }
  848. if ((bool)p_preset->get("codesign/entitlements/disable_library_validation")) {
  849. ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>");
  850. ent_f->store_line("<true/>");
  851. }
  852. if ((bool)p_preset->get("codesign/entitlements/audio_input")) {
  853. ent_f->store_line("<key>com.apple.security.device.audio-input</key>");
  854. ent_f->store_line("<true/>");
  855. }
  856. if ((bool)p_preset->get("codesign/entitlements/camera")) {
  857. ent_f->store_line("<key>com.apple.security.device.camera</key>");
  858. ent_f->store_line("<true/>");
  859. }
  860. if ((bool)p_preset->get("codesign/entitlements/location")) {
  861. ent_f->store_line("<key>com.apple.security.personal-information.location</key>");
  862. ent_f->store_line("<true/>");
  863. }
  864. if ((bool)p_preset->get("codesign/entitlements/address_book")) {
  865. ent_f->store_line("<key>com.apple.security.personal-information.addressbook</key>");
  866. ent_f->store_line("<true/>");
  867. }
  868. if ((bool)p_preset->get("codesign/entitlements/calendars")) {
  869. ent_f->store_line("<key>com.apple.security.personal-information.calendars</key>");
  870. ent_f->store_line("<true/>");
  871. }
  872. if ((bool)p_preset->get("codesign/entitlements/photos_library")) {
  873. ent_f->store_line("<key>com.apple.security.personal-information.photos-library</key>");
  874. ent_f->store_line("<true/>");
  875. }
  876. if ((bool)p_preset->get("codesign/entitlements/apple_events")) {
  877. ent_f->store_line("<key>com.apple.security.automation.apple-events</key>");
  878. ent_f->store_line("<true/>");
  879. }
  880. if ((bool)p_preset->get("codesign/entitlements/debugging")) {
  881. ent_f->store_line("<key>com.apple.security.get-task-allow</key>");
  882. ent_f->store_line("<true/>");
  883. }
  884. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) {
  885. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  886. ent_f->store_line("<true/>");
  887. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) {
  888. ent_f->store_line("<key>com.apple.security.network.server</key>");
  889. ent_f->store_line("<true/>");
  890. }
  891. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) {
  892. ent_f->store_line("<key>com.apple.security.network.client</key>");
  893. ent_f->store_line("<true/>");
  894. }
  895. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) {
  896. ent_f->store_line("<key>com.apple.security.device.usb</key>");
  897. ent_f->store_line("<true/>");
  898. }
  899. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) {
  900. ent_f->store_line("<key>com.apple.security.device.bluetooth</key>");
  901. ent_f->store_line("<true/>");
  902. }
  903. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) {
  904. ent_f->store_line("<key>com.apple.security.files.downloads.read-only</key>");
  905. ent_f->store_line("<true/>");
  906. }
  907. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) {
  908. ent_f->store_line("<key>com.apple.security.files.downloads.read-write</key>");
  909. ent_f->store_line("<true/>");
  910. }
  911. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) {
  912. ent_f->store_line("<key>com.apple.security.files.pictures.read-only</key>");
  913. ent_f->store_line("<true/>");
  914. }
  915. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) {
  916. ent_f->store_line("<key>com.apple.security.files.pictures.read-write</key>");
  917. ent_f->store_line("<true/>");
  918. }
  919. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) {
  920. ent_f->store_line("<key>com.apple.security.files.music.read-only</key>");
  921. ent_f->store_line("<true/>");
  922. }
  923. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) {
  924. ent_f->store_line("<key>com.apple.security.files.music.read-write</key>");
  925. ent_f->store_line("<true/>");
  926. }
  927. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) {
  928. ent_f->store_line("<key>com.apple.security.files.movies.read-only</key>");
  929. ent_f->store_line("<true/>");
  930. }
  931. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) {
  932. ent_f->store_line("<key>com.apple.security.files.movies.read-write</key>");
  933. ent_f->store_line("<true/>");
  934. }
  935. }
  936. ent_f->store_line("</dict>");
  937. ent_f->store_line("</plist>");
  938. ent_f->close();
  939. memdelete(ent_f);
  940. } else {
  941. err = ERR_CANT_CREATE;
  942. }
  943. if ((err == OK) && helpers.size() > 0) {
  944. ent_f = FileAccess::open(hlp_ent_path, FileAccess::WRITE);
  945. if (ent_f) {
  946. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  947. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  948. ent_f->store_line("<plist version=\"1.0\">");
  949. ent_f->store_line("<dict>");
  950. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  951. ent_f->store_line("<true/>");
  952. ent_f->store_line("<key>com.apple.security.inherit</key>");
  953. ent_f->store_line("<true/>");
  954. ent_f->store_line("</dict>");
  955. ent_f->store_line("</plist>");
  956. ent_f->close();
  957. memdelete(ent_f);
  958. } else {
  959. err = ERR_CANT_CREATE;
  960. }
  961. }
  962. }
  963. if ((err == OK) && helpers.size() > 0) {
  964. DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  965. for (int i = 0; i < helpers.size(); i++) {
  966. String hlp_path = helpers[i];
  967. err = da->copy(hlp_path, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file());
  968. if (err == OK && sign_enabled) {
  969. err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), hlp_ent_path);
  970. }
  971. FileAccess::set_unix_permissions(tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), 0755);
  972. }
  973. }
  974. bool ad_hoc = true;
  975. if (err == OK) {
  976. #ifdef OSX_ENABLED
  977. String sign_identity = p_preset->get("codesign/identity");
  978. #else
  979. String sign_identity = "-";
  980. #endif
  981. ad_hoc = (sign_identity == "" || sign_identity == "-");
  982. bool lib_validation = p_preset->get("codesign/entitlements/disable_library_validation");
  983. if ((!dylibs_found.is_empty() || !shared_objects.is_empty()) && sign_enabled && ad_hoc && !lib_validation) {
  984. ERR_PRINT("Application with an ad-hoc signature require 'Disable Library Validation' entitlement to load dynamic libraries.");
  985. err = ERR_CANT_CREATE;
  986. }
  987. }
  988. if (err == OK) {
  989. DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  990. for (int i = 0; i < shared_objects.size(); i++) {
  991. String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path);
  992. String path_in_app{ tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file() };
  993. err = _copy_and_sign_files(da, src_path, path_in_app, sign_enabled, p_preset, ent_path, true);
  994. if (err != OK) {
  995. break;
  996. }
  997. }
  998. Vector<Ref<EditorExportPlugin>> export_plugins{ EditorExport::get_singleton()->get_export_plugins() };
  999. for (int i = 0; i < export_plugins.size(); ++i) {
  1000. err = _export_osx_plugins_for(export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path);
  1001. if (err != OK) {
  1002. break;
  1003. }
  1004. }
  1005. }
  1006. if (sign_enabled) {
  1007. for (int i = 0; i < dylibs_found.size(); i++) {
  1008. if (err == OK) {
  1009. err = _code_sign(p_preset, tmp_app_path_name + "/" + dylibs_found[i], ent_path);
  1010. }
  1011. }
  1012. }
  1013. if (err == OK && sign_enabled) {
  1014. if (ep.step(TTR("Code signing bundle"), 2)) {
  1015. return ERR_SKIP;
  1016. }
  1017. err = _code_sign(p_preset, tmp_app_path_name, ent_path);
  1018. }
  1019. if (export_format == "dmg") {
  1020. // Create a DMG.
  1021. if (err == OK) {
  1022. if (ep.step(TTR("Making DMG"), 3)) {
  1023. return ERR_SKIP;
  1024. }
  1025. err = _create_dmg(p_path, pkg_name, tmp_app_path_name);
  1026. }
  1027. // Sign DMG.
  1028. if (err == OK && sign_enabled && !ad_hoc) {
  1029. if (ep.step(TTR("Code signing DMG"), 3)) {
  1030. return ERR_SKIP;
  1031. }
  1032. err = _code_sign(p_preset, p_path, ent_path);
  1033. }
  1034. } else if (export_format == "zip") {
  1035. // Create ZIP.
  1036. if (err == OK) {
  1037. if (ep.step(TTR("Making ZIP"), 3)) {
  1038. return ERR_SKIP;
  1039. }
  1040. if (FileAccess::exists(p_path)) {
  1041. OS::get_singleton()->move_to_trash(p_path);
  1042. }
  1043. FileAccess *dst_f = nullptr;
  1044. zlib_filefunc_def io_dst = zipio_create_io_from_file(&dst_f);
  1045. zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
  1046. _zip_folder_recursive(zip, EditorPaths::get_singleton()->get_cache_dir(), pkg_name + ".app", pkg_name);
  1047. zipClose(zip, nullptr);
  1048. }
  1049. }
  1050. #ifdef OSX_ENABLED
  1051. bool noto_enabled = p_preset->get("notarization/enable");
  1052. if (err == OK && noto_enabled) {
  1053. if (export_format == "app") {
  1054. WARN_PRINT("Notarization require app to be archived first, select DMG or ZIP export format instead.");
  1055. } else {
  1056. if (ep.step(TTR("Sending archive for notarization"), 4)) {
  1057. return ERR_SKIP;
  1058. }
  1059. err = _notarize(p_preset, p_path);
  1060. }
  1061. }
  1062. #endif
  1063. // Clean up temporary entitlements files.
  1064. DirAccess::remove_file_or_error(hlp_ent_path);
  1065. // Clean up temporary .app dir and generated entitlements.
  1066. if ((String)(p_preset->get("codesign/entitlements/custom_file")) == "") {
  1067. tmp_app_dir->remove(ent_path);
  1068. }
  1069. if (export_format != "app") {
  1070. if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {
  1071. tmp_app_dir->erase_contents_recursive();
  1072. tmp_app_dir->change_dir("..");
  1073. tmp_app_dir->remove(tmp_app_dir_name);
  1074. }
  1075. }
  1076. }
  1077. return err;
  1078. }
  1079. void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name) {
  1080. String dir = p_root_path.plus_file(p_folder);
  1081. DirAccessRef da = DirAccess::open(dir);
  1082. da->list_dir_begin();
  1083. String f = da->get_next();
  1084. while (!f.is_empty()) {
  1085. if (f == "." || f == "..") {
  1086. f = da->get_next();
  1087. continue;
  1088. }
  1089. if (da->is_link(f)) {
  1090. OS::Time time = OS::get_singleton()->get_time();
  1091. OS::Date date = OS::get_singleton()->get_date();
  1092. zip_fileinfo zipfi;
  1093. zipfi.tmz_date.tm_hour = time.hour;
  1094. zipfi.tmz_date.tm_mday = date.day;
  1095. zipfi.tmz_date.tm_min = time.minute;
  1096. zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, https://www.cplusplus.com/reference/ctime/tm/
  1097. zipfi.tmz_date.tm_sec = time.second;
  1098. zipfi.tmz_date.tm_year = date.year;
  1099. zipfi.dosDate = 0;
  1100. // 0120000: symbolic link type
  1101. // 0000755: permissions rwxr-xr-x
  1102. // 0000644: permissions rw-r--r--
  1103. uint32_t _mode = 0120644;
  1104. zipfi.external_fa = (_mode << 16L) | !(_mode & 0200);
  1105. zipfi.internal_fa = 0;
  1106. zipOpenNewFileInZip4(p_zip,
  1107. p_folder.plus_file(f).utf8().get_data(),
  1108. &zipfi,
  1109. nullptr,
  1110. 0,
  1111. nullptr,
  1112. 0,
  1113. nullptr,
  1114. Z_DEFLATED,
  1115. Z_DEFAULT_COMPRESSION,
  1116. 0,
  1117. -MAX_WBITS,
  1118. DEF_MEM_LEVEL,
  1119. Z_DEFAULT_STRATEGY,
  1120. nullptr,
  1121. 0,
  1122. 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions
  1123. 0);
  1124. String target = da->read_link(f);
  1125. zipWriteInFileInZip(p_zip, target.utf8().get_data(), target.utf8().size());
  1126. zipCloseFileInZip(p_zip);
  1127. } else if (da->current_is_dir()) {
  1128. _zip_folder_recursive(p_zip, p_root_path, p_folder.plus_file(f), p_pkg_name);
  1129. } else {
  1130. bool is_executable = (p_folder.ends_with("MacOS") && (f == p_pkg_name)) || p_folder.ends_with("Helpers");
  1131. OS::Time time = OS::get_singleton()->get_time();
  1132. OS::Date date = OS::get_singleton()->get_date();
  1133. zip_fileinfo zipfi;
  1134. zipfi.tmz_date.tm_hour = time.hour;
  1135. zipfi.tmz_date.tm_mday = date.day;
  1136. zipfi.tmz_date.tm_min = time.minute;
  1137. zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, https://www.cplusplus.com/reference/ctime/tm/
  1138. zipfi.tmz_date.tm_sec = time.second;
  1139. zipfi.tmz_date.tm_year = date.year;
  1140. zipfi.dosDate = 0;
  1141. // 0100000: regular file type
  1142. // 0000755: permissions rwxr-xr-x
  1143. // 0000644: permissions rw-r--r--
  1144. uint32_t _mode = (is_executable ? 0100755 : 0100644);
  1145. zipfi.external_fa = (_mode << 16L) | !(_mode & 0200);
  1146. zipfi.internal_fa = 0;
  1147. zipOpenNewFileInZip4(p_zip,
  1148. p_folder.plus_file(f).utf8().get_data(),
  1149. &zipfi,
  1150. nullptr,
  1151. 0,
  1152. nullptr,
  1153. 0,
  1154. nullptr,
  1155. Z_DEFLATED,
  1156. Z_DEFAULT_COMPRESSION,
  1157. 0,
  1158. -MAX_WBITS,
  1159. DEF_MEM_LEVEL,
  1160. Z_DEFAULT_STRATEGY,
  1161. nullptr,
  1162. 0,
  1163. 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions
  1164. 0);
  1165. FileAccessRef fa = FileAccess::open(dir.plus_file(f), FileAccess::READ);
  1166. if (!fa) {
  1167. ERR_FAIL_MSG(vformat("Can't open file to read from path \"%s\".", dir.plus_file(f)));
  1168. }
  1169. const int bufsize = 16384;
  1170. uint8_t buf[bufsize];
  1171. while (true) {
  1172. uint64_t got = fa->get_buffer(buf, bufsize);
  1173. if (got == 0) {
  1174. break;
  1175. }
  1176. zipWriteInFileInZip(p_zip, buf, got);
  1177. }
  1178. zipCloseFileInZip(p_zip);
  1179. }
  1180. f = da->get_next();
  1181. }
  1182. da->list_dir_end();
  1183. }
  1184. bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  1185. String err;
  1186. bool valid = false;
  1187. // Look for export templates (custom templates).
  1188. bool dvalid = false;
  1189. bool rvalid = false;
  1190. if (p_preset->get("custom_template/debug") != "") {
  1191. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  1192. if (!dvalid) {
  1193. err += TTR("Custom debug template not found.") + "\n";
  1194. }
  1195. }
  1196. if (p_preset->get("custom_template/release") != "") {
  1197. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  1198. if (!rvalid) {
  1199. err += TTR("Custom release template not found.") + "\n";
  1200. }
  1201. }
  1202. // Look for export templates (official templates, check only is custom templates are not set).
  1203. if (!dvalid || !rvalid) {
  1204. dvalid = exists_export_template("osx.zip", &err);
  1205. rvalid = dvalid; // Both in the same ZIP.
  1206. }
  1207. valid = dvalid || rvalid;
  1208. r_missing_templates = !valid;
  1209. String identifier = p_preset->get("application/bundle_identifier");
  1210. String pn_err;
  1211. if (!is_package_name_valid(identifier, &pn_err)) {
  1212. err += TTR("Invalid bundle identifier:") + " " + pn_err + "\n";
  1213. valid = false;
  1214. }
  1215. bool sign_enabled = p_preset->get("codesign/enable");
  1216. #ifdef OSX_ENABLED
  1217. bool noto_enabled = p_preset->get("notarization/enable");
  1218. bool ad_hoc = ((p_preset->get("codesign/identity") == "") || (p_preset->get("codesign/identity") == "-"));
  1219. if (!ad_hoc && (bool)EditorSettings::get_singleton()->get("export/macos/force_builtin_codesign")) {
  1220. err += TTR("Warning: Built-in \"codesign\" is selected in the Editor Settings. Code signing is limited to ad-hoc signature only.") + "\n";
  1221. }
  1222. if (!ad_hoc && !FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
  1223. err += TTR("Warning: Xcode command line tools are not installed, using built-in \"codesign\". Code signing is limited to ad-hoc signature only.") + "\n";
  1224. }
  1225. if (noto_enabled) {
  1226. if (ad_hoc) {
  1227. err += TTR("Notarization: Notarization with the ad-hoc signature is not supported.") + "\n";
  1228. valid = false;
  1229. }
  1230. if (!sign_enabled) {
  1231. err += TTR("Notarization: Code signing is required for notarization.") + "\n";
  1232. valid = false;
  1233. }
  1234. if (!(bool)p_preset->get("codesign/hardened_runtime")) {
  1235. err += TTR("Notarization: Hardened runtime is required for notarization.") + "\n";
  1236. valid = false;
  1237. }
  1238. if (!(bool)p_preset->get("codesign/timestamp")) {
  1239. err += TTR("Notarization: Timestamping is required for notarization.") + "\n";
  1240. valid = false;
  1241. }
  1242. if (p_preset->get("notarization/apple_id_name") == "") {
  1243. err += TTR("Notarization: Apple ID name not specified.") + "\n";
  1244. valid = false;
  1245. }
  1246. if (p_preset->get("notarization/apple_id_password") == "") {
  1247. err += TTR("Notarization: Apple ID password not specified.") + "\n";
  1248. valid = false;
  1249. }
  1250. } else {
  1251. err += TTR("Warning: Notarization is disabled. Exported project will be blocked by Gatekeeper, if it's downloaded from an unknown source.") + "\n";
  1252. if (!sign_enabled) {
  1253. err += TTR("Code signing is disabled. Exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n";
  1254. } else {
  1255. if ((bool)p_preset->get("codesign/hardened_runtime") && ad_hoc) {
  1256. err += TTR("Hardened Runtime is not compatible with ad-hoc signature, and will be disabled!") + "\n";
  1257. }
  1258. if ((bool)p_preset->get("codesign/timestamp") && ad_hoc) {
  1259. err += TTR("Timestamping is not compatible with ad-hoc signature, and will be disabled!") + "\n";
  1260. }
  1261. }
  1262. }
  1263. #else
  1264. err += TTR("Warning: Notarization is not supported on this OS. Exported project will be blocked by Gatekeeper, if it's downloaded from an unknown source.") + "\n";
  1265. if (!sign_enabled) {
  1266. err += TTR("Code signing is disabled. Exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n";
  1267. }
  1268. #endif
  1269. if (sign_enabled) {
  1270. if ((bool)p_preset->get("codesign/entitlements/audio_input") && ((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
  1271. err += TTR("Privacy: Microphone access is enabled, but usage description is not specified.") + "\n";
  1272. valid = false;
  1273. }
  1274. if ((bool)p_preset->get("codesign/entitlements/camera") && ((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
  1275. err += TTR("Privacy: Camera access is enabled, but usage description is not specified.") + "\n";
  1276. valid = false;
  1277. }
  1278. if ((bool)p_preset->get("codesign/entitlements/location") && ((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
  1279. err += TTR("Privacy: Location information access is enabled, but usage description is not specified.") + "\n";
  1280. valid = false;
  1281. }
  1282. if ((bool)p_preset->get("codesign/entitlements/address_book") && ((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
  1283. err += TTR("Privacy: Address book access is enabled, but usage description is not specified.") + "\n";
  1284. valid = false;
  1285. }
  1286. if ((bool)p_preset->get("codesign/entitlements/calendars") && ((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
  1287. err += TTR("Privacy: Calendar access is enabled, but usage description is not specified.") + "\n";
  1288. valid = false;
  1289. }
  1290. if ((bool)p_preset->get("codesign/entitlements/photos_library") && ((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
  1291. err += TTR("Privacy: Photo library access is enabled, but usage description is not specified.") + "\n";
  1292. valid = false;
  1293. }
  1294. }
  1295. if (!err.is_empty()) {
  1296. r_error = err;
  1297. }
  1298. return valid;
  1299. }
  1300. EditorExportPlatformOSX::EditorExportPlatformOSX() {
  1301. Ref<Image> img = memnew(Image(_osx_logo));
  1302. logo.instantiate();
  1303. logo->create_from_image(img);
  1304. }
  1305. EditorExportPlatformOSX::~EditorExportPlatformOSX() {
  1306. }