export_plugin.cpp 105 KB

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