export_plugin.cpp 107 KB

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