Flutter Engine
fl_dart_project.cc File Reference
#include "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"
#include <gmodule.h>
#include <string>
#include <vector>
#include "flutter/shell/platform/common/cpp/engine_switches.h"
#include "flutter/shell/platform/linux/fl_dart_project_private.h"

Go to the source code of this file.

Classes

struct  _FlDartProject
 

Functions

static gchar * get_executable_dir ()
 
static void fl_dart_project_dispose (GObject *object)
 
static void fl_dart_project_class_init (FlDartProjectClass *klass)
 
static void fl_dart_project_init (FlDartProject *self)
 
G_MODULE_EXPORT FlDartProject * fl_dart_project_new ()
 
G_MODULE_EXPORT void fl_dart_project_set_enable_mirrors (FlDartProject *self, gboolean enable_mirrors)
 
G_MODULE_EXPORT gboolean fl_dart_project_get_enable_mirrors (FlDartProject *self)
 
G_MODULE_EXPORT const gchar * fl_dart_project_get_aot_library_path (FlDartProject *self)
 
G_MODULE_EXPORT const gchar * fl_dart_project_get_assets_path (FlDartProject *self)
 
G_MODULE_EXPORT const gchar * fl_dart_project_get_icu_data_path (FlDartProject *self)
 
GPtrArray * fl_dart_project_get_switches (FlDartProject *self)
 

Function Documentation

◆ fl_dart_project_class_init()

static void fl_dart_project_class_init ( FlDartProjectClass *  klass)
static

Definition at line 49 of file fl_dart_project.cc.

References fl_dart_project_dispose().

49  {
50  G_OBJECT_CLASS(klass)->dispose = fl_dart_project_dispose;
51 }
static void fl_dart_project_dispose(GObject *object)

◆ fl_dart_project_dispose()

static void fl_dart_project_dispose ( GObject *  object)
static

Definition at line 39 of file fl_dart_project.cc.

Referenced by fl_dart_project_class_init().

39  {
40  FlDartProject* self = FL_DART_PROJECT(object);
41 
42  g_clear_pointer(&self->aot_library_path, g_free);
43  g_clear_pointer(&self->assets_path, g_free);
44  g_clear_pointer(&self->icu_data_path, g_free);
45 
46  G_OBJECT_CLASS(fl_dart_project_parent_class)->dispose(object);
47 }

◆ fl_dart_project_get_aot_library_path()

G_MODULE_EXPORT const gchar* fl_dart_project_get_aot_library_path ( FlDartProject *  project)

fl_dart_project_get_aot_library_path: : an #FlDartProject.

Gets the path to the AOT library in the Flutter application.

Returns: (type filename): an absolute file path, e.g. "/projects/my_dart_project/lib/libapp.so".

Definition at line 83 of file fl_dart_project.cc.

Referenced by fl_engine_start(), and TEST().

84  {
85  g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
86  return self->aot_library_path;
87 }

◆ fl_dart_project_get_assets_path()

G_MODULE_EXPORT const gchar* fl_dart_project_get_assets_path ( FlDartProject *  project)

fl_dart_project_get_assets_path: : an #FlDartProject.

Gets the path to the directory containing the assets used in the Flutter application.

Returns: (type filename): an absolute directory path, e.g. "/projects/my_dart_project/data/flutter_assets".

Definition at line 89 of file fl_dart_project.cc.

Referenced by fl_engine_start(), and TEST().

90  {
91  g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
92  return self->assets_path;
93 }

◆ fl_dart_project_get_enable_mirrors()

G_MODULE_EXPORT gboolean fl_dart_project_get_enable_mirrors ( FlDartProject *  project)

fl_dart_project_get_enable_mirrors: : 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.

Definition at line 78 of file fl_dart_project.cc.

Referenced by TEST().

78  {
79  g_return_val_if_fail(FL_IS_DART_PROJECT(self), FALSE);
80  return self->enable_mirrors;
81 }

◆ fl_dart_project_get_icu_data_path()

G_MODULE_EXPORT const gchar* fl_dart_project_get_icu_data_path ( FlDartProject *  project)

fl_dart_project_get_icu_data_path: : an #FlDartProject.

Gets the path to the ICU data file in the Flutter application.

Returns: (type filename): an absolute file path, e.g. "/projects/my_dart_project/data/icudtl.dat".

Definition at line 95 of file fl_dart_project.cc.

Referenced by fl_engine_start(), and TEST().

96  {
97  g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
98  return self->icu_data_path;
99 }

◆ fl_dart_project_get_switches()

GPtrArray* fl_dart_project_get_switches ( FlDartProject *  project)

fl_dart_project_get_switches: : 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.

Definition at line 101 of file fl_dart_project.cc.

References flutter::GetSwitchesFromEnvironment().

Referenced by fl_engine_start(), and TEST().

101  {
102  GPtrArray* switches = g_ptr_array_new_with_free_func(g_free);
103  std::vector<std::string> env_switches = flutter::GetSwitchesFromEnvironment();
104  for (const auto& env_switch : env_switches) {
105  g_ptr_array_add(switches, g_strdup(env_switch.c_str()));
106  }
107  if (self->enable_mirrors) {
108  g_ptr_array_add(switches, g_strdup("--dart-flags=--enable_mirrors=true"));
109  }
110  return switches;
111 }
std::vector< std::string > GetSwitchesFromEnvironment()

◆ fl_dart_project_init()

static void fl_dart_project_init ( FlDartProject *  self)
static

Definition at line 53 of file fl_dart_project.cc.

53 {}

◆ fl_dart_project_new()

G_MODULE_EXPORT FlDartProject* fl_dart_project_new ( )

FlDartProject:

#FlDartProject represents a Dart project. It is used to provide information about the application when creating an #FlView. fl_dart_project_new:

Creates a Flutter project for the currently running executable. The following data files are required relative to the location of the executable:

  • data/flutter_assets/ (as built by the Flutter tool).
  • data/icudtl.dat (provided as a resource by the Flutter tool).
  • lib/libapp.so (as built by the Flutter tool when in AOT mode).

Returns: a new #FlDartProject.

Definition at line 55 of file fl_dart_project.cc.

References get_executable_dir().

Referenced by make_mock_engine(), and TEST().

55  {
56  FlDartProject* self =
57  FL_DART_PROJECT(g_object_new(fl_dart_project_get_type(), nullptr));
58 
59  g_autofree gchar* executable_dir = get_executable_dir();
60  self->aot_library_path =
61  g_build_filename(executable_dir, "lib", "libapp.so", nullptr);
62  self->assets_path =
63  g_build_filename(executable_dir, "data", "flutter_assets", nullptr);
64  self->icu_data_path =
65  g_build_filename(executable_dir, "data", "icudtl.dat", nullptr);
66 
67  return self;
68 }
static gchar * get_executable_dir()

◆ fl_dart_project_set_enable_mirrors()

G_MODULE_EXPORT void fl_dart_project_set_enable_mirrors ( FlDartProject *  project,
gboolean  enable_mirrors 
)

fl_dart_project_set_enable_mirrors: : an #FlDartProject. : 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.

Definition at line 70 of file fl_dart_project.cc.

References _FlDartProject::enable_mirrors.

Referenced by TEST().

72  {
73  g_return_if_fail(FL_IS_DART_PROJECT(self));
74  self->enable_mirrors = enable_mirrors;
75 }

◆ get_executable_dir()

static gchar* get_executable_dir ( )
static

Definition at line 27 of file fl_dart_project.cc.

References error.

Referenced by fl_dart_project_new().

27  {
28  g_autoptr(GError) error = nullptr;
29  g_autofree gchar* exe_path = g_file_read_link("/proc/self/exe", &error);
30  if (exe_path == nullptr) {
31  g_critical("Failed to determine location of executable: %s",
32  error->message);
33  return nullptr;
34  }
35 
36  return g_path_get_dirname(exe_path);
37 }
FlMethodResponse GError ** error