diff --git a/shell/platform/linux/fl_dart_project.cc b/shell/platform/linux/fl_dart_project.cc index fb749d3d8c03b..a5d7f71c58065 100644 --- a/shell/platform/linux/fl_dart_project.cc +++ b/shell/platform/linux/fl_dart_project.cc @@ -6,16 +6,9 @@ #include -#include -#include - -#include "flutter/shell/platform/common/engine_switches.h" -#include "flutter/shell/platform/linux/fl_dart_project_private.h" - struct _FlDartProject { GObject parent_instance; - gboolean enable_mirrors; gchar* aot_library_path; gchar* assets_path; gchar* icu_data_path; @@ -69,19 +62,6 @@ G_MODULE_EXPORT FlDartProject* fl_dart_project_new() { return self; } -G_MODULE_EXPORT void fl_dart_project_set_enable_mirrors( - FlDartProject* self, - gboolean enable_mirrors) { - g_return_if_fail(FL_IS_DART_PROJECT(self)); - self->enable_mirrors = enable_mirrors; -} - -G_MODULE_EXPORT gboolean -fl_dart_project_get_enable_mirrors(FlDartProject* self) { - g_return_val_if_fail(FL_IS_DART_PROJECT(self), FALSE); - return self->enable_mirrors; -} - G_MODULE_EXPORT const gchar* fl_dart_project_get_aot_library_path( FlDartProject* self) { g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr); @@ -127,15 +107,3 @@ G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments( g_clear_pointer(&self->dart_entrypoint_args, g_strfreev); self->dart_entrypoint_args = g_strdupv(argv); } - -GPtrArray* fl_dart_project_get_switches(FlDartProject* self) { - GPtrArray* switches = g_ptr_array_new_with_free_func(g_free); - std::vector env_switches = flutter::GetSwitchesFromEnvironment(); - for (const auto& env_switch : env_switches) { - g_ptr_array_add(switches, g_strdup(env_switch.c_str())); - } - if (self->enable_mirrors) { - g_ptr_array_add(switches, g_strdup("--dart-flags=--enable_mirrors=true")); - } - return switches; -} diff --git a/shell/platform/linux/fl_dart_project_private.h b/shell/platform/linux/fl_dart_project_private.h index 89422e7264669..be03e58791b42 100644 --- a/shell/platform/linux/fl_dart_project_private.h +++ b/shell/platform/linux/fl_dart_project_private.h @@ -11,16 +11,6 @@ G_BEGIN_DECLS -/** - * fl_dart_project_get_switches: - * @project: an #FlDartProject. - * - * Determines the engine switches that should be passed to the Flutter engine. - * - * Returns: an array of switches to pass to the Flutter engine. - */ -GPtrArray* fl_dart_project_get_switches(FlDartProject* project); - G_END_DECLS #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_DART_PROJECT_PRIVATE_H_ diff --git a/shell/platform/linux/fl_dart_project_test.cc b/shell/platform/linux/fl_dart_project_test.cc index 03a16f560cbfc..75c2ce4fc1f2e 100644 --- a/shell/platform/linux/fl_dart_project_test.cc +++ b/shell/platform/linux/fl_dart_project_test.cc @@ -8,7 +8,6 @@ #include -#include "flutter/shell/platform/linux/fl_dart_project_private.h" #include "gtest/gtest.h" TEST(FlDartProjectTest, GetPaths) { @@ -29,15 +28,6 @@ TEST(FlDartProjectTest, GetPaths) { expected_icu_data_path); } -TEST(FlDartProjectTest, EnableMirrors) { - g_autoptr(FlDartProject) project = fl_dart_project_new(); - G_GNUC_BEGIN_IGNORE_DEPRECATIONS - EXPECT_FALSE(fl_dart_project_get_enable_mirrors(project)); - fl_dart_project_set_enable_mirrors(project, TRUE); - EXPECT_TRUE(fl_dart_project_get_enable_mirrors(project)); - G_GNUC_END_IGNORE_DEPRECATIONS -} - TEST(FlDartProjectTest, OverrideAssetsPath) { g_autoptr(FlDartProject) project = fl_dart_project_new(); @@ -78,35 +68,3 @@ TEST(FlDartProjectTest, DartEntrypointArgs) { EXPECT_EQ(g_strv_length(retrieved_args), 3U); } - -TEST(FlDartProjectTest, SwitchesEmpty) { - g_autoptr(FlDartProject) project = fl_dart_project_new(); - - // Clear the main environment variable, since test order is not guaranteed. - unsetenv("FLUTTER_ENGINE_SWITCHES"); - - g_autoptr(GPtrArray) switches = fl_dart_project_get_switches(project); - - EXPECT_EQ(switches->len, 0U); -} - -#ifndef FLUTTER_RELEASE -TEST(FlDartProjectTest, Switches) { - g_autoptr(FlDartProject) project = fl_dart_project_new(); - - setenv("FLUTTER_ENGINE_SWITCHES", "2", 1); - setenv("FLUTTER_ENGINE_SWITCH_1", "abc", 1); - setenv("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"", 1); - - g_autoptr(GPtrArray) switches = fl_dart_project_get_switches(project); - EXPECT_EQ(switches->len, 2U); - EXPECT_STREQ(static_cast(g_ptr_array_index(switches, 0)), - "--abc"); - EXPECT_STREQ(static_cast(g_ptr_array_index(switches, 1)), - "--foo=\"bar, baz\""); - - unsetenv("FLUTTER_ENGINE_SWITCHES"); - unsetenv("FLUTTER_ENGINE_SWITCH_1"); - unsetenv("FLUTTER_ENGINE_SWITCH_2"); -} -#endif // !FLUTTER_RELEASE diff --git a/shell/platform/linux/fl_engine.cc b/shell/platform/linux/fl_engine.cc index a15e81672881f..0ae331b328375 100644 --- a/shell/platform/linux/fl_engine.cc +++ b/shell/platform/linux/fl_engine.cc @@ -7,7 +7,10 @@ #include #include +#include +#include +#include "flutter/shell/platform/common/engine_switches.h" #include "flutter/shell/platform/embedder/embedder.h" #include "flutter/shell/platform/linux/fl_binary_messenger_private.h" #include "flutter/shell/platform/linux/fl_dart_project_private.h" @@ -483,8 +486,7 @@ gboolean fl_engine_start(FlEngine* self, GError** error) { custom_task_runners.platform_task_runner = &platform_task_runner; custom_task_runners.render_task_runner = &platform_task_runner; - g_autoptr(GPtrArray) command_line_args = - fl_dart_project_get_switches(self->project); + g_autoptr(GPtrArray) command_line_args = fl_engine_get_switches(self); // FlutterProjectArgs expects a full argv, so when processing it for flags // the first item is treated as the executable and ignored. Add a dummy value // so that all switches are used. @@ -885,3 +887,11 @@ void fl_engine_update_accessibility_features(FlEngine* self, int32_t flags) { self->embedder_api.UpdateAccessibilityFeatures( self->engine, static_cast(flags)); } + +GPtrArray* fl_engine_get_switches(FlEngine* self) { + GPtrArray* switches = g_ptr_array_new_with_free_func(g_free); + for (const auto& env_switch : flutter::GetSwitchesFromEnvironment()) { + g_ptr_array_add(switches, g_strdup(env_switch.c_str())); + } + return switches; +} diff --git a/shell/platform/linux/fl_engine_private.h b/shell/platform/linux/fl_engine_private.h index fad99c598137d..0d9d3213a1518 100644 --- a/shell/platform/linux/fl_engine_private.h +++ b/shell/platform/linux/fl_engine_private.h @@ -336,6 +336,16 @@ gboolean fl_engine_unregister_external_texture(FlEngine* engine, */ void fl_engine_update_accessibility_features(FlEngine* engine, int32_t flags); +/** + * fl_engine_get_switches: + * @project: an #FlEngine. + * + * Determines the switches that should be passed to the Flutter engine. + * + * Returns: an array of switches to pass to the Flutter engine. + */ +GPtrArray* fl_engine_get_switches(FlEngine* engine); + G_END_DECLS #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_ENGINE_PRIVATE_H_ diff --git a/shell/platform/linux/fl_engine_test.cc b/shell/platform/linux/fl_engine_test.cc index 727f76d61a902..a1d6e1d650eaf 100644 --- a/shell/platform/linux/fl_engine_test.cc +++ b/shell/platform/linux/fl_engine_test.cc @@ -412,4 +412,36 @@ TEST(FlEngineTest, Locales) { g_free(initial_language); } +TEST(FlEngineTest, SwitchesEmpty) { + g_autoptr(FlEngine) engine = make_mock_engine(); + + // Clear the main environment variable, since test order is not guaranteed. + unsetenv("FLUTTER_ENGINE_SWITCHES"); + + g_autoptr(GPtrArray) switches = fl_engine_get_switches(engine); + + EXPECT_EQ(switches->len, 0U); +} + +#ifndef FLUTTER_RELEASE +TEST(FlEngineTest, Switches) { + g_autoptr(FlEngine) engine = make_mock_engine(); + + setenv("FLUTTER_ENGINE_SWITCHES", "2", 1); + setenv("FLUTTER_ENGINE_SWITCH_1", "abc", 1); + setenv("FLUTTER_ENGINE_SWITCH_2", "foo=\"bar, baz\"", 1); + + g_autoptr(GPtrArray) switches = fl_engine_get_switches(engine); + EXPECT_EQ(switches->len, 2U); + EXPECT_STREQ(static_cast(g_ptr_array_index(switches, 0)), + "--abc"); + EXPECT_STREQ(static_cast(g_ptr_array_index(switches, 1)), + "--foo=\"bar, baz\""); + + unsetenv("FLUTTER_ENGINE_SWITCHES"); + unsetenv("FLUTTER_ENGINE_SWITCH_1"); + unsetenv("FLUTTER_ENGINE_SWITCH_2"); +} +#endif // !FLUTTER_RELEASE + // NOLINTEND(clang-analyzer-core.StackAddressEscape) diff --git a/shell/platform/linux/public/flutter_linux/fl_dart_project.h b/shell/platform/linux/public/flutter_linux/fl_dart_project.h index d54b8b790e83c..93bd9a4c18d99 100644 --- a/shell/platform/linux/public/flutter_linux/fl_dart_project.h +++ b/shell/platform/linux/public/flutter_linux/fl_dart_project.h @@ -35,33 +35,6 @@ G_DECLARE_FINAL_TYPE(FlDartProject, fl_dart_project, FL, DART_PROJECT, GObject) */ FlDartProject* fl_dart_project_new(); -/** - * fl_dart_project_set_enable_mirrors: - * @project: an #FlDartProject. - * @enable_mirrors: %TRUE if the dart:mirrors library should be used. - * - * Sets if this Flutter project can use the dart:mirrors library. - * - * Deprecated: This function is temporary and will be removed in a future - * release. - */ -void fl_dart_project_set_enable_mirrors(FlDartProject* project, - gboolean enable_mirrors) G_DEPRECATED; - -/** - * fl_dart_project_get_enable_mirrors: - * @project: an #FlDartProject. - * - * Gets if this Flutter project can use the dart:mirrors library. - * - * Returns: %TRUE if the dart:mirrors library can be used. - * - * Deprecated: This function is temporary and will be removed in a future - * release. - */ -gboolean fl_dart_project_get_enable_mirrors(FlDartProject* project) - G_DEPRECATED; - /** * fl_dart_project_get_aot_library_path: * @project: an #FlDartProject.