export_plugin.cpp 108 KB

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