editor_export_plugin.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /**************************************************************************/
  2. /* editor_export_plugin.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_export_plugin.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/io/dir_access.h"
  33. #include "core/io/file_access.h"
  34. #include "editor/editor_paths.h"
  35. #include "editor/editor_settings.h"
  36. #include "editor/export/editor_export_platform.h"
  37. #include "scene/resources/resource_format_text.h"
  38. void EditorExportPlugin::set_export_preset(const Ref<EditorExportPreset> &p_preset) {
  39. if (p_preset.is_valid()) {
  40. export_preset = p_preset;
  41. }
  42. }
  43. Ref<EditorExportPreset> EditorExportPlugin::get_export_preset() const {
  44. return export_preset;
  45. }
  46. Ref<EditorExportPlatform> EditorExportPlugin::get_export_platform() const {
  47. if (export_preset.is_valid()) {
  48. return export_preset->get_platform();
  49. } else {
  50. return Ref<EditorExportPlatform>();
  51. }
  52. }
  53. void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {
  54. ExtraFile ef;
  55. ef.data = p_file;
  56. ef.path = p_path;
  57. ef.remap = p_remap;
  58. extra_files.push_back(ef);
  59. }
  60. void EditorExportPlugin::add_shared_object(const String &p_path, const Vector<String> &p_tags, const String &p_target) {
  61. shared_objects.push_back(SharedObject(p_path, p_tags, p_target));
  62. }
  63. void EditorExportPlugin::_add_shared_object(const SharedObject &p_shared_object) {
  64. shared_objects.push_back(p_shared_object);
  65. }
  66. void EditorExportPlugin::add_ios_framework(const String &p_path) {
  67. ios_frameworks.push_back(p_path);
  68. }
  69. void EditorExportPlugin::add_ios_embedded_framework(const String &p_path) {
  70. ios_embedded_frameworks.push_back(p_path);
  71. }
  72. Vector<String> EditorExportPlugin::get_ios_frameworks() const {
  73. return ios_frameworks;
  74. }
  75. Vector<String> EditorExportPlugin::get_ios_embedded_frameworks() const {
  76. return ios_embedded_frameworks;
  77. }
  78. void EditorExportPlugin::add_ios_plist_content(const String &p_plist_content) {
  79. ios_plist_content += p_plist_content + "\n";
  80. }
  81. String EditorExportPlugin::get_ios_plist_content() const {
  82. return ios_plist_content;
  83. }
  84. void EditorExportPlugin::add_ios_linker_flags(const String &p_flags) {
  85. if (ios_linker_flags.length() > 0) {
  86. ios_linker_flags += ' ';
  87. }
  88. ios_linker_flags += p_flags;
  89. }
  90. String EditorExportPlugin::get_ios_linker_flags() const {
  91. return ios_linker_flags;
  92. }
  93. void EditorExportPlugin::add_ios_bundle_file(const String &p_path) {
  94. ios_bundle_files.push_back(p_path);
  95. }
  96. Vector<String> EditorExportPlugin::get_ios_bundle_files() const {
  97. return ios_bundle_files;
  98. }
  99. void EditorExportPlugin::add_ios_cpp_code(const String &p_code) {
  100. ios_cpp_code += p_code;
  101. }
  102. String EditorExportPlugin::get_ios_cpp_code() const {
  103. return ios_cpp_code;
  104. }
  105. void EditorExportPlugin::add_macos_plugin_file(const String &p_path) {
  106. macos_plugin_files.push_back(p_path);
  107. }
  108. const Vector<String> &EditorExportPlugin::get_macos_plugin_files() const {
  109. return macos_plugin_files;
  110. }
  111. void EditorExportPlugin::add_ios_project_static_lib(const String &p_path) {
  112. ios_project_static_libs.push_back(p_path);
  113. }
  114. Vector<String> EditorExportPlugin::get_ios_project_static_libs() const {
  115. return ios_project_static_libs;
  116. }
  117. Variant EditorExportPlugin::get_option(const StringName &p_name) const {
  118. ERR_FAIL_COND_V(export_preset.is_null(), Variant());
  119. return export_preset->get(p_name);
  120. }
  121. String EditorExportPlugin::_has_valid_export_configuration(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset) {
  122. String warning;
  123. if (!supports_platform(p_export_platform)) {
  124. warning += vformat(TTR("Plugin \"%s\" is not supported on \"%s\""), get_name(), p_export_platform->get_name());
  125. warning += "\n";
  126. return warning;
  127. }
  128. set_export_preset(p_preset);
  129. List<EditorExportPlatform::ExportOption> options;
  130. _get_export_options(p_export_platform, &options);
  131. for (const EditorExportPlatform::ExportOption &E : options) {
  132. String option_warning = _get_export_option_warning(p_export_platform, E.option.name);
  133. if (!option_warning.is_empty()) {
  134. warning += option_warning + "\n";
  135. }
  136. }
  137. return warning;
  138. }
  139. void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const Vector<String> &p_features) {
  140. GDVIRTUAL_CALL(_export_file, p_path, p_type, p_features);
  141. }
  142. void EditorExportPlugin::_export_begin_script(const Vector<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
  143. GDVIRTUAL_CALL(_export_begin, p_features, p_debug, p_path, p_flags);
  144. }
  145. void EditorExportPlugin::_export_end_script() {
  146. GDVIRTUAL_CALL(_export_end);
  147. }
  148. // Customization
  149. bool EditorExportPlugin::_begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
  150. bool ret = false;
  151. GDVIRTUAL_CALL(_begin_customize_resources, p_platform, p_features, ret);
  152. return ret;
  153. }
  154. Ref<Resource> EditorExportPlugin::_customize_resource(const Ref<Resource> &p_resource, const String &p_path) {
  155. Ref<Resource> ret;
  156. GDVIRTUAL_CALL(_customize_resource, p_resource, p_path, ret);
  157. return ret;
  158. }
  159. bool EditorExportPlugin::_begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
  160. bool ret = false;
  161. GDVIRTUAL_CALL(_begin_customize_scenes, p_platform, p_features, ret);
  162. return ret;
  163. }
  164. Node *EditorExportPlugin::_customize_scene(Node *p_root, const String &p_path) {
  165. Node *ret = nullptr;
  166. GDVIRTUAL_CALL(_customize_scene, p_root, p_path, ret);
  167. return ret;
  168. }
  169. uint64_t EditorExportPlugin::_get_customization_configuration_hash() const {
  170. uint64_t ret = 0;
  171. GDVIRTUAL_CALL(_get_customization_configuration_hash, ret);
  172. return ret;
  173. }
  174. void EditorExportPlugin::_end_customize_scenes() {
  175. GDVIRTUAL_CALL(_end_customize_scenes);
  176. }
  177. void EditorExportPlugin::_end_customize_resources() {
  178. GDVIRTUAL_CALL(_end_customize_resources);
  179. }
  180. String EditorExportPlugin::get_name() const {
  181. String ret;
  182. GDVIRTUAL_CALL(_get_name, ret);
  183. return ret;
  184. }
  185. bool EditorExportPlugin::supports_platform(const Ref<EditorExportPlatform> &p_export_platform) const {
  186. bool ret = false;
  187. GDVIRTUAL_CALL(_supports_platform, p_export_platform, ret);
  188. return ret;
  189. }
  190. PackedStringArray EditorExportPlugin::get_export_features(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  191. return _get_export_features(p_export_platform, p_debug);
  192. }
  193. PackedStringArray EditorExportPlugin::get_android_dependencies(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  194. PackedStringArray ret;
  195. GDVIRTUAL_CALL(_get_android_dependencies, p_export_platform, p_debug, ret);
  196. return ret;
  197. }
  198. PackedStringArray EditorExportPlugin::get_android_dependencies_maven_repos(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  199. PackedStringArray ret;
  200. GDVIRTUAL_CALL(_get_android_dependencies_maven_repos, p_export_platform, p_debug, ret);
  201. return ret;
  202. }
  203. PackedStringArray EditorExportPlugin::get_android_libraries(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  204. PackedStringArray ret;
  205. GDVIRTUAL_CALL(_get_android_libraries, p_export_platform, p_debug, ret);
  206. return ret;
  207. }
  208. String EditorExportPlugin::get_android_manifest_activity_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  209. String ret;
  210. GDVIRTUAL_CALL(_get_android_manifest_activity_element_contents, p_export_platform, p_debug, ret);
  211. return ret;
  212. }
  213. String EditorExportPlugin::get_android_manifest_application_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  214. String ret;
  215. GDVIRTUAL_CALL(_get_android_manifest_application_element_contents, p_export_platform, p_debug, ret);
  216. return ret;
  217. }
  218. String EditorExportPlugin::get_android_manifest_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  219. String ret;
  220. GDVIRTUAL_CALL(_get_android_manifest_element_contents, p_export_platform, p_debug, ret);
  221. return ret;
  222. }
  223. PackedStringArray EditorExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_platform, bool p_debug) const {
  224. PackedStringArray ret;
  225. GDVIRTUAL_CALL(_get_export_features, p_platform, p_debug, ret);
  226. return ret;
  227. }
  228. void EditorExportPlugin::_get_export_options(const Ref<EditorExportPlatform> &p_platform, List<EditorExportPlatform::ExportOption> *r_options) const {
  229. TypedArray<Dictionary> ret;
  230. GDVIRTUAL_CALL(_get_export_options, p_platform, ret);
  231. for (int i = 0; i < ret.size(); i++) {
  232. Dictionary option = ret[i];
  233. ERR_CONTINUE_MSG(!option.has("option"), "Missing required element 'option'");
  234. ERR_CONTINUE_MSG(!option.has("default_value"), "Missing required element 'default_value'");
  235. PropertyInfo property_info = PropertyInfo::from_dict(option["option"]);
  236. Variant default_value = option["default_value"];
  237. bool update_visibility = option.has("update_visibility") && option["update_visibility"];
  238. r_options->push_back(EditorExportPlatform::ExportOption(property_info, default_value, update_visibility));
  239. }
  240. }
  241. bool EditorExportPlugin::_should_update_export_options(const Ref<EditorExportPlatform> &p_platform) const {
  242. bool ret = false;
  243. GDVIRTUAL_CALL(_should_update_export_options, p_platform, ret);
  244. return ret;
  245. }
  246. bool EditorExportPlugin::_get_export_option_visibility(const Ref<EditorExportPlatform> &p_export_platform, const String &p_option_name) const {
  247. bool ret = true;
  248. GDVIRTUAL_CALL(_get_export_option_visibility, p_export_platform, p_option_name, ret);
  249. return ret;
  250. }
  251. String EditorExportPlugin::_get_export_option_warning(const Ref<EditorExportPlatform> &p_export_platform, const String &p_option_name) const {
  252. String ret;
  253. GDVIRTUAL_CALL(_get_export_option_warning, p_export_platform, p_option_name, ret);
  254. return ret;
  255. }
  256. Dictionary EditorExportPlugin::_get_export_options_overrides(const Ref<EditorExportPlatform> &p_platform) const {
  257. Dictionary ret;
  258. GDVIRTUAL_CALL(_get_export_options_overrides, p_platform, ret);
  259. return ret;
  260. }
  261. void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) {
  262. }
  263. void EditorExportPlugin::_export_begin(const HashSet<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
  264. }
  265. void EditorExportPlugin::_export_end() {}
  266. void EditorExportPlugin::skip() {
  267. skipped = true;
  268. }
  269. void EditorExportPlugin::_bind_methods() {
  270. ClassDB::bind_method(D_METHOD("add_shared_object", "path", "tags", "target"), &EditorExportPlugin::add_shared_object);
  271. ClassDB::bind_method(D_METHOD("add_ios_project_static_lib", "path"), &EditorExportPlugin::add_ios_project_static_lib);
  272. ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file);
  273. ClassDB::bind_method(D_METHOD("add_ios_framework", "path"), &EditorExportPlugin::add_ios_framework);
  274. ClassDB::bind_method(D_METHOD("add_ios_embedded_framework", "path"), &EditorExportPlugin::add_ios_embedded_framework);
  275. ClassDB::bind_method(D_METHOD("add_ios_plist_content", "plist_content"), &EditorExportPlugin::add_ios_plist_content);
  276. ClassDB::bind_method(D_METHOD("add_ios_linker_flags", "flags"), &EditorExportPlugin::add_ios_linker_flags);
  277. ClassDB::bind_method(D_METHOD("add_ios_bundle_file", "path"), &EditorExportPlugin::add_ios_bundle_file);
  278. ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_ios_cpp_code);
  279. ClassDB::bind_method(D_METHOD("add_macos_plugin_file", "path"), &EditorExportPlugin::add_macos_plugin_file);
  280. ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip);
  281. ClassDB::bind_method(D_METHOD("get_option", "name"), &EditorExportPlugin::get_option);
  282. ClassDB::bind_method(D_METHOD("get_export_preset"), &EditorExportPlugin::get_export_preset);
  283. ClassDB::bind_method(D_METHOD("get_export_platform"), &EditorExportPlugin::get_export_platform);
  284. GDVIRTUAL_BIND(_export_file, "path", "type", "features");
  285. GDVIRTUAL_BIND(_export_begin, "features", "is_debug", "path", "flags");
  286. GDVIRTUAL_BIND(_export_end);
  287. GDVIRTUAL_BIND(_begin_customize_resources, "platform", "features");
  288. GDVIRTUAL_BIND(_customize_resource, "resource", "path");
  289. GDVIRTUAL_BIND(_begin_customize_scenes, "platform", "features");
  290. GDVIRTUAL_BIND(_customize_scene, "scene", "path");
  291. GDVIRTUAL_BIND(_get_customization_configuration_hash);
  292. GDVIRTUAL_BIND(_end_customize_scenes);
  293. GDVIRTUAL_BIND(_end_customize_resources);
  294. GDVIRTUAL_BIND(_get_export_options, "platform");
  295. GDVIRTUAL_BIND(_get_export_options_overrides, "platform");
  296. GDVIRTUAL_BIND(_should_update_export_options, "platform");
  297. GDVIRTUAL_BIND(_get_export_option_visibility, "platform", "option");
  298. GDVIRTUAL_BIND(_get_export_option_warning, "platform", "option");
  299. GDVIRTUAL_BIND(_get_export_features, "platform", "debug");
  300. GDVIRTUAL_BIND(_get_name);
  301. GDVIRTUAL_BIND(_supports_platform, "platform");
  302. GDVIRTUAL_BIND(_get_android_dependencies, "platform", "debug");
  303. GDVIRTUAL_BIND(_get_android_dependencies_maven_repos, "platform", "debug");
  304. GDVIRTUAL_BIND(_get_android_libraries, "platform", "debug");
  305. GDVIRTUAL_BIND(_get_android_manifest_activity_element_contents, "platform", "debug");
  306. GDVIRTUAL_BIND(_get_android_manifest_application_element_contents, "platform", "debug");
  307. GDVIRTUAL_BIND(_get_android_manifest_element_contents, "platform", "debug");
  308. }