export_plugin.cpp 109 KB

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