export_plugin.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**************************************************************************/
  2. /* export_plugin.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #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/os/os.h"
  38. #include "core/version.h"
  39. #include "editor/editor_settings.h"
  40. #include "editor/export/editor_export.h"
  41. #include <sys/stat.h>
  42. class EditorExportPlatformMacOS : public EditorExportPlatform {
  43. GDCLASS(EditorExportPlatformMacOS, EditorExportPlatform);
  44. int version_code = 0;
  45. Ref<ImageTexture> logo;
  46. struct SSHCleanupCommand {
  47. String host;
  48. String port;
  49. Vector<String> ssh_args;
  50. String cmd_args;
  51. bool wait = false;
  52. SSHCleanupCommand(){};
  53. SSHCleanupCommand(const String &p_host, const String &p_port, const Vector<String> &p_ssh_arg, const String &p_cmd_args, bool p_wait = false) {
  54. host = p_host;
  55. port = p_port;
  56. ssh_args = p_ssh_arg;
  57. cmd_args = p_cmd_args;
  58. wait = p_wait;
  59. };
  60. };
  61. Ref<ImageTexture> run_icon;
  62. Ref<ImageTexture> stop_icon;
  63. Vector<SSHCleanupCommand> cleanup_commands;
  64. OS::ProcessID ssh_pid = 0;
  65. int menu_options = 0;
  66. void _fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary);
  67. void _make_icon(const Ref<EditorExportPreset> &p_preset, const Ref<Image> &p_icon, Vector<uint8_t> &p_data);
  68. Error _notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path);
  69. Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_warn = true);
  70. 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);
  71. Error _copy_and_sign_files(Ref<DirAccess> &dir_access, const String &p_src_path, const String &p_in_app_path,
  72. bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset, const String &p_ent_path,
  73. bool p_should_error_on_non_code_sign);
  74. Error _export_macos_plugins_for(Ref<EditorExportPlugin> p_editor_export_plugin, const String &p_app_path_name,
  75. Ref<DirAccess> &dir_access, bool p_sign_enabled, const Ref<EditorExportPreset> &p_preset,
  76. const String &p_ent_path);
  77. Error _create_dmg(const String &p_dmg_path, const String &p_pkg_name, const String &p_app_path_name);
  78. Error _export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path);
  79. bool use_codesign() const { return true; }
  80. #ifdef MACOS_ENABLED
  81. bool use_dmg() const {
  82. return true;
  83. }
  84. #else
  85. bool use_dmg() const {
  86. return false;
  87. }
  88. #endif
  89. bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const {
  90. String pname = p_package;
  91. if (pname.length() == 0) {
  92. if (r_error) {
  93. *r_error = TTR("Identifier is missing.");
  94. }
  95. return false;
  96. }
  97. for (int i = 0; i < pname.length(); i++) {
  98. char32_t c = pname[i];
  99. if (!(is_ascii_alphanumeric_char(c) || c == '-' || c == '.')) {
  100. if (r_error) {
  101. *r_error = vformat(TTR("The character '%s' is not allowed in Identifier."), String::chr(c));
  102. }
  103. return false;
  104. }
  105. }
  106. return true;
  107. }
  108. bool is_shebang(const String &p_path) const;
  109. protected:
  110. virtual void get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const override;
  111. virtual void get_export_options(List<ExportOption> *r_options) override;
  112. virtual bool get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
  113. public:
  114. virtual String get_name() const override {
  115. return "macOS";
  116. }
  117. virtual String get_os_name() const override {
  118. return "macOS";
  119. }
  120. virtual Ref<Texture2D> get_logo() const override {
  121. return logo;
  122. }
  123. virtual bool is_executable(const String &p_path) const override;
  124. virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override {
  125. List<String> list;
  126. if (use_dmg()) {
  127. list.push_back("dmg");
  128. }
  129. list.push_back("zip");
  130. list.push_back("app");
  131. return list;
  132. }
  133. virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
  134. virtual bool has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const override;
  135. virtual bool has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const override;
  136. virtual void get_platform_features(List<String> *r_features) const override {
  137. r_features->push_back("pc");
  138. r_features->push_back("s3tc");
  139. r_features->push_back("macos");
  140. }
  141. virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, HashSet<String> &p_features) override {
  142. }
  143. virtual Ref<Texture2D> get_run_icon() const override;
  144. virtual bool poll_export() override;
  145. virtual Ref<ImageTexture> get_option_icon(int p_index) const override;
  146. virtual int get_options_count() const override;
  147. virtual String get_option_label(int p_index) const override;
  148. virtual String get_option_tooltip(int p_index) const override;
  149. virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) override;
  150. virtual void cleanup() override;
  151. EditorExportPlatformMacOS();
  152. };
  153. #endif // MACOS_EXPORT_PLUGIN_H