export_plugin.cpp 94 KB

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