export_plugin.cpp 109 KB

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