mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[linux] Eliminate mirrors support (flutter/engine#39701)
Support for using dart:mirrors has been deprecated for nearly two years. this removes support for enabling mirrors from the embedder as documented in the deprecation comment. This was primarily added as a workaround for an internal tooling usecase, which no longer exists. Issue: https://github.com/flutter/flutter/issues/120924
This commit is contained in:
parent
d2f0f8f790
commit
2b185ea8d8
@ -6,16 +6,9 @@
|
||||
|
||||
#include <gmodule.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<std::string> 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;
|
||||
}
|
||||
|
||||
@ -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_
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#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<const char*>(g_ptr_array_index(switches, 0)),
|
||||
"--abc");
|
||||
EXPECT_STREQ(static_cast<const char*>(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
|
||||
|
||||
@ -7,7 +7,10 @@
|
||||
#include <gmodule.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<FlutterAccessibilityFeature>(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;
|
||||
}
|
||||
|
||||
@ -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_
|
||||
|
||||
@ -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<const char*>(g_ptr_array_index(switches, 0)),
|
||||
"--abc");
|
||||
EXPECT_STREQ(static_cast<const char*>(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)
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user