From 76b5744ea77993853403d17d36724e034e92a9f7 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Mon, 28 Nov 2016 19:44:08 -0800 Subject: [PATCH] Make dylib filename configurable in Info.plist for iOS (flutter/engine#3277) --- engine/src/flutter/common/settings.h | 1 + engine/src/flutter/runtime/dart_init.cc | 10 +++++++++- engine/src/flutter/shell/common/shell.cc | 4 +++- engine/src/flutter/shell/common/shell.h | 3 ++- .../shell/platform/darwin/common/platform_mac.h | 5 ++++- .../shell/platform/darwin/common/platform_mac.mm | 15 +++++++++++---- .../shell/platform/darwin/desktop/main_mac.mm | 2 +- .../ios/framework/Source/FlutterViewController.mm | 5 ++++- 8 files changed, 35 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/common/settings.h b/engine/src/flutter/common/settings.h index 5f6805f1ee9..90d0dd66eff 100644 --- a/engine/src/flutter/common/settings.h +++ b/engine/src/flutter/common/settings.h @@ -26,6 +26,7 @@ struct Settings { std::string aot_vm_isolate_snapshot_file_name; std::string aot_instructions_blob_file_name; std::string aot_rodata_blob_file_name; + std::string application_library_path; std::string temp_directory_path; std::vector dart_flags; diff --git a/engine/src/flutter/runtime/dart_init.cc b/engine/src/flutter/runtime/dart_init.cc index 3d68a60794f..ca7c4070c5b 100644 --- a/engine/src/flutter/runtime/dart_init.cc +++ b/engine/src/flutter/runtime/dart_init.cc @@ -399,12 +399,20 @@ void* _DartSymbolLookup(const char* symbol_name) { return nullptr; } + const char* application_library_path = kDartApplicationLibraryPath; + const Settings& settings = Settings::Get(); + const std::string& application_library_path_setting = + settings.application_library_path; + if (!application_library_path_setting.empty()) { + application_library_path = application_library_path_setting.c_str(); + } + // First the application library is checked for the valid symbols. This // library may not necessarily exist. If it does exist, it is loaded and the // symbols resolved. Once the application library is loaded, there is // currently no provision to unload the same. void* symbol = - DartLookupSymbolInLibrary(symbol_name, kDartApplicationLibraryPath); + DartLookupSymbolInLibrary(symbol_name, application_library_path); if (symbol != nullptr) { return symbol; } diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index 742cc9a2b8f..b9474c6e91b 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -107,7 +107,8 @@ Shell::Shell() { Shell::~Shell() {} -void Shell::InitStandalone(std::string icu_data_path) { +void Shell::InitStandalone(std::string icu_data_path, + std::string application_library_path) { TRACE_EVENT0("flutter", "Shell::InitStandalone"); ftl::UniqueFD icu_fd( @@ -126,6 +127,7 @@ void Shell::InitStandalone(std::string icu_data_path) { base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); blink::Settings settings; + settings.application_library_path = application_library_path; // Enable Observatory settings.enable_observatory = diff --git a/engine/src/flutter/shell/common/shell.h b/engine/src/flutter/shell/common/shell.h index 32e1b623f80..e03b66a87aa 100644 --- a/engine/src/flutter/shell/common/shell.h +++ b/engine/src/flutter/shell/common/shell.h @@ -22,7 +22,8 @@ class Shell { public: ~Shell(); - static void InitStandalone(std::string icu_data_path = ""); + static void InitStandalone(std::string icu_data_path = "", + std::string application_library_path = ""); static void Init(); static Shell& Shared(); diff --git a/engine/src/flutter/shell/platform/darwin/common/platform_mac.h b/engine/src/flutter/shell/platform/darwin/common/platform_mac.h index 396f975f593..fe81a23c6aa 100644 --- a/engine/src/flutter/shell/platform/darwin/common/platform_mac.h +++ b/engine/src/flutter/shell/platform/darwin/common/platform_mac.h @@ -9,7 +9,10 @@ namespace shell { -void PlatformMacMain(int argc, const char* argv[], std::string icu_data_path); +void PlatformMacMain(int argc, + const char* argv[], + std::string icu_data_path, + std::string application_library_path); bool AttemptLaunchFromCommandLineSwitches(Engine* engine); diff --git a/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm b/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm index c8ed203e82d..072c8477d12 100644 --- a/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm +++ b/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm @@ -52,7 +52,10 @@ static void RedirectIOConnectionsToSyslog() { class EmbedderState { public: - EmbedderState(int argc, const char* argv[], std::string icu_data_path) { + EmbedderState(int argc, + const char* argv[], + std::string icu_data_path, + std::string application_library_path) { #if TARGET_OS_IPHONE // This calls crashes on MacOS because we haven't run Dart_Initialize yet. // See https://github.com/flutter/flutter/issues/4006 @@ -90,7 +93,7 @@ class EmbedderState { embedder_message_loop_->Attach(); #endif - shell::Shell::InitStandalone(icu_data_path); + shell::Shell::InitStandalone(icu_data_path, application_library_path); } ~EmbedderState() { @@ -106,12 +109,16 @@ class EmbedderState { FTL_DISALLOW_COPY_AND_ASSIGN(EmbedderState); }; -void PlatformMacMain(int argc, const char* argv[], std::string icu_data_path) { +void PlatformMacMain(int argc, + const char* argv[], + std::string icu_data_path, + std::string application_library_path) { static std::unique_ptr g_embedder; static std::once_flag once_main; std::call_once(once_main, [&]() { - g_embedder = WTF::MakeUnique(argc, argv, icu_data_path); + g_embedder = WTF::MakeUnique(argc, argv, icu_data_path, + application_library_path); }); } diff --git a/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm b/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm index b5db8cc4c87..cd49eb229f1 100644 --- a/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm +++ b/engine/src/flutter/shell/platform/darwin/desktop/main_mac.mm @@ -32,7 +32,7 @@ void AttachMessageLoopToMainRunLoop(void) { int main(int argc, const char* argv[]) { [SkyApplication sharedApplication]; - shell::PlatformMacMain(argc, argv, ""); + shell::PlatformMacMain(argc, argv, "", ""); base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); if (command_line.HasSwitch(shell::FlagForSwitch(shell::Switch::Help))) { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index f609ada2278..5b2b8b5d004 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -58,7 +58,10 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { void FlutterInit(int argc, const char* argv[]) { NSBundle* bundle = [NSBundle bundleForClass:[FlutterViewController class]]; NSString* icuDataPath = [bundle pathForResource:@"icudtl" ofType:@"dat"]; - shell::PlatformMacMain(argc, argv, icuDataPath.UTF8String); + NSString* libraryName = + [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTLibraryPath"]; + shell::PlatformMacMain(argc, argv, icuDataPath.UTF8String, + libraryName != nil ? libraryName.UTF8String : ""); } @implementation FlutterViewController {