export_plugin.cpp 121 KB

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