export_plugin.cpp 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848
  1. /**************************************************************************/
  2. /* export_plugin.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "export_plugin.h"
  31. #include "logo_svg.gen.h"
  32. #include "run_icon_svg.gen.h"
  33. #include "core/io/image_loader.h"
  34. #include "core/io/plist.h"
  35. #include "core/string/translation_server.h"
  36. #include "drivers/png/png_driver_common.h"
  37. #include "editor/editor_node.h"
  38. #include "editor/editor_string_names.h"
  39. #include "editor/export/codesign.h"
  40. #include "editor/export/lipo.h"
  41. #include "editor/export/macho.h"
  42. #include "editor/file_system/editor_paths.h"
  43. #include "editor/import/resource_importer_texture_settings.h"
  44. #include "editor/themes/editor_scale.h"
  45. #include "scene/resources/image_texture.h"
  46. #include "modules/svg/image_loader_svg.h"
  47. void EditorExportPlatformMacOS::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
  48. r_features->push_back(p_preset->get("binary_format/architecture"));
  49. String architecture = p_preset->get("binary_format/architecture");
  50. if (architecture == "universal" || architecture == "x86_64") {
  51. r_features->push_back("s3tc");
  52. r_features->push_back("bptc");
  53. } else if (architecture == "arm64") {
  54. r_features->push_back("etc2");
  55. r_features->push_back("astc");
  56. } else {
  57. ERR_PRINT("Invalid architecture");
  58. }
  59. if (!p_preset->is_dedicated_server() && p_preset->get("shader_baker/enabled")) {
  60. // Don't use the shader baker if exporting as a dedicated server, as no rendering is performed.
  61. r_features->push_back("shader_baker");
  62. }
  63. if (architecture == "universal") {
  64. r_features->push_back("x86_64");
  65. r_features->push_back("arm64");
  66. }
  67. }
  68. String EditorExportPlatformMacOS::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const {
  69. if (p_preset) {
  70. int dist_type = p_preset->get("export/distribution_type");
  71. bool ad_hoc = false;
  72. int codesign_tool = p_preset->get("codesign/codesign");
  73. int notary_tool = p_preset->get("notarization/notarization");
  74. switch (codesign_tool) {
  75. case 1: { // built-in ad-hoc
  76. ad_hoc = true;
  77. } break;
  78. case 2: { // "rcodesign"
  79. ad_hoc = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty() || p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty();
  80. } break;
  81. #ifdef MACOS_ENABLED
  82. case 3: { // "codesign"
  83. ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  84. } break;
  85. #endif
  86. default: {
  87. };
  88. }
  89. if (p_name == "application/bundle_identifier") {
  90. String identifier = p_preset->get("application/bundle_identifier");
  91. String pn_err;
  92. if (!is_package_name_valid(identifier, &pn_err)) {
  93. return TTR("Invalid bundle identifier:") + " " + pn_err;
  94. }
  95. }
  96. if (p_name == "shader_baker/enabled" && bool(p_preset->get("shader_baker/enabled"))) {
  97. String export_renderer = GLOBAL_GET("rendering/renderer/rendering_method");
  98. if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
  99. return TTR("\"Shader Baker\" is not supported when using the Compatibility renderer.");
  100. } else if (OS::get_singleton()->get_current_rendering_method() != export_renderer) {
  101. return vformat(TTR("The editor is currently using a different renderer than what the target platform will use. \"Shader Baker\" won't be able to include core shaders. Switch to the \"%s\" renderer temporarily to fix this."), export_renderer);
  102. }
  103. }
  104. if (p_name == "codesign/certificate_file" || p_name == "codesign/certificate_password" || p_name == "codesign/identity") {
  105. if (dist_type == 2) {
  106. if (ad_hoc) {
  107. return TTR("App Store distribution with ad-hoc code signing is not supported.");
  108. }
  109. } else if (notary_tool > 0 && ad_hoc) {
  110. return TTR("Notarization with an ad-hoc signature is not supported.");
  111. }
  112. }
  113. if (p_name == "codesign/apple_team_id") {
  114. String team_id = p_preset->get("codesign/apple_team_id");
  115. if (team_id.is_empty()) {
  116. if (dist_type == 2) {
  117. return TTR("Apple Team ID is required for App Store distribution.");
  118. } else if (notary_tool > 0) {
  119. return TTR("Apple Team ID is required for notarization.");
  120. }
  121. }
  122. }
  123. if (p_name == "codesign/provisioning_profile" && dist_type == 2) {
  124. String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE);
  125. if (pprof.is_empty()) {
  126. return TTR("Provisioning profile is required for App Store distribution.");
  127. }
  128. }
  129. if (p_name == "codesign/installer_identity" && dist_type == 2) {
  130. String ident = p_preset->get("codesign/installer_identity");
  131. if (ident.is_empty()) {
  132. return TTR("Installer signing identity is required for App Store distribution.");
  133. }
  134. }
  135. if (p_name == "codesign/entitlements/app_sandbox/enabled" && dist_type == 2) {
  136. bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");
  137. if (!sandbox) {
  138. return TTR("App sandbox is required for App Store distribution.");
  139. }
  140. }
  141. if (p_name == "codesign/codesign") {
  142. if (dist_type == 2) {
  143. if (codesign_tool == 2 && ClassDB::class_exists("CSharpScript")) {
  144. return TTR("'rcodesign' doesn't support signing applications with embedded dynamic libraries (GDExtension or .NET).");
  145. }
  146. if (codesign_tool == 0) {
  147. return TTR("Code signing is required for App Store distribution.");
  148. }
  149. if (codesign_tool == 1) {
  150. return TTR("App Store distribution with ad-hoc code signing is not supported.");
  151. }
  152. } else if (notary_tool > 0) {
  153. if (codesign_tool == 0) {
  154. return TTR("Code signing is required for notarization.");
  155. }
  156. if (codesign_tool == 1) {
  157. return TTR("Notarization with an ad-hoc signature is not supported.");
  158. }
  159. }
  160. }
  161. if (notary_tool == 2 || notary_tool == 3) {
  162. if (p_name == "notarization/apple_id_name" || p_name == "notarization/api_uuid") {
  163. String apple_id = p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID);
  164. String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);
  165. if (apple_id.is_empty() && api_uuid.is_empty()) {
  166. return TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified.");
  167. }
  168. if (!apple_id.is_empty() && !api_uuid.is_empty()) {
  169. return TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.");
  170. }
  171. }
  172. if (p_name == "notarization/apple_id_password") {
  173. String apple_id = p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID);
  174. String apple_pass = p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS);
  175. if (!apple_id.is_empty() && apple_pass.is_empty()) {
  176. return TTR("Apple ID password not specified.");
  177. }
  178. }
  179. if (p_name == "notarization/api_key_id") {
  180. String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);
  181. String api_key = p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID);
  182. if (!api_uuid.is_empty() && api_key.is_empty()) {
  183. return TTR("App Store Connect API key ID not specified.");
  184. }
  185. }
  186. } else if (notary_tool == 1) {
  187. if (p_name == "notarization/api_uuid") {
  188. String api_uuid = p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID);
  189. if (api_uuid.is_empty()) {
  190. return TTR("App Store Connect issuer ID name not specified.");
  191. }
  192. }
  193. if (p_name == "notarization/api_key_id") {
  194. String api_key = p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID);
  195. if (api_key.is_empty()) {
  196. return TTR("App Store Connect API key ID not specified.");
  197. }
  198. }
  199. }
  200. if (codesign_tool > 0) {
  201. if (p_name == "privacy/microphone_usage_description") {
  202. String discr = p_preset->get("privacy/microphone_usage_description");
  203. bool enabled = p_preset->get("codesign/entitlements/audio_input");
  204. if (enabled && discr.is_empty()) {
  205. return TTR("Microphone access is enabled, but usage description is not specified.");
  206. }
  207. }
  208. if (p_name == "privacy/camera_usage_description") {
  209. String discr = p_preset->get("privacy/camera_usage_description");
  210. bool enabled = p_preset->get("codesign/entitlements/camera");
  211. if (enabled && discr.is_empty()) {
  212. return TTR("Camera access is enabled, but usage description is not specified.");
  213. }
  214. }
  215. if (p_name == "privacy/location_usage_description") {
  216. String discr = p_preset->get("privacy/location_usage_description");
  217. bool enabled = p_preset->get("codesign/entitlements/location");
  218. if (enabled && discr.is_empty()) {
  219. return TTR("Location information access is enabled, but usage description is not specified.");
  220. }
  221. }
  222. if (p_name == "privacy/address_book_usage_description") {
  223. String discr = p_preset->get("privacy/address_book_usage_description");
  224. bool enabled = p_preset->get("codesign/entitlements/address_book");
  225. if (enabled && discr.is_empty()) {
  226. return TTR("Address book access is enabled, but usage description is not specified.");
  227. }
  228. }
  229. if (p_name == "privacy/calendar_usage_description") {
  230. String discr = p_preset->get("privacy/calendar_usage_description");
  231. bool enabled = p_preset->get("codesign/entitlements/calendars");
  232. if (enabled && discr.is_empty()) {
  233. return TTR("Calendar access is enabled, but usage description is not specified.");
  234. }
  235. }
  236. if (p_name == "privacy/photos_library_usage_description") {
  237. String discr = p_preset->get("privacy/photos_library_usage_description");
  238. bool enabled = p_preset->get("codesign/entitlements/photos_library");
  239. if (enabled && discr.is_empty()) {
  240. return TTR("Photo library access is enabled, but usage description is not specified.");
  241. }
  242. }
  243. }
  244. }
  245. return String();
  246. }
  247. bool EditorExportPlatformMacOS::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {
  248. // Hide irrelevant code signing options.
  249. if (p_preset) {
  250. int codesign_tool = p_preset->get("codesign/codesign");
  251. switch (codesign_tool) {
  252. case 1: { // built-in ad-hoc
  253. if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options" || p_option == "codesign/team_id") {
  254. return false;
  255. }
  256. } break;
  257. case 2: { // "rcodesign"
  258. if (p_option == "codesign/identity") {
  259. return false;
  260. }
  261. } break;
  262. #ifdef MACOS_ENABLED
  263. case 3: { // "codesign"
  264. if (p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password") {
  265. return false;
  266. }
  267. } break;
  268. #endif
  269. default: { // disabled
  270. 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") || p_option == "codesign/team_id") {
  271. return false;
  272. }
  273. } break;
  274. }
  275. // Distribution type.
  276. int dist_type = p_preset->get("export/distribution_type");
  277. if (dist_type != 2 && p_option == "codesign/installer_identity") {
  278. return false;
  279. }
  280. if (dist_type == 2 && p_option.begins_with("notarization/")) {
  281. return false;
  282. }
  283. if (dist_type != 2 && p_option == "codesign/provisioning_profile") {
  284. return false;
  285. }
  286. #ifndef MACOS_ENABLED
  287. if (p_option == "application/liquid_glass_icon") {
  288. return false;
  289. }
  290. #endif
  291. String custom_prof = p_preset->get("codesign/entitlements/custom_file");
  292. if (!custom_prof.is_empty() && p_option != "codesign/entitlements/custom_file" && p_option.begins_with("codesign/entitlements/")) {
  293. return false;
  294. }
  295. // Hide sandbox entitlements.
  296. bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");
  297. if (!sandbox && p_option != "codesign/entitlements/app_sandbox/enabled" && p_option.begins_with("codesign/entitlements/app_sandbox/")) {
  298. return false;
  299. }
  300. // Hide SSH options.
  301. bool ssh = p_preset->get("ssh_remote_deploy/enabled");
  302. if (!ssh && p_option != "ssh_remote_deploy/enabled" && p_option.begins_with("ssh_remote_deploy/")) {
  303. return false;
  304. }
  305. // Hide irrelevant notarization options.
  306. int notary_tool = p_preset->get("notarization/notarization");
  307. switch (notary_tool) {
  308. case 1: { // "rcodesign"
  309. if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password") {
  310. return false;
  311. }
  312. } break;
  313. case 2: { // "notarytool"
  314. // All options are visible.
  315. } break;
  316. default: { // disabled
  317. if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/api_uuid" || p_option == "notarization/api_key" || p_option == "notarization/api_key_id") {
  318. return false;
  319. }
  320. } break;
  321. }
  322. bool advanced_options_enabled = p_preset->are_advanced_options_enabled();
  323. if (p_option.begins_with("privacy") ||
  324. p_option == "codesign/entitlements/additional" ||
  325. p_option == "custom_template/debug" ||
  326. p_option == "custom_template/release" ||
  327. p_option == "application/additional_plist_content" ||
  328. p_option == "application/export_angle" ||
  329. p_option == "application/icon_interpolation" ||
  330. p_option == "application/signature" ||
  331. p_option == "display/high_res" ||
  332. p_option == "xcode/platform_build" ||
  333. p_option == "xcode/sdk_build" ||
  334. p_option == "xcode/sdk_name" ||
  335. p_option == "xcode/sdk_version" ||
  336. p_option == "xcode/xcode_build" ||
  337. p_option == "xcode/xcode_version") {
  338. return advanced_options_enabled;
  339. }
  340. }
  341. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  342. if (ClassDB::class_exists("CSharpScript")) {
  343. 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") {
  344. return false;
  345. }
  346. }
  347. // Hide unsupported .NET embedding option.
  348. if (p_option == "dotnet/embed_build_outputs") {
  349. return false;
  350. }
  351. return true;
  352. }
  353. List<String> EditorExportPlatformMacOS::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
  354. List<String> list;
  355. if (p_preset.is_valid()) {
  356. int dist_type = p_preset->get("export/distribution_type");
  357. if (dist_type == 0) {
  358. #ifdef MACOS_ENABLED
  359. list.push_back("dmg");
  360. #endif
  361. list.push_back("zip");
  362. list.push_back("app");
  363. } else if (dist_type == 1) {
  364. #ifdef MACOS_ENABLED
  365. list.push_back("dmg");
  366. #endif
  367. list.push_back("zip");
  368. list.push_back("app");
  369. } else if (dist_type == 2) {
  370. #ifdef MACOS_ENABLED
  371. list.push_back("pkg");
  372. #endif
  373. }
  374. }
  375. return list;
  376. }
  377. struct DataCollectionInfo {
  378. String prop_name;
  379. String type_name;
  380. };
  381. static const DataCollectionInfo data_collect_type_info[] = {
  382. { "name", "NSPrivacyCollectedDataTypeName" },
  383. { "email_address", "NSPrivacyCollectedDataTypeEmailAddress" },
  384. { "phone_number", "NSPrivacyCollectedDataTypePhoneNumber" },
  385. { "physical_address", "NSPrivacyCollectedDataTypePhysicalAddress" },
  386. { "other_contact_info", "NSPrivacyCollectedDataTypeOtherUserContactInfo" },
  387. { "health", "NSPrivacyCollectedDataTypeHealth" },
  388. { "fitness", "NSPrivacyCollectedDataTypeFitness" },
  389. { "payment_info", "NSPrivacyCollectedDataTypePaymentInfo" },
  390. { "credit_info", "NSPrivacyCollectedDataTypeCreditInfo" },
  391. { "other_financial_info", "NSPrivacyCollectedDataTypeOtherFinancialInfo" },
  392. { "precise_location", "NSPrivacyCollectedDataTypePreciseLocation" },
  393. { "coarse_location", "NSPrivacyCollectedDataTypeCoarseLocation" },
  394. { "sensitive_info", "NSPrivacyCollectedDataTypeSensitiveInfo" },
  395. { "contacts", "NSPrivacyCollectedDataTypeContacts" },
  396. { "emails_or_text_messages", "NSPrivacyCollectedDataTypeEmailsOrTextMessages" },
  397. { "photos_or_videos", "NSPrivacyCollectedDataTypePhotosorVideos" },
  398. { "audio_data", "NSPrivacyCollectedDataTypeAudioData" },
  399. { "gameplay_content", "NSPrivacyCollectedDataTypeGameplayContent" },
  400. { "customer_support", "NSPrivacyCollectedDataTypeCustomerSupport" },
  401. { "other_user_content", "NSPrivacyCollectedDataTypeOtherUserContent" },
  402. { "browsing_history", "NSPrivacyCollectedDataTypeBrowsingHistory" },
  403. { "search_history", "NSPrivacyCollectedDataTypeSearchHistory" },
  404. { "user_id", "NSPrivacyCollectedDataTypeUserID" },
  405. { "device_id", "NSPrivacyCollectedDataTypeDeviceID" },
  406. { "purchase_history", "NSPrivacyCollectedDataTypePurchaseHistory" },
  407. { "product_interaction", "NSPrivacyCollectedDataTypeProductInteraction" },
  408. { "advertising_data", "NSPrivacyCollectedDataTypeAdvertisingData" },
  409. { "other_usage_data", "NSPrivacyCollectedDataTypeOtherUsageData" },
  410. { "crash_data", "NSPrivacyCollectedDataTypeCrashData" },
  411. { "performance_data", "NSPrivacyCollectedDataTypePerformanceData" },
  412. { "other_diagnostic_data", "NSPrivacyCollectedDataTypeOtherDiagnosticData" },
  413. { "environment_scanning", "NSPrivacyCollectedDataTypeEnvironmentScanning" },
  414. { "hands", "NSPrivacyCollectedDataTypeHands" },
  415. { "head", "NSPrivacyCollectedDataTypeHead" },
  416. { "other_data_types", "NSPrivacyCollectedDataTypeOtherDataTypes" },
  417. };
  418. static const DataCollectionInfo data_collect_purpose_info[] = {
  419. { "Analytics", "NSPrivacyCollectedDataTypePurposeAnalytics" },
  420. { "App Functionality", "NSPrivacyCollectedDataTypePurposeAppFunctionality" },
  421. { "Developer Advertising", "NSPrivacyCollectedDataTypePurposeDeveloperAdvertising" },
  422. { "Third-party Advertising", "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising" },
  423. { "Product Personalization", "NSPrivacyCollectedDataTypePurposeProductPersonalization" },
  424. { "Other", "NSPrivacyCollectedDataTypePurposeOther" },
  425. };
  426. void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options) const {
  427. #ifdef MACOS_ENABLED
  428. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution,App Store"), 1, true));
  429. #else
  430. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "export/distribution_type", PROPERTY_HINT_ENUM, "Testing,Distribution"), 1, true));
  431. #endif
  432. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "binary_format/architecture", PROPERTY_HINT_ENUM, "universal,x86_64,arm64", PROPERTY_USAGE_STORAGE), "universal"));
  433. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  434. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  435. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "debug/export_console_wrapper", PROPERTY_HINT_ENUM, "No,Debug Only,Debug and Release"), 1));
  436. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/liquid_glass_icon", PROPERTY_HINT_FILE, "*.icon"), ""));
  437. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.icns,*.png,*.webp,*.svg"), ""));
  438. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
  439. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "", false, true));
  440. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  441. 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"));
  442. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
  443. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
  444. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  445. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "application/copyright_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  446. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version_x86_64"), "10.12"));
  447. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/min_macos_version_arm64"), "11.00"));
  448. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_angle", PROPERTY_HINT_ENUM, "Auto,Yes,No"), 0, true));
  449. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), true));
  450. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "shader_baker/enabled"), false));
  451. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/additional_plist_content", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), ""));
  452. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/platform_build"), "14C18"));
  453. // TODO(sgc): Need to set appropriate version when using Metal
  454. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_version"), "13.1"));
  455. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_build"), "22C55"));
  456. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/sdk_name"), "macosx13.1"));
  457. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_version"), "1420"));
  458. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "xcode/xcode_build"), "14C18"));
  459. #ifdef MACOS_ENABLED
  460. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign,Xcode codesign"), 3, true));
  461. #else
  462. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign"), 1, true, true));
  463. #endif
  464. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/installer_identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "3rd Party Mac Developer Installer: (ID)"), "", false, true));
  465. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/apple_team_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "ID"), "", false, true));
  466. // "codesign" only options:
  467. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), ""));
  468. // "rcodesign" only options:
  469. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_file", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
  470. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_password", PROPERTY_HINT_PASSWORD, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
  471. // "codesign" and "rcodesign" only options:
  472. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/provisioning_profile", PROPERTY_HINT_GLOBAL_FILE, "*.provisionprofile", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
  473. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), "", true));
  474. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false));
  475. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false));
  476. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false));
  477. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false));
  478. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false));
  479. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false));
  480. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/location"), false));
  481. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/address_book"), false));
  482. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/calendars"), false));
  483. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/photos_library"), false));
  484. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/apple_events"), false));
  485. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/debugging"), false));
  486. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/enabled"), false, true, true));
  487. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_server"), false));
  488. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_client"), false));
  489. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_usb"), false));
  490. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_bluetooth"), false));
  491. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_downloads", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  492. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_pictures", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  493. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_music", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  494. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_movies", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  495. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_user_selected", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  496. 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()));
  497. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/additional", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), ""));
  498. r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
  499. #ifdef MACOS_ENABLED
  500. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign,Xcode notarytool"), 0, true));
  501. #else
  502. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign"), 0, true));
  503. #endif
  504. // "notarytool" only options:
  505. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple ID email", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
  506. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_password", PROPERTY_HINT_PASSWORD, "Enable two-factor authentication and provide app-specific password", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
  507. // "notarytool" and "rcodesign" only options:
  508. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_uuid", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect issuer ID UUID", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
  509. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_GLOBAL_FILE, "*.p8", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
  510. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect API key ID", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), "", false, true));
  511. 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"), "", false, true));
  512. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  513. 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"), "", false, true));
  514. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/camera_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  515. 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"), "", false, true));
  516. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/location_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  517. 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"), "", false, true));
  518. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/address_book_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  519. 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"), "", false, true));
  520. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/calendar_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  521. 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"), "", false, true));
  522. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/photos_library_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  523. 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"), "", false, true));
  524. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/desktop_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  525. 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"), "", false, true));
  526. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/documents_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  527. 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"), "", false, true));
  528. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/downloads_folder_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  529. 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"), "", false, true));
  530. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/network_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  531. 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"), "", false, true));
  532. r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/removable_volumes_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()));
  533. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "privacy/tracking_enabled"), false));
  534. r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "privacy/tracking_domains"), Vector<String>()));
  535. {
  536. String hint;
  537. for (uint64_t i = 0; i < std_size(data_collect_purpose_info); ++i) {
  538. if (i != 0) {
  539. hint += ",";
  540. }
  541. hint += vformat("%s:%d", data_collect_purpose_info[i].prop_name, (1 << i));
  542. }
  543. for (uint64_t i = 0; i < std_size(data_collect_type_info); ++i) {
  544. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/collected", data_collect_type_info[i].prop_name)), false));
  545. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[i].prop_name)), false));
  546. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[i].prop_name)), false));
  547. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[i].prop_name), PROPERTY_HINT_FLAGS, hint), 0));
  548. }
  549. }
  550. String run_script = "#!/usr/bin/env bash\n"
  551. "unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"\n"
  552. "open \"{temp_dir}/{exe_name}.app\" --args {cmd_args}";
  553. String cleanup_script = "#!/usr/bin/env bash\n"
  554. "pkill -x -f \"{temp_dir}/{exe_name}.app/Contents/MacOS/{exe_name} {cmd_args}\"\n"
  555. "rm -rf \"{temp_dir}\"";
  556. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true));
  557. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/host"), "user@host_ip"));
  558. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/port"), "22"));
  559. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_ssh", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), ""));
  560. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_scp", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), ""));
  561. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/run_script", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), run_script));
  562. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/cleanup_script", PROPERTY_HINT_MULTILINE_TEXT, "monospace,no_wrap"), cleanup_script));
  563. }
  564. void _rgba8_to_packbits_encode(int p_ch, int p_size, Vector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {
  565. int src_len = p_size * p_size;
  566. Vector<uint8_t> result;
  567. int i = 0;
  568. const uint8_t *src = p_source.ptr();
  569. while (i < src_len) {
  570. Vector<uint8_t> seq;
  571. uint8_t count = 0;
  572. while (count <= 0x7f && i < src_len) {
  573. if (i + 2 < src_len && src[i * 4 + p_ch] == src[(i + 1) * 4 + p_ch] && src[i] == src[(i + 2) * 4 + p_ch]) {
  574. break;
  575. }
  576. seq.push_back(src[i * 4 + p_ch]);
  577. i++;
  578. count++;
  579. }
  580. if (!seq.is_empty()) {
  581. result.push_back(count - 1);
  582. result.append_array(seq);
  583. }
  584. if (i >= src_len) {
  585. break;
  586. }
  587. uint8_t rep = src[i * 4 + p_ch];
  588. count = 0;
  589. while (count <= 0x7f && i < src_len && src[i * 4 + p_ch] == rep) {
  590. i++;
  591. count++;
  592. }
  593. if (count >= 3) {
  594. result.push_back(0x80 + count - 3);
  595. result.push_back(rep);
  596. } else {
  597. result.push_back(count - 1);
  598. for (int j = 0; j < count; j++) {
  599. result.push_back(rep);
  600. }
  601. }
  602. }
  603. int ofs = p_dest.size();
  604. p_dest.resize(p_dest.size() + result.size());
  605. memcpy(&p_dest.write[ofs], result.ptr(), result.size());
  606. }
  607. void EditorExportPlatformMacOS::_make_icon(const Ref<EditorExportPreset> &p_preset, const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
  608. Vector<uint8_t> data;
  609. data.resize(8);
  610. data.write[0] = 'i';
  611. data.write[1] = 'c';
  612. data.write[2] = 'n';
  613. data.write[3] = 's';
  614. struct MacOSIconInfo {
  615. const char *name;
  616. const char *mask_name;
  617. bool is_png;
  618. int size;
  619. };
  620. static const MacOSIconInfo icon_infos[] = {
  621. { "ic10", "", true, 1024 }, //1024×1024 32-bit PNG and 512×512@2x 32-bit "retina" PNG
  622. { "ic09", "", true, 512 }, //512×512 32-bit PNG
  623. { "ic14", "", true, 512 }, //256×256@2x 32-bit "retina" PNG
  624. { "ic08", "", true, 256 }, //256×256 32-bit PNG
  625. { "ic13", "", true, 256 }, //128×128@2x 32-bit "retina" PNG
  626. { "ic07", "", true, 128 }, //128×128 32-bit PNG
  627. { "ic12", "", true, 64 }, //32×32@2× 32-bit "retina" PNG
  628. { "ic11", "", true, 32 }, //16×16@2× 32-bit "retina" PNG
  629. { "il32", "l8mk", false, 32 }, //32×32 24-bit RLE + 8-bit uncompressed mask
  630. { "is32", "s8mk", false, 16 } //16×16 24-bit RLE + 8-bit uncompressed mask
  631. };
  632. for (uint64_t i = 0; i < std_size(icon_infos); ++i) {
  633. Ref<Image> copy = p_icon->duplicate();
  634. copy->convert(Image::FORMAT_RGBA8);
  635. copy->resize(icon_infos[i].size, icon_infos[i].size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
  636. if (icon_infos[i].is_png) {
  637. // Encode PNG icon.
  638. Vector<uint8_t> png_buffer;
  639. Error err = PNGDriverCommon::image_to_png(copy, png_buffer);
  640. if (err == OK) {
  641. int ofs = data.size();
  642. uint64_t len = png_buffer.size();
  643. data.resize(data.size() + len + 8);
  644. memcpy(&data.write[ofs + 8], png_buffer.ptr(), len);
  645. len += 8;
  646. len = BSWAP32(len);
  647. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  648. encode_uint32(len, &data.write[ofs + 4]);
  649. }
  650. } else {
  651. Vector<uint8_t> src_data = copy->get_data();
  652. // Encode 24-bit RGB RLE icon.
  653. {
  654. int ofs = data.size();
  655. data.resize(data.size() + 8);
  656. _rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // Encode R.
  657. _rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // Encode G.
  658. _rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // Encode B.
  659. // Note: workaround for macOS icon decoder bug corrupting last RLE encoded value.
  660. data.push_back(0x00);
  661. int len = data.size() - ofs;
  662. len = BSWAP32(len);
  663. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  664. encode_uint32(len, &data.write[ofs + 4]);
  665. }
  666. // Encode 8-bit mask uncompressed icon.
  667. {
  668. int ofs = data.size();
  669. int len = copy->get_width() * copy->get_height();
  670. data.resize(data.size() + len + 8);
  671. for (int j = 0; j < len; j++) {
  672. data.write[ofs + 8 + j] = src_data.ptr()[j * 4 + 3];
  673. }
  674. len += 8;
  675. len = BSWAP32(len);
  676. memcpy(&data.write[ofs], icon_infos[i].mask_name, 4);
  677. encode_uint32(len, &data.write[ofs + 4]);
  678. }
  679. }
  680. }
  681. uint32_t total_len = data.size();
  682. total_len = BSWAP32(total_len);
  683. encode_uint32(total_len, &data.write[4]);
  684. p_data = data;
  685. }
  686. void EditorExportPlatformMacOS::_fix_privacy_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist) {
  687. String str = String::utf8((const char *)plist.ptr(), plist.size());
  688. String strnew;
  689. Vector<String> lines = str.split("\n");
  690. for (int i = 0; i < lines.size(); i++) {
  691. if (lines[i].find("$priv_collection") != -1) {
  692. bool section_opened = false;
  693. for (uint64_t j = 0; j < std_size(data_collect_type_info); ++j) {
  694. bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name));
  695. bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name));
  696. bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name));
  697. int purposes = p_preset->get(vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[j].prop_name));
  698. if (data_collected) {
  699. if (!section_opened) {
  700. section_opened = true;
  701. strnew += "\t<key>NSPrivacyCollectedDataTypes</key>\n";
  702. strnew += "\t<array>\n";
  703. }
  704. strnew += "\t\t<dict>\n";
  705. strnew += "\t\t\t<key>NSPrivacyCollectedDataType</key>\n";
  706. strnew += vformat("\t\t\t<string>%s</string>\n", data_collect_type_info[j].type_name);
  707. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeLinked</key>\n";
  708. if (linked) {
  709. strnew += "\t\t\t\t<true/>\n";
  710. } else {
  711. strnew += "\t\t\t\t<false/>\n";
  712. }
  713. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeTracking</key>\n";
  714. if (tracking) {
  715. strnew += "\t\t\t\t<true/>\n";
  716. } else {
  717. strnew += "\t\t\t\t<false/>\n";
  718. }
  719. if (purposes != 0) {
  720. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n";
  721. strnew += "\t\t\t\t<array>\n";
  722. for (uint64_t k = 0; k < std_size(data_collect_purpose_info); ++k) {
  723. if (purposes & (1 << k)) {
  724. strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name);
  725. }
  726. }
  727. strnew += "\t\t\t\t</array>\n";
  728. }
  729. strnew += "\t\t\t</dict>\n";
  730. }
  731. }
  732. if (section_opened) {
  733. strnew += "\t</array>\n";
  734. }
  735. } else if (lines[i].find("$priv_tracking") != -1) {
  736. bool tracking = p_preset->get("privacy/tracking_enabled");
  737. strnew += "\t<key>NSPrivacyTracking</key>\n";
  738. if (tracking) {
  739. strnew += "\t<true/>\n";
  740. } else {
  741. strnew += "\t<false/>\n";
  742. }
  743. Vector<String> tracking_domains = p_preset->get("privacy/tracking_domains");
  744. if (!tracking_domains.is_empty()) {
  745. strnew += "\t<key>NSPrivacyTrackingDomains</key>\n";
  746. strnew += "\t<array>\n";
  747. for (const String &E : tracking_domains) {
  748. strnew += "\t\t<string>" + E + "</string>\n";
  749. }
  750. strnew += "\t</array>\n";
  751. }
  752. } else {
  753. strnew += lines[i] + "\n";
  754. }
  755. }
  756. CharString cs = strnew.utf8();
  757. plist.resize(cs.size() - 1);
  758. for (int i = 0; i < cs.size() - 1; i++) {
  759. plist.write[i] = cs[i];
  760. }
  761. }
  762. void EditorExportPlatformMacOS::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary, bool p_lg_icon_exported, const String &p_lg_icon) {
  763. String str = String::utf8((const char *)plist.ptr(), plist.size());
  764. String strnew;
  765. Vector<String> lines = str.split("\n");
  766. for (int i = 0; i < lines.size(); i++) {
  767. if (lines[i].contains("$binary")) {
  768. strnew += lines[i].replace("$binary", p_binary) + "\n";
  769. } else if (lines[i].contains("$name")) {
  770. strnew += lines[i].replace("$name", get_project_setting(p_preset, "application/config/name").operator String().xml_escape(true)) + "\n";
  771. } else if (lines[i].contains("$bundle_identifier")) {
  772. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  773. } else if (lines[i].contains("$short_version")) {
  774. strnew += lines[i].replace("$short_version", p_preset->get_version("application/short_version")) + "\n";
  775. } else if (lines[i].contains("$version")) {
  776. strnew += lines[i].replace("$version", p_preset->get_version("application/version")) + "\n";
  777. } else if (lines[i].contains("$signature")) {
  778. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  779. } else if (lines[i].contains("$app_category")) {
  780. String cat = p_preset->get("application/app_category");
  781. strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n";
  782. } else if (lines[i].contains("$copyright")) {
  783. strnew += lines[i].replace("$copyright", p_preset->get("application/copyright").operator String().xml_escape(true)) + "\n";
  784. } else if (lines[i].contains("$min_version_arm64")) {
  785. strnew += lines[i].replace("$min_version_arm64", p_preset->get("application/min_macos_version_arm64")) + "\n";
  786. } else if (lines[i].contains("$min_version_x86_64")) {
  787. strnew += lines[i].replace("$min_version_x86_64", p_preset->get("application/min_macos_version_x86_64")) + "\n";
  788. } else if (lines[i].contains("$min_version")) {
  789. strnew += lines[i].replace("$min_version", p_preset->get("application/min_macos_version_x86_64")) + "\n"; // Old template, use x86-64 version for both.
  790. } else if (lines[i].contains("$highres")) {
  791. strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "\t<true/>" : "\t<false/>") + "\n";
  792. } else if (lines[i].contains("$additional_plist_content")) {
  793. strnew += lines[i].replace("$additional_plist_content", p_preset->get("application/additional_plist_content")) + "\n";
  794. } else if (lines[i].contains("$platfbuild")) {
  795. strnew += lines[i].replace("$platfbuild", p_preset->get("xcode/platform_build")) + "\n";
  796. } else if (lines[i].contains("$sdkver")) {
  797. strnew += lines[i].replace("$sdkver", p_preset->get("xcode/sdk_version")) + "\n";
  798. } else if (lines[i].contains("$sdkname")) {
  799. strnew += lines[i].replace("$sdkname", p_preset->get("xcode/sdk_name")) + "\n";
  800. } else if (lines[i].contains("$sdkbuild")) {
  801. strnew += lines[i].replace("$sdkbuild", p_preset->get("xcode/sdk_build")) + "\n";
  802. } else if (lines[i].contains("$xcodever")) {
  803. strnew += lines[i].replace("$xcodever", p_preset->get("xcode/xcode_version")) + "\n";
  804. } else if (lines[i].contains("$xcodebuild")) {
  805. strnew += lines[i].replace("$xcodebuild", p_preset->get("xcode/xcode_build")) + "\n";
  806. } else if (lines[i].contains("$liquid_glass_icon")) {
  807. if (p_lg_icon_exported) {
  808. strnew += lines[i].replace("$liquid_glass_icon", "\t<key>CFBundleIconName</key>\n\t<string>" + p_lg_icon + "</string>\n");
  809. } else {
  810. strnew += lines[i].replace("$liquid_glass_icon", "");
  811. }
  812. } else if (lines[i].contains("$usage_descriptions")) {
  813. String descriptions;
  814. if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
  815. descriptions += "\t<key>NSMicrophoneUsageDescription</key>\n";
  816. descriptions += "\t<string>" + p_preset->get("privacy/microphone_usage_description").operator String().xml_escape(true) + "</string>\n";
  817. }
  818. if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
  819. descriptions += "\t<key>NSCameraUsageDescription</key>\n";
  820. descriptions += "\t<string>" + p_preset->get("privacy/camera_usage_description").operator String().xml_escape(true) + "</string>\n";
  821. }
  822. if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
  823. descriptions += "\t<key>NSLocationUsageDescription</key>\n";
  824. descriptions += "\t<string>" + p_preset->get("privacy/location_usage_description").operator String().xml_escape(true) + "</string>\n";
  825. }
  826. if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
  827. descriptions += "\t<key>NSContactsUsageDescription</key>\n";
  828. descriptions += "\t<string>" + p_preset->get("privacy/address_book_usage_description").operator String().xml_escape(true) + "</string>\n";
  829. }
  830. if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
  831. descriptions += "\t<key>NSCalendarsUsageDescription</key>\n";
  832. descriptions += "\t<string>" + p_preset->get("privacy/calendar_usage_description").operator String().xml_escape(true) + "</string>\n";
  833. }
  834. if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
  835. descriptions += "\t<key>NSPhotoLibraryUsageDescription</key>\n";
  836. descriptions += "\t<string>" + p_preset->get("privacy/photos_library_usage_description").operator String().xml_escape(true) + "</string>\n";
  837. }
  838. if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {
  839. descriptions += "\t<key>NSDesktopFolderUsageDescription</key>\n";
  840. descriptions += "\t<string>" + p_preset->get("privacy/desktop_folder_usage_description").operator String().xml_escape(true) + "</string>\n";
  841. }
  842. if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {
  843. descriptions += "\t<key>NSDocumentsFolderUsageDescription</key>\n";
  844. descriptions += "\t<string>" + p_preset->get("privacy/documents_folder_usage_description").operator String().xml_escape(true) + "</string>\n";
  845. }
  846. if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {
  847. descriptions += "\t<key>NSDownloadsFolderUsageDescription</key>\n";
  848. descriptions += "\t<string>" + p_preset->get("privacy/downloads_folder_usage_description").operator String().xml_escape(true) + "</string>\n";
  849. }
  850. if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {
  851. descriptions += "\t<key>NSNetworkVolumesUsageDescription</key>\n";
  852. descriptions += "\t<string>" + p_preset->get("privacy/network_volumes_usage_description").operator String().xml_escape(true) + "</string>\n";
  853. }
  854. if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {
  855. descriptions += "\t<key>NSRemovableVolumesUsageDescription</key>\n";
  856. descriptions += "\t<string>" + p_preset->get("privacy/removable_volumes_usage_description").operator String().xml_escape(true) + "</string>\n";
  857. }
  858. if (!descriptions.is_empty()) {
  859. strnew += lines[i].replace("$usage_descriptions", descriptions);
  860. }
  861. } else {
  862. strnew += lines[i] + "\n";
  863. }
  864. }
  865. CharString cs = strnew.utf8();
  866. plist.resize(cs.size() - 1);
  867. for (int i = 0; i < cs.size() - 1; i++) {
  868. plist.write[i] = cs[i];
  869. }
  870. }
  871. Error EditorExportPlatformMacOS::_export_liquid_glass_icon(const Ref<EditorExportPreset> &p_preset, const String &p_app_path, const String &p_icon_path) {
  872. String actool = EDITOR_GET("export/macos/actool").operator String();
  873. if (actool.is_empty()) {
  874. actool = "actool";
  875. }
  876. List<String> args;
  877. args.push_back("--version");
  878. String str;
  879. String err_str;
  880. int exitcode = 0;
  881. Error err = OS::get_singleton()->execute(actool, args, &str, &exitcode, true);
  882. if (err != OK) {
  883. add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not start 'actool' executable."));
  884. return err;
  885. }
  886. PList info_plist;
  887. if (!info_plist.load_string(str, err_str)) {
  888. print_verbose(str);
  889. add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not read 'actool' version."));
  890. return err;
  891. }
  892. if (info_plist.get_root()->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && info_plist.get_root()->data_dict.has("com.apple.actool.version")) {
  893. Ref<PListNode> dict = info_plist.get_root()->data_dict["com.apple.actool.version"];
  894. if (dict->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && dict->data_dict.has("short-bundle-version")) {
  895. float version = String::utf8(dict->data_dict["short-bundle-version"]->data_string.get_data()).to_float();
  896. if (version < 26.0) {
  897. add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), vformat(TTR("At least version 26.0 of 'actool' is required (version %f found)."), version));
  898. return ERR_UNAVAILABLE;
  899. }
  900. }
  901. }
  902. str.clear();
  903. String plist = EditorPaths::get_singleton()->get_temp_dir().path_join("assetcatalog.plist");
  904. args.clear();
  905. args.push_back(ProjectSettings::get_singleton()->globalize_path(p_icon_path));
  906. args.push_back("--compile");
  907. args.push_back(p_app_path + "/Contents/Resources/");
  908. args.push_back("--output-format");
  909. args.push_back("human-readable-text");
  910. args.push_back("--lightweight-asset-runtime-mode");
  911. args.push_back("enabled");
  912. args.push_back("--app-icon");
  913. args.push_back(p_icon_path.get_file().get_basename());
  914. args.push_back("--include-all-app-icons");
  915. args.push_back("--enable-on-demand-resources");
  916. args.push_back("NO");
  917. args.push_back("--development-region");
  918. args.push_back("en");
  919. args.push_back("--target-device");
  920. args.push_back("mac");
  921. args.push_back("--minimum-deployment-target");
  922. args.push_back("26");
  923. args.push_back("--platform");
  924. args.push_back("macosx");
  925. args.push_back("--output-partial-info-plist");
  926. args.push_back(plist);
  927. err = OS::get_singleton()->execute(actool, args, &str, &exitcode, true);
  928. if (err != OK || str.contains("error:") || !FileAccess::exists(p_app_path + "/Contents/Resources/Assets.car") || !FileAccess::exists(plist)) {
  929. print_verbose(str);
  930. add_message(EXPORT_MESSAGE_WARNING, TTR("Liquid Glass Icons"), TTR("Could not export liquid glass icon:") + "\n" + str);
  931. return err;
  932. }
  933. return OK;
  934. }
  935. /**
  936. * If we're running the macOS version of the Godot editor we'll:
  937. * - export our application bundle to a temporary folder
  938. * - attempt to code sign it
  939. * - and then wrap it up in a DMG
  940. */
  941. Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  942. int notary_tool = p_preset->get("notarization/notarization");
  943. switch (notary_tool) {
  944. case 1: { // "rcodesign"
  945. print_verbose("using rcodesign notarization...");
  946. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  947. if (rcodesign.is_empty()) {
  948. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));
  949. return Error::FAILED;
  950. }
  951. List<String> args;
  952. args.push_back("notary-submit");
  953. if (p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) == "") {
  954. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect issuer ID name not specified."));
  955. return Error::FAILED;
  956. }
  957. if (p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY) == "") {
  958. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));
  959. return Error::FAILED;
  960. }
  961. args.push_back("--api-issuer");
  962. args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID));
  963. args.push_back("--api-key");
  964. args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID));
  965. if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) {
  966. args.push_back("--api-key-path");
  967. args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY));
  968. }
  969. args.push_back(p_path);
  970. String str;
  971. int exitcode = 0;
  972. Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);
  973. if (err != OK) {
  974. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start rcodesign executable."));
  975. return err;
  976. }
  977. int rq_offset = str.find("created submission ID:");
  978. if (exitcode != 0 || rq_offset == -1) {
  979. print_line("rcodesign (" + p_path + "):\n" + str);
  980. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));
  981. return Error::FAILED;
  982. } else {
  983. print_verbose("rcodesign (" + p_path + "):\n" + str);
  984. int next_nl = str.find_char('\n', rq_offset);
  985. String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 23) : str.substr(rq_offset + 23, next_nl - rq_offset - 23);
  986. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));
  987. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour."));
  988. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check the progress manually by opening a Terminal and running the following command:"));
  989. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign notary-log --api-issuer <API UUID> --api-key <API key> <request UUID>\"");
  990. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));
  991. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign staple <app path>\"");
  992. }
  993. } break;
  994. #ifdef MACOS_ENABLED
  995. case 2: { // "notarytool"
  996. print_verbose("using notarytool notarization...");
  997. if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {
  998. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed."));
  999. return Error::FAILED;
  1000. }
  1001. List<String> args;
  1002. args.push_back("notarytool");
  1003. args.push_back("submit");
  1004. args.push_back(p_path);
  1005. if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) == "" && p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) == "") {
  1006. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified."));
  1007. return Error::FAILED;
  1008. }
  1009. if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) != "" && p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) != "") {
  1010. 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."));
  1011. return Error::FAILED;
  1012. }
  1013. if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) != "") {
  1014. if (p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS) == "") {
  1015. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified."));
  1016. return Error::FAILED;
  1017. }
  1018. args.push_back("--apple-id");
  1019. args.push_back(p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID));
  1020. args.push_back("--password");
  1021. args.push_back(p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS));
  1022. } else {
  1023. if (p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID) == "") {
  1024. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));
  1025. return Error::FAILED;
  1026. }
  1027. args.push_back("--issuer");
  1028. args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID));
  1029. if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) {
  1030. args.push_back("--key");
  1031. args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY));
  1032. }
  1033. args.push_back("--key-id");
  1034. args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID));
  1035. }
  1036. args.push_back("--no-progress");
  1037. if (p_preset->get("codesign/apple_team_id")) {
  1038. args.push_back("--team-id");
  1039. args.push_back(p_preset->get("codesign/apple_team_id"));
  1040. }
  1041. String str;
  1042. int exitcode = 0;
  1043. Error err = OS::get_singleton()->execute("xcrun", args, &str, &exitcode, true);
  1044. if (err != OK) {
  1045. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable."));
  1046. return err;
  1047. }
  1048. int rq_offset = str.find("id:");
  1049. if (exitcode != 0 || rq_offset == -1) {
  1050. print_line("notarytool (" + p_path + "):\n" + str);
  1051. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));
  1052. return Error::FAILED;
  1053. } else {
  1054. print_verbose("notarytool (" + p_path + "):\n" + str);
  1055. int next_nl = str.find_char('\n', rq_offset);
  1056. String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 4) : str.substr(rq_offset + 4, next_nl - rq_offset - 4);
  1057. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));
  1058. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour."));
  1059. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("See instructions on finding your team ID: https://developer.apple.com/help/glossary/team-id"));
  1060. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check the progress manually by opening a Terminal and running the following command:"));
  1061. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request UUID> --issuer <API UUID> --key-id <API key ID> --key <API key path>\" or");
  1062. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request UUID> --team-id <team ID> --apple-id <your email> --password <app-specific password>\"");
  1063. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));
  1064. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple <app path>\"");
  1065. }
  1066. } break;
  1067. #endif
  1068. default: {
  1069. };
  1070. }
  1071. return OK;
  1072. }
  1073. void EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_warn, bool p_set_id) {
  1074. int codesign_tool = p_preset->get("codesign/codesign");
  1075. switch (codesign_tool) {
  1076. case 1: { // built-in ad-hoc
  1077. print_verbose("using built-in codesign...");
  1078. String error_msg;
  1079. Error err = CodeSign::codesign(false, true, p_path, p_ent_path, error_msg);
  1080. if (err != OK) {
  1081. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Built-in CodeSign failed with error \"%s\"."), error_msg));
  1082. return;
  1083. }
  1084. } break;
  1085. case 2: { // "rcodesign"
  1086. print_verbose("using rcodesign codesign...");
  1087. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  1088. if (rcodesign.is_empty()) {
  1089. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xrcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));
  1090. return;
  1091. }
  1092. List<String> args;
  1093. args.push_back("sign");
  1094. if (!p_ent_path.is_empty()) {
  1095. args.push_back("--entitlements-xml-path");
  1096. args.push_back(p_ent_path);
  1097. }
  1098. String certificate_file = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE);
  1099. String certificate_pass = p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS);
  1100. if (!certificate_file.is_empty() && !certificate_pass.is_empty()) {
  1101. args.push_back("--p12-file");
  1102. args.push_back(certificate_file);
  1103. args.push_back("--p12-password");
  1104. args.push_back(certificate_pass);
  1105. }
  1106. args.push_back("--code-signature-flags");
  1107. args.push_back("runtime");
  1108. if (p_set_id) {
  1109. String app_id = p_preset->get("application/bundle_identifier");
  1110. args.push_back("--binary-identifier");
  1111. args.push_back(app_id);
  1112. }
  1113. args.push_back("-v"); /* provide some more feedback */
  1114. args.push_back(p_path);
  1115. String str;
  1116. int exitcode = 0;
  1117. Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);
  1118. if (err != OK) {
  1119. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start rcodesign executable."));
  1120. return;
  1121. }
  1122. if (exitcode != 0) {
  1123. print_line("rcodesign (" + p_path + "):\n" + str);
  1124. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  1125. return;
  1126. } else {
  1127. print_verbose("rcodesign (" + p_path + "):\n" + str);
  1128. }
  1129. } break;
  1130. #ifdef MACOS_ENABLED
  1131. case 3: { // "codesign"
  1132. print_verbose("using xcode codesign...");
  1133. if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
  1134. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xcode command line tools are not installed."));
  1135. return;
  1136. }
  1137. bool ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  1138. List<String> args;
  1139. if (!ad_hoc) {
  1140. args.push_back("--timestamp");
  1141. args.push_back("--options");
  1142. args.push_back("runtime");
  1143. }
  1144. if (!p_ent_path.is_empty()) {
  1145. args.push_back("--entitlements");
  1146. args.push_back(p_ent_path);
  1147. }
  1148. PackedStringArray user_args = p_preset->get("codesign/custom_options");
  1149. for (int i = 0; i < user_args.size(); i++) {
  1150. String user_arg = user_args[i].strip_edges();
  1151. if (!user_arg.is_empty()) {
  1152. args.push_back(user_arg);
  1153. }
  1154. }
  1155. args.push_back("-s");
  1156. if (ad_hoc) {
  1157. args.push_back("-");
  1158. } else {
  1159. args.push_back(p_preset->get("codesign/identity"));
  1160. }
  1161. if (p_set_id) {
  1162. String app_id = p_preset->get("application/bundle_identifier");
  1163. args.push_back("-i");
  1164. args.push_back(app_id);
  1165. }
  1166. args.push_back("-v"); /* provide some more feedback */
  1167. args.push_back("-f");
  1168. args.push_back(p_path);
  1169. String str;
  1170. int exitcode = 0;
  1171. Error err = OS::get_singleton()->execute("codesign", args, &str, &exitcode, true);
  1172. if (err != OK) {
  1173. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start codesign executable, make sure Xcode command line tools are installed."));
  1174. return;
  1175. }
  1176. if (exitcode != 0) {
  1177. print_line("codesign (" + p_path + "):\n" + str);
  1178. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  1179. return;
  1180. } else {
  1181. print_verbose("codesign (" + p_path + "):\n" + str);
  1182. }
  1183. } break;
  1184. #endif
  1185. default: {
  1186. };
  1187. }
  1188. }
  1189. void EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path,
  1190. const String &p_ent_path, const String &p_helper_ent_path, bool p_should_error_on_non_code) {
  1191. static Vector<String> extensions_to_sign;
  1192. bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");
  1193. if (extensions_to_sign.is_empty()) {
  1194. extensions_to_sign.push_back("dylib");
  1195. extensions_to_sign.push_back("framework");
  1196. extensions_to_sign.push_back("");
  1197. }
  1198. Error dir_access_error;
  1199. Ref<DirAccess> dir_access{ DirAccess::open(p_path, &dir_access_error) };
  1200. if (dir_access_error != OK) {
  1201. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign directory %s."), p_path));
  1202. return;
  1203. }
  1204. dir_access->list_dir_begin();
  1205. String current_file{ dir_access->get_next() };
  1206. while (!current_file.is_empty()) {
  1207. String current_file_path{ p_path.path_join(current_file) };
  1208. if (current_file == ".." || current_file == ".") {
  1209. current_file = dir_access->get_next();
  1210. continue;
  1211. }
  1212. if (extensions_to_sign.has(current_file.get_extension())) {
  1213. String ent_path;
  1214. bool set_bundle_id = false;
  1215. if (sandbox && FileAccess::exists(current_file_path)) {
  1216. int ftype = MachO::get_filetype(current_file_path);
  1217. if (ftype == 2 || ftype == 5) {
  1218. ent_path = p_helper_ent_path;
  1219. set_bundle_id = true;
  1220. }
  1221. }
  1222. _code_sign(p_preset, current_file_path, ent_path, false, set_bundle_id);
  1223. if (is_executable(current_file_path)) {
  1224. // chmod with 0755 if the file is executable.
  1225. FileAccess::set_unix_permissions(current_file_path, 0755);
  1226. }
  1227. } else if (dir_access->current_is_dir()) {
  1228. _code_sign_directory(p_preset, current_file_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code);
  1229. } else if (p_should_error_on_non_code) {
  1230. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign file %s."), current_file));
  1231. }
  1232. current_file = dir_access->get_next();
  1233. }
  1234. }
  1235. Error EditorExportPlatformMacOS::_copy_and_sign_files(Ref<DirAccess> &dir_access, const String &p_src_path,
  1236. const String &p_in_app_path, bool p_sign_enabled,
  1237. const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,
  1238. const String &p_helper_ent_path,
  1239. bool p_should_error_on_non_code_sign, bool p_sandbox) {
  1240. static Vector<String> extensions_to_sign;
  1241. if (extensions_to_sign.is_empty()) {
  1242. extensions_to_sign.push_back("dylib");
  1243. extensions_to_sign.push_back("framework");
  1244. extensions_to_sign.push_back("");
  1245. }
  1246. Error err{ OK };
  1247. if (dir_access->dir_exists(p_src_path)) {
  1248. #ifndef UNIX_ENABLED
  1249. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Relative symlinks are not supported, exported \"%s\" might be broken!"), p_src_path.get_file()));
  1250. #endif
  1251. print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path);
  1252. bool plist_missing = false;
  1253. Ref<PList> plist;
  1254. plist.instantiate();
  1255. plist->load_file(p_src_path.path_join("Resources").path_join("Info.plist"));
  1256. Ref<PListNode> root_node = plist->get_root();
  1257. if (root_node.is_null()) {
  1258. plist_missing = true;
  1259. } else {
  1260. Dictionary root = root_node->get_value();
  1261. if (!root.has("CFBundleExecutable") || !root.has("CFBundleIdentifier") || !root.has("CFBundlePackageType") || !root.has("CFBundleInfoDictionaryVersion") || !root.has("CFBundleName") || !root.has("CFBundleSupportedPlatforms")) {
  1262. plist_missing = true;
  1263. }
  1264. }
  1265. err = dir_access->make_dir_recursive(p_in_app_path);
  1266. if (err == OK) {
  1267. err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true);
  1268. }
  1269. if (err == OK && plist_missing) {
  1270. add_message(EXPORT_MESSAGE_WARNING, TTR("Export"), vformat(TTR("\"%s\": Info.plist missing or invalid, new Info.plist generated."), p_src_path.get_file()));
  1271. // Generate Info.plist
  1272. String lib_name = p_src_path.get_basename().get_file();
  1273. String lib_id = p_preset->get("application/bundle_identifier");
  1274. String lib_clean_name = lib_name;
  1275. for (int i = 0; i < lib_clean_name.length(); i++) {
  1276. if (!is_ascii_alphanumeric_char(lib_clean_name[i]) && lib_clean_name[i] != '.' && lib_clean_name[i] != '-') {
  1277. lib_clean_name[i] = '-';
  1278. }
  1279. }
  1280. String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1281. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  1282. "<plist version=\"1.0\">\n"
  1283. " <dict>\n"
  1284. " <key>CFBundleExecutable</key>\n"
  1285. " <string>$name</string>\n"
  1286. " <key>CFBundleIdentifier</key>\n"
  1287. " <string>$id.framework.$cl_name</string>\n"
  1288. " <key>CFBundleInfoDictionaryVersion</key>\n"
  1289. " <string>6.0</string>\n"
  1290. " <key>CFBundleName</key>\n"
  1291. " <string>$name</string>\n"
  1292. " <key>CFBundlePackageType</key>\n"
  1293. " <string>FMWK</string>\n"
  1294. " <key>CFBundleShortVersionString</key>\n"
  1295. " <string>1.0.0</string>\n"
  1296. " <key>CFBundleSupportedPlatforms</key>\n"
  1297. " <array>\n"
  1298. " <string>MacOSX</string>\n"
  1299. " </array>\n"
  1300. " <key>CFBundleVersion</key>\n"
  1301. " <string>1.0.0</string>\n"
  1302. " <key>LSMinimumSystemVersion</key>\n"
  1303. " <string>10.12</string>\n"
  1304. " </dict>\n"
  1305. "</plist>";
  1306. String info_plist = info_plist_format.replace("$id", lib_id).replace("$name", lib_name).replace("$cl_name", lib_clean_name);
  1307. err = dir_access->make_dir_recursive(p_in_app_path.path_join("Resources"));
  1308. Ref<FileAccess> f = FileAccess::open(p_in_app_path.path_join("Resources").path_join("Info.plist"), FileAccess::WRITE);
  1309. if (f.is_valid()) {
  1310. f->store_string(info_plist);
  1311. }
  1312. }
  1313. } else {
  1314. print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path);
  1315. err = dir_access->copy(p_src_path, p_in_app_path);
  1316. }
  1317. if (err == OK && p_sign_enabled) {
  1318. if (dir_access->dir_exists(p_src_path) && p_src_path.get_extension().is_empty()) {
  1319. // If it is a directory, find and sign all dynamic libraries.
  1320. _code_sign_directory(p_preset, p_in_app_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code_sign);
  1321. } else {
  1322. if (extensions_to_sign.has(p_in_app_path.get_extension())) {
  1323. String ent_path;
  1324. bool set_bundle_id = false;
  1325. if (p_sandbox && FileAccess::exists(p_in_app_path)) {
  1326. int ftype = MachO::get_filetype(p_in_app_path);
  1327. if (ftype == 2 || ftype == 5) {
  1328. ent_path = p_helper_ent_path;
  1329. set_bundle_id = true;
  1330. }
  1331. }
  1332. _code_sign(p_preset, p_in_app_path, ent_path, false, set_bundle_id);
  1333. }
  1334. if (dir_access->file_exists(p_in_app_path) && is_executable(p_in_app_path)) {
  1335. // chmod with 0755 if the file is executable.
  1336. FileAccess::set_unix_permissions(p_in_app_path, 0755);
  1337. }
  1338. }
  1339. }
  1340. return err;
  1341. }
  1342. Error EditorExportPlatformMacOS::_export_macos_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin,
  1343. const String &p_app_path_name, Ref<DirAccess> &dir_access,
  1344. bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,
  1345. const String &p_ent_path, const String &p_helper_ent_path, bool p_sandbox) {
  1346. Error error{ OK };
  1347. const Vector<String> &macos_plugins{ p_editor_export_plugin->get_macos_plugin_files() };
  1348. for (int i = 0; i < macos_plugins.size(); ++i) {
  1349. String src_path{ ProjectSettings::get_singleton()->globalize_path(macos_plugins[i]) };
  1350. String path_in_app{ p_app_path_name + "/Contents/PlugIns/" + src_path.get_file() };
  1351. error = _copy_and_sign_files(dir_access, src_path, path_in_app, p_sign_enabled, p_preset, p_ent_path, p_helper_ent_path, false, p_sandbox);
  1352. if (error != OK) {
  1353. break;
  1354. }
  1355. }
  1356. return error;
  1357. }
  1358. Error EditorExportPlatformMacOS::_create_pkg(const Ref<EditorExportPreset> &p_preset, const String &p_pkg_path, const String &p_app_path_name) {
  1359. List<String> args;
  1360. if (FileAccess::exists(p_pkg_path)) {
  1361. OS::get_singleton()->move_to_trash(p_pkg_path);
  1362. }
  1363. args.push_back("productbuild");
  1364. args.push_back("--component");
  1365. args.push_back(p_app_path_name);
  1366. args.push_back("/Applications");
  1367. String ident = p_preset->get("codesign/installer_identity");
  1368. if (!ident.is_empty()) {
  1369. args.push_back("--timestamp");
  1370. args.push_back("--sign");
  1371. args.push_back(ident);
  1372. }
  1373. args.push_back("--quiet");
  1374. args.push_back(p_pkg_path);
  1375. String str;
  1376. Error err = OS::get_singleton()->execute("xcrun", args, &str, nullptr, true);
  1377. if (err != OK) {
  1378. add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("Could not start productbuild executable."));
  1379. return err;
  1380. }
  1381. print_verbose("productbuild returned: " + str);
  1382. if (str.contains("productbuild: error:")) {
  1383. add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("`productbuild` failed."));
  1384. return FAILED;
  1385. }
  1386. return OK;
  1387. }
  1388. Error EditorExportPlatformMacOS::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
  1389. List<String> args;
  1390. if (FileAccess::exists(p_dmg_path)) {
  1391. OS::get_singleton()->move_to_trash(p_dmg_path);
  1392. }
  1393. args.push_back("create");
  1394. args.push_back(p_dmg_path);
  1395. args.push_back("-volname");
  1396. args.push_back(p_pkg_name);
  1397. args.push_back("-fs");
  1398. args.push_back("HFS+");
  1399. args.push_back("-srcfolder");
  1400. args.push_back(p_app_path_name);
  1401. String str;
  1402. Error err = OS::get_singleton()->execute("hdiutil", args, &str, nullptr, true);
  1403. if (err != OK) {
  1404. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("Could not start hdiutil executable."));
  1405. return err;
  1406. }
  1407. print_verbose("hdiutil returned: " + str);
  1408. if (str.contains("create failed")) {
  1409. if (str.contains("File exists")) {
  1410. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed - file exists."));
  1411. } else {
  1412. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed."));
  1413. }
  1414. return FAILED;
  1415. }
  1416. return OK;
  1417. }
  1418. bool EditorExportPlatformMacOS::is_shebang(const String &p_path) const {
  1419. Ref<FileAccess> fb = FileAccess::open(p_path, FileAccess::READ);
  1420. ERR_FAIL_COND_V_MSG(fb.is_null(), false, vformat("Can't open file: \"%s\".", p_path));
  1421. uint16_t magic = fb->get_16();
  1422. return (magic == 0x2123);
  1423. }
  1424. bool EditorExportPlatformMacOS::is_executable(const String &p_path) const {
  1425. return MachO::is_macho(p_path) || LipO::is_lipo(p_path) || is_shebang(p_path);
  1426. }
  1427. Error EditorExportPlatformMacOS::_export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path) {
  1428. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE);
  1429. if (f.is_null()) {
  1430. add_message(EXPORT_MESSAGE_ERROR, TTR("Debug Script Export"), vformat(TTR("Could not open file \"%s\"."), p_path));
  1431. return ERR_CANT_CREATE;
  1432. }
  1433. f->store_line("#!/bin/sh");
  1434. f->store_line("printf '\\033c\\033]0;%s\\a' " + p_app_name);
  1435. f->store_line("");
  1436. f->store_line("function app_realpath() {");
  1437. f->store_line(" SOURCE=$1");
  1438. f->store_line(" while [ -h \"$SOURCE\" ]; do");
  1439. f->store_line(" DIR=$(dirname \"$SOURCE\")");
  1440. f->store_line(" SOURCE=$(readlink \"$SOURCE\")");
  1441. f->store_line(" [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE");
  1442. f->store_line(" done");
  1443. f->store_line(" echo \"$( cd -P \"$( dirname \"$SOURCE\" )\" >/dev/null 2>&1 && pwd )\"");
  1444. f->store_line("}");
  1445. f->store_line("");
  1446. f->store_line("BASE_PATH=\"$(app_realpath \"${BASH_SOURCE[0]}\")\"");
  1447. f->store_line("\"$BASE_PATH/" + p_pkg_name + "\" \"$@\"");
  1448. f->store_line("");
  1449. return OK;
  1450. }
  1451. Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) {
  1452. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  1453. const String base_dir = p_path.get_base_dir();
  1454. if (!DirAccess::exists(base_dir)) {
  1455. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Target folder does not exist or is inaccessible: \"%s\""), base_dir));
  1456. return ERR_FILE_BAD_PATH;
  1457. }
  1458. EditorProgress ep("export", TTR("Exporting for macOS"), 3, true);
  1459. String src_pkg_name;
  1460. if (p_debug) {
  1461. src_pkg_name = p_preset->get("custom_template/debug");
  1462. } else {
  1463. src_pkg_name = p_preset->get("custom_template/release");
  1464. }
  1465. if (src_pkg_name.is_empty()) {
  1466. String err;
  1467. src_pkg_name = find_export_template("macos.zip", &err);
  1468. if (src_pkg_name.is_empty()) {
  1469. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found.") + "\n" + err);
  1470. return ERR_FILE_NOT_FOUND;
  1471. }
  1472. }
  1473. Ref<FileAccess> io_fa;
  1474. zlib_filefunc_def io = zipio_create_io(&io_fa);
  1475. if (ep.step(TTR("Creating app bundle"), 0)) {
  1476. return ERR_SKIP;
  1477. }
  1478. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  1479. if (!src_pkg_zip) {
  1480. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not find template app to export: \"%s\"."), src_pkg_name));
  1481. return ERR_FILE_NOT_FOUND;
  1482. }
  1483. int ret = unzGoToFirstFile(src_pkg_zip);
  1484. String architecture = p_preset->get("binary_format/architecture");
  1485. String binary_to_use = "godot_macos_" + String(p_debug ? "debug" : "release") + "." + architecture;
  1486. String pkg_name;
  1487. if (String(get_project_setting(p_preset, "application/config/name")) != "") {
  1488. pkg_name = String(get_project_setting(p_preset, "application/config/name"));
  1489. } else {
  1490. pkg_name = "Unnamed";
  1491. }
  1492. pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
  1493. String export_format;
  1494. if (p_path.ends_with("zip")) {
  1495. export_format = "zip";
  1496. } else if (p_path.ends_with("app")) {
  1497. export_format = "app";
  1498. #ifdef MACOS_ENABLED
  1499. } else if (p_path.ends_with("dmg")) {
  1500. export_format = "dmg";
  1501. } else if (p_path.ends_with("pkg")) {
  1502. export_format = "pkg";
  1503. #endif
  1504. } else {
  1505. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Invalid export format."));
  1506. return ERR_CANT_CREATE;
  1507. }
  1508. // Create our application bundle.
  1509. String tmp_app_dir_name = pkg_name + ".app";
  1510. String tmp_base_path_name;
  1511. String tmp_app_path_name;
  1512. String scr_path;
  1513. if (export_format == "app") {
  1514. tmp_base_path_name = p_path.get_base_dir();
  1515. tmp_app_path_name = p_path;
  1516. scr_path = p_path.get_basename() + ".command";
  1517. } else {
  1518. tmp_base_path_name = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name);
  1519. tmp_app_path_name = tmp_base_path_name.path_join(tmp_app_dir_name);
  1520. scr_path = tmp_base_path_name.path_join(pkg_name + ".command");
  1521. }
  1522. print_verbose("Exporting to " + tmp_app_path_name);
  1523. Error err = OK;
  1524. Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_base_path_name);
  1525. if (tmp_app_dir.is_null()) {
  1526. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory: \"%s\"."), tmp_base_path_name));
  1527. err = ERR_CANT_CREATE;
  1528. }
  1529. if (FileAccess::exists(scr_path)) {
  1530. DirAccess::remove_file_or_error(scr_path);
  1531. }
  1532. if (DirAccess::exists(tmp_app_path_name)) {
  1533. String old_dir = tmp_app_dir->get_current_dir();
  1534. if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {
  1535. tmp_app_dir->erase_contents_recursive();
  1536. tmp_app_dir->change_dir(old_dir);
  1537. }
  1538. }
  1539. Array helpers = p_preset->get("codesign/entitlements/app_sandbox/helper_executables");
  1540. // Create our folder structure.
  1541. if (err == OK) {
  1542. print_verbose("Creating " + tmp_app_path_name + "/Contents/MacOS");
  1543. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
  1544. if (err != OK) {
  1545. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/MacOS"));
  1546. }
  1547. }
  1548. if (err == OK) {
  1549. print_verbose("Creating " + tmp_app_path_name + "/Contents/Frameworks");
  1550. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");
  1551. if (err != OK) {
  1552. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Frameworks"));
  1553. }
  1554. }
  1555. if ((err == OK) && helpers.size() > 0) {
  1556. print_line("Creating " + tmp_app_path_name + "/Contents/Helpers");
  1557. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Helpers");
  1558. if (err != OK) {
  1559. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Helpers"));
  1560. }
  1561. }
  1562. if (err == OK) {
  1563. print_verbose("Creating " + tmp_app_path_name + "/Contents/Resources");
  1564. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
  1565. if (err != OK) {
  1566. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Resources"));
  1567. }
  1568. }
  1569. Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");
  1570. Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");
  1571. Dictionary location_usage_descriptions = p_preset->get("privacy/location_usage_description_localized");
  1572. Dictionary address_book_usage_descriptions = p_preset->get("privacy/address_book_usage_description_localized");
  1573. Dictionary calendar_usage_descriptions = p_preset->get("privacy/calendar_usage_description_localized");
  1574. Dictionary photos_library_usage_descriptions = p_preset->get("privacy/photos_library_usage_description_localized");
  1575. Dictionary desktop_folder_usage_descriptions = p_preset->get("privacy/desktop_folder_usage_description_localized");
  1576. Dictionary documents_folder_usage_descriptions = p_preset->get("privacy/documents_folder_usage_description_localized");
  1577. Dictionary downloads_folder_usage_descriptions = p_preset->get("privacy/downloads_folder_usage_description_localized");
  1578. Dictionary network_volumes_usage_descriptions = p_preset->get("privacy/network_volumes_usage_description_localized");
  1579. Dictionary removable_volumes_usage_descriptions = p_preset->get("privacy/removable_volumes_usage_description_localized");
  1580. Dictionary copyrights = p_preset->get("application/copyright_localized");
  1581. const String project_name = get_project_setting(p_preset, "application/config/name");
  1582. const Dictionary appnames = get_project_setting(p_preset, "application/config/name_localized");
  1583. const StringName domain_name = "godot.project_name_localization";
  1584. Ref<TranslationDomain> domain = TranslationServer::get_singleton()->get_or_add_domain(domain_name);
  1585. TranslationServer::get_singleton()->load_project_translations(domain);
  1586. const Vector<String> locales = domain->get_loaded_locales();
  1587. if (!locales.is_empty()) {
  1588. {
  1589. String fname = tmp_app_path_name + "/Contents/Resources/en.lproj";
  1590. tmp_app_dir->make_dir_recursive(fname);
  1591. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1592. f->store_line("/* Localized versions of Info.plist keys */");
  1593. f->store_line("");
  1594. f->store_line("CFBundleDisplayName = \"" + project_name.xml_escape(true) + "\";");
  1595. if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
  1596. f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String().xml_escape(true) + "\";");
  1597. }
  1598. if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
  1599. f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String().xml_escape(true) + "\";");
  1600. }
  1601. if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
  1602. f->store_line("NSLocationUsageDescription = \"" + p_preset->get("privacy/location_usage_description").operator String().xml_escape(true) + "\";");
  1603. }
  1604. if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
  1605. f->store_line("NSContactsUsageDescription = \"" + p_preset->get("privacy/address_book_usage_description").operator String().xml_escape(true) + "\";");
  1606. }
  1607. if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
  1608. f->store_line("NSCalendarsUsageDescription = \"" + p_preset->get("privacy/calendar_usage_description").operator String().xml_escape(true) + "\";");
  1609. }
  1610. if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
  1611. f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photos_library_usage_description").operator String().xml_escape(true) + "\";");
  1612. }
  1613. if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {
  1614. f->store_line("NSDesktopFolderUsageDescription = \"" + p_preset->get("privacy/desktop_folder_usage_description").operator String().xml_escape(true) + "\";");
  1615. }
  1616. if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {
  1617. f->store_line("NSDocumentsFolderUsageDescription = \"" + p_preset->get("privacy/documents_folder_usage_description").operator String().xml_escape(true) + "\";");
  1618. }
  1619. if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {
  1620. f->store_line("NSDownloadsFolderUsageDescription = \"" + p_preset->get("privacy/downloads_folder_usage_description").operator String().xml_escape(true) + "\";");
  1621. }
  1622. if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {
  1623. f->store_line("NSNetworkVolumesUsageDescription = \"" + p_preset->get("privacy/network_volumes_usage_description").operator String().xml_escape(true) + "\";");
  1624. }
  1625. if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {
  1626. f->store_line("NSRemovableVolumesUsageDescription = \"" + p_preset->get("privacy/removable_volumes_usage_description").operator String().xml_escape(true) + "\";");
  1627. }
  1628. f->store_line("NSHumanReadableCopyright = \"" + p_preset->get("application/copyright").operator String().xml_escape(true) + "\";");
  1629. }
  1630. for (const String &lang : locales) {
  1631. if (lang == "en") {
  1632. continue;
  1633. }
  1634. String fname = tmp_app_path_name + "/Contents/Resources/" + lang + ".lproj";
  1635. tmp_app_dir->make_dir_recursive(fname);
  1636. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1637. f->store_line("/* Localized versions of Info.plist keys */");
  1638. f->store_line("");
  1639. if (appnames.is_empty()) {
  1640. domain->set_locale_override(lang);
  1641. const String &name = domain->translate(project_name, String());
  1642. if (name != project_name) {
  1643. f->store_line("CFBundleDisplayName = \"" + name.xml_escape(true) + "\";");
  1644. }
  1645. } else if (appnames.has(lang)) {
  1646. f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String().xml_escape(true) + "\";");
  1647. }
  1648. if (microphone_usage_descriptions.has(lang)) {
  1649. f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String().xml_escape(true) + "\";");
  1650. }
  1651. if (camera_usage_descriptions.has(lang)) {
  1652. f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String().xml_escape(true) + "\";");
  1653. }
  1654. if (location_usage_descriptions.has(lang)) {
  1655. f->store_line("NSLocationUsageDescription = \"" + location_usage_descriptions[lang].operator String().xml_escape(true) + "\";");
  1656. }
  1657. if (address_book_usage_descriptions.has(lang)) {
  1658. f->store_line("NSContactsUsageDescription = \"" + address_book_usage_descriptions[lang].operator String().xml_escape(true) + "\";");
  1659. }
  1660. if (calendar_usage_descriptions.has(lang)) {
  1661. f->store_line("NSCalendarsUsageDescription = \"" + calendar_usage_descriptions[lang].operator String().xml_escape(true) + "\";");
  1662. }
  1663. if (photos_library_usage_descriptions.has(lang)) {
  1664. f->store_line("NSPhotoLibraryUsageDescription = \"" + photos_library_usage_descriptions[lang].operator String().xml_escape(true) + "\";");
  1665. }
  1666. if (desktop_folder_usage_descriptions.has(lang)) {
  1667. f->store_line("NSDesktopFolderUsageDescription = \"" + desktop_folder_usage_descriptions[lang].operator String().xml_escape(true) + "\";");
  1668. }
  1669. if (documents_folder_usage_descriptions.has(lang)) {
  1670. f->store_line("NSDocumentsFolderUsageDescription = \"" + documents_folder_usage_descriptions[lang].operator String().xml_escape(true) + "\";");
  1671. }
  1672. if (downloads_folder_usage_descriptions.has(lang)) {
  1673. f->store_line("NSDownloadsFolderUsageDescription = \"" + downloads_folder_usage_descriptions[lang].operator String().xml_escape(true) + "\";");
  1674. }
  1675. if (network_volumes_usage_descriptions.has(lang)) {
  1676. f->store_line("NSNetworkVolumesUsageDescription = \"" + network_volumes_usage_descriptions[lang].operator String().xml_escape(true) + "\";");
  1677. }
  1678. if (removable_volumes_usage_descriptions.has(lang)) {
  1679. f->store_line("NSRemovableVolumesUsageDescription = \"" + removable_volumes_usage_descriptions[lang].operator String().xml_escape(true) + "\";");
  1680. }
  1681. if (copyrights.has(lang)) {
  1682. f->store_line("NSHumanReadableCopyright = \"" + copyrights[lang].operator String().xml_escape(true) + "\";");
  1683. }
  1684. }
  1685. }
  1686. TranslationServer::get_singleton()->remove_domain(domain_name);
  1687. // Now process our template.
  1688. bool found_binary = false;
  1689. int export_angle = p_preset->get("application/export_angle");
  1690. bool include_angle_libs = false;
  1691. if (export_angle == 0) {
  1692. include_angle_libs = String(get_project_setting(p_preset, "rendering/gl_compatibility/driver.macos")) == "opengl3_angle";
  1693. } else if (export_angle == 1) {
  1694. include_angle_libs = true;
  1695. }
  1696. while (ret == UNZ_OK && err == OK) {
  1697. // Get filename.
  1698. unz_file_info info;
  1699. char fname[16384];
  1700. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  1701. if (ret != UNZ_OK) {
  1702. break;
  1703. }
  1704. String file = String::utf8(fname);
  1705. Vector<uint8_t> data;
  1706. data.resize(info.uncompressed_size);
  1707. // Read.
  1708. unzOpenCurrentFile(src_pkg_zip);
  1709. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  1710. unzCloseCurrentFile(src_pkg_zip);
  1711. // Write.
  1712. file = file.replace_first("macos_template.app/", "");
  1713. if (((info.external_fa >> 16L) & 0120000) == 0120000) {
  1714. #ifndef UNIX_ENABLED
  1715. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Relative symlinks are not supported on this OS, the exported project might be broken!"));
  1716. #endif
  1717. // Handle symlinks in the archive.
  1718. file = tmp_app_path_name.path_join(file);
  1719. if (err == OK) {
  1720. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  1721. if (err != OK) {
  1722. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));
  1723. }
  1724. }
  1725. if (err == OK) {
  1726. String lnk_data = String::utf8((const char *)data.ptr(), data.size());
  1727. err = tmp_app_dir->create_link(lnk_data, file);
  1728. if (err != OK) {
  1729. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not created symlink \"%s\" -> \"%s\"."), lnk_data, file));
  1730. }
  1731. print_verbose(vformat("ADDING SYMLINK %s => %s\n", file, lnk_data));
  1732. }
  1733. ret = unzGoToNextFile(src_pkg_zip);
  1734. continue; // next
  1735. }
  1736. if (file == "Contents/Frameworks/libEGL.dylib") {
  1737. if (!include_angle_libs) {
  1738. ret = unzGoToNextFile(src_pkg_zip);
  1739. continue; // skip
  1740. }
  1741. }
  1742. if (file == "Contents/Frameworks/libGLESv2.dylib") {
  1743. if (!include_angle_libs) {
  1744. ret = unzGoToNextFile(src_pkg_zip);
  1745. continue; // skip
  1746. }
  1747. }
  1748. if (file == "Contents/Info.plist") {
  1749. bool lg_icon_expored = false;
  1750. String lg_icon = p_preset->get("application/liquid_glass_icon");
  1751. #ifdef MACOS_ENABLED
  1752. // Export liquid glass.
  1753. if (!lg_icon.is_empty()) {
  1754. lg_icon_expored = (_export_liquid_glass_icon(p_preset, tmp_app_path_name, lg_icon) == OK);
  1755. }
  1756. #endif
  1757. // Modify plist.
  1758. _fix_plist(p_preset, data, pkg_name, lg_icon_expored, lg_icon.get_file().get_basename());
  1759. }
  1760. if (file == "Contents/Resources/PrivacyInfo.xcprivacy") {
  1761. _fix_privacy_manifest(p_preset, data);
  1762. }
  1763. if (file.begins_with("Contents/MacOS/godot_")) {
  1764. if (file != "Contents/MacOS/" + binary_to_use) {
  1765. ret = unzGoToNextFile(src_pkg_zip);
  1766. continue; // skip
  1767. }
  1768. found_binary = true;
  1769. file = "Contents/MacOS/" + pkg_name;
  1770. }
  1771. if (file == "Contents/Resources/icon.icns") {
  1772. // See if there is an icon.
  1773. String icon_path;
  1774. if (p_preset->get("application/icon") != "") {
  1775. icon_path = p_preset->get("application/icon");
  1776. } else if (get_project_setting(p_preset, "application/config/macos_native_icon") != "") {
  1777. icon_path = get_project_setting(p_preset, "application/config/macos_native_icon");
  1778. } else {
  1779. icon_path = get_project_setting(p_preset, "application/config/icon");
  1780. }
  1781. if (!icon_path.is_empty()) {
  1782. if (icon_path.get_extension() == "icns") {
  1783. Ref<FileAccess> icon = FileAccess::open(icon_path, FileAccess::READ);
  1784. if (icon.is_valid()) {
  1785. data.resize(icon->get_length());
  1786. icon->get_buffer(&data.write[0], icon->get_length());
  1787. }
  1788. } else {
  1789. Ref<Image> icon = _load_icon_or_splash_image(icon_path, &err);
  1790. if (err == OK && icon.is_valid() && !icon->is_empty()) {
  1791. _make_icon(p_preset, icon, data);
  1792. }
  1793. }
  1794. }
  1795. }
  1796. if (data.size() > 0) {
  1797. print_verbose("ADDING: " + file + " size: " + itos(data.size()));
  1798. // Write it into our application bundle.
  1799. file = tmp_app_path_name.path_join(file);
  1800. if (err == OK) {
  1801. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  1802. if (err != OK) {
  1803. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));
  1804. }
  1805. }
  1806. if (err == OK) {
  1807. Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);
  1808. if (f.is_valid()) {
  1809. f->store_buffer(data.ptr(), data.size());
  1810. f.unref();
  1811. if (is_executable(file)) {
  1812. // chmod with 0755 if the file is executable.
  1813. FileAccess::set_unix_permissions(file, 0755);
  1814. #ifndef UNIX_ENABLED
  1815. if (export_format == "app") {
  1816. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Unable to set Unix permissions for executable \"%s\". Use \"chmod +x\" to set it after transferring the exported .app to macOS or Linux."), "Contents/MacOS/" + file.get_file()));
  1817. }
  1818. #endif
  1819. }
  1820. } else {
  1821. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not open \"%s\"."), file));
  1822. err = ERR_CANT_CREATE;
  1823. }
  1824. }
  1825. }
  1826. ret = unzGoToNextFile(src_pkg_zip);
  1827. }
  1828. // We're done with our source zip.
  1829. unzClose(src_pkg_zip);
  1830. if (!found_binary) {
  1831. 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));
  1832. err = ERR_FILE_NOT_FOUND;
  1833. }
  1834. // Save console wrapper.
  1835. if (err == OK) {
  1836. int con_scr = p_preset->get("debug/export_console_wrapper");
  1837. if ((con_scr == 1 && p_debug) || (con_scr == 2)) {
  1838. err = _export_debug_script(p_preset, pkg_name, tmp_app_path_name.get_file() + "/Contents/MacOS/" + pkg_name, scr_path);
  1839. FileAccess::set_unix_permissions(scr_path, 0755);
  1840. #ifndef UNIX_ENABLED
  1841. if (export_format == "app") {
  1842. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Unable to set Unix permissions for executable \"%s\". Use \"chmod +x\" to set it after transferring the exported .app to macOS or Linux."), scr_path.get_file()));
  1843. }
  1844. #endif
  1845. if (err != OK) {
  1846. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not create console wrapper."));
  1847. }
  1848. }
  1849. }
  1850. if (err == OK) {
  1851. if (ep.step(TTR("Making PKG"), 1)) {
  1852. return ERR_SKIP;
  1853. }
  1854. // See if we can code sign our new package.
  1855. bool sign_enabled = (p_preset->get("codesign/codesign").operator int() > 0);
  1856. bool ad_hoc = false;
  1857. int codesign_tool = p_preset->get("codesign/codesign");
  1858. switch (codesign_tool) {
  1859. case 1: { // built-in ad-hoc
  1860. ad_hoc = true;
  1861. } break;
  1862. case 2: { // "rcodesign"
  1863. ad_hoc = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty() || p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS).operator String().is_empty();
  1864. } break;
  1865. #ifdef MACOS_ENABLED
  1866. case 3: { // "codesign"
  1867. ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  1868. } break;
  1869. #endif
  1870. default: {
  1871. };
  1872. }
  1873. String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
  1874. Vector<SharedObject> shared_objects;
  1875. err = save_pack(p_preset, p_debug, pack_path, &shared_objects);
  1876. bool lib_validation = p_preset->get("codesign/entitlements/disable_library_validation");
  1877. if (!shared_objects.is_empty() && sign_enabled && ad_hoc && !lib_validation) {
  1878. add_message(EXPORT_MESSAGE_INFO, TTR("Entitlements Modified"), TTR("Ad-hoc signed applications require the 'Disable Library Validation' entitlement to load dynamic libraries."));
  1879. lib_validation = true;
  1880. }
  1881. if (!shared_objects.is_empty() && sign_enabled && codesign_tool == 2) {
  1882. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("'rcodesign' doesn't support signing applications with embedded dynamic libraries."));
  1883. }
  1884. bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");
  1885. String ent_path = p_preset->get("codesign/entitlements/custom_file");
  1886. String hlp_ent_path = sandbox ? EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + "_helper.entitlements") : ent_path;
  1887. if (sign_enabled && (ent_path.is_empty())) {
  1888. ent_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".entitlements");
  1889. Ref<FileAccess> ent_f = FileAccess::open(ent_path, FileAccess::WRITE);
  1890. if (ent_f.is_valid()) {
  1891. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  1892. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  1893. ent_f->store_line("<plist version=\"1.0\">");
  1894. ent_f->store_line("<dict>");
  1895. if (ClassDB::class_exists("CSharpScript")) {
  1896. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  1897. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  1898. ent_f->store_line("<true/>");
  1899. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  1900. ent_f->store_line("<true/>");
  1901. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  1902. ent_f->store_line("<true/>");
  1903. } else {
  1904. if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) {
  1905. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  1906. ent_f->store_line("<true/>");
  1907. }
  1908. if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) {
  1909. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  1910. ent_f->store_line("<true/>");
  1911. }
  1912. if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) {
  1913. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  1914. ent_f->store_line("<true/>");
  1915. }
  1916. }
  1917. if (lib_validation) {
  1918. ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>");
  1919. ent_f->store_line("<true/>");
  1920. }
  1921. if ((bool)p_preset->get("codesign/entitlements/audio_input")) {
  1922. ent_f->store_line("<key>com.apple.security.device.audio-input</key>");
  1923. ent_f->store_line("<true/>");
  1924. }
  1925. if ((bool)p_preset->get("codesign/entitlements/camera")) {
  1926. ent_f->store_line("<key>com.apple.security.device.camera</key>");
  1927. ent_f->store_line("<true/>");
  1928. }
  1929. if ((bool)p_preset->get("codesign/entitlements/location")) {
  1930. ent_f->store_line("<key>com.apple.security.personal-information.location</key>");
  1931. ent_f->store_line("<true/>");
  1932. }
  1933. if ((bool)p_preset->get("codesign/entitlements/address_book")) {
  1934. ent_f->store_line("<key>com.apple.security.personal-information.addressbook</key>");
  1935. ent_f->store_line("<true/>");
  1936. }
  1937. if ((bool)p_preset->get("codesign/entitlements/calendars")) {
  1938. ent_f->store_line("<key>com.apple.security.personal-information.calendars</key>");
  1939. ent_f->store_line("<true/>");
  1940. }
  1941. if ((bool)p_preset->get("codesign/entitlements/photos_library")) {
  1942. ent_f->store_line("<key>com.apple.security.personal-information.photos-library</key>");
  1943. ent_f->store_line("<true/>");
  1944. }
  1945. if ((bool)p_preset->get("codesign/entitlements/apple_events")) {
  1946. ent_f->store_line("<key>com.apple.security.automation.apple-events</key>");
  1947. ent_f->store_line("<true/>");
  1948. }
  1949. if ((bool)p_preset->get("codesign/entitlements/debugging")) {
  1950. ent_f->store_line("<key>com.apple.security.get-task-allow</key>");
  1951. ent_f->store_line("<true/>");
  1952. }
  1953. int dist_type = p_preset->get("export/distribution_type");
  1954. if (dist_type == 2) {
  1955. String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE);
  1956. String teamid = p_preset->get("codesign/apple_team_id");
  1957. String bid = p_preset->get("application/bundle_identifier");
  1958. if (!pprof.is_empty() && !teamid.is_empty()) {
  1959. ent_f->store_line("<key>com.apple.developer.team-identifier</key>");
  1960. ent_f->store_line("<string>" + teamid + "</string>");
  1961. ent_f->store_line("<key>com.apple.application-identifier</key>");
  1962. ent_f->store_line("<string>" + teamid + "." + bid + "</string>");
  1963. }
  1964. }
  1965. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) {
  1966. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  1967. ent_f->store_line("<true/>");
  1968. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) {
  1969. ent_f->store_line("<key>com.apple.security.network.server</key>");
  1970. ent_f->store_line("<true/>");
  1971. }
  1972. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) {
  1973. ent_f->store_line("<key>com.apple.security.network.client</key>");
  1974. ent_f->store_line("<true/>");
  1975. }
  1976. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) {
  1977. ent_f->store_line("<key>com.apple.security.device.usb</key>");
  1978. ent_f->store_line("<true/>");
  1979. }
  1980. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) {
  1981. ent_f->store_line("<key>com.apple.security.device.bluetooth</key>");
  1982. ent_f->store_line("<true/>");
  1983. }
  1984. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) {
  1985. ent_f->store_line("<key>com.apple.security.files.downloads.read-only</key>");
  1986. ent_f->store_line("<true/>");
  1987. }
  1988. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) {
  1989. ent_f->store_line("<key>com.apple.security.files.downloads.read-write</key>");
  1990. ent_f->store_line("<true/>");
  1991. }
  1992. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) {
  1993. ent_f->store_line("<key>com.apple.security.files.pictures.read-only</key>");
  1994. ent_f->store_line("<true/>");
  1995. }
  1996. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) {
  1997. ent_f->store_line("<key>com.apple.security.files.pictures.read-write</key>");
  1998. ent_f->store_line("<true/>");
  1999. }
  2000. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) {
  2001. ent_f->store_line("<key>com.apple.security.files.music.read-only</key>");
  2002. ent_f->store_line("<true/>");
  2003. }
  2004. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) {
  2005. ent_f->store_line("<key>com.apple.security.files.music.read-write</key>");
  2006. ent_f->store_line("<true/>");
  2007. }
  2008. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) {
  2009. ent_f->store_line("<key>com.apple.security.files.movies.read-only</key>");
  2010. ent_f->store_line("<true/>");
  2011. }
  2012. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) {
  2013. ent_f->store_line("<key>com.apple.security.files.movies.read-write</key>");
  2014. ent_f->store_line("<true/>");
  2015. }
  2016. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 1) {
  2017. ent_f->store_line("<key>com.apple.security.files.user-selected.read-only</key>");
  2018. ent_f->store_line("<true/>");
  2019. }
  2020. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 2) {
  2021. ent_f->store_line("<key>com.apple.security.files.user-selected.read-write</key>");
  2022. ent_f->store_line("<true/>");
  2023. }
  2024. }
  2025. const String &additional_entitlements = p_preset->get("codesign/entitlements/additional");
  2026. if (!additional_entitlements.is_empty()) {
  2027. ent_f->store_line(additional_entitlements);
  2028. }
  2029. ent_f->store_line("</dict>");
  2030. ent_f->store_line("</plist>");
  2031. } else {
  2032. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create entitlements file."));
  2033. err = ERR_CANT_CREATE;
  2034. }
  2035. if ((err == OK) && sandbox && (helpers.size() > 0 || shared_objects.size() > 0)) {
  2036. ent_f = FileAccess::open(hlp_ent_path, FileAccess::WRITE);
  2037. if (ent_f.is_valid()) {
  2038. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  2039. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  2040. ent_f->store_line("<plist version=\"1.0\">");
  2041. ent_f->store_line("<dict>");
  2042. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  2043. ent_f->store_line("<true/>");
  2044. ent_f->store_line("<key>com.apple.security.inherit</key>");
  2045. ent_f->store_line("<true/>");
  2046. ent_f->store_line("</dict>");
  2047. ent_f->store_line("</plist>");
  2048. } else {
  2049. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create helper entitlements file."));
  2050. err = ERR_CANT_CREATE;
  2051. }
  2052. }
  2053. }
  2054. if ((err == OK) && helpers.size() > 0) {
  2055. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  2056. for (int i = 0; i < helpers.size(); i++) {
  2057. String hlp_path = helpers[i];
  2058. err = da->copy(hlp_path, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file());
  2059. if (err == OK && sign_enabled) {
  2060. _code_sign(p_preset, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), hlp_ent_path, false, true);
  2061. }
  2062. FileAccess::set_unix_permissions(tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), 0755);
  2063. #ifndef UNIX_ENABLED
  2064. if (export_format == "app") {
  2065. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Unable to set Unix permissions for executable \"%s\". Use \"chmod +x\" to set it after transferring the exported .app to macOS or Linux."), "Contents/Helpers/" + hlp_path.get_file()));
  2066. }
  2067. #endif
  2068. }
  2069. }
  2070. if (err == OK) {
  2071. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  2072. for (int i = 0; i < shared_objects.size(); i++) {
  2073. String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path);
  2074. if (shared_objects[i].target.is_empty()) {
  2075. String path_in_app = tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file();
  2076. err = _copy_and_sign_files(da, src_path, path_in_app, sign_enabled, p_preset, ent_path, hlp_ent_path, true, sandbox);
  2077. } else {
  2078. String path_in_app = tmp_app_path_name.path_join(shared_objects[i].target);
  2079. tmp_app_dir->make_dir_recursive(path_in_app);
  2080. err = _copy_and_sign_files(da, src_path, path_in_app.path_join(src_path.get_file()), sign_enabled, p_preset, ent_path, hlp_ent_path, false, sandbox);
  2081. }
  2082. if (err != OK) {
  2083. break;
  2084. }
  2085. }
  2086. Vector<Ref<EditorExportPlugin>> export_plugins{ EditorExport::get_singleton()->get_export_plugins() };
  2087. for (int i = 0; i < export_plugins.size(); ++i) {
  2088. err = _export_macos_plugins_for(export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path, hlp_ent_path, sandbox);
  2089. if (err != OK) {
  2090. break;
  2091. }
  2092. }
  2093. }
  2094. if (err == OK && sign_enabled) {
  2095. int dist_type = p_preset->get("export/distribution_type");
  2096. if (dist_type == 2) {
  2097. String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE).operator String();
  2098. if (!pprof.is_empty()) {
  2099. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  2100. err = da->copy(pprof, tmp_app_path_name + "/Contents/embedded.provisionprofile");
  2101. }
  2102. }
  2103. if (ep.step(TTR("Code signing bundle"), 2)) {
  2104. return ERR_SKIP;
  2105. }
  2106. _code_sign(p_preset, tmp_app_path_name, ent_path, true, false);
  2107. }
  2108. String noto_path = p_path;
  2109. bool noto_enabled = (p_preset->get("notarization/notarization").operator int() > 0);
  2110. if (export_format == "dmg") {
  2111. // Create a DMG.
  2112. if (err == OK) {
  2113. if (ep.step(TTR("Making DMG"), 3)) {
  2114. return ERR_SKIP;
  2115. }
  2116. err = _create_dmg(p_path, pkg_name, tmp_base_path_name);
  2117. }
  2118. // Sign DMG.
  2119. if (err == OK && sign_enabled && !ad_hoc) {
  2120. if (ep.step(TTR("Code signing DMG"), 3)) {
  2121. return ERR_SKIP;
  2122. }
  2123. _code_sign(p_preset, p_path, ent_path, false, false);
  2124. }
  2125. } else if (export_format == "pkg") {
  2126. // Create a Installer.
  2127. if (err == OK) {
  2128. if (ep.step(TTR("Making PKG installer"), 3)) {
  2129. return ERR_SKIP;
  2130. }
  2131. err = _create_pkg(p_preset, p_path, tmp_app_path_name);
  2132. }
  2133. } else if (export_format == "zip") {
  2134. // Create ZIP.
  2135. if (err == OK) {
  2136. if (ep.step(TTR("Making ZIP"), 3)) {
  2137. return ERR_SKIP;
  2138. }
  2139. if (FileAccess::exists(p_path)) {
  2140. OS::get_singleton()->move_to_trash(p_path);
  2141. }
  2142. Ref<FileAccess> io_fa_dst;
  2143. zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);
  2144. zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
  2145. zip_folder_recursive(zip, tmp_base_path_name, "", pkg_name);
  2146. zipClose(zip, nullptr);
  2147. }
  2148. } else if (export_format == "app" && noto_enabled) {
  2149. // Create temporary ZIP.
  2150. if (err == OK) {
  2151. noto_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".zip");
  2152. if (ep.step(TTR("Making ZIP"), 3)) {
  2153. return ERR_SKIP;
  2154. }
  2155. if (FileAccess::exists(noto_path)) {
  2156. OS::get_singleton()->move_to_trash(noto_path);
  2157. }
  2158. Ref<FileAccess> io_fa_dst;
  2159. zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);
  2160. zipFile zip = zipOpen2(noto_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
  2161. zip_folder_recursive(zip, tmp_base_path_name, tmp_app_dir_name, pkg_name);
  2162. zipClose(zip, nullptr);
  2163. }
  2164. }
  2165. if (err == OK && noto_enabled) {
  2166. if (export_format == "pkg") {
  2167. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("Notarization requires the app to be archived first, select the DMG or ZIP export format instead."));
  2168. } else {
  2169. if (ep.step(TTR("Sending archive for notarization"), 4)) {
  2170. return ERR_SKIP;
  2171. }
  2172. err = _notarize(p_preset, noto_path);
  2173. }
  2174. }
  2175. if (FileAccess::exists(ent_path)) {
  2176. print_verbose("entitlements:\n" + FileAccess::get_file_as_string(ent_path));
  2177. }
  2178. if (FileAccess::exists(hlp_ent_path)) {
  2179. print_verbose("helper entitlements:\n" + FileAccess::get_file_as_string(hlp_ent_path));
  2180. }
  2181. // Clean up temporary entitlements files.
  2182. if (FileAccess::exists(hlp_ent_path)) {
  2183. DirAccess::remove_file_or_error(hlp_ent_path);
  2184. }
  2185. // Clean up temporary .app dir and generated entitlements.
  2186. if ((String)(p_preset->get("codesign/entitlements/custom_file")) == "") {
  2187. tmp_app_dir->remove(ent_path);
  2188. }
  2189. if (export_format != "app") {
  2190. if (tmp_app_dir->change_dir(tmp_base_path_name) == OK) {
  2191. tmp_app_dir->erase_contents_recursive();
  2192. tmp_app_dir->change_dir("..");
  2193. tmp_app_dir->remove(pkg_name);
  2194. }
  2195. } else if (noto_path != p_path) {
  2196. if (FileAccess::exists(noto_path)) {
  2197. DirAccess::remove_file_or_error(noto_path);
  2198. }
  2199. }
  2200. }
  2201. return err;
  2202. }
  2203. bool EditorExportPlatformMacOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {
  2204. String err;
  2205. // Look for export templates (official templates first, then custom).
  2206. bool dvalid = exists_export_template("macos.zip", &err);
  2207. bool rvalid = dvalid; // Both in the same ZIP.
  2208. if (p_preset->get("custom_template/debug") != "") {
  2209. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  2210. if (!dvalid) {
  2211. err += TTR("Custom debug template not found.") + "\n";
  2212. }
  2213. }
  2214. if (p_preset->get("custom_template/release") != "") {
  2215. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  2216. if (!rvalid) {
  2217. err += TTR("Custom release template not found.") + "\n";
  2218. }
  2219. }
  2220. bool valid = dvalid || rvalid;
  2221. r_missing_templates = !valid;
  2222. // Check the texture formats, which vary depending on the target architecture.
  2223. String architecture = p_preset->get("binary_format/architecture");
  2224. if (architecture == "universal" || architecture == "x86_64") {
  2225. if (!ResourceImporterTextureSettings::should_import_s3tc_bptc()) {
  2226. err += TTR("Cannot export for universal or x86_64 if S3TC BPTC texture format is disabled. Enable it in the Project Settings (Rendering > Textures > VRAM Compression > Import S3TC BPTC).") + "\n";
  2227. valid = false;
  2228. }
  2229. }
  2230. if (architecture == "universal" || architecture == "arm64") {
  2231. if (!ResourceImporterTextureSettings::should_import_etc2_astc()) {
  2232. err += TTR("Cannot export for universal or arm64 if ETC2 ASTC texture format is disabled. Enable it in the Project Settings (Rendering > Textures > VRAM Compression > Import ETC2 ASTC).") + "\n";
  2233. valid = false;
  2234. }
  2235. }
  2236. if (architecture != "universal" && architecture != "x86_64" && architecture != "arm64") {
  2237. ERR_PRINT("Invalid architecture");
  2238. }
  2239. if (!err.is_empty()) {
  2240. r_error = err;
  2241. }
  2242. return valid;
  2243. }
  2244. bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  2245. String err;
  2246. bool valid = true;
  2247. int dist_type = p_preset->get("export/distribution_type");
  2248. bool ad_hoc = false;
  2249. int codesign_tool = p_preset->get("codesign/codesign");
  2250. int notary_tool = p_preset->get("notarization/notarization");
  2251. switch (codesign_tool) {
  2252. case 1: { // built-in ad-hoc
  2253. ad_hoc = true;
  2254. } break;
  2255. case 2: { // "rcodesign"
  2256. ad_hoc = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE).operator String().is_empty() || p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS).operator String().is_empty();
  2257. } break;
  2258. #ifdef MACOS_ENABLED
  2259. case 3: { // "codesign"
  2260. ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  2261. } break;
  2262. #endif
  2263. default: {
  2264. };
  2265. }
  2266. const String &additional_plist_content = p_preset->get("application/additional_plist_content");
  2267. if (!additional_plist_content.is_empty()) {
  2268. const String &plist = vformat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2269. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
  2270. "<plist version=\"1.0\">"
  2271. "<dict>\n"
  2272. "%s\n"
  2273. "</dict>\n"
  2274. "</plist>\n",
  2275. additional_plist_content);
  2276. String plist_err;
  2277. Ref<PList> plist_parser;
  2278. plist_parser.instantiate();
  2279. if (!plist_parser->load_string(plist, plist_err)) {
  2280. err += TTR("Invalid additional PList content: ") + plist_err + "\n";
  2281. valid = false;
  2282. }
  2283. }
  2284. List<ExportOption> options;
  2285. get_export_options(&options);
  2286. for (const EditorExportPlatform::ExportOption &E : options) {
  2287. if (get_export_option_visibility(p_preset.ptr(), E.option.name)) {
  2288. String warn = get_export_option_warning(p_preset.ptr(), E.option.name);
  2289. if (!warn.is_empty()) {
  2290. err += warn + "\n";
  2291. if (E.required) {
  2292. valid = false;
  2293. }
  2294. }
  2295. }
  2296. }
  2297. if (dist_type != 2) {
  2298. if (notary_tool > 0) {
  2299. if (notary_tool == 2 || notary_tool == 3) {
  2300. if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {
  2301. err += TTR("Notarization: Xcode command line tools are not installed.") + "\n";
  2302. valid = false;
  2303. }
  2304. } else if (notary_tool == 1) {
  2305. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  2306. if (rcodesign.is_empty()) {
  2307. err += TTR("Notarization: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";
  2308. valid = false;
  2309. }
  2310. }
  2311. } else {
  2312. err += TTR("Warning: Notarization is disabled. The exported project will be blocked by Gatekeeper if it's downloaded from an unknown source.") + "\n";
  2313. if (codesign_tool == 0) {
  2314. err += TTR("Code signing is disabled. The exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n";
  2315. }
  2316. }
  2317. }
  2318. if (codesign_tool > 0) {
  2319. if (ad_hoc) {
  2320. err += TTR("Code signing: Using ad-hoc signature. The exported project will be blocked by Gatekeeper") + "\n";
  2321. }
  2322. if (codesign_tool == 3) {
  2323. if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
  2324. err += TTR("Code signing: Xcode command line tools are not installed.") + "\n";
  2325. valid = false;
  2326. }
  2327. } else if (codesign_tool == 2) {
  2328. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  2329. if (rcodesign.is_empty()) {
  2330. err += TTR("Code signing: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";
  2331. valid = false;
  2332. }
  2333. }
  2334. }
  2335. if (!err.is_empty()) {
  2336. r_error = err;
  2337. }
  2338. return valid;
  2339. }
  2340. Ref<Texture2D> EditorExportPlatformMacOS::get_run_icon() const {
  2341. return run_icon;
  2342. }
  2343. bool EditorExportPlatformMacOS::poll_export() {
  2344. Ref<EditorExportPreset> preset;
  2345. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  2346. Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
  2347. if (ep->is_runnable() && ep->get_platform() == this) {
  2348. preset = ep;
  2349. break;
  2350. }
  2351. }
  2352. int prev = menu_options;
  2353. menu_options = (preset.is_valid() && preset->get("ssh_remote_deploy/enabled").operator bool());
  2354. if (ssh_pid != 0 || !cleanup_commands.is_empty()) {
  2355. if (menu_options == 0) {
  2356. cleanup();
  2357. } else {
  2358. menu_options += 1;
  2359. }
  2360. }
  2361. return menu_options != prev;
  2362. }
  2363. Ref<Texture2D> EditorExportPlatformMacOS::get_option_icon(int p_index) const {
  2364. if (p_index == 1) {
  2365. return stop_icon;
  2366. } else {
  2367. return EditorExportPlatform::get_option_icon(p_index);
  2368. }
  2369. }
  2370. int EditorExportPlatformMacOS::get_options_count() const {
  2371. return menu_options;
  2372. }
  2373. String EditorExportPlatformMacOS::get_option_label(int p_index) const {
  2374. return (p_index) ? TTR("Stop and uninstall") : TTR("Run on remote macOS system");
  2375. }
  2376. String EditorExportPlatformMacOS::get_option_tooltip(int p_index) const {
  2377. return (p_index) ? TTR("Stop and uninstall running project from the remote system") : TTR("Run exported project on remote macOS system");
  2378. }
  2379. void EditorExportPlatformMacOS::cleanup() {
  2380. if (ssh_pid != 0 && OS::get_singleton()->is_process_running(ssh_pid)) {
  2381. print_line("Terminating connection...");
  2382. OS::get_singleton()->kill(ssh_pid);
  2383. OS::get_singleton()->delay_usec(1000);
  2384. }
  2385. if (!cleanup_commands.is_empty()) {
  2386. print_line("Stopping and deleting previous version...");
  2387. for (const SSHCleanupCommand &cmd : cleanup_commands) {
  2388. if (cmd.wait) {
  2389. ssh_run_on_remote(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
  2390. } else {
  2391. ssh_run_on_remote_no_wait(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
  2392. }
  2393. }
  2394. }
  2395. ssh_pid = 0;
  2396. cleanup_commands.clear();
  2397. }
  2398. Error EditorExportPlatformMacOS::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) {
  2399. cleanup();
  2400. if (p_device) { // Stop command, cleanup only.
  2401. return OK;
  2402. }
  2403. EditorProgress ep("run", TTR("Running..."), 5);
  2404. const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("macos");
  2405. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  2406. if (!da->dir_exists(dest)) {
  2407. Error err = da->make_dir_recursive(dest);
  2408. if (err != OK) {
  2409. EditorNode::get_singleton()->show_warning(TTR("Could not create temp directory:") + "\n" + dest);
  2410. return err;
  2411. }
  2412. }
  2413. String pkg_name;
  2414. if (String(get_project_setting(p_preset, "application/config/name")) != "") {
  2415. pkg_name = String(get_project_setting(p_preset, "application/config/name"));
  2416. } else {
  2417. pkg_name = "Unnamed";
  2418. }
  2419. pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
  2420. String host = p_preset->get("ssh_remote_deploy/host").operator String();
  2421. String port = p_preset->get("ssh_remote_deploy/port").operator String();
  2422. if (port.is_empty()) {
  2423. port = "22";
  2424. }
  2425. Vector<String> extra_args_ssh = p_preset->get("ssh_remote_deploy/extra_args_ssh").operator String().split(" ", false);
  2426. Vector<String> extra_args_scp = p_preset->get("ssh_remote_deploy/extra_args_scp").operator String().split(" ", false);
  2427. const String basepath = dest.path_join("tmp_macos_export");
  2428. #define CLEANUP_AND_RETURN(m_err) \
  2429. { \
  2430. if (da->file_exists(basepath + ".zip")) { \
  2431. da->remove(basepath + ".zip"); \
  2432. } \
  2433. if (da->file_exists(basepath + "_start.sh")) { \
  2434. da->remove(basepath + "_start.sh"); \
  2435. } \
  2436. if (da->file_exists(basepath + "_clean.sh")) { \
  2437. da->remove(basepath + "_clean.sh"); \
  2438. } \
  2439. return m_err; \
  2440. } \
  2441. ((void)0)
  2442. if (ep.step(TTR("Exporting project..."), 1)) {
  2443. return ERR_SKIP;
  2444. }
  2445. Error err = export_project(p_preset, true, basepath + ".zip", p_debug_flags);
  2446. if (err != OK) {
  2447. DirAccess::remove_file_or_error(basepath + ".zip");
  2448. return err;
  2449. }
  2450. String cmd_args;
  2451. {
  2452. Vector<String> cmd_args_list = gen_export_flags(p_debug_flags);
  2453. for (int i = 0; i < cmd_args_list.size(); i++) {
  2454. if (i != 0) {
  2455. cmd_args += " ";
  2456. }
  2457. cmd_args += cmd_args_list[i];
  2458. }
  2459. }
  2460. const bool use_remote = p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG) || p_debug_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT);
  2461. int dbg_port = EDITOR_GET("network/debug/remote_port");
  2462. print_line("Creating temporary directory...");
  2463. ep.step(TTR("Creating temporary directory..."), 2);
  2464. String temp_dir;
  2465. err = ssh_run_on_remote(host, port, extra_args_ssh, "mktemp -d", &temp_dir);
  2466. if (err != OK || temp_dir.is_empty()) {
  2467. CLEANUP_AND_RETURN(err);
  2468. }
  2469. print_line("Uploading archive...");
  2470. ep.step(TTR("Uploading archive..."), 3);
  2471. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + ".zip", temp_dir);
  2472. if (err != OK) {
  2473. CLEANUP_AND_RETURN(err);
  2474. }
  2475. {
  2476. String run_script = p_preset->get("ssh_remote_deploy/run_script");
  2477. run_script = run_script.replace("{temp_dir}", temp_dir);
  2478. run_script = run_script.replace("{archive_name}", basepath.get_file() + ".zip");
  2479. run_script = run_script.replace("{exe_name}", pkg_name);
  2480. run_script = run_script.replace("{cmd_args}", cmd_args);
  2481. Ref<FileAccess> f = FileAccess::open(basepath + "_start.sh", FileAccess::WRITE);
  2482. if (f.is_null()) {
  2483. CLEANUP_AND_RETURN(err);
  2484. }
  2485. f->store_string(run_script);
  2486. }
  2487. {
  2488. String clean_script = p_preset->get("ssh_remote_deploy/cleanup_script");
  2489. clean_script = clean_script.replace("{temp_dir}", temp_dir);
  2490. clean_script = clean_script.replace("{archive_name}", basepath.get_file() + ".zip");
  2491. clean_script = clean_script.replace("{exe_name}", pkg_name);
  2492. clean_script = clean_script.replace("{cmd_args}", cmd_args);
  2493. Ref<FileAccess> f = FileAccess::open(basepath + "_clean.sh", FileAccess::WRITE);
  2494. if (f.is_null()) {
  2495. CLEANUP_AND_RETURN(err);
  2496. }
  2497. f->store_string(clean_script);
  2498. }
  2499. print_line("Uploading scripts...");
  2500. ep.step(TTR("Uploading scripts..."), 4);
  2501. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_start.sh", temp_dir);
  2502. if (err != OK) {
  2503. CLEANUP_AND_RETURN(err);
  2504. }
  2505. err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_start.sh"));
  2506. if (err != OK || temp_dir.is_empty()) {
  2507. CLEANUP_AND_RETURN(err);
  2508. }
  2509. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_clean.sh", temp_dir);
  2510. if (err != OK) {
  2511. CLEANUP_AND_RETURN(err);
  2512. }
  2513. err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh"));
  2514. if (err != OK || temp_dir.is_empty()) {
  2515. CLEANUP_AND_RETURN(err);
  2516. }
  2517. print_line("Starting project...");
  2518. ep.step(TTR("Starting project..."), 5);
  2519. err = ssh_run_on_remote_no_wait(host, port, extra_args_ssh, vformat("\"%s/%s\"", temp_dir, basepath.get_file() + "_start.sh"), &ssh_pid, (use_remote) ? dbg_port : -1);
  2520. if (err != OK) {
  2521. CLEANUP_AND_RETURN(err);
  2522. }
  2523. cleanup_commands.clear();
  2524. cleanup_commands.push_back(SSHCleanupCommand(host, port, extra_args_ssh, vformat("\"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh")));
  2525. print_line("Project started.");
  2526. CLEANUP_AND_RETURN(OK);
  2527. #undef CLEANUP_AND_RETURN
  2528. }
  2529. void EditorExportPlatformMacOS::initialize() {
  2530. if (EditorNode::get_singleton()) {
  2531. Ref<Image> img = memnew(Image);
  2532. const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
  2533. ImageLoaderSVG::create_image_from_string(img, _macos_logo_svg, EDSCALE, upsample, false);
  2534. logo = ImageTexture::create_from_image(img);
  2535. ImageLoaderSVG::create_image_from_string(img, _macos_run_icon_svg, EDSCALE, upsample, false);
  2536. run_icon = ImageTexture::create_from_image(img);
  2537. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  2538. if (theme.is_valid()) {
  2539. stop_icon = theme->get_icon(SNAME("Stop"), EditorStringName(EditorIcons));
  2540. } else {
  2541. stop_icon.instantiate();
  2542. }
  2543. }
  2544. }