export_plugin.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*************************************************************************/
  2. /* export_plugin.h */
  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. #ifndef MACOS_EXPORT_PLUGIN_H
  31. #define MACOS_EXPORT_PLUGIN_H
  32. #include "core/config/project_settings.h"
  33. #include "core/io/dir_access.h"
  34. #include "core/io/file_access.h"
  35. #include "core/io/marshalls.h"
  36. #include "core/io/resource_saver.h"
  37. #include "core/io/zip_io.h"
  38. #include "core/os/os.h"
  39. #include "core/version.h"
  40. #include "editor/editor_settings.h"
  41. #include "editor/export/editor_export.h"
  42. #include "platform/macos/logo.gen.h"
  43. #include <sys/stat.h>
  44. class EditorExportPlatformMacOS : public EditorExportPlatform {
  45. GDCLASS(EditorExportPlatformMacOS, EditorExportPlatform);
  46. int version_code = 0;
  47. Ref<ImageTexture> logo;
  48. void _fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary);
  49. void _make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data);
  50. Error _notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path);
  51. Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_warn = true);
  52. Error _code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_should_error_on_non_code = true);
  53. Error _copy_and_sign_files(Ref<DirAccess> &dir_access, const String &p_src_path, const String &p_in_app_path,
  54. bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,
  55. bool p_should_error_on_non_code_sign);
  56. Error _export_macos_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin, const String &p_app_path_name,
  57. Ref<DirAccess> &dir_access, bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,
  58. const String &p_ent_path);
  59. Error _create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name);
  60. void _zip_folder_recursive(zipFile &p_zip, const String &p_root_path, const String &p_folder, const String &p_pkg_name);
  61. Error _export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path);
  62. bool use_codesign() const { return true; }
  63. #ifdef MACOS_ENABLED
  64. bool use_dmg() const { return true; }
  65. #else
  66. bool use_dmg() const { return false; }
  67. #endif
  68. bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const {
  69. String pname = p_package;
  70. if (pname.length() == 0) {
  71. if (r_error) {
  72. *r_error = TTR("Identifier is missing.");
  73. }
  74. return false;
  75. }
  76. for (int i = 0; i < pname.length(); i++) {
  77. char32_t c = pname[i];
  78. if (!(is_ascii_alphanumeric_char(c) || c == '-' || c == '.')) {
  79. if (r_error) {
  80. *r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
  81. }
  82. return false;
  83. }
  84. }
  85. return true;
  86. }
  87. bool is_shbang(const String &p_path) const;
  88. protected:
  89. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const override;
  90. virtual void get_export_options(List<ExportOption> *r_options) override;
  91. virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
  92. public:
  93. virtual String get_name() const override { return "macOS"; }
  94. virtual String get_os_name() const override { return "macOS"; }
  95. virtual Ref<Texture2D> get_logo() const override { return logo; }
  96. virtual bool is_executable(const String &p_path) const override;
  97. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override {
  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) override;
  107. virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
  108. virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;
  109. virtual void get_platform_features(List<String> *r_features) const override {
  110. r_features->push_back("pc");
  111. r_features->push_back("s3tc");
  112. r_features->push_back("macos");
  113. }
  114. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) override {
  115. }
  116. EditorExportPlatformMacOS();
  117. ~EditorExportPlatformMacOS();
  118. };
  119. #endif // MACOS_EXPORT_PLUGIN_H