editor_export_plugin.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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 "editor/export/editor_export_platform.h"
  33. void EditorExportPlugin::set_export_base_path(const String &p_export_base_path) {
  34. export_base_path = p_export_base_path;
  35. }
  36. const String &EditorExportPlugin::get_export_base_path() const {
  37. return export_base_path;
  38. }
  39. void EditorExportPlugin::set_export_preset(const Ref<EditorExportPreset> &p_preset) {
  40. if (p_preset.is_valid()) {
  41. export_preset = p_preset;
  42. }
  43. }
  44. Ref<EditorExportPreset> EditorExportPlugin::get_export_preset() const {
  45. return export_preset;
  46. }
  47. Ref<EditorExportPlatform> EditorExportPlugin::get_export_platform() const {
  48. if (export_preset.is_valid()) {
  49. return export_preset->get_platform();
  50. } else {
  51. return Ref<EditorExportPlatform>();
  52. }
  53. }
  54. void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {
  55. ExtraFile ef;
  56. ef.data = p_file;
  57. ef.path = p_path;
  58. ef.remap = p_remap;
  59. extra_files.push_back(ef);
  60. }
  61. void EditorExportPlugin::add_shared_object(const String &p_path, const Vector<String> &p_tags, const String &p_target) {
  62. shared_objects.push_back(SharedObject(p_path, p_tags, p_target));
  63. }
  64. void EditorExportPlugin::_add_shared_object(const SharedObject &p_shared_object) {
  65. shared_objects.push_back(p_shared_object);
  66. }
  67. void EditorExportPlugin::add_apple_embedded_platform_framework(const String &p_path) {
  68. apple_embedded_platform_frameworks.push_back(p_path);
  69. }
  70. void EditorExportPlugin::add_apple_embedded_platform_embedded_framework(const String &p_path) {
  71. apple_embedded_platform_embedded_frameworks.push_back(p_path);
  72. }
  73. Vector<String> EditorExportPlugin::get_apple_embedded_platform_frameworks() const {
  74. return apple_embedded_platform_frameworks;
  75. }
  76. Vector<String> EditorExportPlugin::get_apple_embedded_platform_embedded_frameworks() const {
  77. return apple_embedded_platform_embedded_frameworks;
  78. }
  79. void EditorExportPlugin::add_apple_embedded_platform_plist_content(const String &p_plist_content) {
  80. apple_embedded_platform_plist_content += p_plist_content + "\n";
  81. }
  82. String EditorExportPlugin::get_apple_embedded_platform_plist_content() const {
  83. return apple_embedded_platform_plist_content;
  84. }
  85. void EditorExportPlugin::add_apple_embedded_platform_linker_flags(const String &p_flags) {
  86. if (apple_embedded_platform_linker_flags.length() > 0) {
  87. apple_embedded_platform_linker_flags += ' ';
  88. }
  89. apple_embedded_platform_linker_flags += p_flags;
  90. }
  91. String EditorExportPlugin::get_apple_embedded_platform_linker_flags() const {
  92. return apple_embedded_platform_linker_flags;
  93. }
  94. void EditorExportPlugin::add_apple_embedded_platform_bundle_file(const String &p_path) {
  95. apple_embedded_platform_bundle_files.push_back(p_path);
  96. }
  97. Vector<String> EditorExportPlugin::get_apple_embedded_platform_bundle_files() const {
  98. return apple_embedded_platform_bundle_files;
  99. }
  100. void EditorExportPlugin::add_apple_embedded_platform_cpp_code(const String &p_code) {
  101. apple_embedded_platform_cpp_code += p_code;
  102. }
  103. String EditorExportPlugin::get_apple_embedded_platform_cpp_code() const {
  104. return apple_embedded_platform_cpp_code;
  105. }
  106. void EditorExportPlugin::add_macos_plugin_file(const String &p_path) {
  107. macos_plugin_files.push_back(p_path);
  108. }
  109. const Vector<String> &EditorExportPlugin::get_macos_plugin_files() const {
  110. return macos_plugin_files;
  111. }
  112. void EditorExportPlugin::add_apple_embedded_platform_project_static_lib(const String &p_path) {
  113. apple_embedded_platform_project_static_libs.push_back(p_path);
  114. }
  115. Vector<String> EditorExportPlugin::get_apple_embedded_platform_project_static_libs() const {
  116. return apple_embedded_platform_project_static_libs;
  117. }
  118. Variant EditorExportPlugin::get_option(const StringName &p_name) const {
  119. ERR_FAIL_COND_V(export_preset.is_null(), Variant());
  120. return export_preset->get(p_name);
  121. }
  122. String EditorExportPlugin::_has_valid_export_configuration(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset) {
  123. String warning;
  124. if (!supports_platform(p_export_platform)) {
  125. warning += vformat(TTR("Plugin \"%s\" is not supported on \"%s\""), get_name(), p_export_platform->get_name());
  126. warning += "\n";
  127. return warning;
  128. }
  129. set_export_preset(p_preset);
  130. List<EditorExportPlatform::ExportOption> options;
  131. _get_export_options(p_export_platform, &options);
  132. for (const EditorExportPlatform::ExportOption &E : options) {
  133. String option_warning = _get_export_option_warning(p_export_platform, E.option.name);
  134. if (!option_warning.is_empty()) {
  135. warning += option_warning + "\n";
  136. }
  137. }
  138. return warning;
  139. }
  140. void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const Vector<String> &p_features) {
  141. GDVIRTUAL_CALL(_export_file, p_path, p_type, p_features);
  142. }
  143. void EditorExportPlugin::_export_begin_script(const Vector<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
  144. GDVIRTUAL_CALL(_export_begin, p_features, p_debug, p_path, p_flags);
  145. }
  146. void EditorExportPlugin::_export_end_script() {
  147. GDVIRTUAL_CALL(_export_end);
  148. }
  149. // Customization
  150. bool EditorExportPlugin::_begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
  151. bool ret = false;
  152. GDVIRTUAL_CALL(_begin_customize_resources, p_platform, p_features, ret);
  153. return ret;
  154. }
  155. Ref<Resource> EditorExportPlugin::_customize_resource(const Ref<Resource> &p_resource, const String &p_path) {
  156. Ref<Resource> ret;
  157. GDVIRTUAL_CALL(_customize_resource, p_resource, p_path, ret);
  158. return ret;
  159. }
  160. bool EditorExportPlugin::_begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {
  161. bool ret = false;
  162. GDVIRTUAL_CALL(_begin_customize_scenes, p_platform, p_features, ret);
  163. return ret;
  164. }
  165. Node *EditorExportPlugin::_customize_scene(Node *p_root, const String &p_path) {
  166. Node *ret = nullptr;
  167. GDVIRTUAL_CALL(_customize_scene, p_root, p_path, ret);
  168. return ret;
  169. }
  170. uint64_t EditorExportPlugin::_get_customization_configuration_hash() const {
  171. uint64_t ret = 0;
  172. GDVIRTUAL_CALL(_get_customization_configuration_hash, ret);
  173. return ret;
  174. }
  175. void EditorExportPlugin::_end_customize_scenes() {
  176. GDVIRTUAL_CALL(_end_customize_scenes);
  177. }
  178. void EditorExportPlugin::_end_customize_resources() {
  179. GDVIRTUAL_CALL(_end_customize_resources);
  180. }
  181. String EditorExportPlugin::get_name() const {
  182. String ret;
  183. GDVIRTUAL_CALL(_get_name, ret);
  184. return ret;
  185. }
  186. bool EditorExportPlugin::supports_platform(const Ref<EditorExportPlatform> &p_export_platform) const {
  187. bool ret = false;
  188. GDVIRTUAL_CALL(_supports_platform, p_export_platform, ret);
  189. return ret;
  190. }
  191. PackedStringArray EditorExportPlugin::get_export_features(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  192. return _get_export_features(p_export_platform, p_debug);
  193. }
  194. PackedStringArray EditorExportPlugin::get_android_dependencies(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  195. PackedStringArray ret;
  196. GDVIRTUAL_CALL(_get_android_dependencies, p_export_platform, p_debug, ret);
  197. return ret;
  198. }
  199. PackedStringArray EditorExportPlugin::get_android_dependencies_maven_repos(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  200. PackedStringArray ret;
  201. GDVIRTUAL_CALL(_get_android_dependencies_maven_repos, p_export_platform, p_debug, ret);
  202. return ret;
  203. }
  204. PackedStringArray EditorExportPlugin::get_android_libraries(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  205. PackedStringArray ret;
  206. GDVIRTUAL_CALL(_get_android_libraries, p_export_platform, p_debug, ret);
  207. return ret;
  208. }
  209. String EditorExportPlugin::get_android_manifest_activity_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  210. String ret;
  211. GDVIRTUAL_CALL(_get_android_manifest_activity_element_contents, p_export_platform, p_debug, ret);
  212. return ret;
  213. }
  214. String EditorExportPlugin::get_android_manifest_application_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  215. String ret;
  216. GDVIRTUAL_CALL(_get_android_manifest_application_element_contents, p_export_platform, p_debug, ret);
  217. return ret;
  218. }
  219. String EditorExportPlugin::get_android_manifest_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {
  220. String ret;
  221. GDVIRTUAL_CALL(_get_android_manifest_element_contents, p_export_platform, p_debug, ret);
  222. return ret;
  223. }
  224. PackedByteArray EditorExportPlugin::update_android_prebuilt_manifest(const Ref<EditorExportPlatform> &p_export_platform, const PackedByteArray &p_manifest_data) const {
  225. PackedByteArray ret;
  226. GDVIRTUAL_CALL(_update_android_prebuilt_manifest, p_export_platform, p_manifest_data, ret);
  227. return ret;
  228. }
  229. PackedStringArray EditorExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_platform, bool p_debug) const {
  230. PackedStringArray ret;
  231. GDVIRTUAL_CALL(_get_export_features, p_platform, p_debug, ret);
  232. return ret;
  233. }
  234. void EditorExportPlugin::_get_export_options(const Ref<EditorExportPlatform> &p_platform, List<EditorExportPlatform::ExportOption> *r_options) const {
  235. TypedArray<Dictionary> ret;
  236. GDVIRTUAL_CALL(_get_export_options, p_platform, ret);
  237. for (int i = 0; i < ret.size(); i++) {
  238. Dictionary option = ret[i];
  239. ERR_CONTINUE_MSG(!option.has("option"), "Missing required element 'option'");
  240. ERR_CONTINUE_MSG(!option.has("default_value"), "Missing required element 'default_value'");
  241. PropertyInfo property_info = PropertyInfo::from_dict(option["option"]);
  242. Variant default_value = option["default_value"];
  243. bool update_visibility = option.has("update_visibility") && option["update_visibility"];
  244. r_options->push_back(EditorExportPlatform::ExportOption(property_info, default_value, update_visibility));
  245. }
  246. }
  247. bool EditorExportPlugin::_should_update_export_options(const Ref<EditorExportPlatform> &p_platform) const {
  248. bool ret = false;
  249. GDVIRTUAL_CALL(_should_update_export_options, p_platform, ret);
  250. return ret;
  251. }
  252. bool EditorExportPlugin::_get_export_option_visibility(const Ref<EditorExportPlatform> &p_export_platform, const String &p_option_name) const {
  253. bool ret = true;
  254. GDVIRTUAL_CALL(_get_export_option_visibility, p_export_platform, p_option_name, ret);
  255. return ret;
  256. }
  257. String EditorExportPlugin::_get_export_option_warning(const Ref<EditorExportPlatform> &p_export_platform, const String &p_option_name) const {
  258. String ret;
  259. GDVIRTUAL_CALL(_get_export_option_warning, p_export_platform, p_option_name, ret);
  260. return ret;
  261. }
  262. Dictionary EditorExportPlugin::_get_export_options_overrides(const Ref<EditorExportPlatform> &p_platform) const {
  263. Dictionary ret;
  264. GDVIRTUAL_CALL(_get_export_options_overrides, p_platform, ret);
  265. return ret;
  266. }
  267. void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) {
  268. }
  269. void EditorExportPlugin::_export_begin(const HashSet<String> &p_features, bool p_debug, const String &p_path, int p_flags) {
  270. }
  271. void EditorExportPlugin::_export_end() {}
  272. void EditorExportPlugin::skip() {
  273. skipped = true;
  274. }
  275. void EditorExportPlugin::_bind_methods() {
  276. ClassDB::bind_method(D_METHOD("add_shared_object", "path", "tags", "target"), &EditorExportPlugin::add_shared_object);
  277. ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file);
  278. ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_project_static_lib", "path"), &EditorExportPlugin::add_apple_embedded_platform_project_static_lib);
  279. ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_framework);
  280. ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_embedded_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_embedded_framework);
  281. ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_plist_content", "plist_content"), &EditorExportPlugin::add_apple_embedded_platform_plist_content);
  282. ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_linker_flags", "flags"), &EditorExportPlugin::add_apple_embedded_platform_linker_flags);
  283. ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_bundle_file", "path"), &EditorExportPlugin::add_apple_embedded_platform_bundle_file);
  284. ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_cpp_code", "code"), &EditorExportPlugin::add_apple_embedded_platform_cpp_code);
  285. #ifndef DISABLE_DEPRECATED
  286. ClassDB::bind_method(D_METHOD("add_ios_project_static_lib", "path"), &EditorExportPlugin::add_apple_embedded_platform_project_static_lib);
  287. ClassDB::bind_method(D_METHOD("add_ios_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_framework);
  288. ClassDB::bind_method(D_METHOD("add_ios_embedded_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_embedded_framework);
  289. ClassDB::bind_method(D_METHOD("add_ios_plist_content", "plist_content"), &EditorExportPlugin::add_apple_embedded_platform_plist_content);
  290. ClassDB::bind_method(D_METHOD("add_ios_linker_flags", "flags"), &EditorExportPlugin::add_apple_embedded_platform_linker_flags);
  291. ClassDB::bind_method(D_METHOD("add_ios_bundle_file", "path"), &EditorExportPlugin::add_apple_embedded_platform_bundle_file);
  292. ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_apple_embedded_platform_cpp_code);
  293. #endif
  294. ClassDB::bind_method(D_METHOD("add_macos_plugin_file", "path"), &EditorExportPlugin::add_macos_plugin_file);
  295. ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip);
  296. ClassDB::bind_method(D_METHOD("get_option", "name"), &EditorExportPlugin::get_option);
  297. ClassDB::bind_method(D_METHOD("get_export_preset"), &EditorExportPlugin::get_export_preset);
  298. ClassDB::bind_method(D_METHOD("get_export_platform"), &EditorExportPlugin::get_export_platform);
  299. GDVIRTUAL_BIND(_export_file, "path", "type", "features");
  300. GDVIRTUAL_BIND(_export_begin, "features", "is_debug", "path", "flags");
  301. GDVIRTUAL_BIND(_export_end);
  302. GDVIRTUAL_BIND(_begin_customize_resources, "platform", "features");
  303. GDVIRTUAL_BIND(_customize_resource, "resource", "path");
  304. GDVIRTUAL_BIND(_begin_customize_scenes, "platform", "features");
  305. GDVIRTUAL_BIND(_customize_scene, "scene", "path");
  306. GDVIRTUAL_BIND(_get_customization_configuration_hash);
  307. GDVIRTUAL_BIND(_end_customize_scenes);
  308. GDVIRTUAL_BIND(_end_customize_resources);
  309. GDVIRTUAL_BIND(_get_export_options, "platform");
  310. GDVIRTUAL_BIND(_get_export_options_overrides, "platform");
  311. GDVIRTUAL_BIND(_should_update_export_options, "platform");
  312. GDVIRTUAL_BIND(_get_export_option_visibility, "platform", "option");
  313. GDVIRTUAL_BIND(_get_export_option_warning, "platform", "option");
  314. GDVIRTUAL_BIND(_get_export_features, "platform", "debug");
  315. GDVIRTUAL_BIND(_get_name);
  316. GDVIRTUAL_BIND(_supports_platform, "platform");
  317. GDVIRTUAL_BIND(_get_android_dependencies, "platform", "debug");
  318. GDVIRTUAL_BIND(_get_android_dependencies_maven_repos, "platform", "debug");
  319. GDVIRTUAL_BIND(_get_android_libraries, "platform", "debug");
  320. GDVIRTUAL_BIND(_get_android_manifest_activity_element_contents, "platform", "debug");
  321. GDVIRTUAL_BIND(_get_android_manifest_application_element_contents, "platform", "debug");
  322. GDVIRTUAL_BIND(_get_android_manifest_element_contents, "platform", "debug");
  323. GDVIRTUAL_BIND(_update_android_prebuilt_manifest, "platform", "manifest_data");
  324. }