export_plugin.cpp 84 KB

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