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