export_plugin.cpp 84 KB

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