export_plugin.cpp 108 KB

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