export_plugin.cpp 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  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 "lipo.h"
  33. #include "macho.h"
  34. #include "core/string/translation.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_paths.h"
  37. #include "modules/modules_enabled.gen.h" // For regex.
  38. void EditorExportPlatformMacOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
  39. if (p_preset->get("texture_format/s3tc")) {
  40. r_features->push_back("s3tc");
  41. }
  42. if (p_preset->get("texture_format/etc")) {
  43. r_features->push_back("etc");
  44. }
  45. if (p_preset->get("texture_format/etc2")) {
  46. r_features->push_back("etc2");
  47. }
  48. r_features->push_back(p_preset->get("binary_format/architecture"));
  49. }
  50. bool EditorExportPlatformMacOS::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
  51. // Hide irrelevant code signing options.
  52. if (p_preset) {
  53. int codesign_tool = p_preset->get("codesign/codesign");
  54. switch (codesign_tool) {
  55. case 1: { // built-in ad-hoc
  56. if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options") {
  57. return false;
  58. }
  59. } break;
  60. case 2: { // "rcodesign"
  61. if (p_option == "codesign/identity") {
  62. return false;
  63. }
  64. } break;
  65. #ifdef MACOS_ENABLED
  66. case 3: { // "codesign"
  67. if (p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password") {
  68. return false;
  69. }
  70. } break;
  71. #endif
  72. default: { // disabled
  73. if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options" || p_option.begins_with("codesign/entitlements")) {
  74. return false;
  75. }
  76. } break;
  77. }
  78. // Hide irrelevant notarization options.
  79. int notary_tool = p_preset->get("notarization/notarization");
  80. switch (notary_tool) {
  81. case 1: { // "rcodesign"
  82. if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/apple_team_id") {
  83. return false;
  84. }
  85. } break;
  86. case 2: { // "altool"
  87. // All options are visible.
  88. } break;
  89. default: { // disabled
  90. if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/apple_team_id" || p_option == "notarization/api_uuid" || p_option == "notarization/api_key") {
  91. return false;
  92. }
  93. } break;
  94. }
  95. }
  96. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  97. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  98. 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") {
  99. return false;
  100. }
  101. }
  102. return true;
  103. }
  104. void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options) {
  105. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "binary_format/architecture", PROPERTY_HINT_ENUM, "universal,x86_64,arm64", PROPERTY_USAGE_STORAGE), "universal"));
  106. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  107. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  108. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "debug/export_console_script", PROPERTY_HINT_ENUM, "No,Debug Only,Debug and Release"), 1));
  109. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.png,*.icns"), ""));
  110. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), ""));
  111. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  112. 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"));
  113. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  114. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  115. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  116. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "application/copyright_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  117. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false));
  118. #ifdef MACOS_ENABLED
  119. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),PyOxidizer rcodesign,Xcode codesign"), 3, true));
  120. #else
  121. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),PyOxidizer rcodesign"), 1, true));
  122. #endif
  123. // "codesign" only options:
  124. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), ""));
  125. // "rcodesign" only options:
  126. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_file", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12"), ""));
  127. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_password", PROPERTY_HINT_PASSWORD), ""));
  128. // "codesign" and "rcodesign" only options:
  129. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), ""));
  130. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false));
  131. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false));
  132. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false));
  133. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false));
  134. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false));
  135. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false));
  136. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/location"), false));
  137. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/address_book"), false));
  138. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/calendars"), false));
  139. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/photos_library"), false));
  140. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/apple_events"), false));
  141. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/debugging"), false));
  142. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/enabled"), false));
  143. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_server"), false));
  144. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_client"), false));
  145. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_usb"), false));
  146. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_bluetooth"), false));
  147. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_downloads", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  148. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_pictures", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  149. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_music", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  150. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_movies", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  151. 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()));
  152. r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
  153. #ifdef MACOS_ENABLED
  154. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,PyOxidizer rcodesign,Xcode altool"), 0, true));
  155. #else
  156. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,PyOxidizer rcodesign"), 0, true));
  157. #endif
  158. // "altool" only options:
  159. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple ID email"), ""));
  160. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_password", PROPERTY_HINT_PASSWORD, "Enable two-factor authentication and provide app-specific password"), ""));
  161. 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"), ""));
  162. // "altool" and "rcodesign" only options:
  163. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_uuid", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect issuer ID"), ""));
  164. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect API key ID"), ""));
  165. 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"), ""));
  166. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  167. 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"), ""));
  168. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  169. 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"), ""));
  170. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/location_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  171. 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"), ""));
  172. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/address_book_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  173. 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"), ""));
  174. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/calendar_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  175. 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"), ""));
  176. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photos_library_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  177. 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"), ""));
  178. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/desktop_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  179. 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"), ""));
  180. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/documents_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  181. 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"), ""));
  182. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/downloads_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  183. 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"), ""));
  184. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/network_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  185. 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"), ""));
  186. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/removable_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  187. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
  188. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
  189. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
  190. }
  191. void _rgba8_to_packbits_encode(int p_ch, int p_size, Vector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {
  192. int src_len = p_size * p_size;
  193. Vector<uint8_t> result;
  194. result.resize(src_len * 1.25); //temp vector for rle encoded data, make it 25% larger for worst case scenario
  195. int res_size = 0;
  196. uint8_t buf[128];
  197. int buf_size = 0;
  198. int i = 0;
  199. while (i < src_len) {
  200. uint8_t cur = p_source.ptr()[i * 4 + p_ch];
  201. if (i < src_len - 2) {
  202. if ((p_source.ptr()[(i + 1) * 4 + p_ch] == cur) && (p_source.ptr()[(i + 2) * 4 + p_ch] == cur)) {
  203. if (buf_size > 0) {
  204. result.write[res_size++] = (uint8_t)(buf_size - 1);
  205. memcpy(&result.write[res_size], &buf, buf_size);
  206. res_size += buf_size;
  207. buf_size = 0;
  208. }
  209. uint8_t lim = i + 130 >= src_len ? src_len - i - 1 : 130;
  210. bool hit_lim = true;
  211. for (int j = 3; j <= lim; j++) {
  212. if (p_source.ptr()[(i + j) * 4 + p_ch] != cur) {
  213. hit_lim = false;
  214. i = i + j - 1;
  215. result.write[res_size++] = (uint8_t)(j - 3 + 0x80);
  216. result.write[res_size++] = cur;
  217. break;
  218. }
  219. }
  220. if (hit_lim) {
  221. result.write[res_size++] = (uint8_t)(lim - 3 + 0x80);
  222. result.write[res_size++] = cur;
  223. i = i + lim;
  224. }
  225. } else {
  226. buf[buf_size++] = cur;
  227. if (buf_size == 128) {
  228. result.write[res_size++] = (uint8_t)(buf_size - 1);
  229. memcpy(&result.write[res_size], &buf, buf_size);
  230. res_size += buf_size;
  231. buf_size = 0;
  232. }
  233. }
  234. } else {
  235. buf[buf_size++] = cur;
  236. result.write[res_size++] = (uint8_t)(buf_size - 1);
  237. memcpy(&result.write[res_size], &buf, buf_size);
  238. res_size += buf_size;
  239. buf_size = 0;
  240. }
  241. i++;
  242. }
  243. int ofs = p_dest.size();
  244. p_dest.resize(p_dest.size() + res_size);
  245. memcpy(&p_dest.write[ofs], result.ptr(), res_size);
  246. }
  247. void EditorExportPlatformMacOS::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
  248. Ref<ImageTexture> it = memnew(ImageTexture);
  249. Vector<uint8_t> data;
  250. data.resize(8);
  251. data.write[0] = 'i';
  252. data.write[1] = 'c';
  253. data.write[2] = 'n';
  254. data.write[3] = 's';
  255. struct MacOSIconInfo {
  256. const char *name;
  257. const char *mask_name;
  258. bool is_png;
  259. int size;
  260. };
  261. static const MacOSIconInfo icon_infos[] = {
  262. { "ic10", "", true, 1024 }, //1024×1024 32-bit PNG and 512×512@2x 32-bit "retina" PNG
  263. { "ic09", "", true, 512 }, //512×512 32-bit PNG
  264. { "ic14", "", true, 512 }, //256×256@2x 32-bit "retina" PNG
  265. { "ic08", "", true, 256 }, //256×256 32-bit PNG
  266. { "ic13", "", true, 256 }, //128×128@2x 32-bit "retina" PNG
  267. { "ic07", "", true, 128 }, //128×128 32-bit PNG
  268. { "ic12", "", true, 64 }, //32×32@2× 32-bit "retina" PNG
  269. { "ic11", "", true, 32 }, //16×16@2× 32-bit "retina" PNG
  270. { "il32", "l8mk", false, 32 }, //32×32 24-bit RLE + 8-bit uncompressed mask
  271. { "is32", "s8mk", false, 16 } //16×16 24-bit RLE + 8-bit uncompressed mask
  272. };
  273. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  274. 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?
  275. copy->convert(Image::FORMAT_RGBA8);
  276. copy->resize(icon_infos[i].size, icon_infos[i].size);
  277. if (icon_infos[i].is_png) {
  278. // Encode PNG icon.
  279. it->set_image(copy);
  280. String path = EditorPaths::get_singleton()->get_cache_dir().path_join("icon.png");
  281. ResourceSaver::save(it, path);
  282. {
  283. Ref<FileAccess> f = FileAccess::open(path, FileAccess::READ);
  284. if (f.is_null()) {
  285. // Clean up generated file.
  286. DirAccess::remove_file_or_error(path);
  287. add_message(EXPORT_MESSAGE_ERROR, TTR("Icon Creation"), vformat(TTR("Could not open icon file \"%s\"."), path));
  288. return;
  289. }
  290. int ofs = data.size();
  291. uint64_t len = f->get_length();
  292. data.resize(data.size() + len + 8);
  293. f->get_buffer(&data.write[ofs + 8], len);
  294. len += 8;
  295. len = BSWAP32(len);
  296. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  297. encode_uint32(len, &data.write[ofs + 4]);
  298. }
  299. // Clean up generated file.
  300. DirAccess::remove_file_or_error(path);
  301. } else {
  302. Vector<uint8_t> src_data = copy->get_data();
  303. //encode 24bit RGB RLE icon
  304. {
  305. int ofs = data.size();
  306. data.resize(data.size() + 8);
  307. _rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // encode R
  308. _rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // encode G
  309. _rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // encode B
  310. int len = data.size() - ofs;
  311. len = BSWAP32(len);
  312. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  313. encode_uint32(len, &data.write[ofs + 4]);
  314. }
  315. //encode 8bit mask uncompressed icon
  316. {
  317. int ofs = data.size();
  318. int len = copy->get_width() * copy->get_height();
  319. data.resize(data.size() + len + 8);
  320. for (int j = 0; j < len; j++) {
  321. data.write[ofs + 8 + j] = src_data.ptr()[j * 4 + 3];
  322. }
  323. len += 8;
  324. len = BSWAP32(len);
  325. memcpy(&data.write[ofs], icon_infos[i].mask_name, 4);
  326. encode_uint32(len, &data.write[ofs + 4]);
  327. }
  328. }
  329. }
  330. uint32_t total_len = data.size();
  331. total_len = BSWAP32(total_len);
  332. encode_uint32(total_len, &data.write[4]);
  333. p_data = data;
  334. }
  335. void EditorExportPlatformMacOS::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) {
  336. String str;
  337. String strnew;
  338. str.parse_utf8((const char *)plist.ptr(), plist.size());
  339. Vector<String> lines = str.split("\n");
  340. for (int i = 0; i < lines.size(); i++) {
  341. if (lines[i].find("$binary") != -1) {
  342. strnew += lines[i].replace("$binary", p_binary) + "\n";
  343. } else if (lines[i].find("$name") != -1) {
  344. strnew += lines[i].replace("$name", GLOBAL_GET("application/config/name")) + "\n";
  345. } else if (lines[i].find("$bundle_identifier") != -1) {
  346. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  347. } else if (lines[i].find("$short_version") != -1) {
  348. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  349. } else if (lines[i].find("$version") != -1) {
  350. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  351. } else if (lines[i].find("$signature") != -1) {
  352. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  353. } else if (lines[i].find("$app_category") != -1) {
  354. String cat = p_preset->get("application/app_category");
  355. strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n";
  356. } else if (lines[i].find("$copyright") != -1) {
  357. strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
  358. } else if (lines[i].find("$highres") != -1) {
  359. strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "\t<true/>" : "\t<false/>") + "\n";
  360. } else if (lines[i].find("$usage_descriptions") != -1) {
  361. String descriptions;
  362. if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
  363. descriptions += "\t<key>NSMicrophoneUsageDescription</key>\n";
  364. descriptions += "\t<string>" + (String)p_preset->get("privacy/microphone_usage_description") + "</string>\n";
  365. }
  366. if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
  367. descriptions += "\t<key>NSCameraUsageDescription</key>\n";
  368. descriptions += "\t<string>" + (String)p_preset->get("privacy/camera_usage_description") + "</string>\n";
  369. }
  370. if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
  371. descriptions += "\t<key>NSLocationUsageDescription</key>\n";
  372. descriptions += "\t<string>" + (String)p_preset->get("privacy/location_usage_description") + "</string>\n";
  373. }
  374. if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
  375. descriptions += "\t<key>NSContactsUsageDescription</key>\n";
  376. descriptions += "\t<string>" + (String)p_preset->get("privacy/address_book_usage_description") + "</string>\n";
  377. }
  378. if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
  379. descriptions += "\t<key>NSCalendarsUsageDescription</key>\n";
  380. descriptions += "\t<string>" + (String)p_preset->get("privacy/calendar_usage_description") + "</string>\n";
  381. }
  382. if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
  383. descriptions += "\t<key>NSPhotoLibraryUsageDescription</key>\n";
  384. descriptions += "\t<string>" + (String)p_preset->get("privacy/photos_library_usage_description") + "</string>\n";
  385. }
  386. if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {
  387. descriptions += "\t<key>NSDesktopFolderUsageDescription</key>\n";
  388. descriptions += "\t<string>" + (String)p_preset->get("privacy/desktop_folder_usage_description") + "</string>\n";
  389. }
  390. if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {
  391. descriptions += "\t<key>NSDocumentsFolderUsageDescription</key>\n";
  392. descriptions += "\t<string>" + (String)p_preset->get("privacy/documents_folder_usage_description") + "</string>\n";
  393. }
  394. if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {
  395. descriptions += "\t<key>NSDownloadsFolderUsageDescription</key>\n";
  396. descriptions += "\t<string>" + (String)p_preset->get("privacy/downloads_folder_usage_description") + "</string>\n";
  397. }
  398. if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {
  399. descriptions += "\t<key>NSNetworkVolumesUsageDescription</key>\n";
  400. descriptions += "\t<string>" + (String)p_preset->get("privacy/network_volumes_usage_description") + "</string>\n";
  401. }
  402. if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {
  403. descriptions += "\t<key>NSRemovableVolumesUsageDescription</key>\n";
  404. descriptions += "\t<string>" + (String)p_preset->get("privacy/removable_volumes_usage_description") + "</string>\n";
  405. }
  406. if (!descriptions.is_empty()) {
  407. strnew += lines[i].replace("$usage_descriptions", descriptions);
  408. }
  409. } else {
  410. strnew += lines[i] + "\n";
  411. }
  412. }
  413. CharString cs = strnew.utf8();
  414. plist.resize(cs.size() - 1);
  415. for (int i = 0; i < cs.size() - 1; i++) {
  416. plist.write[i] = cs[i];
  417. }
  418. }
  419. /**
  420. * If we're running the macOS version of the Godot editor we'll:
  421. * - export our application bundle to a temporary folder
  422. * - attempt to code sign it
  423. * - and then wrap it up in a DMG
  424. */
  425. Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  426. int notary_tool = p_preset->get("notarization/notarization");
  427. switch (notary_tool) {
  428. case 1: { // "rcodesign"
  429. print_verbose("using rcodesign notarization...");
  430. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  431. if (rcodesign.is_empty()) {
  432. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));
  433. return Error::FAILED;
  434. }
  435. List<String> args;
  436. args.push_back("notary-submit");
  437. if (p_preset->get("notarization/api_uuid") == "") {
  438. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect issuer ID name not specified."));
  439. return Error::FAILED;
  440. }
  441. if (p_preset->get("notarization/api_key") == "") {
  442. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));
  443. return Error::FAILED;
  444. }
  445. args.push_back("--api-issuer");
  446. args.push_back(p_preset->get("notarization/api_uuid"));
  447. args.push_back("--api-key");
  448. args.push_back(p_preset->get("notarization/api_key"));
  449. args.push_back(p_path);
  450. String str;
  451. int exitcode = 0;
  452. Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);
  453. if (err != OK) {
  454. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start rcodesign executable."));
  455. return err;
  456. }
  457. int rq_offset = str.find("created submission ID:");
  458. if (exitcode != 0 || rq_offset == -1) {
  459. print_line("rcodesign (" + p_path + "):\n" + str);
  460. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));
  461. return Error::FAILED;
  462. } else {
  463. print_verbose("rcodesign (" + p_path + "):\n" + str);
  464. int next_nl = str.find("\n", rq_offset);
  465. String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 14, -1) : str.substr(rq_offset + 14, next_nl - rq_offset - 14);
  466. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));
  467. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour."));
  468. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:"));
  469. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign notary-log --api-issuer <api uuid> --api-key <api key> <request uuid>\"");
  470. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));
  471. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign staple <app path>\"");
  472. }
  473. } break;
  474. #ifdef MACOS_ENABLED
  475. case 2: { // "altool"
  476. print_verbose("using altool notarization...");
  477. if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {
  478. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed."));
  479. return Error::FAILED;
  480. }
  481. List<String> args;
  482. args.push_back("altool");
  483. args.push_back("--notarize-app");
  484. args.push_back("--primary-bundle-id");
  485. args.push_back(p_preset->get("application/bundle_identifier"));
  486. if (p_preset->get("notarization/apple_id_name") == "" && p_preset->get("notarization/api_uuid") == "") {
  487. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified."));
  488. return Error::FAILED;
  489. }
  490. if (p_preset->get("notarization/apple_id_name") != "" && p_preset->get("notarization/api_uuid") != "") {
  491. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time."));
  492. return Error::FAILED;
  493. }
  494. if (p_preset->get("notarization/apple_id_name") != "") {
  495. if (p_preset->get("notarization/apple_id_password") == "") {
  496. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified."));
  497. return Error::FAILED;
  498. }
  499. args.push_back("--username");
  500. args.push_back(p_preset->get("notarization/apple_id_name"));
  501. args.push_back("--password");
  502. args.push_back(p_preset->get("notarization/apple_id_password"));
  503. } else {
  504. if (p_preset->get("notarization/api_key") == "") {
  505. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));
  506. return Error::FAILED;
  507. }
  508. args.push_back("--apiIssuer");
  509. args.push_back(p_preset->get("notarization/api_uuid"));
  510. args.push_back("--apiKey");
  511. args.push_back(p_preset->get("notarization/api_key"));
  512. }
  513. args.push_back("--type");
  514. args.push_back("osx");
  515. if (p_preset->get("notarization/apple_team_id")) {
  516. args.push_back("--asc-provider");
  517. args.push_back(p_preset->get("notarization/apple_team_id"));
  518. }
  519. args.push_back("--file");
  520. args.push_back(p_path);
  521. String str;
  522. int exitcode = 0;
  523. Error err = OS::get_singleton()->execute("xcrun", args, &str, &exitcode, true);
  524. if (err != OK) {
  525. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable."));
  526. return err;
  527. }
  528. int rq_offset = str.find("RequestUUID");
  529. if (exitcode != 0 || rq_offset == -1) {
  530. print_line("xcrun altool (" + p_path + "):\n" + str);
  531. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));
  532. return Error::FAILED;
  533. } else {
  534. print_verbose("xcrun altool (" + p_path + "):\n" + str);
  535. int next_nl = str.find("\n", rq_offset);
  536. String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 14, -1) : str.substr(rq_offset + 14, next_nl - rq_offset - 14);
  537. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));
  538. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour. When the process is completed, you'll receive an email."));
  539. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:"));
  540. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun altool --notarization-history 0 -u <your email> -p <app-specific pwd>\"");
  541. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));
  542. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple <app path>\"");
  543. }
  544. } break;
  545. #endif
  546. default: {
  547. };
  548. }
  549. return OK;
  550. }
  551. Error EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_warn) {
  552. int codesign_tool = p_preset->get("codesign/codesign");
  553. switch (codesign_tool) {
  554. case 1: { // built-in ad-hoc
  555. print_verbose("using built-in codesign...");
  556. #ifdef MODULE_REGEX_ENABLED
  557. String error_msg;
  558. Error err = CodeSign::codesign(false, true, p_path, p_ent_path, error_msg);
  559. if (err != OK) {
  560. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Built-in CodeSign failed with error \"%s\"."), error_msg));
  561. return Error::FAILED;
  562. }
  563. #else
  564. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Built-in CodeSign require regex module."));
  565. #endif
  566. } break;
  567. case 2: { // "rcodesign"
  568. print_verbose("using rcodesign codesign...");
  569. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  570. if (rcodesign.is_empty()) {
  571. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xrcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));
  572. return Error::FAILED;
  573. }
  574. List<String> args;
  575. args.push_back("sign");
  576. if (p_path.get_extension() != "dmg") {
  577. args.push_back("--entitlements-xml-path");
  578. args.push_back(p_ent_path);
  579. }
  580. String certificate_file = p_preset->get("codesign/certificate_file");
  581. String certificate_pass = p_preset->get("codesign/certificate_password");
  582. if (!certificate_file.is_empty() && !certificate_file.is_empty()) {
  583. args.push_back("--p12-file");
  584. args.push_back(certificate_file);
  585. args.push_back("--p12-password");
  586. args.push_back(certificate_pass);
  587. }
  588. args.push_back("-v"); /* provide some more feedback */
  589. args.push_back(p_path);
  590. String str;
  591. int exitcode = 0;
  592. Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);
  593. if (err != OK) {
  594. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start rcodesign executable."));
  595. return err;
  596. }
  597. if (exitcode != 0) {
  598. print_line("rcodesign (" + p_path + "):\n" + str);
  599. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  600. return Error::FAILED;
  601. } else {
  602. print_verbose("rcodesign (" + p_path + "):\n" + str);
  603. }
  604. } break;
  605. #ifdef MACOS_ENABLED
  606. case 3: { // "codesign"
  607. print_verbose("using xcode codesign...");
  608. if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
  609. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xcode command line tools are not installed."));
  610. return Error::FAILED;
  611. }
  612. bool ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  613. List<String> args;
  614. if (!ad_hoc) {
  615. args.push_back("--timestamp");
  616. args.push_back("--options");
  617. args.push_back("runtime");
  618. }
  619. if (p_path.get_extension() != "dmg") {
  620. args.push_back("--entitlements");
  621. args.push_back(p_ent_path);
  622. }
  623. PackedStringArray user_args = p_preset->get("codesign/custom_options");
  624. for (int i = 0; i < user_args.size(); i++) {
  625. String user_arg = user_args[i].strip_edges();
  626. if (!user_arg.is_empty()) {
  627. args.push_back(user_arg);
  628. }
  629. }
  630. args.push_back("-s");
  631. if (ad_hoc) {
  632. args.push_back("-");
  633. } else {
  634. args.push_back(p_preset->get("codesign/identity"));
  635. }
  636. args.push_back("-v"); /* provide some more feedback */
  637. args.push_back("-f");
  638. args.push_back(p_path);
  639. String str;
  640. int exitcode = 0;
  641. Error err = OS::get_singleton()->execute("codesign", args, &str, nullptr, true);
  642. if (err != OK) {
  643. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start codesign executable, make sure Xcode command line tools are installed."));
  644. return err;
  645. }
  646. if (exitcode != 0) {
  647. print_line("codesign (" + p_path + "):\n" + str);
  648. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  649. return Error::FAILED;
  650. } else {
  651. print_verbose("codesign (" + p_path + "):\n" + str);
  652. }
  653. } break;
  654. #endif
  655. default: {
  656. };
  657. }
  658. return OK;
  659. }
  660. Error EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path,
  661. const String &p_ent_path, bool p_should_error_on_non_code) {
  662. #ifdef MACOS_ENABLED
  663. static Vector<String> extensions_to_sign;
  664. if (extensions_to_sign.is_empty()) {
  665. extensions_to_sign.push_back("dylib");
  666. extensions_to_sign.push_back("framework");
  667. extensions_to_sign.push_back("");
  668. }
  669. Error dir_access_error;
  670. Ref<DirAccess> dir_access{ DirAccess::open(p_path, &dir_access_error) };
  671. if (dir_access_error != OK) {
  672. return dir_access_error;
  673. }
  674. dir_access->list_dir_begin();
  675. String current_file{ dir_access->get_next() };
  676. while (!current_file.is_empty()) {
  677. String current_file_path{ p_path.path_join(current_file) };
  678. if (current_file == ".." || current_file == ".") {
  679. current_file = dir_access->get_next();
  680. continue;
  681. }
  682. if (extensions_to_sign.find(current_file.get_extension()) > -1) {
  683. Error code_sign_error{ _code_sign(p_preset, current_file_path, p_ent_path, false) };
  684. if (code_sign_error != OK) {
  685. return code_sign_error;
  686. }
  687. if (is_executable(current_file_path)) {
  688. // chmod with 0755 if the file is executable.
  689. FileAccess::set_unix_permissions(current_file_path, 0755);
  690. }
  691. } else if (dir_access->current_is_dir()) {
  692. Error code_sign_error{ _code_sign_directory(p_preset, current_file_path, p_ent_path, p_should_error_on_non_code) };
  693. if (code_sign_error != OK) {
  694. return code_sign_error;
  695. }
  696. } else if (p_should_error_on_non_code) {
  697. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign file %s."), current_file));
  698. return Error::FAILED;
  699. }
  700. current_file = dir_access->get_next();
  701. }
  702. #endif
  703. return OK;
  704. }
  705. Error EditorExportPlatformMacOS::_copy_and_sign_files(Ref<DirAccess> &dir_access, const String &p_src_path,
  706. const String &p_in_app_path, bool p_sign_enabled,
  707. const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,
  708. bool p_should_error_on_non_code_sign) {
  709. static Vector<String> extensions_to_sign;
  710. if (extensions_to_sign.is_empty()) {
  711. extensions_to_sign.push_back("dylib");
  712. extensions_to_sign.push_back("framework");
  713. extensions_to_sign.push_back("");
  714. }
  715. Error err{ OK };
  716. if (dir_access->dir_exists(p_src_path)) {
  717. #ifndef UNIX_ENABLED
  718. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Relative symlinks are not supported, exported \"%s\" might be broken!"), p_src_path.get_file()));
  719. #endif
  720. print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path);
  721. err = dir_access->make_dir_recursive(p_in_app_path);
  722. if (err == OK) {
  723. err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true);
  724. }
  725. } else {
  726. print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path);
  727. err = dir_access->copy(p_src_path, p_in_app_path);
  728. }
  729. if (err == OK && p_sign_enabled) {
  730. if (dir_access->dir_exists(p_src_path) && p_src_path.get_extension().is_empty()) {
  731. // If it is a directory, find and sign all dynamic libraries.
  732. err = _code_sign_directory(p_preset, p_in_app_path, p_ent_path, p_should_error_on_non_code_sign);
  733. } else {
  734. if (extensions_to_sign.find(p_in_app_path.get_extension()) > -1) {
  735. err = _code_sign(p_preset, p_in_app_path, p_ent_path, false);
  736. }
  737. if (is_executable(p_in_app_path)) {
  738. // chmod with 0755 if the file is executable.
  739. FileAccess::set_unix_permissions(p_in_app_path, 0755);
  740. }
  741. }
  742. }
  743. return err;
  744. }
  745. Error EditorExportPlatformMacOS::_export_macos_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin,
  746. const String &p_app_path_name, Ref<DirAccess> &dir_access,
  747. bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,
  748. const String &p_ent_path) {
  749. Error error{ OK };
  750. const Vector<String> &macos_plugins{ p_editor_export_plugin->get_macos_plugin_files() };
  751. for (int i = 0; i < macos_plugins.size(); ++i) {
  752. String src_path{ ProjectSettings::get_singleton()->globalize_path(macos_plugins[i]) };
  753. String path_in_app{ p_app_path_name + "/Contents/PlugIns/" + src_path.get_file() };
  754. error = _copy_and_sign_files(dir_access, src_path, path_in_app, p_sign_enabled, p_preset, p_ent_path, false);
  755. if (error != OK) {
  756. break;
  757. }
  758. }
  759. return error;
  760. }
  761. Error EditorExportPlatformMacOS::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
  762. List<String> args;
  763. if (FileAccess::exists(p_dmg_path)) {
  764. OS::get_singleton()->move_to_trash(p_dmg_path);
  765. }
  766. args.push_back("create");
  767. args.push_back(p_dmg_path);
  768. args.push_back("-volname");
  769. args.push_back(p_pkg_name);
  770. args.push_back("-fs");
  771. args.push_back("HFS+");
  772. args.push_back("-srcfolder");
  773. args.push_back(p_app_path_name);
  774. String str;
  775. Error err = OS::get_singleton()->execute("hdiutil", args, &str, nullptr, true);
  776. if (err != OK) {
  777. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("Could not start hdiutil executable."));
  778. return err;
  779. }
  780. print_verbose("hdiutil returned: " + str);
  781. if (str.find("create failed") != -1) {
  782. if (str.find("File exists") != -1) {
  783. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed - file exists."));
  784. } else {
  785. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed."));
  786. }
  787. return FAILED;
  788. }
  789. return OK;
  790. }
  791. bool EditorExportPlatformMacOS::is_shbang(const String &p_path) const {
  792. Ref<FileAccess> fb = FileAccess::open(p_path, FileAccess::READ);
  793. ERR_FAIL_COND_V_MSG(fb.is_null(), false, vformat("Can't open file: \"%s\".", p_path));
  794. uint16_t magic = fb->get_16();
  795. return (magic == 0x2123);
  796. }
  797. bool EditorExportPlatformMacOS::is_executable(const String &p_path) const {
  798. return MachO::is_macho(p_path) || LipO::is_lipo(p_path) || is_shbang(p_path);
  799. }
  800. Error EditorExportPlatformMacOS::_export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path) {
  801. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE);
  802. if (f.is_null()) {
  803. add_message(EXPORT_MESSAGE_ERROR, TTR("Debug Script Export"), vformat(TTR("Could not open file \"%s\"."), p_path));
  804. return ERR_CANT_CREATE;
  805. }
  806. f->store_line("#!/bin/sh");
  807. f->store_line("echo -ne '\\033c\\033]0;" + p_app_name + "\\a'");
  808. f->store_line("");
  809. f->store_line("function app_realpath() {");
  810. f->store_line(" SOURCE=$1");
  811. f->store_line(" while [ -h \"$SOURCE\" ]; do");
  812. f->store_line(" DIR=$(dirname \"$SOURCE\")");
  813. f->store_line(" SOURCE=$(readlink \"$SOURCE\")");
  814. f->store_line(" [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE");
  815. f->store_line(" done");
  816. f->store_line(" echo \"$( cd -P \"$( dirname \"$SOURCE\" )\" >/dev/null 2>&1 && pwd )\"");
  817. f->store_line("}");
  818. f->store_line("");
  819. f->store_line("BASE_PATH=\"$(app_realpath \"${BASH_SOURCE[0]}\")\"");
  820. f->store_line("\"$BASE_PATH/" + p_pkg_name + "\" \"$@\"");
  821. f->store_line("");
  822. return OK;
  823. }
  824. Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  825. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  826. String src_pkg_name;
  827. EditorProgress ep("export", "Exporting for macOS", 3, true);
  828. if (p_debug) {
  829. src_pkg_name = p_preset->get("custom_template/debug");
  830. } else {
  831. src_pkg_name = p_preset->get("custom_template/release");
  832. }
  833. if (src_pkg_name.is_empty()) {
  834. String err;
  835. src_pkg_name = find_export_template("macos.zip", &err);
  836. if (src_pkg_name.is_empty()) {
  837. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found."));
  838. return ERR_FILE_NOT_FOUND;
  839. }
  840. }
  841. if (!DirAccess::exists(p_path.get_base_dir())) {
  842. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("The given export path doesn't exist."));
  843. return ERR_FILE_BAD_PATH;
  844. }
  845. Ref<FileAccess> io_fa;
  846. zlib_filefunc_def io = zipio_create_io(&io_fa);
  847. if (ep.step(TTR("Creating app bundle"), 0)) {
  848. return ERR_SKIP;
  849. }
  850. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  851. if (!src_pkg_zip) {
  852. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not find template app to export: \"%s\"."), src_pkg_name));
  853. return ERR_FILE_NOT_FOUND;
  854. }
  855. int ret = unzGoToFirstFile(src_pkg_zip);
  856. String architecture = p_preset->get("binary_format/architecture");
  857. String binary_to_use = "godot_macos_" + String(p_debug ? "debug" : "release") + "." + architecture;
  858. String pkg_name;
  859. if (String(GLOBAL_GET("application/config/name")) != "") {
  860. pkg_name = String(GLOBAL_GET("application/config/name"));
  861. } else {
  862. pkg_name = "Unnamed";
  863. }
  864. pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
  865. String export_format;
  866. if (use_dmg() && p_path.ends_with("dmg")) {
  867. export_format = "dmg";
  868. } else if (p_path.ends_with("zip")) {
  869. export_format = "zip";
  870. } else if (p_path.ends_with("app")) {
  871. export_format = "app";
  872. } else {
  873. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Invalid export format."));
  874. return ERR_CANT_CREATE;
  875. }
  876. // Create our application bundle.
  877. String tmp_app_dir_name = pkg_name + ".app";
  878. String tmp_base_path_name;
  879. String tmp_app_path_name;
  880. String scr_path;
  881. if (export_format == "app") {
  882. tmp_base_path_name = p_path.get_base_dir();
  883. tmp_app_path_name = p_path;
  884. scr_path = p_path.get_basename() + ".command";
  885. } else {
  886. tmp_base_path_name = EditorPaths::get_singleton()->get_cache_dir().path_join(pkg_name);
  887. tmp_app_path_name = tmp_base_path_name.path_join(tmp_app_dir_name);
  888. scr_path = tmp_base_path_name.path_join(pkg_name + ".command");
  889. }
  890. print_verbose("Exporting to " + tmp_app_path_name);
  891. Error err = OK;
  892. Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_base_path_name);
  893. if (tmp_app_dir.is_null()) {
  894. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory: \"%s\"."), tmp_base_path_name));
  895. err = ERR_CANT_CREATE;
  896. }
  897. if (FileAccess::exists(scr_path)) {
  898. DirAccess::remove_file_or_error(scr_path);
  899. }
  900. if (DirAccess::exists(tmp_app_path_name)) {
  901. String old_dir = tmp_app_dir->get_current_dir();
  902. if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {
  903. tmp_app_dir->erase_contents_recursive();
  904. tmp_app_dir->change_dir(old_dir);
  905. }
  906. }
  907. Array helpers = p_preset->get("codesign/entitlements/app_sandbox/helper_executables");
  908. // Create our folder structure.
  909. if (err == OK) {
  910. print_verbose("Creating " + tmp_app_path_name + "/Contents/MacOS");
  911. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
  912. if (err != OK) {
  913. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/MacOS"));
  914. }
  915. }
  916. if (err == OK) {
  917. print_verbose("Creating " + tmp_app_path_name + "/Contents/Frameworks");
  918. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");
  919. if (err != OK) {
  920. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Frameworks"));
  921. }
  922. }
  923. if ((err == OK) && helpers.size() > 0) {
  924. print_line("Creating " + tmp_app_path_name + "/Contents/Helpers");
  925. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Helpers");
  926. if (err != OK) {
  927. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Helpers"));
  928. }
  929. }
  930. if (err == OK) {
  931. print_verbose("Creating " + tmp_app_path_name + "/Contents/Resources");
  932. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
  933. if (err != OK) {
  934. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Resources"));
  935. }
  936. }
  937. Dictionary appnames = GLOBAL_GET("application/config/name_localized");
  938. Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");
  939. Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");
  940. Dictionary location_usage_descriptions = p_preset->get("privacy/location_usage_description_localized");
  941. Dictionary address_book_usage_descriptions = p_preset->get("privacy/address_book_usage_description_localized");
  942. Dictionary calendar_usage_descriptions = p_preset->get("privacy/calendar_usage_description_localized");
  943. Dictionary photos_library_usage_descriptions = p_preset->get("privacy/photos_library_usage_description_localized");
  944. Dictionary desktop_folder_usage_descriptions = p_preset->get("privacy/desktop_folder_usage_description_localized");
  945. Dictionary documents_folder_usage_descriptions = p_preset->get("privacy/documents_folder_usage_description_localized");
  946. Dictionary downloads_folder_usage_descriptions = p_preset->get("privacy/downloads_folder_usage_description_localized");
  947. Dictionary network_volumes_usage_descriptions = p_preset->get("privacy/network_volumes_usage_description_localized");
  948. Dictionary removable_volumes_usage_descriptions = p_preset->get("privacy/removable_volumes_usage_description_localized");
  949. Dictionary copyrights = p_preset->get("application/copyright_localized");
  950. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  951. if (translations.size() > 0) {
  952. {
  953. String fname = tmp_app_path_name + "/Contents/Resources/en.lproj";
  954. tmp_app_dir->make_dir_recursive(fname);
  955. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  956. f->store_line("/* Localized versions of Info.plist keys */");
  957. f->store_line("");
  958. f->store_line("CFBundleDisplayName = \"" + GLOBAL_GET("application/config/name").operator String() + "\";");
  959. if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
  960. f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String() + "\";");
  961. }
  962. if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
  963. f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String() + "\";");
  964. }
  965. if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
  966. f->store_line("NSLocationUsageDescription = \"" + p_preset->get("privacy/location_usage_description").operator String() + "\";");
  967. }
  968. if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
  969. f->store_line("NSContactsUsageDescription = \"" + p_preset->get("privacy/address_book_usage_description").operator String() + "\";");
  970. }
  971. if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
  972. f->store_line("NSCalendarsUsageDescription = \"" + p_preset->get("privacy/calendar_usage_description").operator String() + "\";");
  973. }
  974. if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
  975. f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photos_library_usage_description").operator String() + "\";");
  976. }
  977. if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {
  978. f->store_line("NSDesktopFolderUsageDescription = \"" + p_preset->get("privacy/desktop_folder_usage_description").operator String() + "\";");
  979. }
  980. if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {
  981. f->store_line("NSDocumentsFolderUsageDescription = \"" + p_preset->get("privacy/documents_folder_usage_description").operator String() + "\";");
  982. }
  983. if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {
  984. f->store_line("NSDownloadsFolderUsageDescription = \"" + p_preset->get("privacy/downloads_folder_usage_description").operator String() + "\";");
  985. }
  986. if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {
  987. f->store_line("NSNetworkVolumesUsageDescription = \"" + p_preset->get("privacy/network_volumes_usage_description").operator String() + "\";");
  988. }
  989. if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {
  990. f->store_line("NSRemovableVolumesUsageDescription = \"" + p_preset->get("privacy/removable_volumes_usage_description").operator String() + "\";");
  991. }
  992. f->store_line("NSHumanReadableCopyright = \"" + p_preset->get("application/copyright").operator String() + "\";");
  993. }
  994. HashSet<String> languages;
  995. for (const String &E : translations) {
  996. Ref<Translation> tr = ResourceLoader::load(E);
  997. if (tr.is_valid() && tr->get_locale() != "en") {
  998. languages.insert(tr->get_locale());
  999. }
  1000. }
  1001. for (const String &lang : languages) {
  1002. String fname = tmp_app_path_name + "/Contents/Resources/" + lang + ".lproj";
  1003. tmp_app_dir->make_dir_recursive(fname);
  1004. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1005. f->store_line("/* Localized versions of Info.plist keys */");
  1006. f->store_line("");
  1007. if (appnames.has(lang)) {
  1008. f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String() + "\";");
  1009. }
  1010. if (microphone_usage_descriptions.has(lang)) {
  1011. f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String() + "\";");
  1012. }
  1013. if (camera_usage_descriptions.has(lang)) {
  1014. f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String() + "\";");
  1015. }
  1016. if (location_usage_descriptions.has(lang)) {
  1017. f->store_line("NSLocationUsageDescription = \"" + location_usage_descriptions[lang].operator String() + "\";");
  1018. }
  1019. if (address_book_usage_descriptions.has(lang)) {
  1020. f->store_line("NSContactsUsageDescription = \"" + address_book_usage_descriptions[lang].operator String() + "\";");
  1021. }
  1022. if (calendar_usage_descriptions.has(lang)) {
  1023. f->store_line("NSCalendarsUsageDescription = \"" + calendar_usage_descriptions[lang].operator String() + "\";");
  1024. }
  1025. if (photos_library_usage_descriptions.has(lang)) {
  1026. f->store_line("NSPhotoLibraryUsageDescription = \"" + photos_library_usage_descriptions[lang].operator String() + "\";");
  1027. }
  1028. if (desktop_folder_usage_descriptions.has(lang)) {
  1029. f->store_line("NSDesktopFolderUsageDescription = \"" + desktop_folder_usage_descriptions[lang].operator String() + "\";");
  1030. }
  1031. if (documents_folder_usage_descriptions.has(lang)) {
  1032. f->store_line("NSDocumentsFolderUsageDescription = \"" + documents_folder_usage_descriptions[lang].operator String() + "\";");
  1033. }
  1034. if (downloads_folder_usage_descriptions.has(lang)) {
  1035. f->store_line("NSDownloadsFolderUsageDescription = \"" + downloads_folder_usage_descriptions[lang].operator String() + "\";");
  1036. }
  1037. if (network_volumes_usage_descriptions.has(lang)) {
  1038. f->store_line("NSNetworkVolumesUsageDescription = \"" + network_volumes_usage_descriptions[lang].operator String() + "\";");
  1039. }
  1040. if (removable_volumes_usage_descriptions.has(lang)) {
  1041. f->store_line("NSRemovableVolumesUsageDescription = \"" + removable_volumes_usage_descriptions[lang].operator String() + "\";");
  1042. }
  1043. if (copyrights.has(lang)) {
  1044. f->store_line("NSHumanReadableCopyright = \"" + copyrights[lang].operator String() + "\";");
  1045. }
  1046. }
  1047. }
  1048. // Now process our template.
  1049. bool found_binary = false;
  1050. while (ret == UNZ_OK && err == OK) {
  1051. // Get filename.
  1052. unz_file_info info;
  1053. char fname[16384];
  1054. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  1055. if (ret != UNZ_OK) {
  1056. break;
  1057. }
  1058. String file = String::utf8(fname);
  1059. Vector<uint8_t> data;
  1060. data.resize(info.uncompressed_size);
  1061. // Read.
  1062. unzOpenCurrentFile(src_pkg_zip);
  1063. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  1064. unzCloseCurrentFile(src_pkg_zip);
  1065. // Write.
  1066. file = file.replace_first("macos_template.app/", "");
  1067. if (((info.external_fa >> 16L) & 0120000) == 0120000) {
  1068. #ifndef UNIX_ENABLED
  1069. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Relative symlinks are not supported on this OS, the exported project might be broken!"));
  1070. #endif
  1071. // Handle symlinks in the archive.
  1072. file = tmp_app_path_name.path_join(file);
  1073. if (err == OK) {
  1074. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  1075. if (err != OK) {
  1076. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));
  1077. }
  1078. }
  1079. if (err == OK) {
  1080. String lnk_data = String::utf8((const char *)data.ptr(), data.size());
  1081. err = tmp_app_dir->create_link(lnk_data, file);
  1082. if (err != OK) {
  1083. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not created symlink \"%s\" -> \"%s\"."), lnk_data, file));
  1084. }
  1085. print_verbose(vformat("ADDING SYMLINK %s => %s\n", file, lnk_data));
  1086. }
  1087. ret = unzGoToNextFile(src_pkg_zip);
  1088. continue; // next
  1089. }
  1090. if (file == "Contents/Info.plist") {
  1091. _fix_plist(p_preset, data, pkg_name);
  1092. }
  1093. if (file.begins_with("Contents/MacOS/godot_")) {
  1094. if (file != "Contents/MacOS/" + binary_to_use) {
  1095. ret = unzGoToNextFile(src_pkg_zip);
  1096. continue; // skip
  1097. }
  1098. found_binary = true;
  1099. file = "Contents/MacOS/" + pkg_name;
  1100. }
  1101. if (file == "Contents/Resources/icon.icns") {
  1102. // See if there is an icon.
  1103. String iconpath;
  1104. if (p_preset->get("application/icon") != "") {
  1105. iconpath = p_preset->get("application/icon");
  1106. } else {
  1107. iconpath = GLOBAL_GET("application/config/icon");
  1108. }
  1109. if (!iconpath.is_empty()) {
  1110. if (iconpath.get_extension() == "icns") {
  1111. Ref<FileAccess> icon = FileAccess::open(iconpath, FileAccess::READ);
  1112. if (icon.is_valid()) {
  1113. data.resize(icon->get_length());
  1114. icon->get_buffer(&data.write[0], icon->get_length());
  1115. }
  1116. } else {
  1117. Ref<Image> icon;
  1118. icon.instantiate();
  1119. icon->load(iconpath);
  1120. if (!icon->is_empty()) {
  1121. _make_icon(icon, data);
  1122. }
  1123. }
  1124. }
  1125. }
  1126. if (data.size() > 0) {
  1127. print_verbose("ADDING: " + file + " size: " + itos(data.size()));
  1128. // Write it into our application bundle.
  1129. file = tmp_app_path_name.path_join(file);
  1130. if (err == OK) {
  1131. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  1132. if (err != OK) {
  1133. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));
  1134. }
  1135. }
  1136. if (err == OK) {
  1137. Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);
  1138. if (f.is_valid()) {
  1139. f->store_buffer(data.ptr(), data.size());
  1140. f.unref();
  1141. if (is_executable(file)) {
  1142. // chmod with 0755 if the file is executable.
  1143. FileAccess::set_unix_permissions(file, 0755);
  1144. }
  1145. } else {
  1146. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not open \"%s\"."), file));
  1147. err = ERR_CANT_CREATE;
  1148. }
  1149. }
  1150. }
  1151. ret = unzGoToNextFile(src_pkg_zip);
  1152. }
  1153. // We're done with our source zip.
  1154. unzClose(src_pkg_zip);
  1155. if (!found_binary) {
  1156. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Requested template binary \"%s\" not found. It might be missing from your template archive."), binary_to_use));
  1157. err = ERR_FILE_NOT_FOUND;
  1158. }
  1159. // Save console script.
  1160. if (err == OK) {
  1161. int con_scr = p_preset->get("debug/export_console_script");
  1162. if ((con_scr == 1 && p_debug) || (con_scr == 2)) {
  1163. err = _export_debug_script(p_preset, pkg_name, tmp_app_path_name.get_file() + "/Contents/MacOS/" + pkg_name, scr_path);
  1164. FileAccess::set_unix_permissions(scr_path, 0755);
  1165. if (err != OK) {
  1166. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not create console script."));
  1167. }
  1168. }
  1169. }
  1170. if (err == OK) {
  1171. if (ep.step(TTR("Making PKG"), 1)) {
  1172. return ERR_SKIP;
  1173. }
  1174. // See if we can code sign our new package.
  1175. bool sign_enabled = (p_preset->get("codesign/codesign").operator int() > 0);
  1176. bool ad_hoc = false;
  1177. int codesign_tool = p_preset->get("codesign/codesign");
  1178. switch (codesign_tool) {
  1179. case 1: { // built-in ad-hoc
  1180. ad_hoc = true;
  1181. } break;
  1182. case 2: { // "rcodesign"
  1183. ad_hoc = p_preset->get("codesign/certificate_file").operator String().is_empty() || p_preset->get("codesign/certificate_password").operator String().is_empty();
  1184. } break;
  1185. #ifdef MACOS_ENABLED
  1186. case 3: { // "codesign"
  1187. ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  1188. } break;
  1189. #endif
  1190. default: {
  1191. };
  1192. }
  1193. String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
  1194. Vector<SharedObject> shared_objects;
  1195. err = save_pack(p_preset, p_debug, pack_path, &shared_objects);
  1196. bool lib_validation = p_preset->get("codesign/entitlements/disable_library_validation");
  1197. if (!shared_objects.is_empty() && sign_enabled && ad_hoc && !lib_validation) {
  1198. add_message(EXPORT_MESSAGE_INFO, TTR("Entitlements Modified"), TTR("Ad-hoc signed applications require the 'Disable Library Validation' entitlement to load dynamic libraries."));
  1199. lib_validation = true;
  1200. }
  1201. String ent_path = p_preset->get("codesign/entitlements/custom_file");
  1202. String hlp_ent_path = EditorPaths::get_singleton()->get_cache_dir().path_join(pkg_name + "_helper.entitlements");
  1203. if (sign_enabled && (ent_path.is_empty())) {
  1204. ent_path = EditorPaths::get_singleton()->get_cache_dir().path_join(pkg_name + ".entitlements");
  1205. Ref<FileAccess> ent_f = FileAccess::open(ent_path, FileAccess::WRITE);
  1206. if (ent_f.is_valid()) {
  1207. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  1208. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  1209. ent_f->store_line("<plist version=\"1.0\">");
  1210. ent_f->store_line("<dict>");
  1211. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  1212. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  1213. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  1214. ent_f->store_line("<true/>");
  1215. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  1216. ent_f->store_line("<true/>");
  1217. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  1218. ent_f->store_line("<true/>");
  1219. } else {
  1220. if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) {
  1221. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  1222. ent_f->store_line("<true/>");
  1223. }
  1224. if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) {
  1225. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  1226. ent_f->store_line("<true/>");
  1227. }
  1228. if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) {
  1229. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  1230. ent_f->store_line("<true/>");
  1231. }
  1232. }
  1233. if (lib_validation) {
  1234. ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>");
  1235. ent_f->store_line("<true/>");
  1236. }
  1237. if ((bool)p_preset->get("codesign/entitlements/audio_input")) {
  1238. ent_f->store_line("<key>com.apple.security.device.audio-input</key>");
  1239. ent_f->store_line("<true/>");
  1240. }
  1241. if ((bool)p_preset->get("codesign/entitlements/camera")) {
  1242. ent_f->store_line("<key>com.apple.security.device.camera</key>");
  1243. ent_f->store_line("<true/>");
  1244. }
  1245. if ((bool)p_preset->get("codesign/entitlements/location")) {
  1246. ent_f->store_line("<key>com.apple.security.personal-information.location</key>");
  1247. ent_f->store_line("<true/>");
  1248. }
  1249. if ((bool)p_preset->get("codesign/entitlements/address_book")) {
  1250. ent_f->store_line("<key>com.apple.security.personal-information.addressbook</key>");
  1251. ent_f->store_line("<true/>");
  1252. }
  1253. if ((bool)p_preset->get("codesign/entitlements/calendars")) {
  1254. ent_f->store_line("<key>com.apple.security.personal-information.calendars</key>");
  1255. ent_f->store_line("<true/>");
  1256. }
  1257. if ((bool)p_preset->get("codesign/entitlements/photos_library")) {
  1258. ent_f->store_line("<key>com.apple.security.personal-information.photos-library</key>");
  1259. ent_f->store_line("<true/>");
  1260. }
  1261. if ((bool)p_preset->get("codesign/entitlements/apple_events")) {
  1262. ent_f->store_line("<key>com.apple.security.automation.apple-events</key>");
  1263. ent_f->store_line("<true/>");
  1264. }
  1265. if ((bool)p_preset->get("codesign/entitlements/debugging")) {
  1266. ent_f->store_line("<key>com.apple.security.get-task-allow</key>");
  1267. ent_f->store_line("<true/>");
  1268. }
  1269. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) {
  1270. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  1271. ent_f->store_line("<true/>");
  1272. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) {
  1273. ent_f->store_line("<key>com.apple.security.network.server</key>");
  1274. ent_f->store_line("<true/>");
  1275. }
  1276. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) {
  1277. ent_f->store_line("<key>com.apple.security.network.client</key>");
  1278. ent_f->store_line("<true/>");
  1279. }
  1280. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) {
  1281. ent_f->store_line("<key>com.apple.security.device.usb</key>");
  1282. ent_f->store_line("<true/>");
  1283. }
  1284. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) {
  1285. ent_f->store_line("<key>com.apple.security.device.bluetooth</key>");
  1286. ent_f->store_line("<true/>");
  1287. }
  1288. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) {
  1289. ent_f->store_line("<key>com.apple.security.files.downloads.read-only</key>");
  1290. ent_f->store_line("<true/>");
  1291. }
  1292. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) {
  1293. ent_f->store_line("<key>com.apple.security.files.downloads.read-write</key>");
  1294. ent_f->store_line("<true/>");
  1295. }
  1296. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) {
  1297. ent_f->store_line("<key>com.apple.security.files.pictures.read-only</key>");
  1298. ent_f->store_line("<true/>");
  1299. }
  1300. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) {
  1301. ent_f->store_line("<key>com.apple.security.files.pictures.read-write</key>");
  1302. ent_f->store_line("<true/>");
  1303. }
  1304. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) {
  1305. ent_f->store_line("<key>com.apple.security.files.music.read-only</key>");
  1306. ent_f->store_line("<true/>");
  1307. }
  1308. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) {
  1309. ent_f->store_line("<key>com.apple.security.files.music.read-write</key>");
  1310. ent_f->store_line("<true/>");
  1311. }
  1312. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) {
  1313. ent_f->store_line("<key>com.apple.security.files.movies.read-only</key>");
  1314. ent_f->store_line("<true/>");
  1315. }
  1316. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) {
  1317. ent_f->store_line("<key>com.apple.security.files.movies.read-write</key>");
  1318. ent_f->store_line("<true/>");
  1319. }
  1320. }
  1321. ent_f->store_line("</dict>");
  1322. ent_f->store_line("</plist>");
  1323. } else {
  1324. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create entitlements file."));
  1325. err = ERR_CANT_CREATE;
  1326. }
  1327. if ((err == OK) && helpers.size() > 0) {
  1328. ent_f = FileAccess::open(hlp_ent_path, FileAccess::WRITE);
  1329. if (ent_f.is_valid()) {
  1330. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  1331. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  1332. ent_f->store_line("<plist version=\"1.0\">");
  1333. ent_f->store_line("<dict>");
  1334. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  1335. ent_f->store_line("<true/>");
  1336. ent_f->store_line("<key>com.apple.security.inherit</key>");
  1337. ent_f->store_line("<true/>");
  1338. ent_f->store_line("</dict>");
  1339. ent_f->store_line("</plist>");
  1340. } else {
  1341. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create helper entitlements file."));
  1342. err = ERR_CANT_CREATE;
  1343. }
  1344. }
  1345. }
  1346. if ((err == OK) && helpers.size() > 0) {
  1347. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1348. for (int i = 0; i < helpers.size(); i++) {
  1349. String hlp_path = helpers[i];
  1350. err = da->copy(hlp_path, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file());
  1351. if (err == OK && sign_enabled) {
  1352. err = _code_sign(p_preset, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), hlp_ent_path, false);
  1353. }
  1354. FileAccess::set_unix_permissions(tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), 0755);
  1355. }
  1356. }
  1357. if (err == OK) {
  1358. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1359. for (int i = 0; i < shared_objects.size(); i++) {
  1360. String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path);
  1361. if (shared_objects[i].target.is_empty()) {
  1362. String path_in_app = tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file();
  1363. err = _copy_and_sign_files(da, src_path, path_in_app, sign_enabled, p_preset, ent_path, true);
  1364. } else {
  1365. String path_in_app = tmp_app_path_name.path_join(shared_objects[i].target);
  1366. tmp_app_dir->make_dir_recursive(path_in_app);
  1367. err = _copy_and_sign_files(da, src_path, path_in_app.path_join(src_path.get_file()), sign_enabled, p_preset, ent_path, false);
  1368. }
  1369. if (err != OK) {
  1370. break;
  1371. }
  1372. }
  1373. Vector<Ref<EditorExportPlugin>> export_plugins{ EditorExport::get_singleton()->get_export_plugins() };
  1374. for (int i = 0; i < export_plugins.size(); ++i) {
  1375. err = _export_macos_plugins_for(export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path);
  1376. if (err != OK) {
  1377. break;
  1378. }
  1379. }
  1380. }
  1381. if (err == OK && sign_enabled) {
  1382. if (ep.step(TTR("Code signing bundle"), 2)) {
  1383. return ERR_SKIP;
  1384. }
  1385. err = _code_sign(p_preset, tmp_app_path_name, ent_path);
  1386. }
  1387. if (export_format == "dmg") {
  1388. // Create a DMG.
  1389. if (err == OK) {
  1390. if (ep.step(TTR("Making DMG"), 3)) {
  1391. return ERR_SKIP;
  1392. }
  1393. err = _create_dmg(p_path, pkg_name, tmp_base_path_name);
  1394. }
  1395. // Sign DMG.
  1396. if (err == OK && sign_enabled && !ad_hoc) {
  1397. if (ep.step(TTR("Code signing DMG"), 3)) {
  1398. return ERR_SKIP;
  1399. }
  1400. err = _code_sign(p_preset, p_path, ent_path, false);
  1401. }
  1402. } else if (export_format == "zip") {
  1403. // Create ZIP.
  1404. if (err == OK) {
  1405. if (ep.step(TTR("Making ZIP"), 3)) {
  1406. return ERR_SKIP;
  1407. }
  1408. if (FileAccess::exists(p_path)) {
  1409. OS::get_singleton()->move_to_trash(p_path);
  1410. }
  1411. Ref<FileAccess> io_fa_dst;
  1412. zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);
  1413. zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
  1414. _zip_folder_recursive(zip, tmp_base_path_name, "", pkg_name);
  1415. zipClose(zip, nullptr);
  1416. }
  1417. }
  1418. bool noto_enabled = (p_preset->get("notarization/notarization").operator int() > 0);
  1419. if (err == OK && noto_enabled) {
  1420. if (export_format == "app") {
  1421. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("Notarization requires the app to be archived first, select the DMG or ZIP export format instead."));
  1422. } else {
  1423. if (ep.step(TTR("Sending archive for notarization"), 4)) {
  1424. return ERR_SKIP;
  1425. }
  1426. err = _notarize(p_preset, p_path);
  1427. }
  1428. }
  1429. // Clean up temporary entitlements files.
  1430. if (FileAccess::exists(hlp_ent_path)) {
  1431. DirAccess::remove_file_or_error(hlp_ent_path);
  1432. }
  1433. // Clean up temporary .app dir and generated entitlements.
  1434. if ((String)(p_preset->get("codesign/entitlements/custom_file")) == "") {
  1435. tmp_app_dir->remove(ent_path);
  1436. }
  1437. if (export_format != "app") {
  1438. if (tmp_app_dir->change_dir(tmp_base_path_name) == OK) {
  1439. tmp_app_dir->erase_contents_recursive();
  1440. tmp_app_dir->change_dir("..");
  1441. tmp_app_dir->remove(pkg_name);
  1442. }
  1443. }
  1444. }
  1445. return err;
  1446. }
  1447. void EditorExportPlatformMacOS::_zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name) {
  1448. String dir = p_folder.is_empty() ? p_root_path : p_root_path.path_join(p_folder);
  1449. Ref<DirAccess> da = DirAccess::open(dir);
  1450. da->list_dir_begin();
  1451. String f = da->get_next();
  1452. while (!f.is_empty()) {
  1453. if (f == "." || f == "..") {
  1454. f = da->get_next();
  1455. continue;
  1456. }
  1457. if (da->is_link(f)) {
  1458. OS::DateTime dt = OS::get_singleton()->get_datetime();
  1459. zip_fileinfo zipfi;
  1460. zipfi.tmz_date.tm_year = dt.year;
  1461. zipfi.tmz_date.tm_mon = dt.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, https://www.cplusplus.com/reference/ctime/tm/
  1462. zipfi.tmz_date.tm_mday = dt.day;
  1463. zipfi.tmz_date.tm_hour = dt.hour;
  1464. zipfi.tmz_date.tm_min = dt.minute;
  1465. zipfi.tmz_date.tm_sec = dt.second;
  1466. zipfi.dosDate = 0;
  1467. // 0120000: symbolic link type
  1468. // 0000755: permissions rwxr-xr-x
  1469. // 0000644: permissions rw-r--r--
  1470. uint32_t _mode = 0120644;
  1471. zipfi.external_fa = (_mode << 16L) | !(_mode & 0200);
  1472. zipfi.internal_fa = 0;
  1473. zipOpenNewFileInZip4(p_zip,
  1474. p_folder.path_join(f).utf8().get_data(),
  1475. &zipfi,
  1476. nullptr,
  1477. 0,
  1478. nullptr,
  1479. 0,
  1480. nullptr,
  1481. Z_DEFLATED,
  1482. Z_DEFAULT_COMPRESSION,
  1483. 0,
  1484. -MAX_WBITS,
  1485. DEF_MEM_LEVEL,
  1486. Z_DEFAULT_STRATEGY,
  1487. nullptr,
  1488. 0,
  1489. 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions
  1490. 0);
  1491. String target = da->read_link(f);
  1492. zipWriteInFileInZip(p_zip, target.utf8().get_data(), target.utf8().size());
  1493. zipCloseFileInZip(p_zip);
  1494. } else if (da->current_is_dir()) {
  1495. _zip_folder_recursive(p_zip, p_root_path, p_folder.path_join(f), p_pkg_name);
  1496. } else {
  1497. OS::DateTime dt = OS::get_singleton()->get_datetime();
  1498. zip_fileinfo zipfi;
  1499. zipfi.tmz_date.tm_year = dt.year;
  1500. zipfi.tmz_date.tm_mon = dt.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, https://www.cplusplus.com/reference/ctime/tm/
  1501. zipfi.tmz_date.tm_mday = dt.day;
  1502. zipfi.tmz_date.tm_hour = dt.hour;
  1503. zipfi.tmz_date.tm_min = dt.minute;
  1504. zipfi.tmz_date.tm_sec = dt.second;
  1505. zipfi.dosDate = 0;
  1506. // 0100000: regular file type
  1507. // 0000755: permissions rwxr-xr-x
  1508. // 0000644: permissions rw-r--r--
  1509. uint32_t _mode = (is_executable(dir.path_join(f)) ? 0100755 : 0100644);
  1510. zipfi.external_fa = (_mode << 16L) | !(_mode & 0200);
  1511. zipfi.internal_fa = 0;
  1512. zipOpenNewFileInZip4(p_zip,
  1513. p_folder.path_join(f).utf8().get_data(),
  1514. &zipfi,
  1515. nullptr,
  1516. 0,
  1517. nullptr,
  1518. 0,
  1519. nullptr,
  1520. Z_DEFLATED,
  1521. Z_DEFAULT_COMPRESSION,
  1522. 0,
  1523. -MAX_WBITS,
  1524. DEF_MEM_LEVEL,
  1525. Z_DEFAULT_STRATEGY,
  1526. nullptr,
  1527. 0,
  1528. 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions
  1529. 0);
  1530. Ref<FileAccess> fa = FileAccess::open(dir.path_join(f), FileAccess::READ);
  1531. if (fa.is_null()) {
  1532. add_message(EXPORT_MESSAGE_ERROR, TTR("ZIP Creation"), vformat(TTR("Could not open file to read from path \"%s\"."), dir.path_join(f)));
  1533. return;
  1534. }
  1535. const int bufsize = 16384;
  1536. uint8_t buf[bufsize];
  1537. while (true) {
  1538. uint64_t got = fa->get_buffer(buf, bufsize);
  1539. if (got == 0) {
  1540. break;
  1541. }
  1542. zipWriteInFileInZip(p_zip, buf, got);
  1543. }
  1544. zipCloseFileInZip(p_zip);
  1545. }
  1546. f = da->get_next();
  1547. }
  1548. da->list_dir_end();
  1549. }
  1550. bool EditorExportPlatformMacOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  1551. String err;
  1552. bool valid = false;
  1553. // Look for export templates (custom templates).
  1554. bool dvalid = false;
  1555. bool rvalid = false;
  1556. if (p_preset->get("custom_template/debug") != "") {
  1557. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  1558. if (!dvalid) {
  1559. err += TTR("Custom debug template not found.") + "\n";
  1560. }
  1561. }
  1562. if (p_preset->get("custom_template/release") != "") {
  1563. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  1564. if (!rvalid) {
  1565. err += TTR("Custom release template not found.") + "\n";
  1566. }
  1567. }
  1568. // Look for export templates (official templates, check only is custom templates are not set).
  1569. if (!dvalid || !rvalid) {
  1570. dvalid = exists_export_template("macos.zip", &err);
  1571. rvalid = dvalid; // Both in the same ZIP.
  1572. }
  1573. valid = dvalid || rvalid;
  1574. r_missing_templates = !valid;
  1575. if (!err.is_empty()) {
  1576. r_error = err;
  1577. }
  1578. return valid;
  1579. }
  1580. bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  1581. String err;
  1582. bool valid = true;
  1583. String identifier = p_preset->get("application/bundle_identifier");
  1584. String pn_err;
  1585. if (!is_package_name_valid(identifier, &pn_err)) {
  1586. err += TTR("Invalid bundle identifier:") + " " + pn_err + "\n";
  1587. valid = false;
  1588. }
  1589. bool ad_hoc = false;
  1590. int codesign_tool = p_preset->get("codesign/codesign");
  1591. switch (codesign_tool) {
  1592. case 1: { // built-in ad-hoc
  1593. ad_hoc = true;
  1594. } break;
  1595. case 2: { // "rcodesign"
  1596. ad_hoc = p_preset->get("codesign/certificate_file").operator String().is_empty() || p_preset->get("codesign/certificate_password").operator String().is_empty();
  1597. } break;
  1598. #ifdef MACOS_ENABLED
  1599. case 3: { // "codesign"
  1600. ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  1601. } break;
  1602. #endif
  1603. default: {
  1604. };
  1605. }
  1606. int notary_tool = p_preset->get("notarization/notarization");
  1607. if (notary_tool > 0) {
  1608. if (ad_hoc) {
  1609. err += TTR("Notarization: Notarization with an ad-hoc signature is not supported.") + "\n";
  1610. valid = false;
  1611. }
  1612. if (codesign_tool == 0) {
  1613. err += TTR("Notarization: Code signing is required for notarization.") + "\n";
  1614. valid = false;
  1615. }
  1616. if (notary_tool == 2) {
  1617. if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {
  1618. err += TTR("Notarization: Xcode command line tools are not installed.") + "\n";
  1619. valid = false;
  1620. }
  1621. if (p_preset->get("notarization/apple_id_name") == "" && p_preset->get("notarization/api_uuid") == "") {
  1622. err += TTR("Notarization: Neither Apple ID name nor App Store Connect issuer ID name not specified.") + "\n";
  1623. valid = false;
  1624. } else if (p_preset->get("notarization/apple_id_name") != "" && p_preset->get("notarization/api_uuid") != "") {
  1625. err += TTR("Notarization: Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.") + "\n";
  1626. valid = false;
  1627. } else {
  1628. if (p_preset->get("notarization/apple_id_name") != "") {
  1629. if (p_preset->get("notarization/apple_id_password") == "") {
  1630. err += TTR("Notarization: Apple ID password not specified.") + "\n";
  1631. }
  1632. valid = false;
  1633. }
  1634. if (p_preset->get("notarization/api_uuid") != "") {
  1635. if (p_preset->get("notarization/api_key") == "") {
  1636. err += TTR("Notarization: App Store Connect API key ID not specified.") + "\n";
  1637. valid = false;
  1638. }
  1639. }
  1640. }
  1641. } else if (notary_tool == 1) {
  1642. if (p_preset->get("notarization/api_uuid") == "") {
  1643. err += TTR("Notarization: App Store Connect issuer ID name not specified.") + "\n";
  1644. valid = false;
  1645. }
  1646. if (p_preset->get("notarization/api_key") == "") {
  1647. err += TTR("Notarization: App Store Connect API key ID not specified.") + "\n";
  1648. valid = false;
  1649. }
  1650. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  1651. if (rcodesign.is_empty()) {
  1652. err += TTR("Notarization: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";
  1653. valid = false;
  1654. }
  1655. }
  1656. } else {
  1657. err += TTR("Warning: Notarization is disabled. The exported project will be blocked by Gatekeeper if it's downloaded from an unknown source.") + "\n";
  1658. if (codesign_tool == 0) {
  1659. err += TTR("Code signing is disabled. The exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n";
  1660. }
  1661. }
  1662. if (codesign_tool > 0) {
  1663. if (ad_hoc) {
  1664. err += TTR("Code signing: Using ad-hoc signature. The exported project will be blocked by Gatekeeper") + "\n";
  1665. }
  1666. if (codesign_tool == 3) {
  1667. if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
  1668. err += TTR("Code signing: Xcode command line tools are not installed.") + "\n";
  1669. valid = false;
  1670. }
  1671. } else if (codesign_tool == 2) {
  1672. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  1673. if (rcodesign.is_empty()) {
  1674. err += TTR("Code signing: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";
  1675. valid = false;
  1676. }
  1677. }
  1678. if ((bool)p_preset->get("codesign/entitlements/audio_input") && ((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
  1679. err += TTR("Privacy: Microphone access is enabled, but usage description is not specified.") + "\n";
  1680. valid = false;
  1681. }
  1682. if ((bool)p_preset->get("codesign/entitlements/camera") && ((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
  1683. err += TTR("Privacy: Camera access is enabled, but usage description is not specified.") + "\n";
  1684. valid = false;
  1685. }
  1686. if ((bool)p_preset->get("codesign/entitlements/location") && ((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
  1687. err += TTR("Privacy: Location information access is enabled, but usage description is not specified.") + "\n";
  1688. valid = false;
  1689. }
  1690. if ((bool)p_preset->get("codesign/entitlements/address_book") && ((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
  1691. err += TTR("Privacy: Address book access is enabled, but usage description is not specified.") + "\n";
  1692. valid = false;
  1693. }
  1694. if ((bool)p_preset->get("codesign/entitlements/calendars") && ((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
  1695. err += TTR("Privacy: Calendar access is enabled, but usage description is not specified.") + "\n";
  1696. valid = false;
  1697. }
  1698. if ((bool)p_preset->get("codesign/entitlements/photos_library") && ((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
  1699. err += TTR("Privacy: Photo library access is enabled, but usage description is not specified.") + "\n";
  1700. valid = false;
  1701. }
  1702. }
  1703. if (!err.is_empty()) {
  1704. r_error = err;
  1705. }
  1706. return valid;
  1707. }
  1708. EditorExportPlatformMacOS::EditorExportPlatformMacOS() {
  1709. logo = ImageTexture::create_from_image(memnew(Image(_macos_logo)));
  1710. }
  1711. EditorExportPlatformMacOS::~EditorExportPlatformMacOS() {
  1712. }