export_plugin.cpp 104 KB

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