export_plugin.cpp 118 KB

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