Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions shell/platform/linux/fl_dart_project.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
10 changes: 0 additions & 10 deletions shell/platform/linux/fl_dart_project_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
42 changes: 0 additions & 42 deletions shell/platform/linux/fl_dart_project_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <cstdlib>

#include "flutter/shell/platform/linux/fl_dart_project_private.h"
#include "gtest/gtest.h"

TEST(FlDartProjectTest, GetPaths) {
Expand All @@ -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();

Expand Down Expand Up @@ -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
14 changes: 12 additions & 2 deletions shell/platform/linux/fl_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
10 changes: 10 additions & 0 deletions shell/platform/linux/fl_engine_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
32 changes: 32 additions & 0 deletions shell/platform/linux/fl_engine_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
27 changes: 0 additions & 27 deletions shell/platform/linux/public/flutter_linux/fl_dart_project.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down