From 1661309d5965e2c9910efa1ff88b2322aca832ed Mon Sep 17 00:00:00 2001 From: Sergey Minakov Date: Wed, 5 Aug 2020 20:55:29 +0300 Subject: [PATCH] iOS Export: Add a method to embed a framework By default 'add_ios_framework' would not embed a framework to save previous behavior. New 'add_ios_embedded_framework' would embed framework on export. --- doc/classes/EditorExportPlugin.xml | 12 ++++++++ editor/editor_export.cpp | 9 ++++++ editor/editor_export.h | 4 +++ platform/iphone/export/export.cpp | 48 +++++++++++++++--------------- 4 files changed, 49 insertions(+), 24 deletions(-) diff --git a/doc/classes/EditorExportPlugin.xml b/doc/classes/EditorExportPlugin.xml index 8cfd3b63d62..6bcaabc39eb 100644 --- a/doc/classes/EditorExportPlugin.xml +++ b/doc/classes/EditorExportPlugin.xml @@ -76,6 +76,18 @@ + Adds a static library (*.a) or dynamic library (*.dylib, *.framework) to Linking Phase in iOS's Xcode project. + + + + + + + + + Adds a dynamic library (*.dylib, *.framework) to Linking Phase in iOS's Xcode project and embeds it into resulting binary. + [b]Note:[/b] For static libraries (*.a) works in same way as [code]add_ios_framework[/code]. + This method should not be used for System libraries as they are already present on the device. diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 951bec2c831..16e69734d30 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -512,10 +512,18 @@ void EditorExportPlugin::add_ios_framework(const String &p_path) { ios_frameworks.push_back(p_path); } +void EditorExportPlugin::add_ios_embedded_framework(const String &p_path) { + ios_embedded_frameworks.push_back(p_path); +} + Vector EditorExportPlugin::get_ios_frameworks() const { return ios_frameworks; } +Vector EditorExportPlugin::get_ios_embedded_frameworks() const { + return ios_embedded_frameworks; +} + void EditorExportPlugin::add_ios_plist_content(const String &p_plist_content) { ios_plist_content += p_plist_content + "\n"; } @@ -592,6 +600,7 @@ void EditorExportPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_ios_project_static_lib", "path"), &EditorExportPlugin::add_ios_project_static_lib); ClassDB::bind_method(D_METHOD("add_file", "path", "file", "remap"), &EditorExportPlugin::add_file); ClassDB::bind_method(D_METHOD("add_ios_framework", "path"), &EditorExportPlugin::add_ios_framework); + ClassDB::bind_method(D_METHOD("add_ios_embedded_framework", "path"), &EditorExportPlugin::add_ios_embedded_framework); ClassDB::bind_method(D_METHOD("add_ios_plist_content", "plist_content"), &EditorExportPlugin::add_ios_plist_content); ClassDB::bind_method(D_METHOD("add_ios_linker_flags", "flags"), &EditorExportPlugin::add_ios_linker_flags); ClassDB::bind_method(D_METHOD("add_ios_bundle_file", "path"), &EditorExportPlugin::add_ios_bundle_file); diff --git a/editor/editor_export.h b/editor/editor_export.h index e31b53ad67b..bb701b94ec5 100644 --- a/editor/editor_export.h +++ b/editor/editor_export.h @@ -290,6 +290,7 @@ class EditorExportPlugin : public Reference { bool skipped; Vector ios_frameworks; + Vector ios_embedded_frameworks; Vector ios_project_static_libs; String ios_plist_content; String ios_linker_flags; @@ -304,6 +305,7 @@ class EditorExportPlugin : public Reference { _FORCE_INLINE_ void _export_end() { ios_frameworks.clear(); + ios_embedded_frameworks.clear(); ios_bundle_files.clear(); ios_plist_content = ""; ios_linker_flags = ""; @@ -322,6 +324,7 @@ protected: void add_shared_object(const String &p_path, const Vector &tags); void add_ios_framework(const String &p_path); + void add_ios_embedded_framework(const String &p_path); void add_ios_project_static_lib(const String &p_path); void add_ios_plist_content(const String &p_plist_content); void add_ios_linker_flags(const String &p_flags); @@ -337,6 +340,7 @@ protected: public: Vector get_ios_frameworks() const; + Vector get_ios_embedded_frameworks() const; Vector get_ios_project_static_libs() const; String get_ios_plist_content() const; String get_ios_linker_flags() const; diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp index 4a751488cb7..a889717f208 100644 --- a/platform/iphone/export/export.cpp +++ b/platform/iphone/export/export.cpp @@ -86,6 +86,7 @@ class EditorExportPlatformIOS : public EditorExportPlatform { struct IOSExportAsset { String exported_path; bool is_framework; // framework is anything linked to the binary, otherwise it's a resource + bool should_embed; }; String _get_additional_plist_content(); @@ -100,7 +101,7 @@ class EditorExportPlatformIOS : public EditorExportPlatform { Vector _get_preset_architectures(const Ref &p_preset); void _add_assets_to_project(const Ref &p_preset, Vector &p_project_data, const Vector &p_additional_assets); - Error _export_additional_assets(const String &p_out_dir, const Vector &p_assets, bool p_is_framework, Vector &r_exported_assets); + Error _export_additional_assets(const String &p_out_dir, const Vector &p_assets, bool p_is_framework, bool p_should_embed, Vector &r_exported_assets); Error _export_additional_assets(const String &p_out_dir, const Vector &p_libraries, Vector &r_exported_assets); bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const { @@ -912,15 +913,6 @@ struct ExportLibsData { }; void EditorExportPlatformIOS::_add_assets_to_project(const Ref &p_preset, Vector &p_project_data, const Vector &p_additional_assets) { - Vector> export_plugins = EditorExport::get_singleton()->get_export_plugins(); - Vector frameworks; - for (int i = 0; i < export_plugins.size(); ++i) { - Vector plugin_frameworks = export_plugins[i]->get_ios_frameworks(); - for (int j = 0; j < plugin_frameworks.size(); ++j) { - frameworks.push_back(plugin_frameworks[j]); - } - } - // that is just a random number, we just need Godot IDs not to clash with // existing IDs in the project. PbxId current_id = { 0x58938401, 0, 0 }; @@ -945,15 +937,19 @@ void EditorExportPlatformIOS::_add_assets_to_project(const Ref &p_assets, bool p_is_framework, Vector &r_exported_assets) { +Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector &p_assets, bool p_is_framework, bool p_should_embed, Vector &r_exported_assets) { DirAccess *filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); String binary_name = p_out_dir.get_file().get_basename(); @@ -1035,7 +1031,7 @@ Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir String asset = p_assets[f_idx]; if (!asset.begins_with("res://")) { // either SDK-builtin or already a part of the export template - IOSExportAsset exported_asset = { asset, p_is_framework }; + IOSExportAsset exported_asset = { asset, p_is_framework, p_should_embed }; r_exported_assets.push_back(exported_asset); } else { DirAccess *da = DirAccess::create_for_path(asset); @@ -1101,7 +1097,7 @@ Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir memdelete(filesystem_da); return err; } - IOSExportAsset exported_asset = { binary_name.plus_file(asset_path), p_is_framework }; + IOSExportAsset exported_asset = { binary_name.plus_file(asset_path), p_is_framework, p_should_embed }; r_exported_assets.push_back(exported_asset); if (create_framework) { @@ -1165,19 +1161,23 @@ Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector &p_libraries, Vector &r_exported_assets) { Vector> export_plugins = EditorExport::get_singleton()->get_export_plugins(); for (int i = 0; i < export_plugins.size(); i++) { - Vector frameworks = export_plugins[i]->get_ios_frameworks(); - Error err = _export_additional_assets(p_out_dir, frameworks, true, r_exported_assets); + Vector linked_frameworks = export_plugins[i]->get_ios_frameworks(); + Error err = _export_additional_assets(p_out_dir, linked_frameworks, true, false, r_exported_assets); + ERR_FAIL_COND_V(err, err); + + Vector embedded_frameworks = export_plugins[i]->get_ios_embedded_frameworks(); + err = _export_additional_assets(p_out_dir, embedded_frameworks, true, true, r_exported_assets); ERR_FAIL_COND_V(err, err); Vector project_static_libs = export_plugins[i]->get_ios_project_static_libs(); for (int j = 0; j < project_static_libs.size(); j++) { project_static_libs.write[j] = project_static_libs[j].get_file(); // Only the file name as it's copied to the project } - err = _export_additional_assets(p_out_dir, project_static_libs, true, r_exported_assets); + err = _export_additional_assets(p_out_dir, project_static_libs, true, true, r_exported_assets); ERR_FAIL_COND_V(err, err); Vector ios_bundle_files = export_plugins[i]->get_ios_bundle_files(); - err = _export_additional_assets(p_out_dir, ios_bundle_files, false, r_exported_assets); + err = _export_additional_assets(p_out_dir, ios_bundle_files, false, false, r_exported_assets); ERR_FAIL_COND_V(err, err); } @@ -1185,7 +1185,7 @@ Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir for (int i = 0; i < p_libraries.size(); ++i) { library_paths.push_back(p_libraries[i].path); } - Error err = _export_additional_assets(p_out_dir, library_paths, true, r_exported_assets); + Error err = _export_additional_assets(p_out_dir, library_paths, true, true, r_exported_assets); ERR_FAIL_COND_V(err, err); return OK;