export.cpp 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  1. /*************************************************************************/
  2. /* export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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.h"
  31. #include "codesign.h"
  32. #include "core/io/marshalls.h"
  33. #include "core/io/resource_saver.h"
  34. #include "core/io/zip_io.h"
  35. #include "core/os/dir_access.h"
  36. #include "core/os/file_access.h"
  37. #include "core/os/os.h"
  38. #include "core/project_settings.h"
  39. #include "core/version.h"
  40. #include "editor/editor_export.h"
  41. #include "editor/editor_node.h"
  42. #include "editor/editor_settings.h"
  43. #include "modules/modules_enabled.gen.h" // For regex.
  44. #include "platform/osx/logo.gen.h"
  45. #include <sys/stat.h>
  46. class EditorExportPlatformOSX : public EditorExportPlatform {
  47. GDCLASS(EditorExportPlatformOSX, EditorExportPlatform);
  48. int version_code;
  49. Ref<ImageTexture> logo;
  50. void _fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary);
  51. void _make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data);
  52. Error _notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path);
  53. Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path);
  54. Error _code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path,
  55. bool p_should_error_on_non_code = true);
  56. Error _copy_and_sign_files(DirAccessRef &dir_access, const String &p_src_path, const String &p_in_app_path,
  57. bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,
  58. bool p_should_error_on_non_code_sign);
  59. Error _export_osx_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin, const String &p_app_path_name,
  60. DirAccessRef &dir_access, bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,
  61. const String &p_ent_path);
  62. Error _create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name);
  63. void _zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name);
  64. bool use_codesign() const { return true; }
  65. #ifdef OSX_ENABLED
  66. bool use_dmg() const { return true; }
  67. #else
  68. bool use_dmg() const { return false; }
  69. #endif
  70. bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const {
  71. String pname = p_package;
  72. if (pname.length() == 0) {
  73. if (r_error) {
  74. *r_error = TTR("Identifier is missing.");
  75. }
  76. return false;
  77. }
  78. for (int i = 0; i < pname.length(); i++) {
  79. char32_t c = pname[i];
  80. if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '.')) {
  81. if (r_error) {
  82. *r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
  83. }
  84. return false;
  85. }
  86. }
  87. return true;
  88. }
  89. protected:
  90. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features);
  91. virtual void get_export_options(List<ExportOption> *r_options);
  92. virtual bool get_option_visibility(const EditorExportPreset *p_preset, const String &p_option, const Map<StringName, Variant> &p_options) const;
  93. public:
  94. virtual String get_name() const { return "Mac OSX"; }
  95. virtual String get_os_name() const { return "OSX"; }
  96. virtual Ref<Texture> get_logo() const { return logo; }
  97. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
  98. List<String> list;
  99. if (use_dmg()) {
  100. list.push_back("dmg");
  101. }
  102. list.push_back("zip");
  103. list.push_back("app");
  104. return list;
  105. }
  106. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
  107. virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
  108. virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const;
  109. virtual void get_platform_features(List<String> *r_features) {
  110. r_features->push_back("pc");
  111. r_features->push_back("s3tc");
  112. r_features->push_back("OSX");
  113. }
  114. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
  115. }
  116. EditorExportPlatformOSX();
  117. ~EditorExportPlatformOSX();
  118. };
  119. void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) {
  120. if (p_preset->get("texture_format/s3tc")) {
  121. r_features->push_back("s3tc");
  122. }
  123. if (p_preset->get("texture_format/etc")) {
  124. r_features->push_back("etc");
  125. }
  126. if (p_preset->get("texture_format/etc2")) {
  127. r_features->push_back("etc2");
  128. }
  129. r_features->push_back("64");
  130. }
  131. bool EditorExportPlatformOSX::get_option_visibility(const EditorExportPreset *p_preset, const String &p_option, const Map<StringName, Variant> &p_options) const {
  132. // Hide irrelevant code signing options.
  133. if (p_preset) {
  134. int codesign_tool = p_preset->get("codesign/codesign");
  135. switch (codesign_tool) {
  136. case 1: { // built-in ad-hoc
  137. if (p_option == "codesign/identity" || p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password" || p_option == "codesign/custom_options") {
  138. return false;
  139. }
  140. } break;
  141. case 2: { // "rcodesign"
  142. if (p_option == "codesign/identity") {
  143. return false;
  144. }
  145. } break;
  146. #ifdef OSX_ENABLED
  147. case 3: { // "codesign"
  148. if (p_option == "codesign/certificate_file" || p_option == "codesign/certificate_password") {
  149. return false;
  150. }
  151. } break;
  152. #endif
  153. default: { // disabled
  154. 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")) {
  155. return false;
  156. }
  157. } break;
  158. }
  159. // Hide irrelevant notarization options.
  160. int notary_tool = p_preset->get("notarization/notarization");
  161. switch (notary_tool) {
  162. case 1: { // "rcodesign"
  163. if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/apple_team_id") {
  164. return false;
  165. }
  166. } break;
  167. case 2: { // "altool"
  168. // All options are visible.
  169. } break;
  170. default: { // disabled
  171. if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/apple_team_id" || p_option == "notarization/api_uuid" || p_option == "notarization/api_key") {
  172. return false;
  173. }
  174. } break;
  175. }
  176. }
  177. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  178. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  179. 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") {
  180. return false;
  181. }
  182. }
  183. return true;
  184. }
  185. void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) {
  186. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  187. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
  188. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
  189. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine"));
  190. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.png,*.icns"), ""));
  191. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), ""));
  192. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
  193. 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"));
  194. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
  195. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
  196. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
  197. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false));
  198. #ifdef OSX_ENABLED
  199. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),PyOxidizer rcodesign,Xcode codesign"), 3, true));
  200. #else
  201. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),PyOxidizer rcodesign"), 1, true));
  202. #endif
  203. // "codesign" only options:
  204. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), ""));
  205. // "rcodesign" only options:
  206. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_file", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12"), ""));
  207. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/certificate_password"), ""));
  208. // "codesign" and "rcodesign" only options:
  209. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements/custom_file", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), ""));
  210. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_jit_code_execution"), false));
  211. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_unsigned_executable_memory"), false));
  212. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/allow_dyld_environment_variables"), false));
  213. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/disable_library_validation"), false));
  214. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/audio_input"), false));
  215. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/camera"), false));
  216. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/location"), false));
  217. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/address_book"), false));
  218. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/calendars"), false));
  219. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/photos_library"), false));
  220. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/apple_events"), false));
  221. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/debugging"), false));
  222. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/enabled"), false));
  223. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_server"), false));
  224. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/network_client"), false));
  225. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_usb"), false));
  226. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/entitlements/app_sandbox/device_bluetooth"), false));
  227. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_downloads", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  228. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_pictures", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  229. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_music", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  230. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/entitlements/app_sandbox/files_movies", PROPERTY_HINT_ENUM, "No,Read-only,Read-write"), 0));
  231. r_options->push_back(ExportOption(PropertyInfo(Variant::POOL_STRING_ARRAY, "codesign/custom_options"), PoolStringArray()));
  232. #ifdef OSX_ENABLED
  233. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,PyOxidizer rcodesign,Xcode altool"), 0, true));
  234. #else
  235. r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,PyOxidizer rcodesign"), 0, true));
  236. #endif
  237. // "altool" only options:
  238. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple ID email"), ""));
  239. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_password", PROPERTY_HINT_PLACEHOLDER_TEXT, "Enable two-factor authentication and provide app-specific password"), ""));
  240. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_team_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide team ID if your Apple ID belongs to multiple teams"), ""));
  241. // "altool" and "rcodesign" only options:
  242. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_uuid", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect issuer ID"), ""));
  243. r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect API key ID"), ""));
  244. 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"), ""));
  245. 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"), ""));
  246. 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"), ""));
  247. 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"), ""));
  248. 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"), ""));
  249. 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"), ""));
  250. 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"), ""));
  251. 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"), ""));
  252. 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"), ""));
  253. 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"), ""));
  254. 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"), ""));
  255. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
  256. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
  257. r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
  258. }
  259. void _rgba8_to_packbits_encode(int p_ch, int p_size, PoolVector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {
  260. int src_len = p_size * p_size;
  261. Vector<uint8_t> result;
  262. result.resize(src_len * 1.25); //temp vector for rle encoded data, make it 25% larger for worst case scenario
  263. int res_size = 0;
  264. uint8_t buf[128];
  265. int buf_size = 0;
  266. int i = 0;
  267. while (i < src_len) {
  268. uint8_t cur = p_source.read()[i * 4 + p_ch];
  269. if (i < src_len - 2) {
  270. if ((p_source.read()[(i + 1) * 4 + p_ch] == cur) && (p_source.read()[(i + 2) * 4 + p_ch] == cur)) {
  271. if (buf_size > 0) {
  272. result.write[res_size++] = (uint8_t)(buf_size - 1);
  273. memcpy(&result.write[res_size], &buf, buf_size);
  274. res_size += buf_size;
  275. buf_size = 0;
  276. }
  277. uint8_t lim = i + 130 >= src_len ? src_len - i - 1 : 130;
  278. bool hit_lim = true;
  279. for (int j = 3; j <= lim; j++) {
  280. if (p_source.read()[(i + j) * 4 + p_ch] != cur) {
  281. hit_lim = false;
  282. i = i + j - 1;
  283. result.write[res_size++] = (uint8_t)(j - 3 + 0x80);
  284. result.write[res_size++] = cur;
  285. break;
  286. }
  287. }
  288. if (hit_lim) {
  289. result.write[res_size++] = (uint8_t)(lim - 3 + 0x80);
  290. result.write[res_size++] = cur;
  291. i = i + lim;
  292. }
  293. } else {
  294. buf[buf_size++] = cur;
  295. if (buf_size == 128) {
  296. result.write[res_size++] = (uint8_t)(buf_size - 1);
  297. memcpy(&result.write[res_size], &buf, buf_size);
  298. res_size += buf_size;
  299. buf_size = 0;
  300. }
  301. }
  302. } else {
  303. buf[buf_size++] = cur;
  304. result.write[res_size++] = (uint8_t)(buf_size - 1);
  305. memcpy(&result.write[res_size], &buf, buf_size);
  306. res_size += buf_size;
  307. buf_size = 0;
  308. }
  309. i++;
  310. }
  311. int ofs = p_dest.size();
  312. p_dest.resize(p_dest.size() + res_size);
  313. memcpy(&p_dest.write[ofs], result.ptr(), res_size);
  314. }
  315. void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
  316. Ref<ImageTexture> it = memnew(ImageTexture);
  317. Vector<uint8_t> data;
  318. data.resize(8);
  319. data.write[0] = 'i';
  320. data.write[1] = 'c';
  321. data.write[2] = 'n';
  322. data.write[3] = 's';
  323. struct MacOSIconInfo {
  324. const char *name;
  325. const char *mask_name;
  326. bool is_png;
  327. int size;
  328. };
  329. static const MacOSIconInfo icon_infos[] = {
  330. { "ic10", "", true, 1024 }, //1024x1024 32-bit PNG and 512x512@2x 32-bit "retina" PNG
  331. { "ic09", "", true, 512 }, //512×512 32-bit PNG
  332. { "ic14", "", true, 512 }, //256x256@2x 32-bit "retina" PNG
  333. { "ic08", "", true, 256 }, //256×256 32-bit PNG
  334. { "ic13", "", true, 256 }, //128x128@2x 32-bit "retina" PNG
  335. { "ic07", "", true, 128 }, //128x128 32-bit PNG
  336. { "ic12", "", true, 64 }, //32x32@2x 32-bit "retina" PNG
  337. { "ic11", "", true, 32 }, //16x16@2x 32-bit "retina" PNG
  338. { "il32", "l8mk", false, 32 }, //32x32 24-bit RLE + 8-bit uncompressed mask
  339. { "is32", "s8mk", false, 16 } //16x16 24-bit RLE + 8-bit uncompressed mask
  340. };
  341. for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
  342. 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?
  343. copy->convert(Image::FORMAT_RGBA8);
  344. copy->resize(icon_infos[i].size, icon_infos[i].size);
  345. if (icon_infos[i].is_png) {
  346. // Encode PNG icon.
  347. it->create_from_image(copy);
  348. String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png");
  349. ResourceSaver::save(path, it);
  350. FileAccess *f = FileAccess::open(path, FileAccess::READ);
  351. if (!f) {
  352. // Clean up generated file.
  353. DirAccess::remove_file_or_error(path);
  354. add_message(EXPORT_MESSAGE_ERROR, TTR("Icon Creation"), vformat(TTR("Could not open icon file \"%s\"."), path));
  355. return;
  356. }
  357. int ofs = data.size();
  358. uint64_t len = f->get_len();
  359. data.resize(data.size() + len + 8);
  360. f->get_buffer(&data.write[ofs + 8], len);
  361. memdelete(f);
  362. len += 8;
  363. len = BSWAP32(len);
  364. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  365. encode_uint32(len, &data.write[ofs + 4]);
  366. // Clean up generated file.
  367. DirAccess::remove_file_or_error(path);
  368. } else {
  369. PoolVector<uint8_t> src_data = copy->get_data();
  370. //encode 24bit RGB RLE icon
  371. {
  372. int ofs = data.size();
  373. data.resize(data.size() + 8);
  374. _rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // encode R
  375. _rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // encode G
  376. _rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // encode B
  377. int len = data.size() - ofs;
  378. len = BSWAP32(len);
  379. memcpy(&data.write[ofs], icon_infos[i].name, 4);
  380. encode_uint32(len, &data.write[ofs + 4]);
  381. }
  382. //encode 8bit mask uncompressed icon
  383. {
  384. int ofs = data.size();
  385. int len = copy->get_width() * copy->get_height();
  386. data.resize(data.size() + len + 8);
  387. for (int j = 0; j < len; j++) {
  388. data.write[ofs + 8 + j] = src_data.read()[j * 4 + 3];
  389. }
  390. len += 8;
  391. len = BSWAP32(len);
  392. memcpy(&data.write[ofs], icon_infos[i].mask_name, 4);
  393. encode_uint32(len, &data.write[ofs + 4]);
  394. }
  395. }
  396. }
  397. uint32_t total_len = data.size();
  398. total_len = BSWAP32(total_len);
  399. encode_uint32(total_len, &data.write[4]);
  400. p_data = data;
  401. }
  402. void EditorExportPlatformOSX::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) {
  403. String str;
  404. String strnew;
  405. str.parse_utf8((const char *)plist.ptr(), plist.size());
  406. Vector<String> lines = str.split("\n");
  407. for (int i = 0; i < lines.size(); i++) {
  408. if (lines[i].find("$binary") != -1) {
  409. strnew += lines[i].replace("$binary", p_binary) + "\n";
  410. } else if (lines[i].find("$name") != -1) {
  411. strnew += lines[i].replace("$name", p_binary) + "\n";
  412. } else if (lines[i].find("$info") != -1) {
  413. strnew += lines[i].replace("$info", p_preset->get("application/info")) + "\n";
  414. } else if (lines[i].find("$identifier") != -1) {
  415. strnew += lines[i].replace("$identifier", p_preset->get("application/identifier")) + "\n";
  416. } else if (lines[i].find("$short_version") != -1) {
  417. strnew += lines[i].replace("$short_version", p_preset->get("application/short_version")) + "\n";
  418. } else if (lines[i].find("$version") != -1) {
  419. strnew += lines[i].replace("$version", p_preset->get("application/version")) + "\n";
  420. } else if (lines[i].find("$signature") != -1) {
  421. strnew += lines[i].replace("$signature", p_preset->get("application/signature")) + "\n";
  422. } else if (lines[i].find("$app_category") != -1) {
  423. String cat = p_preset->get("application/app_category");
  424. strnew += lines[i].replace("$app_category", cat.to_lower()) + "\n";
  425. } else if (lines[i].find("$copyright") != -1) {
  426. strnew += lines[i].replace("$copyright", p_preset->get("application/copyright")) + "\n";
  427. } else if (lines[i].find("$highres") != -1) {
  428. strnew += lines[i].replace("$highres", p_preset->get("display/high_res") ? "\t<true/>" : "\t<false/>") + "\n";
  429. } else if (lines[i].find("$usage_descriptions") != -1) {
  430. String descriptions;
  431. if (!((String)p_preset->get("privacy/microphone_usage_description")).empty()) {
  432. descriptions += "\t<key>NSMicrophoneUsageDescription</key>\n";
  433. descriptions += "\t<string>" + (String)p_preset->get("privacy/microphone_usage_description") + "</string>\n";
  434. }
  435. if (!((String)p_preset->get("privacy/camera_usage_description")).empty()) {
  436. descriptions += "\t<key>NSCameraUsageDescription</key>\n";
  437. descriptions += "\t<string>" + (String)p_preset->get("privacy/camera_usage_description") + "</string>\n";
  438. }
  439. if (!((String)p_preset->get("privacy/location_usage_description")).empty()) {
  440. descriptions += "\t<key>NSLocationUsageDescription</key>\n";
  441. descriptions += "\t<string>" + (String)p_preset->get("privacy/location_usage_description") + "</string>\n";
  442. }
  443. if (!((String)p_preset->get("privacy/address_book_usage_description")).empty()) {
  444. descriptions += "\t<key>NSContactsUsageDescription</key>\n";
  445. descriptions += "\t<string>" + (String)p_preset->get("privacy/address_book_usage_description") + "</string>\n";
  446. }
  447. if (!((String)p_preset->get("privacy/calendar_usage_description")).empty()) {
  448. descriptions += "\t<key>NSCalendarsUsageDescription</key>\n";
  449. descriptions += "\t<string>" + (String)p_preset->get("privacy/calendar_usage_description") + "</string>\n";
  450. }
  451. if (!((String)p_preset->get("privacy/photos_library_usage_description")).empty()) {
  452. descriptions += "\t<key>NSPhotoLibraryUsageDescription</key>\n";
  453. descriptions += "\t<string>" + (String)p_preset->get("privacy/photos_library_usage_description") + "</string>\n";
  454. }
  455. if (!((String)p_preset->get("privacy/desktop_folder_usage_description")).empty()) {
  456. descriptions += "\t<key>NSDesktopFolderUsageDescription</key>\n";
  457. descriptions += "\t<string>" + (String)p_preset->get("privacy/desktop_folder_usage_description") + "</string>\n";
  458. }
  459. if (!((String)p_preset->get("privacy/documents_folder_usage_description")).empty()) {
  460. descriptions += "\t<key>NSDocumentsFolderUsageDescription</key>\n";
  461. descriptions += "\t<string>" + (String)p_preset->get("privacy/documents_folder_usage_description") + "</string>\n";
  462. }
  463. if (!((String)p_preset->get("privacy/downloads_folder_usage_description")).empty()) {
  464. descriptions += "\t<key>NSDownloadsFolderUsageDescription</key>\n";
  465. descriptions += "\t<string>" + (String)p_preset->get("privacy/downloads_folder_usage_description") + "</string>\n";
  466. }
  467. if (!((String)p_preset->get("privacy/network_volumes_usage_description")).empty()) {
  468. descriptions += "\t<key>NSNetworkVolumesUsageDescription</key>\n";
  469. descriptions += "\t<string>" + (String)p_preset->get("privacy/network_volumes_usage_description") + "</string>\n";
  470. }
  471. if (!((String)p_preset->get("privacy/removable_volumes_usage_description")).empty()) {
  472. descriptions += "\t<key>NSRemovableVolumesUsageDescription</key>\n";
  473. descriptions += "\t<string>" + (String)p_preset->get("privacy/removable_volumes_usage_description") + "</string>\n";
  474. }
  475. if (!descriptions.empty()) {
  476. strnew += lines[i].replace("$usage_descriptions", descriptions);
  477. }
  478. } else {
  479. strnew += lines[i] + "\n";
  480. }
  481. }
  482. CharString cs = strnew.utf8();
  483. plist.resize(cs.size() - 1);
  484. for (int i = 0; i < cs.size() - 1; i++) {
  485. plist.write[i] = cs[i];
  486. }
  487. }
  488. /**
  489. If we're running the OSX version of the Godot editor we'll:
  490. - export our application bundle to a temporary folder
  491. - attempt to code sign it
  492. - and then wrap it up in a DMG
  493. **/
  494. Error EditorExportPlatformOSX::_notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
  495. int notary_tool = p_preset->get("notarization/notarization");
  496. switch (notary_tool) {
  497. case 1: { // "rcodesign"
  498. print_verbose("using rcodesign notarization...");
  499. String rcodesign = EditorSettings::get_singleton()->get("export/macos/rcodesign").operator String();
  500. if (rcodesign.empty()) {
  501. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));
  502. return Error::FAILED;
  503. }
  504. List<String> args;
  505. args.push_back("notary-submit");
  506. if (p_preset->get("notarization/api_uuid") == "") {
  507. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect issuer ID name not specified."));
  508. return Error::FAILED;
  509. }
  510. if (p_preset->get("notarization/api_key") == "") {
  511. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));
  512. return Error::FAILED;
  513. }
  514. args.push_back("--api-issuer");
  515. args.push_back(p_preset->get("notarization/api_uuid"));
  516. args.push_back("--api-key");
  517. args.push_back(p_preset->get("notarization/api_key"));
  518. args.push_back(p_path);
  519. String str;
  520. int exitcode = 0;
  521. Error err = OS::get_singleton()->execute(rcodesign, args, true, NULL, &str, &exitcode, true);
  522. if (err != OK) {
  523. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start rcodesign executable."));
  524. return err;
  525. }
  526. int rq_offset = str.find("created submission ID:");
  527. if (exitcode != 0 || rq_offset == -1) {
  528. print_line("rcodesign (" + p_path + "):\n" + str);
  529. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));
  530. return Error::FAILED;
  531. } else {
  532. print_verbose("rcodesign (" + p_path + "):\n" + str);
  533. int next_nl = str.find("\n", rq_offset);
  534. String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 14, -1) : str.substr(rq_offset + 14, next_nl - rq_offset - 14);
  535. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));
  536. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour."));
  537. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:"));
  538. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign notary-log --api-issuer <api uuid> --api-key <api key> <request uuid>\"");
  539. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));
  540. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"rcodesign staple <app path>\"");
  541. }
  542. } break;
  543. #ifdef OSX_ENABLED
  544. case 2: { // "altool"
  545. print_verbose("using altool notarization...");
  546. if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {
  547. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed."));
  548. return Error::FAILED;
  549. }
  550. List<String> args;
  551. args.push_back("altool");
  552. args.push_back("--notarize-app");
  553. args.push_back("--primary-bundle-id");
  554. args.push_back(p_preset->get("application/bundle_identifier"));
  555. if (p_preset->get("notarization/apple_id_name") == "" && p_preset->get("notarization/api_uuid") == "") {
  556. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified."));
  557. return Error::FAILED;
  558. }
  559. if (p_preset->get("notarization/apple_id_name") != "" && p_preset->get("notarization/api_uuid") != "") {
  560. 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."));
  561. return Error::FAILED;
  562. }
  563. if (p_preset->get("notarization/apple_id_name") != "") {
  564. if (p_preset->get("notarization/apple_id_password") == "") {
  565. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified."));
  566. return Error::FAILED;
  567. }
  568. args.push_back("--username");
  569. args.push_back(p_preset->get("notarization/apple_id_name"));
  570. args.push_back("--password");
  571. args.push_back(p_preset->get("notarization/apple_id_password"));
  572. } else {
  573. if (p_preset->get("notarization/api_key") == "") {
  574. add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified."));
  575. return Error::FAILED;
  576. }
  577. args.push_back("--apiIssuer");
  578. args.push_back(p_preset->get("notarization/api_uuid"));
  579. args.push_back("--apiKey");
  580. args.push_back(p_preset->get("notarization/api_key"));
  581. }
  582. args.push_back("--type");
  583. args.push_back("osx");
  584. if (p_preset->get("notarization/apple_team_id")) {
  585. args.push_back("--asc-provider");
  586. args.push_back(p_preset->get("notarization/apple_team_id"));
  587. }
  588. args.push_back("--file");
  589. args.push_back(p_path);
  590. String str;
  591. int exitcode = 0;
  592. Error err = OS::get_singleton()->execute("xcrun", args, true, NULL, &str, &exitcode, true);
  593. if (err != OK) {
  594. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable."));
  595. return err;
  596. }
  597. int rq_offset = str.find("RequestUUID");
  598. if (exitcode != 0 || rq_offset == -1) {
  599. print_line("xcrun altool (" + p_path + "):\n" + str);
  600. add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details."));
  601. return Error::FAILED;
  602. } else {
  603. print_verbose("xcrun altool (" + p_path + "):\n" + str);
  604. int next_nl = str.find("\n", rq_offset);
  605. String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 14, -1) : str.substr(rq_offset + 14, next_nl - rq_offset - 14);
  606. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid));
  607. 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."));
  608. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:"));
  609. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun altool --notarization-history 0 -u <your email> -p <app-specific pwd>\"");
  610. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):"));
  611. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple <app path>\"");
  612. }
  613. } break;
  614. #endif
  615. default: {
  616. };
  617. }
  618. return OK;
  619. }
  620. Error EditorExportPlatformOSX::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path) {
  621. int codesign_tool = p_preset->get("codesign/codesign");
  622. switch (codesign_tool) {
  623. case 1: { // built-in ad-hoc
  624. print_verbose("using built-in codesign...");
  625. #ifdef MODULE_REGEX_ENABLED
  626. String error_msg;
  627. Error err = CodeSign::codesign(false, true, p_path, p_ent_path, error_msg);
  628. if (err != OK) {
  629. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Built-in CodeSign failed with error \"%s\"."), error_msg));
  630. return Error::FAILED;
  631. }
  632. #else
  633. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Built-in CodeSign require regex module."));
  634. #endif
  635. } break;
  636. case 2: { // "rcodesign"
  637. print_verbose("using rcodesign codesign...");
  638. String rcodesign = EditorSettings::get_singleton()->get("export/macos/rcodesign").operator String();
  639. if (rcodesign.empty()) {
  640. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xrcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign)."));
  641. return Error::FAILED;
  642. }
  643. List<String> args;
  644. args.push_back("sign");
  645. if (p_path.get_extension() != "dmg") {
  646. args.push_back("--entitlements-xml-path");
  647. args.push_back(p_ent_path);
  648. }
  649. String certificate_file = p_preset->get("codesign/certificate_file");
  650. String certificate_pass = p_preset->get("codesign/certificate_password");
  651. if (!certificate_file.empty() && !certificate_file.empty()) {
  652. args.push_back("--p12-file");
  653. args.push_back(certificate_file);
  654. args.push_back("--p12-password");
  655. args.push_back(certificate_pass);
  656. }
  657. args.push_back("-v"); /* provide some more feedback */
  658. args.push_back(p_path);
  659. String str;
  660. int exitcode = 0;
  661. Error err = OS::get_singleton()->execute(rcodesign, args, true, NULL, &str, &exitcode, true);
  662. if (err != OK) {
  663. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start rcodesign executable."));
  664. return err;
  665. }
  666. if (exitcode != 0) {
  667. print_line("rcodesign (" + p_path + "):\n" + str);
  668. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  669. return Error::FAILED;
  670. } else {
  671. print_verbose("rcodesign (" + p_path + "):\n" + str);
  672. }
  673. } break;
  674. #ifdef OSX_ENABLED
  675. case 3: { // "codesign"
  676. print_verbose("using xcode codesign...");
  677. if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
  678. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Xcode command line tools are not installed."));
  679. return Error::FAILED;
  680. }
  681. bool ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  682. List<String> args;
  683. if (!ad_hoc) {
  684. args.push_back("--timestamp");
  685. args.push_back("--options");
  686. args.push_back("runtime");
  687. }
  688. if (p_path.get_extension() != "dmg") {
  689. args.push_back("--entitlements");
  690. args.push_back(p_ent_path);
  691. }
  692. PoolStringArray user_args = p_preset->get("codesign/custom_options");
  693. for (int i = 0; i < user_args.size(); i++) {
  694. String user_arg = user_args[i].strip_edges();
  695. if (!user_arg.empty()) {
  696. args.push_back(user_arg);
  697. }
  698. }
  699. args.push_back("-s");
  700. if (ad_hoc) {
  701. args.push_back("-");
  702. } else {
  703. args.push_back(p_preset->get("codesign/identity"));
  704. }
  705. args.push_back("-v"); /* provide some more feedback */
  706. args.push_back("-f");
  707. args.push_back(p_path);
  708. String str;
  709. int exitcode = 0;
  710. Error err = OS::get_singleton()->execute("codesign", args, true, NULL, &str, NULL, true);
  711. if (err != OK) {
  712. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start codesign executable, make sure Xcode command line tools are installed."));
  713. return err;
  714. }
  715. if (exitcode != 0) {
  716. print_line("codesign (" + p_path + "):\n" + str);
  717. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Code signing failed, see editor log for details."));
  718. return Error::FAILED;
  719. } else {
  720. print_verbose("codesign (" + p_path + "):\n" + str);
  721. }
  722. } break;
  723. #endif
  724. default: {
  725. };
  726. }
  727. return OK;
  728. }
  729. Error EditorExportPlatformOSX::_code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path,
  730. const String &p_ent_path, bool p_should_error_on_non_code) {
  731. #ifdef OSX_ENABLED
  732. static Vector<String> extensions_to_sign;
  733. if (extensions_to_sign.empty()) {
  734. extensions_to_sign.push_back("dylib");
  735. extensions_to_sign.push_back("framework");
  736. }
  737. Error dir_access_error;
  738. DirAccessRef dir_access{ DirAccess::open(p_path, &dir_access_error) };
  739. if (dir_access_error != OK) {
  740. return dir_access_error;
  741. }
  742. dir_access->list_dir_begin();
  743. String current_file{ dir_access->get_next() };
  744. while (!current_file.empty()) {
  745. String current_file_path{ p_path.plus_file(current_file) };
  746. if (current_file == ".." || current_file == ".") {
  747. current_file = dir_access->get_next();
  748. continue;
  749. }
  750. if (extensions_to_sign.find(current_file.get_extension()) > -1) {
  751. Error code_sign_error{ _code_sign(p_preset, current_file_path, p_ent_path) };
  752. if (code_sign_error != OK) {
  753. return code_sign_error;
  754. }
  755. } else if (dir_access->current_is_dir()) {
  756. Error code_sign_error{ _code_sign_directory(p_preset, current_file_path, p_ent_path, p_should_error_on_non_code) };
  757. if (code_sign_error != OK) {
  758. return code_sign_error;
  759. }
  760. } else if (p_should_error_on_non_code) {
  761. add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Cannot sign file %s."), current_file));
  762. return Error::FAILED;
  763. }
  764. current_file = dir_access->get_next();
  765. }
  766. #endif
  767. return OK;
  768. }
  769. Error EditorExportPlatformOSX::_copy_and_sign_files(DirAccessRef &dir_access, const String &p_src_path,
  770. const String &p_in_app_path, bool p_sign_enabled,
  771. const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,
  772. bool p_should_error_on_non_code_sign) {
  773. Error err{ OK };
  774. if (dir_access->dir_exists(p_src_path)) {
  775. #ifndef UNIX_ENABLED
  776. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), vformat(TTR("Relative symlinks are not supported, exported \"%s\" might be broken!"), p_src_path.get_file()));
  777. #endif
  778. print_verbose("export framework: " + p_src_path + " -> " + p_in_app_path);
  779. err = dir_access->make_dir_recursive(p_in_app_path);
  780. if (err == OK) {
  781. err = dir_access->copy_dir(p_src_path, p_in_app_path, -1, true);
  782. }
  783. } else {
  784. print_verbose("export dylib: " + p_src_path + " -> " + p_in_app_path);
  785. err = dir_access->copy(p_src_path, p_in_app_path);
  786. }
  787. if (err == OK && p_sign_enabled) {
  788. if (dir_access->dir_exists(p_src_path) && p_src_path.get_extension().empty()) {
  789. // If it is a directory, find and sign all dynamic libraries.
  790. err = _code_sign_directory(p_preset, p_in_app_path, p_ent_path, p_should_error_on_non_code_sign);
  791. } else {
  792. err = _code_sign(p_preset, p_in_app_path, p_ent_path);
  793. }
  794. }
  795. return err;
  796. }
  797. Error EditorExportPlatformOSX::_export_osx_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin,
  798. const String &p_app_path_name, DirAccessRef &dir_access,
  799. bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,
  800. const String &p_ent_path) {
  801. Error error{ OK };
  802. const Vector<String> &osx_plugins{ p_editor_export_plugin->get_osx_plugin_files() };
  803. for (int i = 0; i < osx_plugins.size(); ++i) {
  804. String src_path{ ProjectSettings::get_singleton()->globalize_path(osx_plugins[i]) };
  805. String path_in_app{ p_app_path_name + "/Contents/PlugIns/" + src_path.get_file() };
  806. error = _copy_and_sign_files(dir_access, src_path, path_in_app, p_sign_enabled, p_preset, p_ent_path, false);
  807. if (error != OK) {
  808. break;
  809. }
  810. }
  811. return error;
  812. }
  813. Error EditorExportPlatformOSX::_create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name) {
  814. List<String> args;
  815. if (FileAccess::exists(p_dmg_path)) {
  816. OS::get_singleton()->move_to_trash(p_dmg_path);
  817. }
  818. args.push_back("create");
  819. args.push_back(p_dmg_path);
  820. args.push_back("-volname");
  821. args.push_back(p_pkg_name);
  822. args.push_back("-fs");
  823. args.push_back("HFS+");
  824. args.push_back("-srcfolder");
  825. args.push_back(p_app_path_name);
  826. String str;
  827. Error err = OS::get_singleton()->execute("hdiutil", args, true, nullptr, &str, nullptr, true);
  828. if (err != OK) {
  829. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("Could not start hdiutil executable."));
  830. return err;
  831. }
  832. print_line("hdiutil returned: " + str);
  833. if (str.find("create failed") != -1) {
  834. if (str.find("File exists") != -1) {
  835. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed - file exists."));
  836. } else {
  837. add_message(EXPORT_MESSAGE_ERROR, TTR("DMG Creation"), TTR("`hdiutil create` failed."));
  838. }
  839. return FAILED;
  840. }
  841. return OK;
  842. }
  843. Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  844. ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
  845. String src_pkg_name;
  846. EditorProgress ep("export", "Exporting for OSX", 3, true);
  847. if (p_debug) {
  848. src_pkg_name = p_preset->get("custom_template/debug");
  849. } else {
  850. src_pkg_name = p_preset->get("custom_template/release");
  851. }
  852. if (src_pkg_name == "") {
  853. String err;
  854. src_pkg_name = find_export_template("osx.zip", &err);
  855. if (src_pkg_name == "") {
  856. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("Export template not found."));
  857. return ERR_FILE_NOT_FOUND;
  858. }
  859. }
  860. if (!DirAccess::exists(p_path.get_base_dir())) {
  861. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), TTR("The given export path doesn't exist."));
  862. return ERR_FILE_BAD_PATH;
  863. }
  864. FileAccess *src_f = nullptr;
  865. zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
  866. if (ep.step(TTR("Creating app bundle"), 0)) {
  867. return ERR_SKIP;
  868. }
  869. unzFile src_pkg_zip = unzOpen2(src_pkg_name.utf8().get_data(), &io);
  870. if (!src_pkg_zip) {
  871. add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not find template app to export: \"%s\"."), src_pkg_name));
  872. return ERR_FILE_NOT_FOUND;
  873. }
  874. int ret = unzGoToFirstFile(src_pkg_zip);
  875. String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + ".64";
  876. String pkg_name;
  877. if (p_preset->get("application/name") != "") {
  878. pkg_name = p_preset->get("application/name"); // app_name
  879. } else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") {
  880. pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  881. } else {
  882. pkg_name = "Unnamed";
  883. }
  884. pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
  885. String export_format;
  886. if (use_dmg() && p_path.ends_with("dmg")) {
  887. export_format = "dmg";
  888. } else if (p_path.ends_with("zip")) {
  889. export_format = "zip";
  890. } else if (p_path.ends_with("app")) {
  891. export_format = "app";
  892. } else {
  893. add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Invalid export format."));
  894. return ERR_CANT_CREATE;
  895. }
  896. // Create our application bundle.
  897. String tmp_app_dir_name = pkg_name + ".app";
  898. String tmp_app_path_name;
  899. if (export_format == "app") {
  900. tmp_app_path_name = p_path;
  901. } else {
  902. tmp_app_path_name = EditorSettings::get_singleton()->get_cache_dir().plus_file(tmp_app_dir_name);
  903. }
  904. print_verbose("Exporting to " + tmp_app_path_name);
  905. Error err = OK;
  906. DirAccessRef tmp_app_dir = DirAccess::create_for_path(tmp_app_path_name);
  907. if (!tmp_app_dir) {
  908. err = ERR_CANT_CREATE;
  909. }
  910. if (DirAccess::exists(tmp_app_dir_name)) {
  911. String old_dir = tmp_app_dir->get_current_dir();
  912. if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {
  913. tmp_app_dir->erase_contents_recursive();
  914. tmp_app_dir->change_dir(old_dir);
  915. }
  916. }
  917. // Create our folder structure.
  918. if (err == OK) {
  919. print_verbose("Creating " + tmp_app_path_name + "/Contents/MacOS");
  920. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/MacOS");
  921. }
  922. if (err == OK) {
  923. print_verbose("Creating " + tmp_app_path_name + "/Contents/Frameworks");
  924. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Frameworks");
  925. }
  926. if (err == OK) {
  927. print_verbose("Creating " + tmp_app_path_name + "/Contents/Resources");
  928. err = tmp_app_dir->make_dir_recursive(tmp_app_path_name + "/Contents/Resources");
  929. }
  930. Vector<String> translations = ProjectSettings::get_singleton()->get("locale/translations");
  931. if (translations.size() > 0) {
  932. {
  933. String fname = tmp_app_path_name + "/Contents/Resources/en.lproj";
  934. tmp_app_dir->make_dir_recursive(fname);
  935. FileAccessRef f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  936. f->store_line("CFBundleDisplayName = \"" + ProjectSettings::get_singleton()->get("application/config/name").operator String() + "\";");
  937. }
  938. Set<String> languages;
  939. for (int j = 0; j < translations.size(); j++) {
  940. Ref<Translation> tr = ResourceLoader::load(translations[j]);
  941. if (tr.is_valid() && tr->get_locale() != "en") {
  942. languages.insert(tr->get_locale());
  943. }
  944. }
  945. for (const Set<String>::Element *E = languages.front(); E; E = E->next()) {
  946. String fname = tmp_app_path_name + "/Contents/Resources/" + E->get() + ".lproj";
  947. tmp_app_dir->make_dir_recursive(fname);
  948. FileAccessRef f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
  949. String prop = "application/config/name_" + E->get();
  950. if (ProjectSettings::get_singleton()->has_setting(prop)) {
  951. f->store_line("CFBundleDisplayName = \"" + ProjectSettings::get_singleton()->get(prop).operator String() + "\";");
  952. }
  953. }
  954. }
  955. // Now process our template.
  956. bool found_binary = false;
  957. Vector<String> dylibs_found;
  958. while (ret == UNZ_OK && err == OK) {
  959. bool is_execute = false;
  960. // Get filename.
  961. unz_file_info info;
  962. char fname[16384];
  963. ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0);
  964. String file = String::utf8(fname);
  965. Vector<uint8_t> data;
  966. data.resize(info.uncompressed_size);
  967. // Read.
  968. unzOpenCurrentFile(src_pkg_zip);
  969. unzReadCurrentFile(src_pkg_zip, data.ptrw(), data.size());
  970. unzCloseCurrentFile(src_pkg_zip);
  971. // Write.
  972. file = file.replace_first("osx_template.app/", "");
  973. if (((info.external_fa >> 16L) & 0120000) == 0120000) {
  974. #ifndef UNIX_ENABLED
  975. add_message(EXPORT_MESSAGE_INFO, TTR("Export"), TTR("Relative symlinks are not supported on this OS, the exported project might be broken!"));
  976. #endif
  977. // Handle symlinks in the archive.
  978. file = tmp_app_path_name.plus_file(file);
  979. if (err == OK) {
  980. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  981. }
  982. if (err == OK) {
  983. String lnk_data = String::utf8((const char *)data.ptr(), data.size());
  984. err = tmp_app_dir->create_link(lnk_data, file);
  985. print_verbose(vformat("ADDING SYMLINK %s => %s\n", file, lnk_data));
  986. }
  987. ret = unzGoToNextFile(src_pkg_zip);
  988. continue; // next
  989. }
  990. if (file == "Contents/Info.plist") {
  991. _fix_plist(p_preset, data, pkg_name);
  992. }
  993. if (file.begins_with("Contents/MacOS/godot_")) {
  994. if (file != "Contents/MacOS/" + binary_to_use) {
  995. ret = unzGoToNextFile(src_pkg_zip);
  996. continue; // skip
  997. }
  998. found_binary = true;
  999. is_execute = true;
  1000. file = "Contents/MacOS/" + pkg_name;
  1001. }
  1002. if (file == "Contents/Resources/icon.icns") {
  1003. // See if there is an icon.
  1004. String iconpath;
  1005. if (p_preset->get("application/icon") != "") {
  1006. iconpath = p_preset->get("application/icon");
  1007. } else {
  1008. iconpath = ProjectSettings::get_singleton()->get("application/config/icon");
  1009. }
  1010. if (iconpath != "") {
  1011. if (iconpath.get_extension() == "icns") {
  1012. FileAccess *icon = FileAccess::open(iconpath, FileAccess::READ);
  1013. if (icon) {
  1014. data.resize(icon->get_len());
  1015. icon->get_buffer(&data.write[0], icon->get_len());
  1016. icon->close();
  1017. memdelete(icon);
  1018. }
  1019. } else {
  1020. Ref<Image> icon;
  1021. icon.instance();
  1022. icon->load(iconpath);
  1023. if (!icon->empty()) {
  1024. _make_icon(icon, data);
  1025. }
  1026. }
  1027. }
  1028. }
  1029. if (data.size() > 0) {
  1030. if (file.find("/data.mono.osx.64.release_debug/") != -1) {
  1031. if (!p_debug) {
  1032. ret = unzGoToNextFile(src_pkg_zip);
  1033. continue; // skip
  1034. }
  1035. file = file.replace("/data.mono.osx.64.release_debug/", "/GodotSharp/");
  1036. }
  1037. if (file.find("/data.mono.osx.64.release/") != -1) {
  1038. if (p_debug) {
  1039. ret = unzGoToNextFile(src_pkg_zip);
  1040. continue; // skip
  1041. }
  1042. file = file.replace("/data.mono.osx.64.release/", "/GodotSharp/");
  1043. }
  1044. if (file.ends_with(".dylib")) {
  1045. dylibs_found.push_back(file);
  1046. }
  1047. print_verbose("ADDING: " + file + " size: " + itos(data.size()));
  1048. // Write it into our application bundle.
  1049. file = tmp_app_path_name.plus_file(file);
  1050. if (err == OK) {
  1051. err = tmp_app_dir->make_dir_recursive(file.get_base_dir());
  1052. }
  1053. if (err == OK) {
  1054. FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
  1055. if (f) {
  1056. f->store_buffer(data.ptr(), data.size());
  1057. f->close();
  1058. if (is_execute) {
  1059. // chmod with 0755 if the file is executable.
  1060. FileAccess::set_unix_permissions(file, 0755);
  1061. }
  1062. memdelete(f);
  1063. } else {
  1064. err = ERR_CANT_CREATE;
  1065. }
  1066. }
  1067. }
  1068. ret = unzGoToNextFile(src_pkg_zip);
  1069. }
  1070. // We're done with our source zip.
  1071. unzClose(src_pkg_zip);
  1072. if (!found_binary) {
  1073. 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));
  1074. err = ERR_FILE_NOT_FOUND;
  1075. }
  1076. if (err == OK) {
  1077. if (ep.step(TTR("Making PKG"), 1)) {
  1078. return ERR_SKIP;
  1079. }
  1080. String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
  1081. Vector<SharedObject> shared_objects;
  1082. err = save_pack(p_preset, pack_path, &shared_objects);
  1083. // See if we can code sign our new package.
  1084. bool sign_enabled = (p_preset->get("codesign/codesign").operator int() > 0);
  1085. String ent_path = p_preset->get("codesign/entitlements/custom_file");
  1086. if (sign_enabled && (ent_path == "")) {
  1087. ent_path = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".entitlements");
  1088. FileAccess *ent_f = FileAccess::open(ent_path, FileAccess::WRITE);
  1089. if (ent_f) {
  1090. ent_f->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  1091. ent_f->store_line("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
  1092. ent_f->store_line("<plist version=\"1.0\">");
  1093. ent_f->store_line("<dict>");
  1094. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  1095. // These entitlements are required to run managed code, and are always enabled in Mono builds.
  1096. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  1097. ent_f->store_line("<true/>");
  1098. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  1099. ent_f->store_line("<true/>");
  1100. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  1101. ent_f->store_line("<true/>");
  1102. } else {
  1103. if ((bool)p_preset->get("codesign/entitlements/allow_jit_code_execution")) {
  1104. ent_f->store_line("<key>com.apple.security.cs.allow-jit</key>");
  1105. ent_f->store_line("<true/>");
  1106. }
  1107. if ((bool)p_preset->get("codesign/entitlements/allow_unsigned_executable_memory")) {
  1108. ent_f->store_line("<key>com.apple.security.cs.allow-unsigned-executable-memory</key>");
  1109. ent_f->store_line("<true/>");
  1110. }
  1111. if ((bool)p_preset->get("codesign/entitlements/allow_dyld_environment_variables")) {
  1112. ent_f->store_line("<key>com.apple.security.cs.allow-dyld-environment-variables</key>");
  1113. ent_f->store_line("<true/>");
  1114. }
  1115. }
  1116. if ((bool)p_preset->get("codesign/entitlements/disable_library_validation")) {
  1117. ent_f->store_line("<key>com.apple.security.cs.disable-library-validation</key>");
  1118. ent_f->store_line("<true/>");
  1119. }
  1120. if ((bool)p_preset->get("codesign/entitlements/audio_input")) {
  1121. ent_f->store_line("<key>com.apple.security.device.audio-input</key>");
  1122. ent_f->store_line("<true/>");
  1123. }
  1124. if ((bool)p_preset->get("codesign/entitlements/camera")) {
  1125. ent_f->store_line("<key>com.apple.security.device.camera</key>");
  1126. ent_f->store_line("<true/>");
  1127. }
  1128. if ((bool)p_preset->get("codesign/entitlements/location")) {
  1129. ent_f->store_line("<key>com.apple.security.personal-information.location</key>");
  1130. ent_f->store_line("<true/>");
  1131. }
  1132. if ((bool)p_preset->get("codesign/entitlements/address_book")) {
  1133. ent_f->store_line("<key>com.apple.security.personal-information.addressbook</key>");
  1134. ent_f->store_line("<true/>");
  1135. }
  1136. if ((bool)p_preset->get("codesign/entitlements/calendars")) {
  1137. ent_f->store_line("<key>com.apple.security.personal-information.calendars</key>");
  1138. ent_f->store_line("<true/>");
  1139. }
  1140. if ((bool)p_preset->get("codesign/entitlements/photos_library")) {
  1141. ent_f->store_line("<key>com.apple.security.personal-information.photos-library</key>");
  1142. ent_f->store_line("<true/>");
  1143. }
  1144. if ((bool)p_preset->get("codesign/entitlements/apple_events")) {
  1145. ent_f->store_line("<key>com.apple.security.automation.apple-events</key>");
  1146. ent_f->store_line("<true/>");
  1147. }
  1148. if ((bool)p_preset->get("codesign/entitlements/debugging")) {
  1149. ent_f->store_line("<key>com.apple.security.get-task-allow</key>");
  1150. ent_f->store_line("<true/>");
  1151. }
  1152. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/enabled")) {
  1153. ent_f->store_line("<key>com.apple.security.app-sandbox</key>");
  1154. ent_f->store_line("<true/>");
  1155. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_server")) {
  1156. ent_f->store_line("<key>com.apple.security.network.server</key>");
  1157. ent_f->store_line("<true/>");
  1158. }
  1159. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/network_client")) {
  1160. ent_f->store_line("<key>com.apple.security.network.client</key>");
  1161. ent_f->store_line("<true/>");
  1162. }
  1163. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_usb")) {
  1164. ent_f->store_line("<key>com.apple.security.device.usb</key>");
  1165. ent_f->store_line("<true/>");
  1166. }
  1167. if ((bool)p_preset->get("codesign/entitlements/app_sandbox/device_bluetooth")) {
  1168. ent_f->store_line("<key>com.apple.security.device.bluetooth</key>");
  1169. ent_f->store_line("<true/>");
  1170. }
  1171. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 1) {
  1172. ent_f->store_line("<key>com.apple.security.files.downloads.read-only</key>");
  1173. ent_f->store_line("<true/>");
  1174. }
  1175. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_downloads") == 2) {
  1176. ent_f->store_line("<key>com.apple.security.files.downloads.read-write</key>");
  1177. ent_f->store_line("<true/>");
  1178. }
  1179. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 1) {
  1180. ent_f->store_line("<key>com.apple.security.files.pictures.read-only</key>");
  1181. ent_f->store_line("<true/>");
  1182. }
  1183. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_pictures") == 2) {
  1184. ent_f->store_line("<key>com.apple.security.files.pictures.read-write</key>");
  1185. ent_f->store_line("<true/>");
  1186. }
  1187. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 1) {
  1188. ent_f->store_line("<key>com.apple.security.files.music.read-only</key>");
  1189. ent_f->store_line("<true/>");
  1190. }
  1191. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_music") == 2) {
  1192. ent_f->store_line("<key>com.apple.security.files.music.read-write</key>");
  1193. ent_f->store_line("<true/>");
  1194. }
  1195. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 1) {
  1196. ent_f->store_line("<key>com.apple.security.files.movies.read-only</key>");
  1197. ent_f->store_line("<true/>");
  1198. }
  1199. if ((int)p_preset->get("codesign/entitlements/app_sandbox/files_movies") == 2) {
  1200. ent_f->store_line("<key>com.apple.security.files.movies.read-write</key>");
  1201. ent_f->store_line("<true/>");
  1202. }
  1203. }
  1204. ent_f->store_line("</dict>");
  1205. ent_f->store_line("</plist>");
  1206. ent_f->close();
  1207. memdelete(ent_f);
  1208. } else {
  1209. err = ERR_CANT_CREATE;
  1210. }
  1211. }
  1212. bool ad_hoc = false;
  1213. int codesign_tool = p_preset->get("codesign/codesign");
  1214. switch (codesign_tool) {
  1215. case 1: { // built-in ad-hoc
  1216. ad_hoc = true;
  1217. } break;
  1218. case 2: { // "rcodesign"
  1219. ad_hoc = p_preset->get("codesign/certificate_file").operator String().empty() || p_preset->get("codesign/certificate_password").operator String().empty();
  1220. } break;
  1221. #ifdef OSX_ENABLED
  1222. case 3: { // "codesign"
  1223. ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  1224. } break;
  1225. #endif
  1226. default: {
  1227. };
  1228. }
  1229. if (err == OK) {
  1230. bool lib_validation = p_preset->get("codesign/entitlements/disable_library_validation");
  1231. if ((!dylibs_found.empty() || !shared_objects.empty()) && sign_enabled && ad_hoc && !lib_validation) {
  1232. add_message(EXPORT_MESSAGE_ERROR, TTR("Code Signing"), TTR("Ad-hoc signed applications require the 'Disable Library Validation' entitlement to load dynamic libraries."));
  1233. err = ERR_CANT_CREATE;
  1234. }
  1235. }
  1236. if (err == OK) {
  1237. DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  1238. for (int i = 0; i < shared_objects.size(); i++) {
  1239. String src_path = ProjectSettings::get_singleton()->globalize_path(shared_objects[i].path);
  1240. String path_in_app{ tmp_app_path_name + "/Contents/Frameworks/" + src_path.get_file() };
  1241. err = _copy_and_sign_files(da, src_path, path_in_app, sign_enabled, p_preset, ent_path, true);
  1242. if (err != OK) {
  1243. break;
  1244. }
  1245. }
  1246. Vector<Ref<EditorExportPlugin>> export_plugins{ EditorExport::get_singleton()->get_export_plugins() };
  1247. for (int i = 0; i < export_plugins.size(); ++i) {
  1248. err = _export_osx_plugins_for(export_plugins[i], tmp_app_path_name, da, sign_enabled, p_preset, ent_path);
  1249. if (err != OK) {
  1250. break;
  1251. }
  1252. }
  1253. }
  1254. if (sign_enabled) {
  1255. for (int i = 0; i < dylibs_found.size(); i++) {
  1256. if (err == OK) {
  1257. err = _code_sign(p_preset, tmp_app_path_name + "/" + dylibs_found[i], ent_path);
  1258. }
  1259. }
  1260. }
  1261. if (err == OK && sign_enabled) {
  1262. if (ep.step(TTR("Code signing bundle"), 2)) {
  1263. return ERR_SKIP;
  1264. }
  1265. err = _code_sign(p_preset, tmp_app_path_name, ent_path);
  1266. }
  1267. if (export_format == "dmg") {
  1268. // Create a DMG.
  1269. if (err == OK) {
  1270. if (ep.step(TTR("Making DMG"), 3)) {
  1271. return ERR_SKIP;
  1272. }
  1273. err = _create_dmg(p_path, pkg_name, tmp_app_path_name);
  1274. }
  1275. // Sign DMG.
  1276. if (err == OK && sign_enabled && !ad_hoc) {
  1277. if (ep.step(TTR("Code signing DMG"), 3)) {
  1278. return ERR_SKIP;
  1279. }
  1280. err = _code_sign(p_preset, p_path, ent_path);
  1281. }
  1282. } else if (export_format == "zip") {
  1283. // Create ZIP.
  1284. if (err == OK) {
  1285. if (ep.step(TTR("Making ZIP"), 3)) {
  1286. return ERR_SKIP;
  1287. }
  1288. if (FileAccess::exists(p_path)) {
  1289. OS::get_singleton()->move_to_trash(p_path);
  1290. }
  1291. FileAccess *dst_f = nullptr;
  1292. zlib_filefunc_def io_dst = zipio_create_io_from_file(&dst_f);
  1293. zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
  1294. _zip_folder_recursive(zip, EditorSettings::get_singleton()->get_cache_dir(), pkg_name + ".app", pkg_name);
  1295. zipClose(zip, nullptr);
  1296. }
  1297. }
  1298. bool noto_enabled = (p_preset->get("notarization/notarization").operator int() > 0);
  1299. if (err == OK && noto_enabled) {
  1300. if (export_format == "app") {
  1301. add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("Notarization requires the app to be archived first, select the DMG or ZIP export format instead."));
  1302. } else {
  1303. if (ep.step(TTR("Sending archive for notarization"), 4)) {
  1304. return ERR_SKIP;
  1305. }
  1306. err = _notarize(p_preset, p_path);
  1307. }
  1308. }
  1309. // Clean up temporary .app dir and generated entitlements.
  1310. if ((String)(p_preset->get("codesign/entitlements/custom_file")) == "") {
  1311. tmp_app_dir->remove(ent_path);
  1312. }
  1313. if (export_format != "app") {
  1314. if (tmp_app_dir->change_dir(tmp_app_path_name) == OK) {
  1315. tmp_app_dir->erase_contents_recursive();
  1316. tmp_app_dir->change_dir("..");
  1317. tmp_app_dir->remove(tmp_app_dir_name);
  1318. }
  1319. }
  1320. }
  1321. return err;
  1322. }
  1323. void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name) {
  1324. String dir = p_root_path.plus_file(p_folder);
  1325. DirAccess *da = DirAccess::open(dir);
  1326. da->list_dir_begin();
  1327. String f;
  1328. while ((f = da->get_next()) != "") {
  1329. if (f == "." || f == "..") {
  1330. continue;
  1331. }
  1332. if (da->is_link(f)) {
  1333. OS::Time time = OS::get_singleton()->get_time();
  1334. OS::Date date = OS::get_singleton()->get_date();
  1335. zip_fileinfo zipfi;
  1336. zipfi.tmz_date.tm_hour = time.hour;
  1337. zipfi.tmz_date.tm_mday = date.day;
  1338. zipfi.tmz_date.tm_min = time.min;
  1339. zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, http://www.cplusplus.com/reference/ctime/tm/
  1340. zipfi.tmz_date.tm_sec = time.sec;
  1341. zipfi.tmz_date.tm_year = date.year;
  1342. zipfi.dosDate = 0;
  1343. // 0120000: symbolic link type
  1344. // 0000755: permissions rwxr-xr-x
  1345. // 0000644: permissions rw-r--r--
  1346. uint32_t _mode = 0120644;
  1347. zipfi.external_fa = (_mode << 16L) | !(_mode & 0200);
  1348. zipfi.internal_fa = 0;
  1349. zipOpenNewFileInZip4(p_zip,
  1350. p_folder.plus_file(f).utf8().get_data(),
  1351. &zipfi,
  1352. nullptr,
  1353. 0,
  1354. nullptr,
  1355. 0,
  1356. nullptr,
  1357. Z_DEFLATED,
  1358. Z_DEFAULT_COMPRESSION,
  1359. 0,
  1360. -MAX_WBITS,
  1361. DEF_MEM_LEVEL,
  1362. Z_DEFAULT_STRATEGY,
  1363. nullptr,
  1364. 0,
  1365. 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions
  1366. 0);
  1367. String target = da->read_link(f);
  1368. zipWriteInFileInZip(p_zip, target.utf8().get_data(), target.utf8().size());
  1369. zipCloseFileInZip(p_zip);
  1370. } else if (da->current_is_dir()) {
  1371. _zip_folder_recursive(p_zip, p_root_path, p_folder.plus_file(f), p_pkg_name);
  1372. } else {
  1373. bool is_executable = (p_folder.ends_with("MacOS") && (f == p_pkg_name));
  1374. OS::Time time = OS::get_singleton()->get_time();
  1375. OS::Date date = OS::get_singleton()->get_date();
  1376. zip_fileinfo zipfi;
  1377. zipfi.tmz_date.tm_hour = time.hour;
  1378. zipfi.tmz_date.tm_mday = date.day;
  1379. zipfi.tmz_date.tm_min = time.min;
  1380. zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, http://www.cplusplus.com/reference/ctime/tm/
  1381. zipfi.tmz_date.tm_sec = time.sec;
  1382. zipfi.tmz_date.tm_year = date.year;
  1383. zipfi.dosDate = 0;
  1384. // 0100000: regular file type
  1385. // 0000755: permissions rwxr-xr-x
  1386. // 0000644: permissions rw-r--r--
  1387. uint32_t _mode = (is_executable ? 0100755 : 0100644);
  1388. zipfi.external_fa = (_mode << 16L) | !(_mode & 0200);
  1389. zipfi.internal_fa = 0;
  1390. zipOpenNewFileInZip4(p_zip,
  1391. p_folder.plus_file(f).utf8().get_data(),
  1392. &zipfi,
  1393. nullptr,
  1394. 0,
  1395. nullptr,
  1396. 0,
  1397. nullptr,
  1398. Z_DEFLATED,
  1399. Z_DEFAULT_COMPRESSION,
  1400. 0,
  1401. -MAX_WBITS,
  1402. DEF_MEM_LEVEL,
  1403. Z_DEFAULT_STRATEGY,
  1404. nullptr,
  1405. 0,
  1406. 0x0314, // "version made by", 0x03 - Unix, 0x14 - ZIP specification version 2.0, required to store Unix file permissions
  1407. 0);
  1408. FileAccessRef fa = FileAccess::open(dir.plus_file(f), FileAccess::READ);
  1409. if (!fa) {
  1410. add_message(EXPORT_MESSAGE_ERROR, TTR("ZIP Creation"), vformat(TTR("Could not open file to read from path \"%s\"."), dir.plus_file(f)));
  1411. return;
  1412. }
  1413. const int bufsize = 16384;
  1414. uint8_t buf[bufsize];
  1415. while (true) {
  1416. uint64_t got = fa->get_buffer(buf, bufsize);
  1417. if (got == 0) {
  1418. break;
  1419. }
  1420. zipWriteInFileInZip(p_zip, buf, got);
  1421. }
  1422. zipCloseFileInZip(p_zip);
  1423. }
  1424. }
  1425. da->list_dir_end();
  1426. memdelete(da);
  1427. }
  1428. bool EditorExportPlatformOSX::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
  1429. String err;
  1430. bool valid = false;
  1431. // Look for export templates (custom templates).
  1432. bool dvalid = false;
  1433. bool rvalid = false;
  1434. if (p_preset->get("custom_template/debug") != "") {
  1435. dvalid = FileAccess::exists(p_preset->get("custom_template/debug"));
  1436. if (!dvalid) {
  1437. err += TTR("Custom debug template not found.") + "\n";
  1438. }
  1439. }
  1440. if (p_preset->get("custom_template/release") != "") {
  1441. rvalid = FileAccess::exists(p_preset->get("custom_template/release"));
  1442. if (!rvalid) {
  1443. err += TTR("Custom release template not found.") + "\n";
  1444. }
  1445. }
  1446. // Look for export templates (official templates, check only is custom templates are not set).
  1447. if (!dvalid || !rvalid) {
  1448. dvalid = exists_export_template("osx.zip", &err);
  1449. rvalid = dvalid; // Both in the same ZIP.
  1450. }
  1451. valid = dvalid || rvalid;
  1452. r_missing_templates = !valid;
  1453. if (!err.empty()) {
  1454. r_error = err;
  1455. }
  1456. return valid;
  1457. }
  1458. bool EditorExportPlatformOSX::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
  1459. String err;
  1460. bool valid = true;
  1461. String identifier = p_preset->get("application/identifier");
  1462. String pn_err;
  1463. if (!is_package_name_valid(identifier, &pn_err)) {
  1464. err += TTR("Invalid bundle identifier:") + " " + pn_err + "\n";
  1465. valid = false;
  1466. }
  1467. bool ad_hoc = false;
  1468. int codesign_tool = p_preset->get("codesign/codesign");
  1469. switch (codesign_tool) {
  1470. case 1: { // built-in ad-hoc
  1471. ad_hoc = true;
  1472. } break;
  1473. case 2: { // "rcodesign"
  1474. ad_hoc = p_preset->get("codesign/certificate_file").operator String().empty() || p_preset->get("codesign/certificate_password").operator String().empty();
  1475. } break;
  1476. #ifdef OSX_ENABLED
  1477. case 3: { // "codesign"
  1478. ad_hoc = (p_preset->get("codesign/identity") == "" || p_preset->get("codesign/identity") == "-");
  1479. } break;
  1480. #endif
  1481. default: {
  1482. };
  1483. }
  1484. int notary_tool = p_preset->get("notarization/notarization");
  1485. if (notary_tool > 0) {
  1486. if (ad_hoc) {
  1487. err += TTR("Notarization: Notarization with an ad-hoc signature is not supported.") + "\n";
  1488. valid = false;
  1489. }
  1490. if (codesign_tool == 0) {
  1491. err += TTR("Notarization: Code signing is required for notarization.") + "\n";
  1492. valid = false;
  1493. }
  1494. if (notary_tool == 2) {
  1495. if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) {
  1496. err += TTR("Notarization: Xcode command line tools are not installed.") + "\n";
  1497. valid = false;
  1498. }
  1499. if (p_preset->get("notarization/apple_id_name") == "" && p_preset->get("notarization/api_uuid") == "") {
  1500. err += TTR("Notarization: Neither Apple ID name nor App Store Connect issuer ID name not specified.") + "\n";
  1501. valid = false;
  1502. } else if (p_preset->get("notarization/apple_id_name") != "" && p_preset->get("notarization/api_uuid") != "") {
  1503. err += TTR("Notarization: Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.") + "\n";
  1504. valid = false;
  1505. } else {
  1506. if (p_preset->get("notarization/apple_id_name") != "") {
  1507. if (p_preset->get("notarization/apple_id_password") == "") {
  1508. err += TTR("Notarization: Apple ID password not specified.") + "\n";
  1509. }
  1510. valid = false;
  1511. }
  1512. if (p_preset->get("notarization/api_uuid") != "") {
  1513. if (p_preset->get("notarization/api_key") == "") {
  1514. err += TTR("Notarization: App Store Connect API key ID not specified.") + "\n";
  1515. valid = false;
  1516. }
  1517. }
  1518. }
  1519. } else if (notary_tool == 1) {
  1520. if (p_preset->get("notarization/api_uuid") == "") {
  1521. err += TTR("Notarization: App Store Connect issuer ID name not specified.") + "\n";
  1522. valid = false;
  1523. }
  1524. if (p_preset->get("notarization/api_key") == "") {
  1525. err += TTR("Notarization: App Store Connect API key ID not specified.") + "\n";
  1526. valid = false;
  1527. }
  1528. String rcodesign = EditorSettings::get_singleton()->get("export/macos/rcodesign").operator String();
  1529. if (rcodesign.empty()) {
  1530. err += TTR("Notarization: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";
  1531. valid = false;
  1532. }
  1533. }
  1534. } else {
  1535. err += TTR("Warning: Notarization is disabled. The exported project will be blocked by Gatekeeper if it's downloaded from an unknown source.") + "\n";
  1536. if (codesign_tool == 0) {
  1537. err += TTR("Code signing is disabled. The exported project will not run on Macs with enabled Gatekeeper and Apple Silicon powered Macs.") + "\n";
  1538. }
  1539. }
  1540. if (codesign_tool > 0) {
  1541. if (ad_hoc) {
  1542. err += TTR("Code signing: Using ad-hoc signature. The exported project will be blocked by Gatekeeper") + "\n";
  1543. }
  1544. if (codesign_tool == 3) {
  1545. if (!FileAccess::exists("/usr/bin/codesign") && !FileAccess::exists("/bin/codesign")) {
  1546. err += TTR("Code signing: Xcode command line tools are not installed.") + "\n";
  1547. valid = false;
  1548. }
  1549. } else if (codesign_tool == 2) {
  1550. String rcodesign = EditorSettings::get_singleton()->get("export/macos/rcodesign").operator String();
  1551. if (rcodesign.empty()) {
  1552. err += TTR("Code signing: rcodesign path is not set. Configure rcodesign path in the Editor Settings (Export > macOS > rcodesign).") + "\n";
  1553. valid = false;
  1554. }
  1555. }
  1556. if ((bool)p_preset->get("codesign/entitlements/audio_input") && ((String)p_preset->get("privacy/microphone_usage_description")).empty()) {
  1557. err += TTR("Privacy: Microphone access is enabled, but usage description is not specified.") + "\n";
  1558. valid = false;
  1559. }
  1560. if ((bool)p_preset->get("codesign/entitlements/camera") && ((String)p_preset->get("privacy/camera_usage_description")).empty()) {
  1561. err += TTR("Privacy: Camera access is enabled, but usage description is not specified.") + "\n";
  1562. valid = false;
  1563. }
  1564. if ((bool)p_preset->get("codesign/entitlements/location") && ((String)p_preset->get("privacy/location_usage_description")).empty()) {
  1565. err += TTR("Privacy: Location information access is enabled, but usage description is not specified.") + "\n";
  1566. valid = false;
  1567. }
  1568. if ((bool)p_preset->get("codesign/entitlements/address_book") && ((String)p_preset->get("privacy/address_book_usage_description")).empty()) {
  1569. err += TTR("Privacy: Address book access is enabled, but usage description is not specified.") + "\n";
  1570. valid = false;
  1571. }
  1572. if ((bool)p_preset->get("codesign/entitlements/calendars") && ((String)p_preset->get("privacy/calendar_usage_description")).empty()) {
  1573. err += TTR("Privacy: Calendar access is enabled, but usage description is not specified.") + "\n";
  1574. valid = false;
  1575. }
  1576. if ((bool)p_preset->get("codesign/entitlements/photos_library") && ((String)p_preset->get("privacy/photos_library_usage_description")).empty()) {
  1577. err += TTR("Privacy: Photo library access is enabled, but usage description is not specified.") + "\n";
  1578. valid = false;
  1579. }
  1580. }
  1581. if (!err.empty()) {
  1582. r_error = err;
  1583. }
  1584. return valid;
  1585. }
  1586. EditorExportPlatformOSX::EditorExportPlatformOSX() {
  1587. Ref<Image> img = memnew(Image(_osx_logo));
  1588. logo.instance();
  1589. logo->create_from_image(img);
  1590. }
  1591. EditorExportPlatformOSX::~EditorExportPlatformOSX() {
  1592. }
  1593. void register_osx_exporter() {
  1594. EDITOR_DEF("export/macos/rcodesign", "");
  1595. #ifdef WINDOWS_ENABLED
  1596. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/macos/rcodesign", PROPERTY_HINT_GLOBAL_FILE, "*.exe"));
  1597. #else
  1598. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/macos/rcodesign", PROPERTY_HINT_GLOBAL_FILE));
  1599. #endif
  1600. Ref<EditorExportPlatformOSX> platform;
  1601. platform.instance();
  1602. EditorExport::get_singleton()->add_export_platform(platform);
  1603. }