export_plugin.cpp 107 KB

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