export_plugin.cpp 84 KB

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