export_plugin.cpp 95 KB

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