Path: blob/master/editor/export/editor_export_plugin.cpp
9896 views
/**************************************************************************/1/* editor_export_plugin.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "editor_export_plugin.h"3132#include "core/config/project_settings.h"33#include "editor/export/editor_export_platform.h"3435void EditorExportPlugin::set_export_base_path(const String &p_export_base_path) {36export_base_path = p_export_base_path;37}3839const String &EditorExportPlugin::get_export_base_path() const {40return export_base_path;41}4243void EditorExportPlugin::set_export_preset(const Ref<EditorExportPreset> &p_preset) {44if (p_preset.is_valid()) {45export_preset = p_preset;46}47}4849Ref<EditorExportPreset> EditorExportPlugin::get_export_preset() const {50return export_preset;51}5253Ref<EditorExportPlatform> EditorExportPlugin::get_export_platform() const {54if (export_preset.is_valid()) {55return export_preset->get_platform();56} else {57return Ref<EditorExportPlatform>();58}59}6061void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {62ExtraFile ef;63ef.data = p_file;64ef.path = p_path;65ef.remap = p_remap;66extra_files.push_back(ef);67}6869void EditorExportPlugin::add_shared_object(const String &p_path, const Vector<String> &p_tags, const String &p_target) {70shared_objects.push_back(SharedObject(p_path, p_tags, p_target));71}7273void EditorExportPlugin::_add_shared_object(const SharedObject &p_shared_object) {74shared_objects.push_back(p_shared_object);75}7677void EditorExportPlugin::add_apple_embedded_platform_framework(const String &p_path) {78apple_embedded_platform_frameworks.push_back(p_path);79}8081void EditorExportPlugin::add_apple_embedded_platform_embedded_framework(const String &p_path) {82apple_embedded_platform_embedded_frameworks.push_back(p_path);83}8485Vector<String> EditorExportPlugin::get_apple_embedded_platform_frameworks() const {86return apple_embedded_platform_frameworks;87}8889Vector<String> EditorExportPlugin::get_apple_embedded_platform_embedded_frameworks() const {90return apple_embedded_platform_embedded_frameworks;91}9293void EditorExportPlugin::add_apple_embedded_platform_plist_content(const String &p_plist_content) {94apple_embedded_platform_plist_content += p_plist_content + "\n";95}9697String EditorExportPlugin::get_apple_embedded_platform_plist_content() const {98return apple_embedded_platform_plist_content;99}100101void EditorExportPlugin::add_apple_embedded_platform_linker_flags(const String &p_flags) {102if (apple_embedded_platform_linker_flags.length() > 0) {103apple_embedded_platform_linker_flags += ' ';104}105apple_embedded_platform_linker_flags += p_flags;106}107108String EditorExportPlugin::get_apple_embedded_platform_linker_flags() const {109return apple_embedded_platform_linker_flags;110}111112void EditorExportPlugin::add_apple_embedded_platform_bundle_file(const String &p_path) {113apple_embedded_platform_bundle_files.push_back(p_path);114}115116Vector<String> EditorExportPlugin::get_apple_embedded_platform_bundle_files() const {117return apple_embedded_platform_bundle_files;118}119120void EditorExportPlugin::add_apple_embedded_platform_cpp_code(const String &p_code) {121apple_embedded_platform_cpp_code += p_code;122}123124String EditorExportPlugin::get_apple_embedded_platform_cpp_code() const {125return apple_embedded_platform_cpp_code;126}127128void EditorExportPlugin::add_macos_plugin_file(const String &p_path) {129macos_plugin_files.push_back(p_path);130}131132const Vector<String> &EditorExportPlugin::get_macos_plugin_files() const {133return macos_plugin_files;134}135136void EditorExportPlugin::add_apple_embedded_platform_project_static_lib(const String &p_path) {137apple_embedded_platform_project_static_libs.push_back(p_path);138}139140Vector<String> EditorExportPlugin::get_apple_embedded_platform_project_static_libs() const {141return apple_embedded_platform_project_static_libs;142}143144Variant EditorExportPlugin::get_option(const StringName &p_name) const {145ERR_FAIL_COND_V(export_preset.is_null(), Variant());146return export_preset->get(p_name);147}148149String EditorExportPlugin::_has_valid_export_configuration(const Ref<EditorExportPlatform> &p_export_platform, const Ref<EditorExportPreset> &p_preset) {150String warning;151if (!supports_platform(p_export_platform)) {152warning += vformat(TTR("Plugin \"%s\" is not supported on \"%s\""), get_name(), p_export_platform->get_name());153warning += "\n";154return warning;155}156157set_export_preset(p_preset);158List<EditorExportPlatform::ExportOption> options;159_get_export_options(p_export_platform, &options);160for (const EditorExportPlatform::ExportOption &E : options) {161String option_warning = _get_export_option_warning(p_export_platform, E.option.name);162if (!option_warning.is_empty()) {163warning += option_warning + "\n";164}165}166167return warning;168}169170void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const Vector<String> &p_features) {171GDVIRTUAL_CALL(_export_file, p_path, p_type, p_features);172}173174void EditorExportPlugin::_export_begin_script(const Vector<String> &p_features, bool p_debug, const String &p_path, int p_flags) {175GDVIRTUAL_CALL(_export_begin, p_features, p_debug, p_path, p_flags);176}177178void EditorExportPlugin::_export_end_script() {179GDVIRTUAL_CALL(_export_end);180}181182// Customization183184bool EditorExportPlugin::_begin_customize_resources(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {185bool ret = false;186GDVIRTUAL_CALL(_begin_customize_resources, p_platform, p_features, ret);187return ret;188}189190Ref<Resource> EditorExportPlugin::_customize_resource(const Ref<Resource> &p_resource, const String &p_path) {191Ref<Resource> ret;192GDVIRTUAL_CALL(_customize_resource, p_resource, p_path, ret);193return ret;194}195196bool EditorExportPlugin::_begin_customize_scenes(const Ref<EditorExportPlatform> &p_platform, const Vector<String> &p_features) {197bool ret = false;198GDVIRTUAL_CALL(_begin_customize_scenes, p_platform, p_features, ret);199return ret;200}201202Node *EditorExportPlugin::_customize_scene(Node *p_root, const String &p_path) {203Node *ret = nullptr;204GDVIRTUAL_CALL(_customize_scene, p_root, p_path, ret);205return ret;206}207208uint64_t EditorExportPlugin::_get_customization_configuration_hash() const {209uint64_t ret = 0;210GDVIRTUAL_CALL(_get_customization_configuration_hash, ret);211return ret;212}213214void EditorExportPlugin::_end_customize_scenes() {215GDVIRTUAL_CALL(_end_customize_scenes);216}217218void EditorExportPlugin::_end_customize_resources() {219GDVIRTUAL_CALL(_end_customize_resources);220}221222String EditorExportPlugin::get_name() const {223String ret;224GDVIRTUAL_CALL(_get_name, ret);225return ret;226}227228bool EditorExportPlugin::supports_platform(const Ref<EditorExportPlatform> &p_export_platform) const {229bool ret = false;230GDVIRTUAL_CALL(_supports_platform, p_export_platform, ret);231return ret;232}233234PackedStringArray EditorExportPlugin::get_export_features(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {235return _get_export_features(p_export_platform, p_debug);236}237238PackedStringArray EditorExportPlugin::get_android_dependencies(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {239PackedStringArray ret;240GDVIRTUAL_CALL(_get_android_dependencies, p_export_platform, p_debug, ret);241return ret;242}243244PackedStringArray EditorExportPlugin::get_android_dependencies_maven_repos(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {245PackedStringArray ret;246GDVIRTUAL_CALL(_get_android_dependencies_maven_repos, p_export_platform, p_debug, ret);247return ret;248}249250PackedStringArray EditorExportPlugin::get_android_libraries(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {251PackedStringArray ret;252GDVIRTUAL_CALL(_get_android_libraries, p_export_platform, p_debug, ret);253return ret;254}255256String EditorExportPlugin::get_android_manifest_activity_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {257String ret;258GDVIRTUAL_CALL(_get_android_manifest_activity_element_contents, p_export_platform, p_debug, ret);259return ret;260}261262String EditorExportPlugin::get_android_manifest_application_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {263String ret;264GDVIRTUAL_CALL(_get_android_manifest_application_element_contents, p_export_platform, p_debug, ret);265return ret;266}267268String EditorExportPlugin::get_android_manifest_element_contents(const Ref<EditorExportPlatform> &p_export_platform, bool p_debug) const {269String ret;270GDVIRTUAL_CALL(_get_android_manifest_element_contents, p_export_platform, p_debug, ret);271return ret;272}273274PackedByteArray EditorExportPlugin::update_android_prebuilt_manifest(const Ref<EditorExportPlatform> &p_export_platform, const PackedByteArray &p_manifest_data) const {275PackedByteArray ret;276GDVIRTUAL_CALL(_update_android_prebuilt_manifest, p_export_platform, p_manifest_data, ret);277return ret;278}279280PackedStringArray EditorExportPlugin::_get_export_features(const Ref<EditorExportPlatform> &p_platform, bool p_debug) const {281PackedStringArray ret;282GDVIRTUAL_CALL(_get_export_features, p_platform, p_debug, ret);283return ret;284}285286void EditorExportPlugin::_get_export_options(const Ref<EditorExportPlatform> &p_platform, List<EditorExportPlatform::ExportOption> *r_options) const {287TypedArray<Dictionary> ret;288GDVIRTUAL_CALL(_get_export_options, p_platform, ret);289for (int i = 0; i < ret.size(); i++) {290Dictionary option = ret[i];291ERR_CONTINUE_MSG(!option.has("option"), "Missing required element 'option'");292ERR_CONTINUE_MSG(!option.has("default_value"), "Missing required element 'default_value'");293PropertyInfo property_info = PropertyInfo::from_dict(option["option"]);294Variant default_value = option["default_value"];295bool update_visibility = option.has("update_visibility") && option["update_visibility"];296r_options->push_back(EditorExportPlatform::ExportOption(property_info, default_value, update_visibility));297}298}299300bool EditorExportPlugin::_should_update_export_options(const Ref<EditorExportPlatform> &p_platform) const {301bool ret = false;302GDVIRTUAL_CALL(_should_update_export_options, p_platform, ret);303return ret;304}305306bool EditorExportPlugin::_get_export_option_visibility(const Ref<EditorExportPlatform> &p_export_platform, const String &p_option_name) const {307bool ret = true;308GDVIRTUAL_CALL(_get_export_option_visibility, p_export_platform, p_option_name, ret);309return ret;310}311312String EditorExportPlugin::_get_export_option_warning(const Ref<EditorExportPlatform> &p_export_platform, const String &p_option_name) const {313String ret;314GDVIRTUAL_CALL(_get_export_option_warning, p_export_platform, p_option_name, ret);315return ret;316}317318Dictionary EditorExportPlugin::_get_export_options_overrides(const Ref<EditorExportPlatform> &p_platform) const {319Dictionary ret;320GDVIRTUAL_CALL(_get_export_options_overrides, p_platform, ret);321return ret;322}323324void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) {325}326327void EditorExportPlugin::_export_begin(const HashSet<String> &p_features, bool p_debug, const String &p_path, int p_flags) {328}329330void EditorExportPlugin::_export_end() {}331332void EditorExportPlugin::skip() {333skipped = true;334}335336void EditorExportPlugin::_bind_methods() {337ClassDB::bind_method(D_METHOD("add_shared_object", "path", "tags", "target"), &EditorExportPlugin::add_shared_object);338ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file);339340ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_project_static_lib", "path"), &EditorExportPlugin::add_apple_embedded_platform_project_static_lib);341ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_framework);342ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_embedded_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_embedded_framework);343ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_plist_content", "plist_content"), &EditorExportPlugin::add_apple_embedded_platform_plist_content);344ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_linker_flags", "flags"), &EditorExportPlugin::add_apple_embedded_platform_linker_flags);345ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_bundle_file", "path"), &EditorExportPlugin::add_apple_embedded_platform_bundle_file);346ClassDB::bind_method(D_METHOD("add_apple_embedded_platform_cpp_code", "code"), &EditorExportPlugin::add_apple_embedded_platform_cpp_code);347348#ifndef DISABLE_DEPRECATED349ClassDB::bind_method(D_METHOD("add_ios_project_static_lib", "path"), &EditorExportPlugin::add_apple_embedded_platform_project_static_lib);350ClassDB::bind_method(D_METHOD("add_ios_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_framework);351ClassDB::bind_method(D_METHOD("add_ios_embedded_framework", "path"), &EditorExportPlugin::add_apple_embedded_platform_embedded_framework);352ClassDB::bind_method(D_METHOD("add_ios_plist_content", "plist_content"), &EditorExportPlugin::add_apple_embedded_platform_plist_content);353ClassDB::bind_method(D_METHOD("add_ios_linker_flags", "flags"), &EditorExportPlugin::add_apple_embedded_platform_linker_flags);354ClassDB::bind_method(D_METHOD("add_ios_bundle_file", "path"), &EditorExportPlugin::add_apple_embedded_platform_bundle_file);355ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_apple_embedded_platform_cpp_code);356#endif357358ClassDB::bind_method(D_METHOD("add_macos_plugin_file", "path"), &EditorExportPlugin::add_macos_plugin_file);359ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip);360ClassDB::bind_method(D_METHOD("get_option", "name"), &EditorExportPlugin::get_option);361362ClassDB::bind_method(D_METHOD("get_export_preset"), &EditorExportPlugin::get_export_preset);363ClassDB::bind_method(D_METHOD("get_export_platform"), &EditorExportPlugin::get_export_platform);364365GDVIRTUAL_BIND(_export_file, "path", "type", "features");366GDVIRTUAL_BIND(_export_begin, "features", "is_debug", "path", "flags");367GDVIRTUAL_BIND(_export_end);368369GDVIRTUAL_BIND(_begin_customize_resources, "platform", "features");370GDVIRTUAL_BIND(_customize_resource, "resource", "path");371372GDVIRTUAL_BIND(_begin_customize_scenes, "platform", "features");373GDVIRTUAL_BIND(_customize_scene, "scene", "path");374375GDVIRTUAL_BIND(_get_customization_configuration_hash);376377GDVIRTUAL_BIND(_end_customize_scenes);378GDVIRTUAL_BIND(_end_customize_resources);379380GDVIRTUAL_BIND(_get_export_options, "platform");381GDVIRTUAL_BIND(_get_export_options_overrides, "platform");382GDVIRTUAL_BIND(_should_update_export_options, "platform");383GDVIRTUAL_BIND(_get_export_option_visibility, "platform", "option");384GDVIRTUAL_BIND(_get_export_option_warning, "platform", "option");385386GDVIRTUAL_BIND(_get_export_features, "platform", "debug");387GDVIRTUAL_BIND(_get_name);388389GDVIRTUAL_BIND(_supports_platform, "platform");390391GDVIRTUAL_BIND(_get_android_dependencies, "platform", "debug");392GDVIRTUAL_BIND(_get_android_dependencies_maven_repos, "platform", "debug");393GDVIRTUAL_BIND(_get_android_libraries, "platform", "debug");394GDVIRTUAL_BIND(_get_android_manifest_activity_element_contents, "platform", "debug");395GDVIRTUAL_BIND(_get_android_manifest_application_element_contents, "platform", "debug");396GDVIRTUAL_BIND(_get_android_manifest_element_contents, "platform", "debug");397GDVIRTUAL_BIND(_update_android_prebuilt_manifest, "platform", "manifest_data");398}399400401