export_plugin.cpp 105 KB

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