[Plugins] Rename 'PluginConfig' struct to platform specific name

This commit is contained in:
Sergey Minakov 2021-01-14 15:05:42 +03:00
parent cb15abda29
commit 64923945b3
4 changed files with 149 additions and 114 deletions

View file

@ -264,7 +264,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
EditorProgress *ep; EditorProgress *ep;
}; };
Vector<PluginConfig> plugins; Vector<PluginConfigAndroid> plugins;
String last_plugin_names; String last_plugin_names;
uint64_t last_custom_build_time = 0; uint64_t last_custom_build_time = 0;
volatile bool plugins_changed; volatile bool plugins_changed;
@ -283,7 +283,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
{ {
// Nothing to do if we already know the plugins have changed. // Nothing to do if we already know the plugins have changed.
if (!ea->plugins_changed) { if (!ea->plugins_changed) {
Vector<PluginConfig> loaded_plugins = get_plugins(); Vector<PluginConfigAndroid> loaded_plugins = get_plugins();
ea->plugins_lock->lock(); ea->plugins_lock->lock();
@ -640,7 +640,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
continue; continue;
} }
if (file.ends_with(PLUGIN_CONFIG_EXT)) { if (file.ends_with(PluginConfigAndroid::PLUGIN_CONFIG_EXT)) {
dir_files.push_back(file); dir_files.push_back(file);
} }
} }
@ -650,8 +650,8 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
return dir_files; return dir_files;
} }
static Vector<PluginConfig> get_plugins() { static Vector<PluginConfigAndroid> get_plugins() {
Vector<PluginConfig> loaded_plugins; Vector<PluginConfigAndroid> loaded_plugins;
String plugins_dir = ProjectSettings::get_singleton()->get_resource_path().plus_file("android/plugins"); String plugins_dir = ProjectSettings::get_singleton()->get_resource_path().plus_file("android/plugins");
@ -664,7 +664,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
if (!plugins_filenames.empty()) { if (!plugins_filenames.empty()) {
Ref<ConfigFile> config_file = memnew(ConfigFile); Ref<ConfigFile> config_file = memnew(ConfigFile);
for (int i = 0; i < plugins_filenames.size(); i++) { for (int i = 0; i < plugins_filenames.size(); i++) {
PluginConfig config = load_plugin_config(config_file, plugins_dir.plus_file(plugins_filenames[i])); PluginConfigAndroid config = load_plugin_config(config_file, plugins_dir.plus_file(plugins_filenames[i]));
if (config.valid_config) { if (config.valid_config) {
loaded_plugins.push_back(config); loaded_plugins.push_back(config);
} else { } else {
@ -677,11 +677,11 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
return loaded_plugins; return loaded_plugins;
} }
static Vector<PluginConfig> get_enabled_plugins(const Ref<EditorExportPreset> &p_presets) { static Vector<PluginConfigAndroid> get_enabled_plugins(const Ref<EditorExportPreset> &p_presets) {
Vector<PluginConfig> enabled_plugins; Vector<PluginConfigAndroid> enabled_plugins;
Vector<PluginConfig> all_plugins = get_plugins(); Vector<PluginConfigAndroid> all_plugins = get_plugins();
for (int i = 0; i < all_plugins.size(); i++) { for (int i = 0; i < all_plugins.size(); i++) {
PluginConfig plugin = all_plugins[i]; PluginConfigAndroid plugin = all_plugins[i];
bool enabled = p_presets->get("plugins/" + plugin.name); bool enabled = p_presets->get("plugins/" + plugin.name);
if (enabled) { if (enabled) {
enabled_plugins.push_back(plugin); enabled_plugins.push_back(plugin);
@ -1655,7 +1655,7 @@ public:
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "custom_template/use_custom_build"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "custom_template/use_custom_build"), false));
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "custom_template/export_format", PROPERTY_HINT_ENUM, "Export APK,Export AAB"), EXPORT_FORMAT_APK)); r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "custom_template/export_format", PROPERTY_HINT_ENUM, "Export APK,Export AAB"), EXPORT_FORMAT_APK));
Vector<PluginConfig> plugins_configs = get_plugins(); Vector<PluginConfigAndroid> plugins_configs = get_plugins();
for (int i = 0; i < plugins_configs.size(); i++) { for (int i = 0; i < plugins_configs.size(); i++) {
print_verbose("Found Android plugin " + plugins_configs[i].name); print_verbose("Found Android plugin " + plugins_configs[i].name);
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "plugins/" + plugins_configs[i].name), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "plugins/" + plugins_configs[i].name), false));
@ -2487,7 +2487,7 @@ public:
} }
} }
inline bool is_clean_build_required(Vector<PluginConfig> enabled_plugins) { inline bool is_clean_build_required(Vector<PluginConfigAndroid> enabled_plugins) {
String plugin_names = get_plugins_names(enabled_plugins); String plugin_names = get_plugins_names(enabled_plugins);
bool first_build = last_custom_build_time == 0; bool first_build = last_custom_build_time == 0;
bool have_plugins_changed = false; bool have_plugins_changed = false;
@ -2797,9 +2797,9 @@ public:
String sign_flag = should_sign ? "true" : "false"; String sign_flag = should_sign ? "true" : "false";
String zipalign_flag = "true"; String zipalign_flag = "true";
Vector<PluginConfig> enabled_plugins = get_enabled_plugins(p_preset); Vector<PluginConfigAndroid> enabled_plugins = get_enabled_plugins(p_preset);
String local_plugins_binaries = get_plugins_binaries(BINARY_TYPE_LOCAL, enabled_plugins); String local_plugins_binaries = get_plugins_binaries(PluginConfigAndroid::BINARY_TYPE_LOCAL, enabled_plugins);
String remote_plugins_binaries = get_plugins_binaries(BINARY_TYPE_REMOTE, enabled_plugins); String remote_plugins_binaries = get_plugins_binaries(PluginConfigAndroid::BINARY_TYPE_REMOTE, enabled_plugins);
String custom_maven_repos = get_plugins_custom_maven_repos(enabled_plugins); String custom_maven_repos = get_plugins_custom_maven_repos(enabled_plugins);
bool clean_build_required = is_clean_build_required(enabled_plugins); bool clean_build_required = is_clean_build_required(enabled_plugins);

View file

@ -35,23 +35,6 @@
#include "core/io/config_file.h" #include "core/io/config_file.h"
#include "core/ustring.h" #include "core/ustring.h"
static const char *PLUGIN_CONFIG_EXT = ".gdap";
static const char *CONFIG_SECTION = "config";
static const char *CONFIG_NAME_KEY = "name";
static const char *CONFIG_BINARY_TYPE_KEY = "binary_type";
static const char *CONFIG_BINARY_KEY = "binary";
static const char *DEPENDENCIES_SECTION = "dependencies";
static const char *DEPENDENCIES_LOCAL_KEY = "local";
static const char *DEPENDENCIES_REMOTE_KEY = "remote";
static const char *DEPENDENCIES_CUSTOM_MAVEN_REPOS_KEY = "custom_maven_repos";
static const char *BINARY_TYPE_LOCAL = "local";
static const char *BINARY_TYPE_REMOTE = "remote";
static const char *PLUGIN_VALUE_SEPARATOR = "|";
/* /*
The `config` section and fields are required and defined as follow: The `config` section and fields are required and defined as follow:
- **name**: name of the plugin - **name**: name of the plugin
@ -67,7 +50,25 @@ The `dependencies` section and fields are optional and defined as follow:
See https://github.com/godotengine/godot/issues/38157#issuecomment-618773871 See https://github.com/godotengine/godot/issues/38157#issuecomment-618773871
*/ */
struct PluginConfig { struct PluginConfigAndroid {
static const char *PLUGIN_CONFIG_EXT;
static const char *CONFIG_SECTION;
static const char *CONFIG_NAME_KEY;
static const char *CONFIG_BINARY_TYPE_KEY;
static const char *CONFIG_BINARY_KEY;
static const char *DEPENDENCIES_SECTION;
static const char *DEPENDENCIES_LOCAL_KEY;
static const char *DEPENDENCIES_REMOTE_KEY;
static const char *DEPENDENCIES_CUSTOM_MAVEN_REPOS_KEY;
static const char *BINARY_TYPE_LOCAL;
static const char *BINARY_TYPE_REMOTE;
static const char *PLUGIN_VALUE_SEPARATOR;
// Set to true when the config file is properly loaded. // Set to true when the config file is properly loaded.
bool valid_config = false; bool valid_config = false;
// Unix timestamp of last change to this plugin. // Unix timestamp of last change to this plugin.
@ -84,11 +85,28 @@ struct PluginConfig {
Vector<String> custom_maven_repos; Vector<String> custom_maven_repos;
}; };
const char *PluginConfigAndroid::PLUGIN_CONFIG_EXT = ".gdap";
const char *PluginConfigAndroid::CONFIG_SECTION = "config";
const char *PluginConfigAndroid::CONFIG_NAME_KEY = "name";
const char *PluginConfigAndroid::CONFIG_BINARY_TYPE_KEY = "binary_type";
const char *PluginConfigAndroid::CONFIG_BINARY_KEY = "binary";
const char *PluginConfigAndroid::DEPENDENCIES_SECTION = "dependencies";
const char *PluginConfigAndroid::DEPENDENCIES_LOCAL_KEY = "local";
const char *PluginConfigAndroid::DEPENDENCIES_REMOTE_KEY = "remote";
const char *PluginConfigAndroid::DEPENDENCIES_CUSTOM_MAVEN_REPOS_KEY = "custom_maven_repos";
const char *PluginConfigAndroid::BINARY_TYPE_LOCAL = "local";
const char *PluginConfigAndroid::BINARY_TYPE_REMOTE = "remote";
const char *PluginConfigAndroid::PLUGIN_VALUE_SEPARATOR = "|";
/* /*
* Set of prebuilt plugins. * Set of prebuilt plugins.
* Currently unused, this is just for future reference: * Currently unused, this is just for future reference:
*/ */
// static const PluginConfig MY_PREBUILT_PLUGIN = { // static const PluginConfigAndroid MY_PREBUILT_PLUGIN = {
// /*.valid_config =*/true, // /*.valid_config =*/true,
// /*.last_updated =*/0, // /*.last_updated =*/0,
// /*.name =*/"GodotPayment", // /*.name =*/"GodotPayment",
@ -112,9 +130,9 @@ static inline String resolve_local_dependency_path(String plugin_config_dir, Str
return absolute_path; return absolute_path;
} }
static inline PluginConfig resolve_prebuilt_plugin(PluginConfig prebuilt_plugin, String plugin_config_dir) { static inline PluginConfigAndroid resolve_prebuilt_plugin(PluginConfigAndroid prebuilt_plugin, String plugin_config_dir) {
PluginConfig resolved = prebuilt_plugin; PluginConfigAndroid resolved = prebuilt_plugin;
resolved.binary = resolved.binary_type == BINARY_TYPE_LOCAL ? resolve_local_dependency_path(plugin_config_dir, prebuilt_plugin.binary) : prebuilt_plugin.binary; resolved.binary = resolved.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ? resolve_local_dependency_path(plugin_config_dir, prebuilt_plugin.binary) : prebuilt_plugin.binary;
if (!prebuilt_plugin.local_dependencies.empty()) { if (!prebuilt_plugin.local_dependencies.empty()) {
resolved.local_dependencies.clear(); resolved.local_dependencies.clear();
for (int i = 0; i < prebuilt_plugin.local_dependencies.size(); i++) { for (int i = 0; i < prebuilt_plugin.local_dependencies.size(); i++) {
@ -124,21 +142,21 @@ static inline PluginConfig resolve_prebuilt_plugin(PluginConfig prebuilt_plugin,
return resolved; return resolved;
} }
static inline Vector<PluginConfig> get_prebuilt_plugins(String plugins_base_dir) { static inline Vector<PluginConfigAndroid> get_prebuilt_plugins(String plugins_base_dir) {
Vector<PluginConfig> prebuilt_plugins; Vector<PluginConfigAndroid> prebuilt_plugins;
// prebuilt_plugins.push_back(resolve_prebuilt_plugin(MY_PREBUILT_PLUGIN, plugins_base_dir)); // prebuilt_plugins.push_back(resolve_prebuilt_plugin(MY_PREBUILT_PLUGIN, plugins_base_dir));
return prebuilt_plugins; return prebuilt_plugins;
} }
static inline bool is_plugin_config_valid(PluginConfig plugin_config) { static inline bool is_plugin_config_valid(PluginConfigAndroid plugin_config) {
bool valid_name = !plugin_config.name.empty(); bool valid_name = !plugin_config.name.empty();
bool valid_binary_type = plugin_config.binary_type == BINARY_TYPE_LOCAL || bool valid_binary_type = plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ||
plugin_config.binary_type == BINARY_TYPE_REMOTE; plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE;
bool valid_binary = false; bool valid_binary = false;
if (valid_binary_type) { if (valid_binary_type) {
valid_binary = !plugin_config.binary.empty() && valid_binary = !plugin_config.binary.empty() &&
(plugin_config.binary_type == BINARY_TYPE_REMOTE || (plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE ||
FileAccess::exists(plugin_config.binary)); FileAccess::exists(plugin_config.binary));
} }
@ -154,7 +172,7 @@ static inline bool is_plugin_config_valid(PluginConfig plugin_config) {
return valid_name && valid_binary && valid_binary_type && valid_local_dependencies; return valid_name && valid_binary && valid_binary_type && valid_local_dependencies;
} }
static inline uint64_t get_plugin_modification_time(const PluginConfig &plugin_config, const String &config_path) { static inline uint64_t get_plugin_modification_time(const PluginConfigAndroid &plugin_config, const String &config_path) {
uint64_t last_updated = FileAccess::get_modified_time(config_path); uint64_t last_updated = FileAccess::get_modified_time(config_path);
last_updated = MAX(last_updated, FileAccess::get_modified_time(plugin_config.binary)); last_updated = MAX(last_updated, FileAccess::get_modified_time(plugin_config.binary));
@ -166,30 +184,30 @@ static inline uint64_t get_plugin_modification_time(const PluginConfig &plugin_c
return last_updated; return last_updated;
} }
static inline PluginConfig load_plugin_config(Ref<ConfigFile> config_file, const String &path) { static inline PluginConfigAndroid load_plugin_config(Ref<ConfigFile> config_file, const String &path) {
PluginConfig plugin_config = {}; PluginConfigAndroid plugin_config = {};
if (config_file.is_valid()) { if (config_file.is_valid()) {
Error err = config_file->load(path); Error err = config_file->load(path);
if (err == OK) { if (err == OK) {
String config_base_dir = path.get_base_dir(); String config_base_dir = path.get_base_dir();
plugin_config.name = config_file->get_value(CONFIG_SECTION, CONFIG_NAME_KEY, String()); plugin_config.name = config_file->get_value(PluginConfigAndroid::CONFIG_SECTION, PluginConfigAndroid::CONFIG_NAME_KEY, String());
plugin_config.binary_type = config_file->get_value(CONFIG_SECTION, CONFIG_BINARY_TYPE_KEY, String()); plugin_config.binary_type = config_file->get_value(PluginConfigAndroid::CONFIG_SECTION, PluginConfigAndroid::CONFIG_BINARY_TYPE_KEY, String());
String binary_path = config_file->get_value(CONFIG_SECTION, CONFIG_BINARY_KEY, String()); String binary_path = config_file->get_value(PluginConfigAndroid::CONFIG_SECTION, PluginConfigAndroid::CONFIG_BINARY_KEY, String());
plugin_config.binary = plugin_config.binary_type == BINARY_TYPE_LOCAL ? resolve_local_dependency_path(config_base_dir, binary_path) : binary_path; plugin_config.binary = plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ? resolve_local_dependency_path(config_base_dir, binary_path) : binary_path;
if (config_file->has_section(DEPENDENCIES_SECTION)) { if (config_file->has_section(PluginConfigAndroid::DEPENDENCIES_SECTION)) {
Vector<String> local_dependencies_paths = config_file->get_value(DEPENDENCIES_SECTION, DEPENDENCIES_LOCAL_KEY, Vector<String>()); Vector<String> local_dependencies_paths = config_file->get_value(PluginConfigAndroid::DEPENDENCIES_SECTION, PluginConfigAndroid::DEPENDENCIES_LOCAL_KEY, Vector<String>());
if (!local_dependencies_paths.empty()) { if (!local_dependencies_paths.empty()) {
for (int i = 0; i < local_dependencies_paths.size(); i++) { for (int i = 0; i < local_dependencies_paths.size(); i++) {
plugin_config.local_dependencies.push_back(resolve_local_dependency_path(config_base_dir, local_dependencies_paths[i])); plugin_config.local_dependencies.push_back(resolve_local_dependency_path(config_base_dir, local_dependencies_paths[i]));
} }
} }
plugin_config.remote_dependencies = config_file->get_value(DEPENDENCIES_SECTION, DEPENDENCIES_REMOTE_KEY, Vector<String>()); plugin_config.remote_dependencies = config_file->get_value(PluginConfigAndroid::DEPENDENCIES_SECTION, PluginConfigAndroid::DEPENDENCIES_REMOTE_KEY, Vector<String>());
plugin_config.custom_maven_repos = config_file->get_value(DEPENDENCIES_SECTION, DEPENDENCIES_CUSTOM_MAVEN_REPOS_KEY, Vector<String>()); plugin_config.custom_maven_repos = config_file->get_value(PluginConfigAndroid::DEPENDENCIES_SECTION, PluginConfigAndroid::DEPENDENCIES_CUSTOM_MAVEN_REPOS_KEY, Vector<String>());
} }
plugin_config.valid_config = is_plugin_config_valid(plugin_config); plugin_config.valid_config = is_plugin_config_valid(plugin_config);
@ -200,12 +218,12 @@ static inline PluginConfig load_plugin_config(Ref<ConfigFile> config_file, const
return plugin_config; return plugin_config;
} }
static inline String get_plugins_binaries(String binary_type, Vector<PluginConfig> plugins_configs) { static inline String get_plugins_binaries(String binary_type, Vector<PluginConfigAndroid> plugins_configs) {
String plugins_binaries; String plugins_binaries;
if (!plugins_configs.empty()) { if (!plugins_configs.empty()) {
Vector<String> binaries; Vector<String> binaries;
for (int i = 0; i < plugins_configs.size(); i++) { for (int i = 0; i < plugins_configs.size(); i++) {
PluginConfig config = plugins_configs[i]; PluginConfigAndroid config = plugins_configs[i];
if (!config.valid_config) { if (!config.valid_config) {
continue; continue;
} }
@ -214,27 +232,27 @@ static inline String get_plugins_binaries(String binary_type, Vector<PluginConfi
binaries.push_back(config.binary); binaries.push_back(config.binary);
} }
if (binary_type == BINARY_TYPE_LOCAL) { if (binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL) {
binaries.append_array(config.local_dependencies); binaries.append_array(config.local_dependencies);
} }
if (binary_type == BINARY_TYPE_REMOTE) { if (binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE) {
binaries.append_array(config.remote_dependencies); binaries.append_array(config.remote_dependencies);
} }
} }
plugins_binaries = String(PLUGIN_VALUE_SEPARATOR).join(binaries); plugins_binaries = String(PluginConfigAndroid::PLUGIN_VALUE_SEPARATOR).join(binaries);
} }
return plugins_binaries; return plugins_binaries;
} }
static inline String get_plugins_custom_maven_repos(Vector<PluginConfig> plugins_configs) { static inline String get_plugins_custom_maven_repos(Vector<PluginConfigAndroid> plugins_configs) {
String custom_maven_repos; String custom_maven_repos;
if (!plugins_configs.empty()) { if (!plugins_configs.empty()) {
Vector<String> repos_urls; Vector<String> repos_urls;
for (int i = 0; i < plugins_configs.size(); i++) { for (int i = 0; i < plugins_configs.size(); i++) {
PluginConfig config = plugins_configs[i]; PluginConfigAndroid config = plugins_configs[i];
if (!config.valid_config) { if (!config.valid_config) {
continue; continue;
} }
@ -242,24 +260,24 @@ static inline String get_plugins_custom_maven_repos(Vector<PluginConfig> plugins
repos_urls.append_array(config.custom_maven_repos); repos_urls.append_array(config.custom_maven_repos);
} }
custom_maven_repos = String(PLUGIN_VALUE_SEPARATOR).join(repos_urls); custom_maven_repos = String(PluginConfigAndroid::PLUGIN_VALUE_SEPARATOR).join(repos_urls);
} }
return custom_maven_repos; return custom_maven_repos;
} }
static inline String get_plugins_names(Vector<PluginConfig> plugins_configs) { static inline String get_plugins_names(Vector<PluginConfigAndroid> plugins_configs) {
String plugins_names; String plugins_names;
if (!plugins_configs.empty()) { if (!plugins_configs.empty()) {
Vector<String> names; Vector<String> names;
for (int i = 0; i < plugins_configs.size(); i++) { for (int i = 0; i < plugins_configs.size(); i++) {
PluginConfig config = plugins_configs[i]; PluginConfigAndroid config = plugins_configs[i];
if (!config.valid_config) { if (!config.valid_config) {
continue; continue;
} }
names.push_back(config.name); names.push_back(config.name);
} }
plugins_names = String(PLUGIN_VALUE_SEPARATOR).join(names); plugins_names = String(PluginConfigAndroid::PLUGIN_VALUE_SEPARATOR).join(names);
} }
return plugins_names; return plugins_names;

View file

@ -59,7 +59,7 @@ class EditorExportPlatformIOS : public EditorExportPlatform {
Thread *check_for_changes_thread; Thread *check_for_changes_thread;
volatile bool quit_request; volatile bool quit_request;
Mutex *plugins_lock; Mutex *plugins_lock;
Vector<PluginConfig> plugins; Vector<PluginConfigIOS> plugins;
typedef Error (*FileHandler)(String p_file, void *p_userdata); typedef Error (*FileHandler)(String p_file, void *p_userdata);
static Error _walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata); static Error _walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata);
@ -150,7 +150,7 @@ class EditorExportPlatformIOS : public EditorExportPlatform {
ea->plugins_lock->lock(); ea->plugins_lock->lock();
Vector<PluginConfig> loaded_plugins = get_plugins(); Vector<PluginConfigIOS> loaded_plugins = get_plugins();
if (ea->plugins.size() != loaded_plugins.size()) { if (ea->plugins.size() != loaded_plugins.size()) {
ea->plugins_changed = true; ea->plugins_changed = true;
@ -249,7 +249,7 @@ public:
continue; continue;
} }
if (file.ends_with(PLUGIN_CONFIG_EXT)) { if (file.ends_with(PluginConfigIOS::PLUGIN_CONFIG_EXT)) {
dir_files.push_back(file); dir_files.push_back(file);
} }
} }
@ -259,8 +259,8 @@ public:
return dir_files; return dir_files;
} }
static Vector<PluginConfig> get_plugins() { static Vector<PluginConfigIOS> get_plugins() {
Vector<PluginConfig> loaded_plugins; Vector<PluginConfigIOS> loaded_plugins;
String plugins_dir = ProjectSettings::get_singleton()->get_resource_path().plus_file("ios/plugins"); String plugins_dir = ProjectSettings::get_singleton()->get_resource_path().plus_file("ios/plugins");
@ -270,7 +270,7 @@ public:
if (!plugins_filenames.empty()) { if (!plugins_filenames.empty()) {
Ref<ConfigFile> config_file = memnew(ConfigFile); Ref<ConfigFile> config_file = memnew(ConfigFile);
for (int i = 0; i < plugins_filenames.size(); i++) { for (int i = 0; i < plugins_filenames.size(); i++) {
PluginConfig config = load_plugin_config(config_file, plugins_dir.plus_file(plugins_filenames[i])); PluginConfigIOS config = load_plugin_config(config_file, plugins_dir.plus_file(plugins_filenames[i]));
if (config.valid_config) { if (config.valid_config) {
loaded_plugins.push_back(config); loaded_plugins.push_back(config);
} else { } else {
@ -283,11 +283,11 @@ public:
return loaded_plugins; return loaded_plugins;
} }
static Vector<PluginConfig> get_enabled_plugins(const Ref<EditorExportPreset> &p_presets) { static Vector<PluginConfigIOS> get_enabled_plugins(const Ref<EditorExportPreset> &p_presets) {
Vector<PluginConfig> enabled_plugins; Vector<PluginConfigIOS> enabled_plugins;
Vector<PluginConfig> all_plugins = get_plugins(); Vector<PluginConfigIOS> all_plugins = get_plugins();
for (int i = 0; i < all_plugins.size(); i++) { for (int i = 0; i < all_plugins.size(); i++) {
PluginConfig plugin = all_plugins[i]; PluginConfigIOS plugin = all_plugins[i];
bool enabled = p_presets->get("plugins/" + plugin.name); bool enabled = p_presets->get("plugins/" + plugin.name);
if (enabled) { if (enabled) {
enabled_plugins.push_back(plugin); enabled_plugins.push_back(plugin);
@ -366,8 +366,7 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options)
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
Vector<PluginConfig> found_plugins = get_plugins(); Vector<PluginConfigIOS> found_plugins = get_plugins();
for (int i = 0; i < found_plugins.size(); i++) { for (int i = 0; i < found_plugins.size(); i++) {
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "plugins/" + found_plugins[i].name), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "plugins/" + found_plugins[i].name), false));
} }
@ -1219,7 +1218,7 @@ Error EditorExportPlatformIOS::_export_ios_plugins(const Ref<EditorExportPreset>
Vector<String> plugin_embedded_dependencies; Vector<String> plugin_embedded_dependencies;
Vector<String> plugin_files; Vector<String> plugin_files;
Vector<PluginConfig> enabled_plugins = get_enabled_plugins(p_preset); Vector<PluginConfigIOS> enabled_plugins = get_enabled_plugins(p_preset);
Vector<String> added_linked_dependenciy_names; Vector<String> added_linked_dependenciy_names;
Vector<String> added_embedded_dependenciy_names; Vector<String> added_embedded_dependenciy_names;
@ -1228,7 +1227,7 @@ Error EditorExportPlatformIOS::_export_ios_plugins(const Ref<EditorExportPreset>
Error err; Error err;
for (int i = 0; i < enabled_plugins.size(); i++) { for (int i = 0; i < enabled_plugins.size(); i++) {
PluginConfig plugin = enabled_plugins[i]; PluginConfigIOS plugin = enabled_plugins[i];
// Export plugin binary. // Export plugin binary.
if (!plugin.supports_targets) { if (!plugin.supports_targets) {

View file

@ -35,23 +35,6 @@
#include "core/io/config_file.h" #include "core/io/config_file.h"
#include "core/ustring.h" #include "core/ustring.h"
static const char *PLUGIN_CONFIG_EXT = ".gdip";
static const char *CONFIG_SECTION = "config";
static const char *CONFIG_NAME_KEY = "name";
static const char *CONFIG_BINARY_KEY = "binary";
static const char *CONFIG_INITIALIZE_KEY = "initialization";
static const char *CONFIG_DEINITIALIZE_KEY = "deinitialization";
static const char *DEPENDENCIES_SECTION = "dependencies";
static const char *DEPENDENCIES_LINKED_KEY = "linked";
static const char *DEPENDENCIES_EMBEDDED_KEY = "embedded";
static const char *DEPENDENCIES_SYSTEM_KEY = "system";
static const char *DEPENDENCIES_CAPABILITIES_KEY = "capabilities";
static const char *DEPENDENCIES_FILES_KEY = "files";
static const char *PLIST_SECTION = "plist";
/* /*
The `config` section and fields are required and defined as follow: The `config` section and fields are required and defined as follow:
- **name**: name of the plugin - **name**: name of the plugin
@ -68,7 +51,25 @@ The `plist` section are optional.
- **key**: key and value that would be added in Info.plist file. - **key**: key and value that would be added in Info.plist file.
*/ */
struct PluginConfig { struct PluginConfigIOS {
static const char *PLUGIN_CONFIG_EXT;
static const char *CONFIG_SECTION;
static const char *CONFIG_NAME_KEY;
static const char *CONFIG_BINARY_KEY;
static const char *CONFIG_INITIALIZE_KEY;
static const char *CONFIG_DEINITIALIZE_KEY;
static const char *DEPENDENCIES_SECTION;
static const char *DEPENDENCIES_LINKED_KEY;
static const char *DEPENDENCIES_EMBEDDED_KEY;
static const char *DEPENDENCIES_SYSTEM_KEY;
static const char *DEPENDENCIES_CAPABILITIES_KEY;
static const char *DEPENDENCIES_FILES_KEY;
static const char *PLIST_SECTION;
// Set to true when the config file is properly loaded. // Set to true when the config file is properly loaded.
bool valid_config = false; bool valid_config = false;
bool supports_targets = false; bool supports_targets = false;
@ -94,6 +95,23 @@ struct PluginConfig {
HashMap<String, String> plist; HashMap<String, String> plist;
}; };
const char *PluginConfigIOS::PLUGIN_CONFIG_EXT = ".gdip";
const char *PluginConfigIOS::CONFIG_SECTION = "config";
const char *PluginConfigIOS::CONFIG_NAME_KEY = "name";
const char *PluginConfigIOS::CONFIG_BINARY_KEY = "binary";
const char *PluginConfigIOS::CONFIG_INITIALIZE_KEY = "initialization";
const char *PluginConfigIOS::CONFIG_DEINITIALIZE_KEY = "deinitialization";
const char *PluginConfigIOS::DEPENDENCIES_SECTION = "dependencies";
const char *PluginConfigIOS::DEPENDENCIES_LINKED_KEY = "linked";
const char *PluginConfigIOS::DEPENDENCIES_EMBEDDED_KEY = "embedded";
const char *PluginConfigIOS::DEPENDENCIES_SYSTEM_KEY = "system";
const char *PluginConfigIOS::DEPENDENCIES_CAPABILITIES_KEY = "capabilities";
const char *PluginConfigIOS::DEPENDENCIES_FILES_KEY = "files";
const char *PluginConfigIOS::PLIST_SECTION = "plist";
static inline String resolve_local_dependency_path(String plugin_config_dir, String dependency_path) { static inline String resolve_local_dependency_path(String plugin_config_dir, String dependency_path) {
String absolute_path; String absolute_path;
@ -159,7 +177,7 @@ static inline Vector<String> resolve_system_dependencies(Vector<String> p_paths)
return paths; return paths;
} }
static inline bool validate_plugin(PluginConfig &plugin_config) { static inline bool validate_plugin(PluginConfigIOS &plugin_config) {
bool valid_name = !plugin_config.name.empty(); bool valid_name = !plugin_config.name.empty();
bool valid_binary_name = !plugin_config.binary.empty(); bool valid_binary_name = !plugin_config.binary.empty();
bool valid_initialize = !plugin_config.initialization_method.empty(); bool valid_initialize = !plugin_config.initialization_method.empty();
@ -185,7 +203,7 @@ static inline bool validate_plugin(PluginConfig &plugin_config) {
return plugin_config.valid_config; return plugin_config.valid_config;
} }
static inline uint64_t get_plugin_modification_time(const PluginConfig &plugin_config, const String &config_path) { static inline uint64_t get_plugin_modification_time(const PluginConfigIOS &plugin_config, const String &config_path) {
uint64_t last_updated = FileAccess::get_modified_time(config_path); uint64_t last_updated = FileAccess::get_modified_time(config_path);
if (!plugin_config.supports_targets) { if (!plugin_config.supports_targets) {
@ -203,8 +221,8 @@ static inline uint64_t get_plugin_modification_time(const PluginConfig &plugin_c
return last_updated; return last_updated;
} }
static inline PluginConfig load_plugin_config(Ref<ConfigFile> config_file, const String &path) { static inline PluginConfigIOS load_plugin_config(Ref<ConfigFile> config_file, const String &path) {
PluginConfig plugin_config = {}; PluginConfigIOS plugin_config = {};
if (!config_file.is_valid()) { if (!config_file.is_valid()) {
return plugin_config; return plugin_config;
@ -218,18 +236,18 @@ static inline PluginConfig load_plugin_config(Ref<ConfigFile> config_file, const
String config_base_dir = path.get_base_dir(); String config_base_dir = path.get_base_dir();
plugin_config.name = config_file->get_value(CONFIG_SECTION, CONFIG_NAME_KEY, String()); plugin_config.name = config_file->get_value(PluginConfigIOS::CONFIG_SECTION, PluginConfigIOS::CONFIG_NAME_KEY, String());
plugin_config.initialization_method = config_file->get_value(CONFIG_SECTION, CONFIG_INITIALIZE_KEY, String()); plugin_config.initialization_method = config_file->get_value(PluginConfigIOS::CONFIG_SECTION, PluginConfigIOS::CONFIG_INITIALIZE_KEY, String());
plugin_config.deinitialization_method = config_file->get_value(CONFIG_SECTION, CONFIG_DEINITIALIZE_KEY, String()); plugin_config.deinitialization_method = config_file->get_value(PluginConfigIOS::CONFIG_SECTION, PluginConfigIOS::CONFIG_DEINITIALIZE_KEY, String());
String binary_path = config_file->get_value(CONFIG_SECTION, CONFIG_BINARY_KEY, String()); String binary_path = config_file->get_value(PluginConfigIOS::CONFIG_SECTION, PluginConfigIOS::CONFIG_BINARY_KEY, String());
plugin_config.binary = resolve_local_dependency_path(config_base_dir, binary_path); plugin_config.binary = resolve_local_dependency_path(config_base_dir, binary_path);
if (config_file->has_section(DEPENDENCIES_SECTION)) { if (config_file->has_section(PluginConfigIOS::DEPENDENCIES_SECTION)) {
Vector<String> linked_dependencies = config_file->get_value(DEPENDENCIES_SECTION, DEPENDENCIES_LINKED_KEY, Vector<String>()); Vector<String> linked_dependencies = config_file->get_value(PluginConfigIOS::DEPENDENCIES_SECTION, PluginConfigIOS::DEPENDENCIES_LINKED_KEY, Vector<String>());
Vector<String> embedded_dependencies = config_file->get_value(DEPENDENCIES_SECTION, DEPENDENCIES_EMBEDDED_KEY, Vector<String>()); Vector<String> embedded_dependencies = config_file->get_value(PluginConfigIOS::DEPENDENCIES_SECTION, PluginConfigIOS::DEPENDENCIES_EMBEDDED_KEY, Vector<String>());
Vector<String> system_dependencies = config_file->get_value(DEPENDENCIES_SECTION, DEPENDENCIES_SYSTEM_KEY, Vector<String>()); Vector<String> system_dependencies = config_file->get_value(PluginConfigIOS::DEPENDENCIES_SECTION, PluginConfigIOS::DEPENDENCIES_SYSTEM_KEY, Vector<String>());
Vector<String> files = config_file->get_value(DEPENDENCIES_SECTION, DEPENDENCIES_FILES_KEY, Vector<String>()); Vector<String> files = config_file->get_value(PluginConfigIOS::DEPENDENCIES_SECTION, PluginConfigIOS::DEPENDENCIES_FILES_KEY, Vector<String>());
plugin_config.linked_dependencies = resolve_local_dependencies(config_base_dir, linked_dependencies); plugin_config.linked_dependencies = resolve_local_dependencies(config_base_dir, linked_dependencies);
plugin_config.embedded_dependencies = resolve_local_dependencies(config_base_dir, embedded_dependencies); plugin_config.embedded_dependencies = resolve_local_dependencies(config_base_dir, embedded_dependencies);
@ -237,15 +255,15 @@ static inline PluginConfig load_plugin_config(Ref<ConfigFile> config_file, const
plugin_config.files_to_copy = resolve_local_dependencies(config_base_dir, files); plugin_config.files_to_copy = resolve_local_dependencies(config_base_dir, files);
plugin_config.capabilities = config_file->get_value(DEPENDENCIES_SECTION, DEPENDENCIES_CAPABILITIES_KEY, Vector<String>()); plugin_config.capabilities = config_file->get_value(PluginConfigIOS::DEPENDENCIES_SECTION, PluginConfigIOS::DEPENDENCIES_CAPABILITIES_KEY, Vector<String>());
} }
if (config_file->has_section(PLIST_SECTION)) { if (config_file->has_section(PluginConfigIOS::PLIST_SECTION)) {
List<String> keys; List<String> keys;
config_file->get_section_keys(PLIST_SECTION, &keys); config_file->get_section_keys(PluginConfigIOS::PLIST_SECTION, &keys);
for (int i = 0; i < keys.size(); i++) { for (int i = 0; i < keys.size(); i++) {
String value = config_file->get_value(PLIST_SECTION, keys[i], String()); String value = config_file->get_value(PluginConfigIOS::PLIST_SECTION, keys[i], String());
if (value.empty()) { if (value.empty()) {
continue; continue;