export_plugin.cpp 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728
  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 < sizeof(data_collect_purpose_info) / sizeof(data_collect_purpose_info[0]); ++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 < sizeof(data_collect_type_info) / sizeof(data_collect_type_info[0]); ++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 < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++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;
  669. String strnew;
  670. str.parse_utf8((const char *)plist.ptr(), plist.size());
  671. Vector<String> lines = str.split("\n");
  672. for (int i = 0; i < lines.size(); i++) {
  673. if (lines[i].find("$priv_collection") != -1) {
  674. bool section_opened = false;
  675. for (uint64_t j = 0; j < sizeof(data_collect_type_info) / sizeof(data_collect_type_info[0]); ++j) {
  676. bool data_collected = p_preset->get(vformat("privacy/collected_data/%s/collected", data_collect_type_info[j].prop_name));
  677. bool linked = p_preset->get(vformat("privacy/collected_data/%s/linked_to_user", data_collect_type_info[j].prop_name));
  678. bool tracking = p_preset->get(vformat("privacy/collected_data/%s/used_for_tracking", data_collect_type_info[j].prop_name));
  679. int purposes = p_preset->get(vformat("privacy/collected_data/%s/collection_purposes", data_collect_type_info[j].prop_name));
  680. if (data_collected) {
  681. if (!section_opened) {
  682. section_opened = true;
  683. strnew += "\t<key>NSPrivacyCollectedDataTypes</key>\n";
  684. strnew += "\t<array>\n";
  685. }
  686. strnew += "\t\t<dict>\n";
  687. strnew += "\t\t\t<key>NSPrivacyCollectedDataType</key>\n";
  688. strnew += vformat("\t\t\t<string>%s</string>\n", data_collect_type_info[j].type_name);
  689. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeLinked</key>\n";
  690. if (linked) {
  691. strnew += "\t\t\t\t<true/>\n";
  692. } else {
  693. strnew += "\t\t\t\t<false/>\n";
  694. }
  695. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypeTracking</key>\n";
  696. if (tracking) {
  697. strnew += "\t\t\t\t<true/>\n";
  698. } else {
  699. strnew += "\t\t\t\t<false/>\n";
  700. }
  701. if (purposes != 0) {
  702. strnew += "\t\t\t\t<key>NSPrivacyCollectedDataTypePurposes</key>\n";
  703. strnew += "\t\t\t\t<array>\n";
  704. for (uint64_t k = 0; k < sizeof(data_collect_purpose_info) / sizeof(data_collect_purpose_info[0]); ++k) {
  705. if (purposes & (1 << k)) {
  706. strnew += vformat("\t\t\t\t\t<string>%s</string>\n", data_collect_purpose_info[k].type_name);
  707. }
  708. }
  709. strnew += "\t\t\t\t</array>\n";
  710. }
  711. strnew += "\t\t\t</dict>\n";
  712. }
  713. }
  714. if (section_opened) {
  715. strnew += "\t</array>\n";
  716. }
  717. } else if (lines[i].find("$priv_tracking") != -1) {
  718. bool tracking = p_preset->get("privacy/tracking_enabled");
  719. strnew += "\t<key>NSPrivacyTracking</key>\n";
  720. if (tracking) {
  721. strnew += "\t<true/>\n";
  722. } else {
  723. strnew += "\t<false/>\n";
  724. }
  725. Vector<String> tracking_domains = p_preset->get("privacy/tracking_domains");
  726. if (!tracking_domains.is_empty()) {
  727. strnew += "\t<key>NSPrivacyTrackingDomains</key>\n";
  728. strnew += "\t<array>\n";
  729. for (const String &E : tracking_domains) {
  730. strnew += "\t\t<string>" + E + "</string>\n";
  731. }
  732. strnew += "\t</array>\n";
  733. }
  734. } else {
  735. strnew += lines[i] + "\n";
  736. }
  737. }
  738. CharString cs = strnew.utf8();
  739. plist.resize(cs.size() - 1);
  740. for (int i = 0; i < cs.size() - 1; i++) {
  741. plist.write[i] = cs[i];
  742. }
  743. }
  744. void EditorExportPlatformMacOS::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) {
  745. String str;
  746. String strnew;
  747. str.parse_utf8((const char *)plist.ptr(), plist.size());
  748. Vector<String> lines = str.split("\n");
  749. for (int i = 0; i < lines.size(); i++) {
  750. if (lines[i].contains("$binary")) {
  751. strnew += lines[i].replace("$binary", p_binary) + "\n";
  752. } else if (lines[i].contains("$name")) {
  753. strnew += lines[i].replace("$name", GLOBAL_GET("application/config/name")) + "\n";
  754. } else if (lines[i].contains("$bundle_identifier")) {
  755. strnew += lines[i].replace("$bundle_identifier", p_preset->get("application/bundle_identifier")) + "\n";
  756. } else if (lines[i].contains("$short_version")) {
  757. strnew += lines[i].replace("$short_version", p_preset->get_version("application/short_version")) + "\n";
  758. } else if (lines[i].contains("$version")) {
  759. strnew += lines[i].replace("$version", p_preset->get_version("application/version")) + "\n";
  760. } else if (lines[i].contains("$signature")) {
  761. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  762. } else if (lines[i].contains("$app_category")) {
  763. String cat = p_preset->get("application/app_category");
  764. strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n";
  765. } else if (lines[i].contains("$copyright")) {
  766. strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
  767. } else if (lines[i].contains("$min_version_arm64")) {
  768. strnew += lines[i].replace("$min_version_arm64", p_preset->get("application/min_macos_version_arm64")) + "\n";
  769. } else if (lines[i].contains("$min_version_x86_64")) {
  770. strnew += lines[i].replace("$min_version_x86_64", p_preset->get("application/min_macos_version_x86_64")) + "\n";
  771. } else if (lines[i].contains("$min_version")) {
  772. strnew += lines[i].replace("$min_version", p_preset->get("application/min_macos_version_x86_64")) + "\n"; // Old template, use x86-64 version for both.
  773. } else if (lines[i].contains("$highres")) {
  774. strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "\t<true/>" : "\t<false/>") + "\n";
  775. } else if (lines[i].contains("$additional_plist_content")) {
  776. strnew += lines[i].replace("$additional_plist_content", p_preset->get("application/additional_plist_content")) + "\n";
  777. } else if (lines[i].contains("$platfbuild")) {
  778. strnew += lines[i].replace("$platfbuild", p_preset->get("xcode/platform_build")) + "\n";
  779. } else if (lines[i].contains("$sdkver")) {
  780. strnew += lines[i].replace("$sdkver", p_preset->get("xcode/sdk_version")) + "\n";
  781. } else if (lines[i].contains("$sdkname")) {
  782. strnew += lines[i].replace("$sdkname", p_preset->get("xcode/sdk_name")) + "\n";
  783. } else if (lines[i].contains("$sdkbuild")) {
  784. strnew += lines[i].replace("$sdkbuild", p_preset->get("xcode/sdk_build")) + "\n";
  785. } else if (lines[i].contains("$xcodever")) {
  786. strnew += lines[i].replace("$xcodever", p_preset->get("xcode/xcode_version")) + "\n";
  787. } else if (lines[i].contains("$xcodebuild")) {
  788. strnew += lines[i].replace("$xcodebuild", p_preset->get("xcode/xcode_build")) + "\n";
  789. } else if (lines[i].contains("$usage_descriptions")) {
  790. String descriptions;
  791. if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
  792. descriptions += "\t<key>NSMicrophoneUsageDescription</key>\n";
  793. descriptions += "\t<string>" + (String)p_preset->get("privacy/microphone_usage_description") + "</string>\n";
  794. }
  795. if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
  796. descriptions += "\t<key>NSCameraUsageDescription</key>\n";
  797. descriptions += "\t<string>" + (String)p_preset->get("privacy/camera_usage_description") + "</string>\n";
  798. }
  799. if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
  800. descriptions += "\t<key>NSLocationUsageDescription</key>\n";
  801. descriptions += "\t<string>" + (String)p_preset->get("privacy/location_usage_description") + "</string>\n";
  802. }
  803. if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
  804. descriptions += "\t<key>NSContactsUsageDescription</key>\n";
  805. descriptions += "\t<string>" + (String)p_preset->get("privacy/address_book_usage_description") + "</string>\n";
  806. }
  807. if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
  808. descriptions += "\t<key>NSCalendarsUsageDescription</key>\n";
  809. descriptions += "\t<string>" + (String)p_preset->get("privacy/calendar_usage_description") + "</string>\n";
  810. }
  811. if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
  812. descriptions += "\t<key>NSPhotoLibraryUsageDescription</key>\n";
  813. descriptions += "\t<string>" + (String)p_preset->get("privacy/photos_library_usage_description") + "</string>\n";
  814. }
  815. if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {
  816. descriptions += "\t<key>NSDesktopFolderUsageDescription</key>\n";
  817. descriptions += "\t<string>" + (String)p_preset->get("privacy/desktop_folder_usage_description") + "</string>\n";
  818. }
  819. if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {
  820. descriptions += "\t<key>NSDocumentsFolderUsageDescription</key>\n";
  821. descriptions += "\t<string>" + (String)p_preset->get("privacy/documents_folder_usage_description") + "</string>\n";
  822. }
  823. if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {
  824. descriptions += "\t<key>NSDownloadsFolderUsageDescription</key>\n";
  825. descriptions += "\t<string>" + (String)p_preset->get("privacy/downloads_folder_usage_description") + "</string>\n";
  826. }
  827. if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {
  828. descriptions += "\t<key>NSNetworkVolumesUsageDescription</key>\n";
  829. descriptions += "\t<string>" + (String)p_preset->get("privacy/network_volumes_usage_description") + "</string>\n";
  830. }
  831. if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {
  832. descriptions += "\t<key>NSRemovableVolumesUsageDescription</key>\n";
  833. descriptions += "\t<string>" + (String)p_preset->get("privacy/removable_volumes_usage_description") + "</string>\n";
  834. }
  835. if (!descriptions.is_empty()) {
  836. strnew += lines[i].replace("$usage_descriptions", descriptions);
  837. }
  838. } else {
  839. strnew += lines[i] + "\n";
  840. }
  841. }
  842. CharString cs = strnew.utf8();
  843. plist.resize(cs.size() - 1);
  844. for (int i = 0; i < cs.size() - 1; i++) {
  845. plist.write[i] = cs[i];
  846. }
  847. }
  848. /**
  849. * If we're running the macOS version of the Godot editor we'll:
  850. * - export our application bundle to a temporary folder
  851. * - attempt to code sign it
  852. * - and then wrap it up in a DMG
  853. */
  854. Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  855. int notary_tool = p_preset->get("notarization/notarization");
  856. switch (notary_tool) {
  857. case 1: { // "rcodesign"
  858. print_verbose("using rcodesign notarization...");
  859. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  860. if (rcodesign.is_empty()) {
  861. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));
  862. return Error::FAILED;
  863. }
  864. List<String> args;
  865. args.push_back("notary-submit");
  866. if (p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID) == "") {
  867. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect issuer ID name not specified."));
  868. return Error::FAILED;
  869. }
  870. if (p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY) == "") {
  871. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));
  872. return Error::FAILED;
  873. }
  874. args.push_back("--api-issuer");
  875. args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID));
  876. args.push_back("--api-key");
  877. args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID));
  878. if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) {
  879. args.push_back("--api-key-path");
  880. args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY));
  881. }
  882. args.push_back(p_path);
  883. String str;
  884. int exitcode = 0;
  885. Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);
  886. if (err != OK) {
  887. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start rcodesign executable."));
  888. return err;
  889. }
  890. int rq_offset = str.find("created submission ID:");
  891. if (exitcode != 0 || rq_offset == -1) {
  892. print_line("rcodesign (" + p_path + "):\n" + str);
  893. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));
  894. return Error::FAILED;
  895. } else {
  896. print_verbose("rcodesign (" + p_path + "):\n" + str);
  897. int next_nl = str.find_char('\n', rq_offset);
  898. String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 23, -1) : str.substr(rq_offset + 23, next_nl - rq_offset - 23);
  899. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));
  900. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour."));
  901. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:"));
  902. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign notary-log --api-issuer <api uuid> --api-key <api key> <request uuid>\"");
  903. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));
  904. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign staple <app path>\"");
  905. }
  906. } break;
  907. #ifdef MACOS_ENABLED
  908. case 2: { // "notarytool"
  909. print_verbose("using notarytool notarization...");
  910. if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {
  911. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed."));
  912. return Error::FAILED;
  913. }
  914. List<String> args;
  915. args.push_back("notarytool");
  916. args.push_back("submit");
  917. args.push_back(p_path);
  918. 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) == "") {
  919. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified."));
  920. return Error::FAILED;
  921. }
  922. 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) != "") {
  923. 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."));
  924. return Error::FAILED;
  925. }
  926. if (p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID) != "") {
  927. if (p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS) == "") {
  928. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified."));
  929. return Error::FAILED;
  930. }
  931. args.push_back("--apple-id");
  932. args.push_back(p_preset->get_or_env("notarization/apple_id_name", ENV_MAC_NOTARIZATION_APPLE_ID));
  933. args.push_back("--password");
  934. args.push_back(p_preset->get_or_env("notarization/apple_id_password", ENV_MAC_NOTARIZATION_APPLE_PASS));
  935. } else {
  936. if (p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID) == "") {
  937. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));
  938. return Error::FAILED;
  939. }
  940. args.push_back("--issuer");
  941. args.push_back(p_preset->get_or_env("notarization/api_uuid", ENV_MAC_NOTARIZATION_UUID));
  942. if (!p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY).operator String().is_empty()) {
  943. args.push_back("--key");
  944. args.push_back(p_preset->get_or_env("notarization/api_key", ENV_MAC_NOTARIZATION_KEY));
  945. }
  946. args.push_back("--key-id");
  947. args.push_back(p_preset->get_or_env("notarization/api_key_id", ENV_MAC_NOTARIZATION_KEY_ID));
  948. }
  949. args.push_back("--no-progress");
  950. if (p_preset->get("codesign/apple_team_id")) {
  951. args.push_back("--team-id");
  952. args.push_back(p_preset->get("codesign/apple_team_id"));
  953. }
  954. String str;
  955. int exitcode = 0;
  956. Error err = OS::get_singleton()->execute("xcrun", args, &str, &exitcode, true);
  957. if (err != OK) {
  958. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable."));
  959. return err;
  960. }
  961. int rq_offset = str.find("id:");
  962. if (exitcode != 0 || rq_offset == -1) {
  963. print_line("notarytool (" + p_path + "):\n" + str);
  964. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));
  965. return Error::FAILED;
  966. } else {
  967. print_verbose("notarytool (" + p_path + "):\n" + str);
  968. int next_nl = str.find_char('\n', rq_offset);
  969. String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 4, -1) : str.substr(rq_offset + 4, next_nl - rq_offset - 4);
  970. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));
  971. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour."));
  972. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:"));
  973. 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");
  974. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request uuid> --apple-id <your email> --password <app-specific pwd>>\"");
  975. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));
  976. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple <app path>\"");
  977. }
  978. } break;
  979. #endif
  980. default: {
  981. };
  982. }
  983. return OK;
  984. }
  985. 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) {
  986. int codesign_tool = p_preset->get("codesign/codesign");
  987. switch (codesign_tool) {
  988. case 1: { // built-in ad-hoc
  989. print_verbose("using built-in codesign...");
  990. String error_msg;
  991. Error err = CodeSign::codesign(false, true, p_path, p_ent_path, error_msg);
  992. if (err != OK) {
  993. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Built-in CodeSign failed with error \"%s\"."), error_msg));
  994. return;
  995. }
  996. } break;
  997. case 2: { // "rcodesign"
  998. print_verbose("using rcodesign codesign...");
  999. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  1000. if (rcodesign.is_empty()) {
  1001. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xrcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));
  1002. return;
  1003. }
  1004. List<String> args;
  1005. args.push_back("sign");
  1006. if (!p_ent_path.is_empty()) {
  1007. args.push_back("--entitlements-xml-path");
  1008. args.push_back(p_ent_path);
  1009. }
  1010. String certificate_file = p_preset->get_or_env("codesign/certificate_file", ENV_MAC_CODESIGN_CERT_FILE);
  1011. String certificate_pass = p_preset->get_or_env("codesign/certificate_password", ENV_MAC_CODESIGN_CERT_PASS);
  1012. if (!certificate_file.is_empty() && !certificate_pass.is_empty()) {
  1013. args.push_back("--p12-file");
  1014. args.push_back(certificate_file);
  1015. args.push_back("--p12-password");
  1016. args.push_back(certificate_pass);
  1017. }
  1018. args.push_back("--code-signature-flags");
  1019. args.push_back("runtime");
  1020. if (p_set_id) {
  1021. String app_id = p_preset->get("application/bundle_identifier");
  1022. args.push_back("--binary-identifier");
  1023. args.push_back(app_id);
  1024. }
  1025. args.push_back("-v"); /* provide some more feedback */
  1026. args.push_back(p_path);
  1027. String str;
  1028. int exitcode = 0;
  1029. Error err = OS::get_singleton()->execute(rcodesign, args, &str, &exitcode, true);
  1030. if (err != OK) {
  1031. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start rcodesign executable."));
  1032. return;
  1033. }
  1034. if (exitcode != 0) {
  1035. print_line("rcodesign (" + p_path + "):\n" + str);
  1036. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  1037. return;
  1038. } else {
  1039. print_verbose("rcodesign (" + p_path + "):\n" + str);
  1040. }
  1041. } break;
  1042. #ifdef MACOS_ENABLED
  1043. case 3: { // "codesign"
  1044. print_verbose("using xcode codesign...");
  1045. if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
  1046. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xcode command line tools are not installed."));
  1047. return;
  1048. }
  1049. bool ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  1050. List<String> args;
  1051. if (!ad_hoc) {
  1052. args.push_back("--timestamp");
  1053. args.push_back("--options");
  1054. args.push_back("runtime");
  1055. }
  1056. if (!p_ent_path.is_empty()) {
  1057. args.push_back("--entitlements");
  1058. args.push_back(p_ent_path);
  1059. }
  1060. PackedStringArray user_args = p_preset->get("codesign/custom_options");
  1061. for (int i = 0; i < user_args.size(); i++) {
  1062. String user_arg = user_args[i].strip_edges();
  1063. if (!user_arg.is_empty()) {
  1064. args.push_back(user_arg);
  1065. }
  1066. }
  1067. args.push_back("-s");
  1068. if (ad_hoc) {
  1069. args.push_back("-");
  1070. } else {
  1071. args.push_back(p_preset->get("codesign/identity"));
  1072. }
  1073. if (p_set_id) {
  1074. String app_id = p_preset->get("application/bundle_identifier");
  1075. args.push_back("-i");
  1076. args.push_back(app_id);
  1077. }
  1078. args.push_back("-v"); /* provide some more feedback */
  1079. args.push_back("-f");
  1080. args.push_back(p_path);
  1081. String str;
  1082. int exitcode = 0;
  1083. Error err = OS::get_singleton()->execute("codesign", args, &str, &exitcode, true);
  1084. if (err != OK) {
  1085. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start codesign executable, make sure Xcode command line tools are installed."));
  1086. return;
  1087. }
  1088. if (exitcode != 0) {
  1089. print_line("codesign (" + p_path + "):\n" + str);
  1090. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  1091. return;
  1092. } else {
  1093. print_verbose("codesign (" + p_path + "):\n" + str);
  1094. }
  1095. } break;
  1096. #endif
  1097. default: {
  1098. };
  1099. }
  1100. }
  1101. void EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path,
  1102. const String &p_ent_path, const String &p_helper_ent_path, bool p_should_error_on_non_code) {
  1103. static Vector<String> extensions_to_sign;
  1104. bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");
  1105. if (extensions_to_sign.is_empty()) {
  1106. extensions_to_sign.push_back("dylib");
  1107. extensions_to_sign.push_back("framework");
  1108. extensions_to_sign.push_back("");
  1109. }
  1110. Error dir_access_error;
  1111. Ref<DirAccess> dir_access{ DirAccess::open(p_path, &dir_access_error) };
  1112. if (dir_access_error != OK) {
  1113. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign directory %s."), p_path));
  1114. return;
  1115. }
  1116. dir_access->list_dir_begin();
  1117. String current_file{ dir_access->get_next() };
  1118. while (!current_file.is_empty()) {
  1119. String current_file_path{ p_path.path_join(current_file) };
  1120. if (current_file == ".." || current_file == ".") {
  1121. current_file = dir_access->get_next();
  1122. continue;
  1123. }
  1124. if (extensions_to_sign.has(current_file.get_extension())) {
  1125. String ent_path;
  1126. bool set_bundle_id = false;
  1127. if (sandbox && FileAccess::exists(current_file_path)) {
  1128. int ftype = MachO::get_filetype(current_file_path);
  1129. if (ftype == 2 || ftype == 5) {
  1130. ent_path = p_helper_ent_path;
  1131. set_bundle_id = true;
  1132. }
  1133. }
  1134. _code_sign(p_preset, current_file_path, ent_path, false, set_bundle_id);
  1135. if (is_executable(current_file_path)) {
  1136. // chmod with 0755 if the file is executable.
  1137. FileAccess::set_unix_permissions(current_file_path, 0755);
  1138. }
  1139. } else if (dir_access->current_is_dir()) {
  1140. _code_sign_directory(p_preset, current_file_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code);
  1141. } else if (p_should_error_on_non_code) {
  1142. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign file %s."), current_file));
  1143. }
  1144. current_file = dir_access->get_next();
  1145. }
  1146. }
  1147. Error EditorExportPlatformMacOS::_copy_and_sign_files(Ref<DirAccess> &dir_access, const String &p_src_path,
  1148. const String &p_in_app_path, bool p_sign_enabled,
  1149. const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,
  1150. const String &p_helper_ent_path,
  1151. bool p_should_error_on_non_code_sign, bool p_sandbox) {
  1152. static Vector<String> extensions_to_sign;
  1153. if (extensions_to_sign.is_empty()) {
  1154. extensions_to_sign.push_back("dylib");
  1155. extensions_to_sign.push_back("framework");
  1156. extensions_to_sign.push_back("");
  1157. }
  1158. Error err{ OK };
  1159. if (dir_access->dir_exists(p_src_path)) {
  1160. #ifndef UNIX_ENABLED
  1161. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Relative symlinks are not supported, exported \"%s\" might be broken!"), p_src_path.get_file()));
  1162. #endif
  1163. print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path);
  1164. bool plist_missing = false;
  1165. Ref<PList> plist;
  1166. plist.instantiate();
  1167. plist->load_file(p_src_path.path_join("Resources").path_join("Info.plist"));
  1168. Ref<PListNode> root_node = plist->get_root();
  1169. if (root_node.is_null()) {
  1170. plist_missing = true;
  1171. } else {
  1172. Dictionary root = root_node->get_value();
  1173. if (!root.has("CFBundleExecutable") || !root.has("CFBundleIdentifier") || !root.has("CFBundlePackageType") || !root.has("CFBundleInfoDictionaryVersion") || !root.has("CFBundleName") || !root.has("CFBundleSupportedPlatforms")) {
  1174. plist_missing = true;
  1175. }
  1176. }
  1177. err = dir_access->make_dir_recursive(p_in_app_path);
  1178. if (err == OK) {
  1179. err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true);
  1180. }
  1181. if (err == OK && plist_missing) {
  1182. add_message(EXPORT_MESSAGE_WARNING, TTR("Export"), vformat(TTR("\"%s\": Info.plist missing or invalid, new Info.plist generated."), p_src_path.get_file()));
  1183. // Generate Info.plist
  1184. String lib_name = p_src_path.get_basename().get_file();
  1185. String lib_id = p_preset->get("application/bundle_identifier");
  1186. String lib_clean_name = lib_name;
  1187. for (int i = 0; i < lib_clean_name.length(); i++) {
  1188. if (!is_ascii_alphanumeric_char(lib_clean_name[i]) && lib_clean_name[i] != '.' && lib_clean_name[i] != '-') {
  1189. lib_clean_name[i] = '-';
  1190. }
  1191. }
  1192. String info_plist_format = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1193. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
  1194. "<plist version=\"1.0\">\n"
  1195. " <dict>\n"
  1196. " <key>CFBundleExecutable</key>\n"
  1197. " <string>$name</string>\n"
  1198. " <key>CFBundleIdentifier</key>\n"
  1199. " <string>$id.framework.$cl_name</string>\n"
  1200. " <key>CFBundleInfoDictionaryVersion</key>\n"
  1201. " <string>6.0</string>\n"
  1202. " <key>CFBundleName</key>\n"
  1203. " <string>$name</string>\n"
  1204. " <key>CFBundlePackageType</key>\n"
  1205. " <string>FMWK</string>\n"
  1206. " <key>CFBundleShortVersionString</key>\n"
  1207. " <string>1.0.0</string>\n"
  1208. " <key>CFBundleSupportedPlatforms</key>\n"
  1209. " <array>\n"
  1210. " <string>MacOSX</string>\n"
  1211. " </array>\n"
  1212. " <key>CFBundleVersion</key>\n"
  1213. " <string>1.0.0</string>\n"
  1214. " <key>LSMinimumSystemVersion</key>\n"
  1215. " <string>10.12</string>\n"
  1216. " </dict>\n"
  1217. "</plist>";
  1218. String info_plist = info_plist_format.replace("$id", lib_id).replace("$name", lib_name).replace("$cl_name", lib_clean_name);
  1219. err = dir_access->make_dir_recursive(p_in_app_path.path_join("Resources"));
  1220. Ref<FileAccess> f = FileAccess::open(p_in_app_path.path_join("Resources").path_join("Info.plist"), FileAccess::WRITE);
  1221. if (f.is_valid()) {
  1222. f->store_string(info_plist);
  1223. }
  1224. }
  1225. } else {
  1226. print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path);
  1227. err = dir_access->copy(p_src_path, p_in_app_path);
  1228. }
  1229. if (err == OK && p_sign_enabled) {
  1230. if (dir_access->dir_exists(p_src_path) && p_src_path.get_extension().is_empty()) {
  1231. // If it is a directory, find and sign all dynamic libraries.
  1232. _code_sign_directory(p_preset, p_in_app_path, p_ent_path, p_helper_ent_path, p_should_error_on_non_code_sign);
  1233. } else {
  1234. if (extensions_to_sign.has(p_in_app_path.get_extension())) {
  1235. String ent_path;
  1236. bool set_bundle_id = false;
  1237. if (p_sandbox && FileAccess::exists(p_in_app_path)) {
  1238. int ftype = MachO::get_filetype(p_in_app_path);
  1239. if (ftype == 2 || ftype == 5) {
  1240. ent_path = p_helper_ent_path;
  1241. set_bundle_id = true;
  1242. }
  1243. }
  1244. _code_sign(p_preset, p_in_app_path, ent_path, false, set_bundle_id);
  1245. }
  1246. if (dir_access->file_exists(p_in_app_path) && is_executable(p_in_app_path)) {
  1247. // chmod with 0755 if the file is executable.
  1248. FileAccess::set_unix_permissions(p_in_app_path, 0755);
  1249. }
  1250. }
  1251. }
  1252. return err;
  1253. }
  1254. Error EditorExportPlatformMacOS::_export_macos_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin,
  1255. const String &p_app_path_name, Ref<DirAccess> &dir_access,
  1256. bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,
  1257. const String &p_ent_path, const String &p_helper_ent_path, bool p_sandbox) {
  1258. Error error{ OK };
  1259. const Vector<String> &macos_plugins{ p_editor_export_plugin->get_macos_plugin_files() };
  1260. for (int i = 0; i < macos_plugins.size(); ++i) {
  1261. String src_path{ ProjectSettings::get_singleton()->globalize_path(macos_plugins[i]) };
  1262. String path_in_app{ p_app_path_name + "/Contents/PlugIns/" + src_path.get_file() };
  1263. 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);
  1264. if (error != OK) {
  1265. break;
  1266. }
  1267. }
  1268. return error;
  1269. }
  1270. Error EditorExportPlatformMacOS::_create_pkg(const Ref<EditorExportPreset> &p_preset, const String &p_pkg_path, const String &p_app_path_name) {
  1271. List<String> args;
  1272. if (FileAccess::exists(p_pkg_path)) {
  1273. OS::get_singleton()->move_to_trash(p_pkg_path);
  1274. }
  1275. args.push_back("productbuild");
  1276. args.push_back("--component");
  1277. args.push_back(p_app_path_name);
  1278. args.push_back("/Applications");
  1279. String ident = p_preset->get("codesign/installer_identity");
  1280. if (!ident.is_empty()) {
  1281. args.push_back("--timestamp");
  1282. args.push_back("--sign");
  1283. args.push_back(ident);
  1284. }
  1285. args.push_back("--quiet");
  1286. args.push_back(p_pkg_path);
  1287. String str;
  1288. Error err = OS::get_singleton()->execute("xcrun", args, &str, nullptr, true);
  1289. if (err != OK) {
  1290. add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("Could not start productbuild executable."));
  1291. return err;
  1292. }
  1293. print_verbose("productbuild returned: " + str);
  1294. if (str.contains("productbuild: error:")) {
  1295. add_message(EXPORT_MESSAGE_ERROR, TTR("PKG Creation"), TTR("`productbuild` failed."));
  1296. return FAILED;
  1297. }
  1298. return OK;
  1299. }
  1300. Error EditorExportPlatformMacOS::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
  1301. List<String> args;
  1302. if (FileAccess::exists(p_dmg_path)) {
  1303. OS::get_singleton()->move_to_trash(p_dmg_path);
  1304. }
  1305. args.push_back("create");
  1306. args.push_back(p_dmg_path);
  1307. args.push_back("-volname");
  1308. args.push_back(p_pkg_name);
  1309. args.push_back("-fs");
  1310. args.push_back("HFS+");
  1311. args.push_back("-srcfolder");
  1312. args.push_back(p_app_path_name);
  1313. String str;
  1314. Error err = OS::get_singleton()->execute("hdiutil", args, &str, nullptr, true);
  1315. if (err != OK) {
  1316. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("Could not start hdiutil executable."));
  1317. return err;
  1318. }
  1319. print_verbose("hdiutil returned: " + str);
  1320. if (str.contains("create failed")) {
  1321. if (str.contains("File exists")) {
  1322. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed - file exists."));
  1323. } else {
  1324. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed."));
  1325. }
  1326. return FAILED;
  1327. }
  1328. return OK;
  1329. }
  1330. bool EditorExportPlatformMacOS::is_shebang(const String &p_path) const {
  1331. Ref<FileAccess> fb = FileAccess::open(p_path, FileAccess::READ);
  1332. ERR_FAIL_COND_V_MSG(fb.is_null(), false, vformat("Can't open file: \"%s\".", p_path));
  1333. uint16_t magic = fb->get_16();
  1334. return (magic == 0x2123);
  1335. }
  1336. bool EditorExportPlatformMacOS::is_executable(const String &p_path) const {
  1337. return MachO::is_macho(p_path) || LipO::is_lipo(p_path) || is_shebang(p_path);
  1338. }
  1339. Error EditorExportPlatformMacOS::_export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path) {
  1340. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE);
  1341. if (f.is_null()) {
  1342. add_message(EXPORT_MESSAGE_ERROR, TTR("Debug Script Export"), vformat(TTR("Could not open file \"%s\"."), p_path));
  1343. return ERR_CANT_CREATE;
  1344. }
  1345. f->store_line("#!/bin/sh");
  1346. f->store_line("echo -ne '\\033c\\033]0;" + p_app_name + "\\a'");
  1347. f->store_line("");
  1348. f->store_line("function app_realpath() {");
  1349. f->store_line(" SOURCE=$1");
  1350. f->store_line(" while [ -h \"$SOURCE\" ]; do");
  1351. f->store_line(" DIR=$(dirname \"$SOURCE\")");
  1352. f->store_line(" SOURCE=$(readlink \"$SOURCE\")");
  1353. f->store_line(" [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE");
  1354. f->store_line(" done");
  1355. f->store_line(" echo \"$( cd -P \"$( dirname \"$SOURCE\" )\" >/dev/null 2>&1 && pwd )\"");
  1356. f->store_line("}");
  1357. f->store_line("");
  1358. f->store_line("BASE_PATH=\"$(app_realpath \"${BASH_SOURCE[0]}\")\"");
  1359. f->store_line("\"$BASE_PATH/" + p_pkg_name + "\" \"$@\"");
  1360. f->store_line("");
  1361. return OK;
  1362. }
  1363. Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) {
  1364. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  1365. const String base_dir = p_path.get_base_dir();
  1366. if (!DirAccess::exists(base_dir)) {
  1367. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Target folder does not exist or is inaccessible: \"%s\""), base_dir));
  1368. return ERR_FILE_BAD_PATH;
  1369. }
  1370. EditorProgress ep("export", TTR("Exporting for macOS"), 3, true);
  1371. String src_pkg_name;
  1372. if (p_debug) {
  1373. src_pkg_name = p_preset->get("custom_template/debug");
  1374. } else {
  1375. src_pkg_name = p_preset->get("custom_template/release");
  1376. }
  1377. if (src_pkg_name.is_empty()) {
  1378. String err;
  1379. src_pkg_name = find_export_template("macos.zip", &err);
  1380. if (src_pkg_name.is_empty()) {
  1381. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found.") + "\n" + err);
  1382. return ERR_FILE_NOT_FOUND;
  1383. }
  1384. }
  1385. Ref<FileAccess> io_fa;
  1386. zlib_filefunc_def io = zipio_create_io(&io_fa);
  1387. if (ep.step(TTR("Creating app bundle"), 0)) {
  1388. return ERR_SKIP;
  1389. }
  1390. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  1391. if (!src_pkg_zip) {
  1392. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not find template app to export: \"%s\"."), src_pkg_name));
  1393. return ERR_FILE_NOT_FOUND;
  1394. }
  1395. int ret = unzGoToFirstFile(src_pkg_zip);
  1396. String architecture = p_preset->get("binary_format/architecture");
  1397. String binary_to_use = "godot_macos_" + String(p_debug ? "debug" : "release") + "." + architecture;
  1398. String pkg_name;
  1399. if (String(GLOBAL_GET("application/config/name")) != "") {
  1400. pkg_name = String(GLOBAL_GET("application/config/name"));
  1401. } else {
  1402. pkg_name = "Unnamed";
  1403. }
  1404. pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
  1405. String export_format;
  1406. if (p_path.ends_with("zip")) {
  1407. export_format = "zip";
  1408. } else if (p_path.ends_with("app")) {
  1409. export_format = "app";
  1410. #ifdef MACOS_ENABLED
  1411. } else if (p_path.ends_with("dmg")) {
  1412. export_format = "dmg";
  1413. } else if (p_path.ends_with("pkg")) {
  1414. export_format = "pkg";
  1415. #endif
  1416. } else {
  1417. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Invalid export format."));
  1418. return ERR_CANT_CREATE;
  1419. }
  1420. // Create our application bundle.
  1421. String tmp_app_dir_name = pkg_name + ".app";
  1422. String tmp_base_path_name;
  1423. String tmp_app_path_name;
  1424. String scr_path;
  1425. if (export_format == "app") {
  1426. tmp_base_path_name = p_path.get_base_dir();
  1427. tmp_app_path_name = p_path;
  1428. scr_path = p_path.get_basename() + ".command";
  1429. } else {
  1430. tmp_base_path_name = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name);
  1431. tmp_app_path_name = tmp_base_path_name.path_join(tmp_app_dir_name);
  1432. scr_path = tmp_base_path_name.path_join(pkg_name + ".command");
  1433. }
  1434. print_verbose("Exporting to " + tmp_app_path_name);
  1435. Error err = OK;
  1436. Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_base_path_name);
  1437. if (tmp_app_dir.is_null()) {
  1438. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory: \"%s\"."), tmp_base_path_name));
  1439. err = ERR_CANT_CREATE;
  1440. }
  1441. if (FileAccess::exists(scr_path)) {
  1442. DirAccess::remove_file_or_error(scr_path);
  1443. }
  1444. if (DirAccess::exists(tmp_app_path_name)) {
  1445. String old_dir = tmp_app_dir->get_current_dir();
  1446. if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {
  1447. tmp_app_dir->erase_contents_recursive();
  1448. tmp_app_dir->change_dir(old_dir);
  1449. }
  1450. }
  1451. Array helpers = p_preset->get("codesign/entitlements/app_sandbox/helper_executables");
  1452. // Create our folder structure.
  1453. if (err == OK) {
  1454. print_verbose("Creating " + tmp_app_path_name + "/Contents/MacOS");
  1455. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
  1456. if (err != OK) {
  1457. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/MacOS"));
  1458. }
  1459. }
  1460. if (err == OK) {
  1461. print_verbose("Creating " + tmp_app_path_name + "/Contents/Frameworks");
  1462. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");
  1463. if (err != OK) {
  1464. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Frameworks"));
  1465. }
  1466. }
  1467. if ((err == OK) && helpers.size() > 0) {
  1468. print_line("Creating " + tmp_app_path_name + "/Contents/Helpers");
  1469. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Helpers");
  1470. if (err != OK) {
  1471. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Helpers"));
  1472. }
  1473. }
  1474. if (err == OK) {
  1475. print_verbose("Creating " + tmp_app_path_name + "/Contents/Resources");
  1476. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
  1477. if (err != OK) {
  1478. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), tmp_app_path_name + "/Contents/Resources"));
  1479. }
  1480. }
  1481. Dictionary appnames = GLOBAL_GET("application/config/name_localized");
  1482. Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");
  1483. Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");
  1484. Dictionary location_usage_descriptions = p_preset->get("privacy/location_usage_description_localized");
  1485. Dictionary address_book_usage_descriptions = p_preset->get("privacy/address_book_usage_description_localized");
  1486. Dictionary calendar_usage_descriptions = p_preset->get("privacy/calendar_usage_description_localized");
  1487. Dictionary photos_library_usage_descriptions = p_preset->get("privacy/photos_library_usage_description_localized");
  1488. Dictionary desktop_folder_usage_descriptions = p_preset->get("privacy/desktop_folder_usage_description_localized");
  1489. Dictionary documents_folder_usage_descriptions = p_preset->get("privacy/documents_folder_usage_description_localized");
  1490. Dictionary downloads_folder_usage_descriptions = p_preset->get("privacy/downloads_folder_usage_description_localized");
  1491. Dictionary network_volumes_usage_descriptions = p_preset->get("privacy/network_volumes_usage_description_localized");
  1492. Dictionary removable_volumes_usage_descriptions = p_preset->get("privacy/removable_volumes_usage_description_localized");
  1493. Dictionary copyrights = p_preset->get("application/copyright_localized");
  1494. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  1495. if (translations.size() > 0) {
  1496. {
  1497. String fname = tmp_app_path_name + "/Contents/Resources/en.lproj";
  1498. tmp_app_dir->make_dir_recursive(fname);
  1499. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1500. f->store_line("/* Localized versions of Info.plist keys */");
  1501. f->store_line("");
  1502. f->store_line("CFBundleDisplayName = \"" + GLOBAL_GET("application/config/name").operator String() + "\";");
  1503. if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
  1504. f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String() + "\";");
  1505. }
  1506. if (!((String)p_preset->get("privacy/camera_usage_description")).is_empty()) {
  1507. f->store_line("NSCameraUsageDescription = \"" + p_preset->get("privacy/camera_usage_description").operator String() + "\";");
  1508. }
  1509. if (!((String)p_preset->get("privacy/location_usage_description")).is_empty()) {
  1510. f->store_line("NSLocationUsageDescription = \"" + p_preset->get("privacy/location_usage_description").operator String() + "\";");
  1511. }
  1512. if (!((String)p_preset->get("privacy/address_book_usage_description")).is_empty()) {
  1513. f->store_line("NSContactsUsageDescription = \"" + p_preset->get("privacy/address_book_usage_description").operator String() + "\";");
  1514. }
  1515. if (!((String)p_preset->get("privacy/calendar_usage_description")).is_empty()) {
  1516. f->store_line("NSCalendarsUsageDescription = \"" + p_preset->get("privacy/calendar_usage_description").operator String() + "\";");
  1517. }
  1518. if (!((String)p_preset->get("privacy/photos_library_usage_description")).is_empty()) {
  1519. f->store_line("NSPhotoLibraryUsageDescription = \"" + p_preset->get("privacy/photos_library_usage_description").operator String() + "\";");
  1520. }
  1521. if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).is_empty()) {
  1522. f->store_line("NSDesktopFolderUsageDescription = \"" + p_preset->get("privacy/desktop_folder_usage_description").operator String() + "\";");
  1523. }
  1524. if (!((String)p_preset->get("privacy/documents_folder_usage_description")).is_empty()) {
  1525. f->store_line("NSDocumentsFolderUsageDescription = \"" + p_preset->get("privacy/documents_folder_usage_description").operator String() + "\";");
  1526. }
  1527. if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).is_empty()) {
  1528. f->store_line("NSDownloadsFolderUsageDescription = \"" + p_preset->get("privacy/downloads_folder_usage_description").operator String() + "\";");
  1529. }
  1530. if (!((String)p_preset->get("privacy/network_volumes_usage_description")).is_empty()) {
  1531. f->store_line("NSNetworkVolumesUsageDescription = \"" + p_preset->get("privacy/network_volumes_usage_description").operator String() + "\";");
  1532. }
  1533. if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).is_empty()) {
  1534. f->store_line("NSRemovableVolumesUsageDescription = \"" + p_preset->get("privacy/removable_volumes_usage_description").operator String() + "\";");
  1535. }
  1536. f->store_line("NSHumanReadableCopyright = \"" + p_preset->get("application/copyright").operator String() + "\";");
  1537. }
  1538. HashSet<String> languages;
  1539. for (const String &E : translations) {
  1540. Ref<Translation> tr = ResourceLoader::load(E);
  1541. if (tr.is_valid() && tr->get_locale() != "en") {
  1542. languages.insert(tr->get_locale());
  1543. }
  1544. }
  1545. for (const String &lang : languages) {
  1546. String fname = tmp_app_path_name + "/Contents/Resources/" + lang + ".lproj";
  1547. tmp_app_dir->make_dir_recursive(fname);
  1548. Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  1549. f->store_line("/* Localized versions of Info.plist keys */");
  1550. f->store_line("");
  1551. if (appnames.has(lang)) {
  1552. f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String() + "\";");
  1553. }
  1554. if (microphone_usage_descriptions.has(lang)) {
  1555. f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String() + "\";");
  1556. }
  1557. if (camera_usage_descriptions.has(lang)) {
  1558. f->store_line("NSCameraUsageDescription = \"" + camera_usage_descriptions[lang].operator String() + "\";");
  1559. }
  1560. if (location_usage_descriptions.has(lang)) {
  1561. f->store_line("NSLocationUsageDescription = \"" + location_usage_descriptions[lang].operator String() + "\";");
  1562. }
  1563. if (address_book_usage_descriptions.has(lang)) {
  1564. f->store_line("NSContactsUsageDescription = \"" + address_book_usage_descriptions[lang].operator String() + "\";");
  1565. }
  1566. if (calendar_usage_descriptions.has(lang)) {
  1567. f->store_line("NSCalendarsUsageDescription = \"" + calendar_usage_descriptions[lang].operator String() + "\";");
  1568. }
  1569. if (photos_library_usage_descriptions.has(lang)) {
  1570. f->store_line("NSPhotoLibraryUsageDescription = \"" + photos_library_usage_descriptions[lang].operator String() + "\";");
  1571. }
  1572. if (desktop_folder_usage_descriptions.has(lang)) {
  1573. f->store_line("NSDesktopFolderUsageDescription = \"" + desktop_folder_usage_descriptions[lang].operator String() + "\";");
  1574. }
  1575. if (documents_folder_usage_descriptions.has(lang)) {
  1576. f->store_line("NSDocumentsFolderUsageDescription = \"" + documents_folder_usage_descriptions[lang].operator String() + "\";");
  1577. }
  1578. if (downloads_folder_usage_descriptions.has(lang)) {
  1579. f->store_line("NSDownloadsFolderUsageDescription = \"" + downloads_folder_usage_descriptions[lang].operator String() + "\";");
  1580. }
  1581. if (network_volumes_usage_descriptions.has(lang)) {
  1582. f->store_line("NSNetworkVolumesUsageDescription = \"" + network_volumes_usage_descriptions[lang].operator String() + "\";");
  1583. }
  1584. if (removable_volumes_usage_descriptions.has(lang)) {
  1585. f->store_line("NSRemovableVolumesUsageDescription = \"" + removable_volumes_usage_descriptions[lang].operator String() + "\";");
  1586. }
  1587. if (copyrights.has(lang)) {
  1588. f->store_line("NSHumanReadableCopyright = \"" + copyrights[lang].operator String() + "\";");
  1589. }
  1590. }
  1591. }
  1592. // Now process our template.
  1593. bool found_binary = false;
  1594. int export_angle = p_preset->get("application/export_angle");
  1595. bool include_angle_libs = false;
  1596. if (export_angle == 0) {
  1597. include_angle_libs = String(GLOBAL_GET("rendering/gl_compatibility/driver.macos")) == "opengl3_angle";
  1598. } else if (export_angle == 1) {
  1599. include_angle_libs = true;
  1600. }
  1601. while (ret == UNZ_OK && err == OK) {
  1602. // Get filename.
  1603. unz_file_info info;
  1604. char fname[16384];
  1605. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  1606. if (ret != UNZ_OK) {
  1607. break;
  1608. }
  1609. String file = String::utf8(fname);
  1610. Vector<uint8_t> data;
  1611. data.resize(info.uncompressed_size);
  1612. // Read.
  1613. unzOpenCurrentFile(src_pkg_zip);
  1614. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  1615. unzCloseCurrentFile(src_pkg_zip);
  1616. // Write.
  1617. file = file.replace_first("macos_template.app/", "");
  1618. if (((info.external_fa >> 16L) & 0120000) == 0120000) {
  1619. #ifndef UNIX_ENABLED
  1620. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Relative symlinks are not supported on this OS, the exported project might be broken!"));
  1621. #endif
  1622. // Handle symlinks in the archive.
  1623. file = tmp_app_path_name.path_join(file);
  1624. if (err == OK) {
  1625. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  1626. if (err != OK) {
  1627. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));
  1628. }
  1629. }
  1630. if (err == OK) {
  1631. String lnk_data = String::utf8((const char *)data.ptr(), data.size());
  1632. err = tmp_app_dir->create_link(lnk_data, file);
  1633. if (err != OK) {
  1634. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not created symlink \"%s\" -> \"%s\"."), lnk_data, file));
  1635. }
  1636. print_verbose(vformat("ADDING SYMLINK %s => %s\n", file, lnk_data));
  1637. }
  1638. ret = unzGoToNextFile(src_pkg_zip);
  1639. continue; // next
  1640. }
  1641. if (file == "Contents/Frameworks/libEGL.dylib") {
  1642. if (!include_angle_libs) {
  1643. ret = unzGoToNextFile(src_pkg_zip);
  1644. continue; // skip
  1645. }
  1646. }
  1647. if (file == "Contents/Frameworks/libGLESv2.dylib") {
  1648. if (!include_angle_libs) {
  1649. ret = unzGoToNextFile(src_pkg_zip);
  1650. continue; // skip
  1651. }
  1652. }
  1653. if (file == "Contents/Info.plist") {
  1654. _fix_plist(p_preset, data, pkg_name);
  1655. }
  1656. if (file == "Contents/Resources/PrivacyInfo.xcprivacy") {
  1657. _fix_privacy_manifest(p_preset, data);
  1658. }
  1659. if (file.begins_with("Contents/MacOS/godot_")) {
  1660. if (file != "Contents/MacOS/" + binary_to_use) {
  1661. ret = unzGoToNextFile(src_pkg_zip);
  1662. continue; // skip
  1663. }
  1664. found_binary = true;
  1665. file = "Contents/MacOS/" + pkg_name;
  1666. }
  1667. if (file == "Contents/Resources/icon.icns") {
  1668. // See if there is an icon.
  1669. String icon_path;
  1670. if (p_preset->get("application/icon") != "") {
  1671. icon_path = p_preset->get("application/icon");
  1672. } else if (GLOBAL_GET("application/config/macos_native_icon") != "") {
  1673. icon_path = GLOBAL_GET("application/config/macos_native_icon");
  1674. } else {
  1675. icon_path = GLOBAL_GET("application/config/icon");
  1676. }
  1677. if (!icon_path.is_empty()) {
  1678. if (icon_path.get_extension() == "icns") {
  1679. Ref<FileAccess> icon = FileAccess::open(icon_path, FileAccess::READ);
  1680. if (icon.is_valid()) {
  1681. data.resize(icon->get_length());
  1682. icon->get_buffer(&data.write[0], icon->get_length());
  1683. }
  1684. } else {
  1685. Ref<Image> icon;
  1686. icon.instantiate();
  1687. err = ImageLoader::load_image(icon_path, icon);
  1688. if (err == OK && !icon->is_empty()) {
  1689. _make_icon(p_preset, icon, data);
  1690. }
  1691. }
  1692. }
  1693. }
  1694. if (data.size() > 0) {
  1695. print_verbose("ADDING: " + file + " size: " + itos(data.size()));
  1696. // Write it into our application bundle.
  1697. file = tmp_app_path_name.path_join(file);
  1698. if (err == OK) {
  1699. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  1700. if (err != OK) {
  1701. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create directory \"%s\"."), file.get_base_dir()));
  1702. }
  1703. }
  1704. if (err == OK) {
  1705. Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE);
  1706. if (f.is_valid()) {
  1707. f->store_buffer(data.ptr(), data.size());
  1708. f.unref();
  1709. if (is_executable(file)) {
  1710. // chmod with 0755 if the file is executable.
  1711. FileAccess::set_unix_permissions(file, 0755);
  1712. #ifndef UNIX_ENABLED
  1713. if (export_format == "app") {
  1714. 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()));
  1715. }
  1716. #endif
  1717. }
  1718. } else {
  1719. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not open \"%s\"."), file));
  1720. err = ERR_CANT_CREATE;
  1721. }
  1722. }
  1723. }
  1724. ret = unzGoToNextFile(src_pkg_zip);
  1725. }
  1726. // We're done with our source zip.
  1727. unzClose(src_pkg_zip);
  1728. if (!found_binary) {
  1729. 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));
  1730. err = ERR_FILE_NOT_FOUND;
  1731. }
  1732. // Save console wrapper.
  1733. if (err == OK) {
  1734. int con_scr = p_preset->get("debug/export_console_wrapper");
  1735. if ((con_scr == 1 && p_debug) || (con_scr == 2)) {
  1736. err = _export_debug_script(p_preset, pkg_name, tmp_app_path_name.get_file() + "/Contents/MacOS/" + pkg_name, scr_path);
  1737. FileAccess::set_unix_permissions(scr_path, 0755);
  1738. #ifndef UNIX_ENABLED
  1739. if (export_format == "app") {
  1740. 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()));
  1741. }
  1742. #endif
  1743. if (err != OK) {
  1744. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not create console wrapper."));
  1745. }
  1746. }
  1747. }
  1748. if (err == OK) {
  1749. if (ep.step(TTR("Making PKG"), 1)) {
  1750. return ERR_SKIP;
  1751. }
  1752. // See if we can code sign our new package.
  1753. bool sign_enabled = (p_preset->get("codesign/codesign").operator int() > 0);
  1754. bool ad_hoc = false;
  1755. int codesign_tool = p_preset->get("codesign/codesign");
  1756. switch (codesign_tool) {
  1757. case 1: { // built-in ad-hoc
  1758. ad_hoc = true;
  1759. } break;
  1760. case 2: { // "rcodesign"
  1761. 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();
  1762. } break;
  1763. #ifdef MACOS_ENABLED
  1764. case 3: { // "codesign"
  1765. ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  1766. } break;
  1767. #endif
  1768. default: {
  1769. };
  1770. }
  1771. String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
  1772. Vector<SharedObject> shared_objects;
  1773. err = save_pack(p_preset, p_debug, pack_path, &shared_objects);
  1774. bool lib_validation = p_preset->get("codesign/entitlements/disable_library_validation");
  1775. if (!shared_objects.is_empty() && sign_enabled && ad_hoc && !lib_validation) {
  1776. add_message(EXPORT_MESSAGE_INFO, TTR("Entitlements Modified"), TTR("Ad-hoc signed applications require the 'Disable Library Validation' entitlement to load dynamic libraries."));
  1777. lib_validation = true;
  1778. }
  1779. if (!shared_objects.is_empty() && sign_enabled && codesign_tool == 2) {
  1780. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("'rcodesign' doesn't support signing applications with embedded dynamic libraries."));
  1781. }
  1782. bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");
  1783. String ent_path = p_preset->get("codesign/entitlements/custom_file");
  1784. String hlp_ent_path = sandbox ? EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + "_helper.entitlements") : ent_path;
  1785. if (sign_enabled && (ent_path.is_empty())) {
  1786. ent_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".entitlements");
  1787. Ref<FileAccess> ent_f = FileAccess::open(ent_path, FileAccess::WRITE);
  1788. if (ent_f.is_valid()) {
  1789. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  1790. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  1791. ent_f->store_line("<plist version=\"1.0\">");
  1792. ent_f->store_line("<dict>");
  1793. if (ClassDB::class_exists("CSharpScript")) {
  1794. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  1795. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  1796. ent_f->store_line("<true/>");
  1797. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  1798. ent_f->store_line("<true/>");
  1799. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  1800. ent_f->store_line("<true/>");
  1801. } else {
  1802. if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) {
  1803. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  1804. ent_f->store_line("<true/>");
  1805. }
  1806. if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) {
  1807. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  1808. ent_f->store_line("<true/>");
  1809. }
  1810. if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) {
  1811. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  1812. ent_f->store_line("<true/>");
  1813. }
  1814. }
  1815. if (lib_validation) {
  1816. ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>");
  1817. ent_f->store_line("<true/>");
  1818. }
  1819. if ((bool)p_preset->get("codesign/entitlements/audio_input")) {
  1820. ent_f->store_line("<key>com.apple.security.device.audio-input</key>");
  1821. ent_f->store_line("<true/>");
  1822. }
  1823. if ((bool)p_preset->get("codesign/entitlements/camera")) {
  1824. ent_f->store_line("<key>com.apple.security.device.camera</key>");
  1825. ent_f->store_line("<true/>");
  1826. }
  1827. if ((bool)p_preset->get("codesign/entitlements/location")) {
  1828. ent_f->store_line("<key>com.apple.security.personal-information.location</key>");
  1829. ent_f->store_line("<true/>");
  1830. }
  1831. if ((bool)p_preset->get("codesign/entitlements/address_book")) {
  1832. ent_f->store_line("<key>com.apple.security.personal-information.addressbook</key>");
  1833. ent_f->store_line("<true/>");
  1834. }
  1835. if ((bool)p_preset->get("codesign/entitlements/calendars")) {
  1836. ent_f->store_line("<key>com.apple.security.personal-information.calendars</key>");
  1837. ent_f->store_line("<true/>");
  1838. }
  1839. if ((bool)p_preset->get("codesign/entitlements/photos_library")) {
  1840. ent_f->store_line("<key>com.apple.security.personal-information.photos-library</key>");
  1841. ent_f->store_line("<true/>");
  1842. }
  1843. if ((bool)p_preset->get("codesign/entitlements/apple_events")) {
  1844. ent_f->store_line("<key>com.apple.security.automation.apple-events</key>");
  1845. ent_f->store_line("<true/>");
  1846. }
  1847. if ((bool)p_preset->get("codesign/entitlements/debugging")) {
  1848. ent_f->store_line("<key>com.apple.security.get-task-allow</key>");
  1849. ent_f->store_line("<true/>");
  1850. }
  1851. int dist_type = p_preset->get("export/distribution_type");
  1852. if (dist_type == 2) {
  1853. String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE);
  1854. String teamid = p_preset->get("codesign/apple_team_id");
  1855. String bid = p_preset->get("application/bundle_identifier");
  1856. if (!pprof.is_empty() && !teamid.is_empty()) {
  1857. ent_f->store_line("<key>com.apple.developer.team-identifier</key>");
  1858. ent_f->store_line("<string>" + teamid + "</string>");
  1859. ent_f->store_line("<key>com.apple.application-identifier</key>");
  1860. ent_f->store_line("<string>" + teamid + "." + bid + "</string>");
  1861. }
  1862. }
  1863. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) {
  1864. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  1865. ent_f->store_line("<true/>");
  1866. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) {
  1867. ent_f->store_line("<key>com.apple.security.network.server</key>");
  1868. ent_f->store_line("<true/>");
  1869. }
  1870. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) {
  1871. ent_f->store_line("<key>com.apple.security.network.client</key>");
  1872. ent_f->store_line("<true/>");
  1873. }
  1874. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) {
  1875. ent_f->store_line("<key>com.apple.security.device.usb</key>");
  1876. ent_f->store_line("<true/>");
  1877. }
  1878. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) {
  1879. ent_f->store_line("<key>com.apple.security.device.bluetooth</key>");
  1880. ent_f->store_line("<true/>");
  1881. }
  1882. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) {
  1883. ent_f->store_line("<key>com.apple.security.files.downloads.read-only</key>");
  1884. ent_f->store_line("<true/>");
  1885. }
  1886. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) {
  1887. ent_f->store_line("<key>com.apple.security.files.downloads.read-write</key>");
  1888. ent_f->store_line("<true/>");
  1889. }
  1890. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) {
  1891. ent_f->store_line("<key>com.apple.security.files.pictures.read-only</key>");
  1892. ent_f->store_line("<true/>");
  1893. }
  1894. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) {
  1895. ent_f->store_line("<key>com.apple.security.files.pictures.read-write</key>");
  1896. ent_f->store_line("<true/>");
  1897. }
  1898. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) {
  1899. ent_f->store_line("<key>com.apple.security.files.music.read-only</key>");
  1900. ent_f->store_line("<true/>");
  1901. }
  1902. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) {
  1903. ent_f->store_line("<key>com.apple.security.files.music.read-write</key>");
  1904. ent_f->store_line("<true/>");
  1905. }
  1906. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) {
  1907. ent_f->store_line("<key>com.apple.security.files.movies.read-only</key>");
  1908. ent_f->store_line("<true/>");
  1909. }
  1910. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) {
  1911. ent_f->store_line("<key>com.apple.security.files.movies.read-write</key>");
  1912. ent_f->store_line("<true/>");
  1913. }
  1914. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 1) {
  1915. ent_f->store_line("<key>com.apple.security.files.user-selected.read-only</key>");
  1916. ent_f->store_line("<true/>");
  1917. }
  1918. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_user_selected") == 2) {
  1919. ent_f->store_line("<key>com.apple.security.files.user-selected.read-write</key>");
  1920. ent_f->store_line("<true/>");
  1921. }
  1922. }
  1923. const String &additional_entitlements = p_preset->get("codesign/entitlements/additional");
  1924. if (!additional_entitlements.is_empty()) {
  1925. ent_f->store_line(additional_entitlements);
  1926. }
  1927. ent_f->store_line("</dict>");
  1928. ent_f->store_line("</plist>");
  1929. } else {
  1930. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create entitlements file."));
  1931. err = ERR_CANT_CREATE;
  1932. }
  1933. if ((err == OK) && sandbox && (helpers.size() > 0 || shared_objects.size() > 0)) {
  1934. ent_f = FileAccess::open(hlp_ent_path, FileAccess::WRITE);
  1935. if (ent_f.is_valid()) {
  1936. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  1937. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  1938. ent_f->store_line("<plist version=\"1.0\">");
  1939. ent_f->store_line("<dict>");
  1940. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  1941. ent_f->store_line("<true/>");
  1942. ent_f->store_line("<key>com.apple.security.inherit</key>");
  1943. ent_f->store_line("<true/>");
  1944. ent_f->store_line("</dict>");
  1945. ent_f->store_line("</plist>");
  1946. } else {
  1947. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Could not create helper entitlements file."));
  1948. err = ERR_CANT_CREATE;
  1949. }
  1950. }
  1951. }
  1952. if ((err == OK) && helpers.size() > 0) {
  1953. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1954. for (int i = 0; i < helpers.size(); i++) {
  1955. String hlp_path = helpers[i];
  1956. err = da->copy(hlp_path, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file());
  1957. if (err == OK && sign_enabled) {
  1958. _code_sign(p_preset, tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), hlp_ent_path, false, true);
  1959. }
  1960. FileAccess::set_unix_permissions(tmp_app_path_name + "/Contents/Helpers/" + hlp_path.get_file(), 0755);
  1961. #ifndef UNIX_ENABLED
  1962. if (export_format == "app") {
  1963. 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()));
  1964. }
  1965. #endif
  1966. }
  1967. }
  1968. if (err == OK) {
  1969. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1970. for (int i = 0; i < shared_objects.size(); i++) {
  1971. String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path);
  1972. if (shared_objects[i].target.is_empty()) {
  1973. String path_in_app = tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file();
  1974. err = _copy_and_sign_files(da, src_path, path_in_app, sign_enabled, p_preset, ent_path, hlp_ent_path, true, sandbox);
  1975. } else {
  1976. String path_in_app = tmp_app_path_name.path_join(shared_objects[i].target);
  1977. tmp_app_dir->make_dir_recursive(path_in_app);
  1978. 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);
  1979. }
  1980. if (err != OK) {
  1981. break;
  1982. }
  1983. }
  1984. Vector<Ref<EditorExportPlugin>> export_plugins{ EditorExport::get_singleton()->get_export_plugins() };
  1985. for (int i = 0; i < export_plugins.size(); ++i) {
  1986. err = _export_macos_plugins_for(export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path, hlp_ent_path, sandbox);
  1987. if (err != OK) {
  1988. break;
  1989. }
  1990. }
  1991. }
  1992. if (err == OK && sign_enabled) {
  1993. int dist_type = p_preset->get("export/distribution_type");
  1994. if (dist_type == 2) {
  1995. String pprof = p_preset->get_or_env("codesign/provisioning_profile", ENV_MAC_CODESIGN_PROFILE).operator String();
  1996. if (!pprof.is_empty()) {
  1997. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1998. err = da->copy(pprof, tmp_app_path_name + "/Contents/embedded.provisionprofile");
  1999. }
  2000. }
  2001. if (ep.step(TTR("Code signing bundle"), 2)) {
  2002. return ERR_SKIP;
  2003. }
  2004. _code_sign(p_preset, tmp_app_path_name, ent_path, true, false);
  2005. }
  2006. String noto_path = p_path;
  2007. bool noto_enabled = (p_preset->get("notarization/notarization").operator int() > 0);
  2008. if (export_format == "dmg") {
  2009. // Create a DMG.
  2010. if (err == OK) {
  2011. if (ep.step(TTR("Making DMG"), 3)) {
  2012. return ERR_SKIP;
  2013. }
  2014. err = _create_dmg(p_path, pkg_name, tmp_base_path_name);
  2015. }
  2016. // Sign DMG.
  2017. if (err == OK && sign_enabled && !ad_hoc) {
  2018. if (ep.step(TTR("Code signing DMG"), 3)) {
  2019. return ERR_SKIP;
  2020. }
  2021. _code_sign(p_preset, p_path, ent_path, false, false);
  2022. }
  2023. } else if (export_format == "pkg") {
  2024. // Create a Installer.
  2025. if (err == OK) {
  2026. if (ep.step(TTR("Making PKG installer"), 3)) {
  2027. return ERR_SKIP;
  2028. }
  2029. err = _create_pkg(p_preset, p_path, tmp_app_path_name);
  2030. }
  2031. } else if (export_format == "zip") {
  2032. // Create ZIP.
  2033. if (err == OK) {
  2034. if (ep.step(TTR("Making ZIP"), 3)) {
  2035. return ERR_SKIP;
  2036. }
  2037. if (FileAccess::exists(p_path)) {
  2038. OS::get_singleton()->move_to_trash(p_path);
  2039. }
  2040. Ref<FileAccess> io_fa_dst;
  2041. zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);
  2042. zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
  2043. zip_folder_recursive(zip, tmp_base_path_name, "", pkg_name);
  2044. zipClose(zip, nullptr);
  2045. }
  2046. } else if (export_format == "app" && noto_enabled) {
  2047. // Create temporary ZIP.
  2048. if (err == OK) {
  2049. noto_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".zip");
  2050. if (ep.step(TTR("Making ZIP"), 3)) {
  2051. return ERR_SKIP;
  2052. }
  2053. if (FileAccess::exists(noto_path)) {
  2054. OS::get_singleton()->move_to_trash(noto_path);
  2055. }
  2056. Ref<FileAccess> io_fa_dst;
  2057. zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);
  2058. zipFile zip = zipOpen2(noto_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
  2059. zip_folder_recursive(zip, tmp_base_path_name, tmp_app_dir_name, pkg_name);
  2060. zipClose(zip, nullptr);
  2061. }
  2062. }
  2063. if (err == OK && noto_enabled) {
  2064. if (export_format == "pkg") {
  2065. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("Notarization requires the app to be archived first, select the DMG or ZIP export format instead."));
  2066. } else {
  2067. if (ep.step(TTR("Sending archive for notarization"), 4)) {
  2068. return ERR_SKIP;
  2069. }
  2070. err = _notarize(p_preset, noto_path);
  2071. }
  2072. }
  2073. if (FileAccess::exists(ent_path)) {
  2074. print_verbose("entitlements:\n" + FileAccess::get_file_as_string(ent_path));
  2075. }
  2076. if (FileAccess::exists(hlp_ent_path)) {
  2077. print_verbose("helper entitlements:\n" + FileAccess::get_file_as_string(hlp_ent_path));
  2078. }
  2079. // Clean up temporary entitlements files.
  2080. if (FileAccess::exists(hlp_ent_path)) {
  2081. DirAccess::remove_file_or_error(hlp_ent_path);
  2082. }
  2083. // Clean up temporary .app dir and generated entitlements.
  2084. if ((String)(p_preset->get("codesign/entitlements/custom_file")) == "") {
  2085. tmp_app_dir->remove(ent_path);
  2086. }
  2087. if (export_format != "app") {
  2088. if (tmp_app_dir->change_dir(tmp_base_path_name) == OK) {
  2089. tmp_app_dir->erase_contents_recursive();
  2090. tmp_app_dir->change_dir("..");
  2091. tmp_app_dir->remove(pkg_name);
  2092. }
  2093. } else if (noto_path != p_path) {
  2094. if (FileAccess::exists(noto_path)) {
  2095. DirAccess::remove_file_or_error(noto_path);
  2096. }
  2097. }
  2098. }
  2099. return err;
  2100. }
  2101. bool EditorExportPlatformMacOS::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {
  2102. String err;
  2103. // Look for export templates (official templates first, then custom).
  2104. bool dvalid = exists_export_template("macos.zip", &err);
  2105. bool rvalid = dvalid; // Both in the same ZIP.
  2106. if (p_preset->get("custom_template/debug") != "") {
  2107. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  2108. if (!dvalid) {
  2109. err += TTR("Custom debug template not found.") + "\n";
  2110. }
  2111. }
  2112. if (p_preset->get("custom_template/release") != "") {
  2113. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  2114. if (!rvalid) {
  2115. err += TTR("Custom release template not found.") + "\n";
  2116. }
  2117. }
  2118. bool valid = dvalid || rvalid;
  2119. r_missing_templates = !valid;
  2120. // Check the texture formats, which vary depending on the target architecture.
  2121. String architecture = p_preset->get("binary_format/architecture");
  2122. if (architecture == "universal" || architecture == "x86_64") {
  2123. if (!ResourceImporterTextureSettings::should_import_s3tc_bptc()) {
  2124. 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";
  2125. valid = false;
  2126. }
  2127. }
  2128. if (architecture == "universal" || architecture == "arm64") {
  2129. if (!ResourceImporterTextureSettings::should_import_etc2_astc()) {
  2130. 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";
  2131. valid = false;
  2132. }
  2133. }
  2134. if (architecture != "universal" && architecture != "x86_64" && architecture != "arm64") {
  2135. ERR_PRINT("Invalid architecture");
  2136. }
  2137. if (!err.is_empty()) {
  2138. r_error = err;
  2139. }
  2140. return valid;
  2141. }
  2142. bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  2143. String err;
  2144. bool valid = true;
  2145. int dist_type = p_preset->get("export/distribution_type");
  2146. bool ad_hoc = false;
  2147. int codesign_tool = p_preset->get("codesign/codesign");
  2148. int notary_tool = p_preset->get("notarization/notarization");
  2149. switch (codesign_tool) {
  2150. case 1: { // built-in ad-hoc
  2151. ad_hoc = true;
  2152. } break;
  2153. case 2: { // "rcodesign"
  2154. 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();
  2155. } break;
  2156. #ifdef MACOS_ENABLED
  2157. case 3: { // "codesign"
  2158. ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  2159. } break;
  2160. #endif
  2161. default: {
  2162. };
  2163. }
  2164. const String &additional_plist_content = p_preset->get("application/additional_plist_content");
  2165. if (!additional_plist_content.is_empty()) {
  2166. const String &plist = vformat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2167. "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
  2168. "<plist version=\"1.0\">"
  2169. "<dict>\n"
  2170. "%s\n"
  2171. "</dict>\n"
  2172. "</plist>\n",
  2173. additional_plist_content);
  2174. String plist_err;
  2175. Ref<PList> plist_parser;
  2176. plist_parser.instantiate();
  2177. if (!plist_parser->load_string(plist, plist_err)) {
  2178. err += TTR("Invalid additional PList content: ") + plist_err + "\n";
  2179. valid = false;
  2180. }
  2181. }
  2182. List<ExportOption> options;
  2183. get_export_options(&options);
  2184. for (const EditorExportPlatform::ExportOption &E : options) {
  2185. if (get_export_option_visibility(p_preset.ptr(), E.option.name)) {
  2186. String warn = get_export_option_warning(p_preset.ptr(), E.option.name);
  2187. if (!warn.is_empty()) {
  2188. err += warn + "\n";
  2189. if (E.required) {
  2190. valid = false;
  2191. }
  2192. }
  2193. }
  2194. }
  2195. if (dist_type != 2) {
  2196. if (notary_tool > 0) {
  2197. if (notary_tool == 2 || notary_tool == 3) {
  2198. if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {
  2199. err += TTR("Notarization: Xcode command line tools are not installed.") + "\n";
  2200. valid = false;
  2201. }
  2202. } else if (notary_tool == 1) {
  2203. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  2204. if (rcodesign.is_empty()) {
  2205. err += TTR("Notarization: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";
  2206. valid = false;
  2207. }
  2208. }
  2209. } else {
  2210. err += TTR("Warning: Notarization is disabled. The exported project will be blocked by Gatekeeper if it's downloaded from an unknown source.") + "\n";
  2211. if (codesign_tool == 0) {
  2212. err += TTR("Code signing is disabled. The exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n";
  2213. }
  2214. }
  2215. }
  2216. if (codesign_tool > 0) {
  2217. if (ad_hoc) {
  2218. err += TTR("Code signing: Using ad-hoc signature. The exported project will be blocked by Gatekeeper") + "\n";
  2219. }
  2220. if (codesign_tool == 3) {
  2221. if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
  2222. err += TTR("Code signing: Xcode command line tools are not installed.") + "\n";
  2223. valid = false;
  2224. }
  2225. } else if (codesign_tool == 2) {
  2226. String rcodesign = EDITOR_GET("export/macos/rcodesign").operator String();
  2227. if (rcodesign.is_empty()) {
  2228. err += TTR("Code signing: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";
  2229. valid = false;
  2230. }
  2231. }
  2232. }
  2233. if (!err.is_empty()) {
  2234. r_error = err;
  2235. }
  2236. return valid;
  2237. }
  2238. Ref<Texture2D> EditorExportPlatformMacOS::get_run_icon() const {
  2239. return run_icon;
  2240. }
  2241. bool EditorExportPlatformMacOS::poll_export() {
  2242. Ref<EditorExportPreset> preset;
  2243. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  2244. Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
  2245. if (ep->is_runnable() && ep->get_platform() == this) {
  2246. preset = ep;
  2247. break;
  2248. }
  2249. }
  2250. int prev = menu_options;
  2251. menu_options = (preset.is_valid() && preset->get("ssh_remote_deploy/enabled").operator bool());
  2252. if (ssh_pid != 0 || !cleanup_commands.is_empty()) {
  2253. if (menu_options == 0) {
  2254. cleanup();
  2255. } else {
  2256. menu_options += 1;
  2257. }
  2258. }
  2259. return menu_options != prev;
  2260. }
  2261. Ref<ImageTexture> EditorExportPlatformMacOS::get_option_icon(int p_index) const {
  2262. return p_index == 1 ? stop_icon : EditorExportPlatform::get_option_icon(p_index);
  2263. }
  2264. int EditorExportPlatformMacOS::get_options_count() const {
  2265. return menu_options;
  2266. }
  2267. String EditorExportPlatformMacOS::get_option_label(int p_index) const {
  2268. return (p_index) ? TTR("Stop and uninstall") : TTR("Run on remote macOS system");
  2269. }
  2270. String EditorExportPlatformMacOS::get_option_tooltip(int p_index) const {
  2271. return (p_index) ? TTR("Stop and uninstall running project from the remote system") : TTR("Run exported project on remote macOS system");
  2272. }
  2273. void EditorExportPlatformMacOS::cleanup() {
  2274. if (ssh_pid != 0 && OS::get_singleton()->is_process_running(ssh_pid)) {
  2275. print_line("Terminating connection...");
  2276. OS::get_singleton()->kill(ssh_pid);
  2277. OS::get_singleton()->delay_usec(1000);
  2278. }
  2279. if (!cleanup_commands.is_empty()) {
  2280. print_line("Stopping and deleting previous version...");
  2281. for (const SSHCleanupCommand &cmd : cleanup_commands) {
  2282. if (cmd.wait) {
  2283. ssh_run_on_remote(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
  2284. } else {
  2285. ssh_run_on_remote_no_wait(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
  2286. }
  2287. }
  2288. }
  2289. ssh_pid = 0;
  2290. cleanup_commands.clear();
  2291. }
  2292. Error EditorExportPlatformMacOS::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) {
  2293. cleanup();
  2294. if (p_device) { // Stop command, cleanup only.
  2295. return OK;
  2296. }
  2297. EditorProgress ep("run", TTR("Running..."), 5);
  2298. const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("macos");
  2299. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  2300. if (!da->dir_exists(dest)) {
  2301. Error err = da->make_dir_recursive(dest);
  2302. if (err != OK) {
  2303. EditorNode::get_singleton()->show_warning(TTR("Could not create temp directory:") + "\n" + dest);
  2304. return err;
  2305. }
  2306. }
  2307. String pkg_name;
  2308. if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") {
  2309. pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  2310. } else {
  2311. pkg_name = "Unnamed";
  2312. }
  2313. pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
  2314. String host = p_preset->get("ssh_remote_deploy/host").operator String();
  2315. String port = p_preset->get("ssh_remote_deploy/port").operator String();
  2316. if (port.is_empty()) {
  2317. port = "22";
  2318. }
  2319. Vector<String> extra_args_ssh = p_preset->get("ssh_remote_deploy/extra_args_ssh").operator String().split(" ", false);
  2320. Vector<String> extra_args_scp = p_preset->get("ssh_remote_deploy/extra_args_scp").operator String().split(" ", false);
  2321. const String basepath = dest.path_join("tmp_macos_export");
  2322. #define CLEANUP_AND_RETURN(m_err) \
  2323. { \
  2324. if (da->file_exists(basepath + ".zip")) { \
  2325. da->remove(basepath + ".zip"); \
  2326. } \
  2327. if (da->file_exists(basepath + "_start.sh")) { \
  2328. da->remove(basepath + "_start.sh"); \
  2329. } \
  2330. if (da->file_exists(basepath + "_clean.sh")) { \
  2331. da->remove(basepath + "_clean.sh"); \
  2332. } \
  2333. return m_err; \
  2334. } \
  2335. ((void)0)
  2336. if (ep.step(TTR("Exporting project..."), 1)) {
  2337. return ERR_SKIP;
  2338. }
  2339. Error err = export_project(p_preset, true, basepath + ".zip", p_debug_flags);
  2340. if (err != OK) {
  2341. DirAccess::remove_file_or_error(basepath + ".zip");
  2342. return err;
  2343. }
  2344. String cmd_args;
  2345. {
  2346. Vector<String> cmd_args_list = gen_export_flags(p_debug_flags);
  2347. for (int i = 0; i < cmd_args_list.size(); i++) {
  2348. if (i != 0) {
  2349. cmd_args += " ";
  2350. }
  2351. cmd_args += cmd_args_list[i];
  2352. }
  2353. }
  2354. const bool use_remote = p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG) || p_debug_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT);
  2355. int dbg_port = EditorSettings::get_singleton()->get("network/debug/remote_port");
  2356. print_line("Creating temporary directory...");
  2357. ep.step(TTR("Creating temporary directory..."), 2);
  2358. String temp_dir;
  2359. err = ssh_run_on_remote(host, port, extra_args_ssh, "mktemp -d", &temp_dir);
  2360. if (err != OK || temp_dir.is_empty()) {
  2361. CLEANUP_AND_RETURN(err);
  2362. }
  2363. print_line("Uploading archive...");
  2364. ep.step(TTR("Uploading archive..."), 3);
  2365. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + ".zip", temp_dir);
  2366. if (err != OK) {
  2367. CLEANUP_AND_RETURN(err);
  2368. }
  2369. {
  2370. String run_script = p_preset->get("ssh_remote_deploy/run_script");
  2371. run_script = run_script.replace("{temp_dir}", temp_dir);
  2372. run_script = run_script.replace("{archive_name}", basepath.get_file() + ".zip");
  2373. run_script = run_script.replace("{exe_name}", pkg_name);
  2374. run_script = run_script.replace("{cmd_args}", cmd_args);
  2375. Ref<FileAccess> f = FileAccess::open(basepath + "_start.sh", FileAccess::WRITE);
  2376. if (f.is_null()) {
  2377. CLEANUP_AND_RETURN(err);
  2378. }
  2379. f->store_string(run_script);
  2380. }
  2381. {
  2382. String clean_script = p_preset->get("ssh_remote_deploy/cleanup_script");
  2383. clean_script = clean_script.replace("{temp_dir}", temp_dir);
  2384. clean_script = clean_script.replace("{archive_name}", basepath.get_file() + ".zip");
  2385. clean_script = clean_script.replace("{exe_name}", pkg_name);
  2386. clean_script = clean_script.replace("{cmd_args}", cmd_args);
  2387. Ref<FileAccess> f = FileAccess::open(basepath + "_clean.sh", FileAccess::WRITE);
  2388. if (f.is_null()) {
  2389. CLEANUP_AND_RETURN(err);
  2390. }
  2391. f->store_string(clean_script);
  2392. }
  2393. print_line("Uploading scripts...");
  2394. ep.step(TTR("Uploading scripts..."), 4);
  2395. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_start.sh", temp_dir);
  2396. if (err != OK) {
  2397. CLEANUP_AND_RETURN(err);
  2398. }
  2399. err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_start.sh"));
  2400. if (err != OK || temp_dir.is_empty()) {
  2401. CLEANUP_AND_RETURN(err);
  2402. }
  2403. err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_clean.sh", temp_dir);
  2404. if (err != OK) {
  2405. CLEANUP_AND_RETURN(err);
  2406. }
  2407. err = ssh_run_on_remote(host, port, extra_args_ssh, vformat("chmod +x \"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh"));
  2408. if (err != OK || temp_dir.is_empty()) {
  2409. CLEANUP_AND_RETURN(err);
  2410. }
  2411. print_line("Starting project...");
  2412. ep.step(TTR("Starting project..."), 5);
  2413. 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);
  2414. if (err != OK) {
  2415. CLEANUP_AND_RETURN(err);
  2416. }
  2417. cleanup_commands.clear();
  2418. cleanup_commands.push_back(SSHCleanupCommand(host, port, extra_args_ssh, vformat("\"%s/%s\"", temp_dir, basepath.get_file() + "_clean.sh")));
  2419. print_line("Project started.");
  2420. CLEANUP_AND_RETURN(OK);
  2421. #undef CLEANUP_AND_RETURN
  2422. }
  2423. EditorExportPlatformMacOS::EditorExportPlatformMacOS() {
  2424. if (EditorNode::get_singleton()) {
  2425. Ref<Image> img = memnew(Image);
  2426. const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
  2427. ImageLoaderSVG::create_image_from_string(img, _macos_logo_svg, EDSCALE, upsample, false);
  2428. logo = ImageTexture::create_from_image(img);
  2429. ImageLoaderSVG::create_image_from_string(img, _macos_run_icon_svg, EDSCALE, upsample, false);
  2430. run_icon = ImageTexture::create_from_image(img);
  2431. Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
  2432. if (theme.is_valid()) {
  2433. stop_icon = theme->get_icon(SNAME("Stop"), EditorStringName(EditorIcons));
  2434. } else {
  2435. stop_icon.instantiate();
  2436. }
  2437. }
  2438. }