export_plugin.cpp 84 KB

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