export_plugin.cpp 108 KB

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