export_plugin.cpp 120 KB

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