export_plugin.cpp 120 KB

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