2
0

export_plugin.cpp 60 KB

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