export_plugin.cpp 125 KB

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